From 75c0985e38193e3787aa269e95be29f6f9639c13 Mon Sep 17 00:00:00 2001 From: tsantalis Date: Wed, 15 Jan 2025 14:51:08 -0500 Subject: [PATCH] inferClassRenameBasedOnFilePaths() utilizes rename hints if available https://github.com/junit-team/junit5/commit/89a0201073efd12b0732ceaeba52c6d7d7029f3a --- .../gr/uom/java/xmi/diff/UMLModelDiff.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) 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 8d4ce47bd..16ec15c46 100644 --- a/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java +++ b/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java @@ -1269,22 +1269,56 @@ public void inferClassRenameBasedOnFilePaths(UMLClassMatcher matcher) throws Ref UMLClass removedClass = removedClassIterator.next(); String removedClassFilePath = removedClass.getSourceFile(); TreeSet diffSet = new TreeSet(new ClassRenameComparator()); + UMLClassRenameDiff promotedDiff = null; for(Iterator addedClassIterator = addedClasses.iterator(); addedClassIterator.hasNext();) { UMLClass addedClass = addedClassIterator.next(); String addedClassFilePath = addedClass.getSourceFile(); for(UMLClassRenameDiff classRenameDiff : classRenameDiffList) { + Map renameHint = new LinkedHashMap(); + if(!classRenameDiff.getOriginalClass().isTopLevel() && !classRenameDiff.getNextClass().isTopLevel()) { + String outerClassName = classRenameDiff.getNextClassName().substring(0, classRenameDiff.getNextClassName().lastIndexOf(".")); + UMLClassBaseDiff outerClassDiff = getUMLClassDiff(outerClassName); + if(outerClassDiff != null) { + for(Refactoring r : outerClassDiff.getRefactoringsBeforePostProcessing()) { + if(r instanceof ExtractOperationRefactoring) { + ExtractOperationRefactoring extract = (ExtractOperationRefactoring)r; + for(String key : extract.getParameterToArgumentMap().keySet()) { + String value = extract.getParameterToArgumentMap().get(key); + if(value.endsWith(".class")) { + for(Replacement replacement : extract.getReplacements()) { + if(replacement.getAfter().equals(value)) { + String before = replacement.getBefore(); + if(replacement.getBefore().endsWith(".class")) { + before = replacement.getBefore().substring(0, replacement.getBefore().length()-6); + } + String after = value.substring(0, value.length()-6); + renameHint.put(before, after); + } + } + } + } + } + } + } + } if(classRenameDiff.getOriginalClass().getSourceFile().equals(removedClassFilePath) && classRenameDiff.getNextClass().getSourceFile().equals(addedClassFilePath)) { MatchResult matchResult = matcher.match(removedClass, addedClass); if(matchResult.getMatchedOperations() > 0 || matchResult.getMatchedAttributes() > 0) { UMLClassRenameDiff newClassRenameDiff = new UMLClassRenameDiff(removedClass, addedClass, this, matchResult); diffSet.add(newClassRenameDiff); + for(String key : renameHint.keySet()) { + if(removedClass.getName().endsWith(key) && addedClass.getName().endsWith(renameHint.get(key))) { + promotedDiff = newClassRenameDiff; + break; + } + } } } } } if(diffSet.size() > 0) { - UMLClassRenameDiff first = diffSet.first(); + UMLClassRenameDiff first = promotedDiff != null ? promotedDiff : diffSet.first(); diffsToBeAdded.add(first); first.process(); addedClassesToBeRemoved.add(first.getNextClass());