Skip to content

Commit

Permalink
Handle multiple matches
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Dec 10, 2024
1 parent 2013f70 commit 3813c59
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -1269,18 +1269,35 @@ private static boolean conflictingPair(Pair<String, String> currentPair, Set<Pai
}

private static String matches(String s, Set<String> classNames, AbstractCodeFragment fragment) {
Set<String> matches = new LinkedHashSet<String>();
for(String className : classNames) {
for(LeafExpression expr : fragment.getStringLiterals()) {
if(expr.getString().equals(s) && s.contains(className)) {
return className;
matches.add(className);
}
}
for(AbstractCall call : fragment.getMethodInvocations()) {
if(call.actualString().equals(s) && s.contains(className)) {
return className;
matches.add(className);
}
}
}
if(matches.size() == 1) {
return matches.iterator().next();
}
else if(matches.size() > 1) {
//return the longest match
String longest = null;
for(String match : matches) {
if(longest == null) {
longest = match;
}
else if(match.length() > longest.length()) {
longest = match;
}
}
return longest;
}
return null;
}

Expand Down

0 comments on commit 3813c59

Please sign in to comment.