From 3813c59e3d53fa1486c3deed49b696da4c6f3da8 Mon Sep 17 00:00:00 2001 From: tsantalis Date: Mon, 9 Dec 2024 21:26:32 -0500 Subject: [PATCH] Handle multiple matches https://github.com/checkstyle/checkstyle/commit/7dc907356508ce037afe1ae4d5aa7859239ada45 --- .../gr/uom/java/xmi/diff/UMLModelDiff.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java b/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java index a3db17bf65..9bcfd67f68 100644 --- a/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java +++ b/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java @@ -1269,18 +1269,35 @@ private static boolean conflictingPair(Pair currentPair, Set classNames, AbstractCodeFragment fragment) { + Set matches = new LinkedHashSet(); 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; }