Skip to content

Commit

Permalink
Extract condition
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Dec 8, 2024
1 parent bdc90ce commit 7514f94
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ public void inferClassRenameBasedOnReferencesInStringLiterals() throws Refactori
if(!r.getBefore().contains("{\n") && !r.getAfter().contains("{\n")) {
String matchingClassNameBefore = matches(r.getBefore(), removedClassNames, mapping.getFragment1());
String matchingClassNameAfter = matches(r.getAfter(), addedClassNames, mapping.getFragment2());
if(matchingClassNameBefore != null && matchingClassNameAfter != null && !r.getAfter().contains(matchingClassNameBefore) && !r.getBefore().contains(matchingClassNameAfter)) {
if(condition(matchingClassNameBefore, matchingClassNameAfter, r)) {
Pair<String, String> pair = Pair.of(matchingClassNameBefore, matchingClassNameAfter);
if(countMap.containsKey(pair)) {
countMap.put(pair, countMap.get(pair) + 1);
Expand Down Expand Up @@ -1244,6 +1244,18 @@ public void inferClassRenameBasedOnReferencesInStringLiterals() throws Refactori
addedClasses.removeAll(addedClassesToBeRemoved);
}

private static boolean condition(String matchingClassNameBefore, String matchingClassNameAfter, Replacement r) {
if(matchingClassNameBefore != null && matchingClassNameAfter != null) {
if(matchingClassNameBefore.contains(matchingClassNameAfter) || matchingClassNameAfter.contains(matchingClassNameBefore)) {
return true;
}
else {
return !r.getAfter().contains(matchingClassNameBefore) && !r.getBefore().contains(matchingClassNameAfter);
}
}
return false;
}

private static boolean conflictingPair(Pair<String, String> currentPair, Set<Pair<String, String>> allPairs) {
for(Pair<String, String> pair : allPairs) {
if(!pair.equals(currentPair)) {
Expand Down

0 comments on commit 7514f94

Please sign in to comment.