Skip to content

Commit

Permalink
Improved callable name matching from Lizard to metadata DB (again).
Browse files Browse the repository at this point in the history
  • Loading branch information
MagielBruntink committed Jun 16, 2022
1 parent cca7adc commit afa4bb1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,28 +79,29 @@ public void processJsonRecord(JSONObject jsonRecord) throws IllegalStateExceptio
}

public static String normalizeCallableName(String callableName) {
StringBuilder result = new StringBuilder();
if(callableName == null) {
if(callableName == null || callableName.equals("")) {
return "";
}
var components = callableName.split(LIZARD_CALLABLE_SEPARATOR);

if(components.length == 1) {
result = new StringBuilder(components[0]);
}
else if(components.length > 1) {
if(components[components.length - 2].equals(components[components.length - 1])) {
components[components.length - 1] = JAVA_CONSTRUCTOR_NAME;
else {
StringBuilder result = new StringBuilder();
var components = callableName.split(LIZARD_CALLABLE_SEPARATOR);
if(components.length == 1) {
result = new StringBuilder(components[0]);
}
result.append(components[0]);
int i = 1;
while(i < components.length - 1) {
result.append("$").append(components[i]);
i++;
else if(components.length > 1) {
if(components[components.length - 2].equals(components[components.length - 1])) {
components[components.length - 1] = JAVA_CONSTRUCTOR_NAME;
}
result.append(components[0]);
int i = 1;
while(i < components.length - 1) {
result.append("$").append(components[i]);
i++;
}
result.append(".").append(components[i]);
}
result.append(".").append(components[i]);
return result.append("(").toString();
}
return result.toString();
}

private JSONObject getQualityMetadata(JSONObject payload, String rapidVersion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,37 @@ void normalizeCallableNameJavaTest() {
assertEquals("",
normalizeCallableName(""));

assertEquals("NDC.clear",
assertEquals("NDC.clear(",
normalizeCallableName("NDC::clear"));

assertEquals("SMTPAppender.%3Cinit%3E",
assertEquals("SMTPAppender.%3Cinit%3E(",
normalizeCallableName("SMTPAppender::SMTPAppender"));

assertEquals("LoggingReceiver$Slurper.run",
assertEquals("LoggingReceiver$Slurper.run(",
normalizeCallableName("LoggingReceiver::Slurper::run"));

assertEquals("LoggingReceiver$Slurper.%3Cinit%3E",
assertEquals("LoggingReceiver$Slurper.%3Cinit%3E(",
normalizeCallableName("LoggingReceiver::Slurper::Slurper"));

assertEquals("PatternParser$NamedPatternConverter.%3Cinit%3E",
assertEquals("PatternParser$NamedPatternConverter.%3Cinit%3E(",
normalizeCallableName("PatternParser::NamedPatternConverter::NamedPatternConverter"));
}

@Test
void normalizeCallableNamePythonTest() {
assertEquals("get_filing_list",
assertEquals("get_filing_list(",
normalizeCallableName("get_filing_list"));

assertEquals("_get_daily_listing_url",
assertEquals("_get_daily_listing_url(",
normalizeCallableName("_get_daily_listing_url"));
}

@Test
void normalizeCallableNameCTest() {
assertEquals("drop_excludes",
assertEquals("drop_excludes(",
normalizeCallableName("drop_excludes"));

assertEquals("gda_xslt_getxmlvalue_function",
assertEquals("gda_xslt_getxmlvalue_function(",
normalizeCallableName("gda_xslt_getxmlvalue_function"));
}
}

0 comments on commit afa4bb1

Please sign in to comment.