diff --git a/src/org/refactoringminer/astDiff/matchers/BasicTreeMatcher.java b/src/org/refactoringminer/astDiff/matchers/BasicTreeMatcher.java index 2eaaca9e9b..00767f530d 100644 --- a/src/org/refactoringminer/astDiff/matchers/BasicTreeMatcher.java +++ b/src/org/refactoringminer/astDiff/matchers/BasicTreeMatcher.java @@ -19,10 +19,10 @@ public void match(Tree src, Tree dst, ExtendedMultiMappingStore mappingStore) { basicMatcher(src, dst, mappingStore); } private void basicMatcher(Tree src, Tree dst, ExtendedMultiMappingStore mappingStore) { - mappingStore.add(apply(src, dst)); + mappingStore.add(process(src, dst)); } - public MappingStore apply(Tree src, Tree dst) { + public static MappingStore process(Tree src, Tree dst) { MappingStore match; match = new CustomGreedy(0, false).match(src, dst); CustomBottomUpMatcher customBottomUpMatcher = new CustomBottomUpMatcher(); diff --git a/src/org/refactoringminer/astDiff/matchers/CompositeMatcher.java b/src/org/refactoringminer/astDiff/matchers/CompositeMatcher.java index a4fe627f9d..b5ced2a3fa 100644 --- a/src/org/refactoringminer/astDiff/matchers/CompositeMatcher.java +++ b/src/org/refactoringminer/astDiff/matchers/CompositeMatcher.java @@ -8,7 +8,7 @@ import java.util.HashMap; import java.util.Map; -/** +/** Use this matcher when both code fragments are {@link gr.uom.java.xmi.decomposition.CompositeStatementObject}.
* @author Pourya Alikhani Fard pouryafard75@gmail.com */ public class CompositeMatcher extends BasicTreeMatcher implements TreeMatcher { @@ -48,10 +48,6 @@ private void process(Tree src, Tree dst, ExtendedMultiMappingStore mappingStore) } } - private void compositeMatcher(Tree src, Tree dst, ExtendedMultiMappingStore mappingStore) { - process(src, dst, mappingStore); - } - private static Tree makeFakeTree(Tree tree, CompositeStatementObject fragment, Map cpyMap) { Tree cpy = TreeUtilFunctions.makeDefaultTree(tree); cpyMap.put(cpy,tree); diff --git a/src/org/refactoringminer/astDiff/matchers/GeneralTreeMatcher.java b/src/org/refactoringminer/astDiff/matchers/GeneralMatcher.java similarity index 78% rename from src/org/refactoringminer/astDiff/matchers/GeneralTreeMatcher.java rename to src/org/refactoringminer/astDiff/matchers/GeneralMatcher.java index 6164e2aca0..0359f6b186 100644 --- a/src/org/refactoringminer/astDiff/matchers/GeneralTreeMatcher.java +++ b/src/org/refactoringminer/astDiff/matchers/GeneralMatcher.java @@ -6,12 +6,15 @@ import gr.uom.java.xmi.decomposition.CompositeStatementObject; import org.refactoringminer.astDiff.utils.TreeUtilFunctions; -/* Created by pourya on 2023-04-25 1:08 p.m. */ -public class GeneralTreeMatcher extends BasicTreeMatcher implements TreeMatcher { +/** Use this matcher when two code fragments must be matched.
+ * If you know that both fragments are composite, use {@link org.refactoringminer.astDiff.matchers.CompositeMatcher} instead.
+ * @author Pourya Alikhani Fard pouryafard75@gmail.com +*/ +public class GeneralMatcher extends BasicTreeMatcher implements TreeMatcher { AbstractCodeFragment st1; AbstractCodeFragment st2; - public GeneralTreeMatcher(AbstractCodeFragment st1, AbstractCodeFragment st2) { + public GeneralMatcher(AbstractCodeFragment st1, AbstractCodeFragment st2) { this.st1 = st1; this.st2 = st2; } @@ -38,6 +41,9 @@ public void match(Tree src, Tree dst, ExtendedMultiMappingStore mappingStore) { new LeafMatcher(false).match(srcExpTree,dst,mappingStore); } } + else { + new LeafMatcher(false).match(src,dst,mappingStore); + } } diff --git a/src/org/refactoringminer/astDiff/matchers/LeafMatcher.java b/src/org/refactoringminer/astDiff/matchers/LeafMatcher.java index 4b5f40b248..09758fc9fb 100644 --- a/src/org/refactoringminer/astDiff/matchers/LeafMatcher.java +++ b/src/org/refactoringminer/astDiff/matchers/LeafMatcher.java @@ -32,7 +32,7 @@ public void match(Tree src, Tree dst, ExtendedMultiMappingStore mappingStore) { match.addMappingRecursively(prunedPair.first, prunedPair.second); } else { - match = apply(prunedPair.first, prunedPair.second); + match = process(prunedPair.first, prunedPair.second); } if (!overwrite) mappingStore.addWithMaps(match, srcCopy, dstCopy); diff --git a/src/org/refactoringminer/astDiff/matchers/ProjectASTDiffer.java b/src/org/refactoringminer/astDiff/matchers/ProjectASTDiffer.java index 21d86de640..74eaacebb2 100644 --- a/src/org/refactoringminer/astDiff/matchers/ProjectASTDiffer.java +++ b/src/org/refactoringminer/astDiff/matchers/ProjectASTDiffer.java @@ -679,27 +679,33 @@ else if (refactoring instanceof MergeVariableRefactoring) else if (refactoring instanceof SplitConditionalRefactoring) { SplitConditionalRefactoring splitConditionalRefactoring = (SplitConditionalRefactoring) refactoring; + Tree srcSubTree = TreeUtilFunctions.findByLocationInfo(srcTree,splitConditionalRefactoring.getOriginalConditional().getLocationInfo()); Set splitConditionals = splitConditionalRefactoring.getSplitConditionals(); for (AbstractCodeFragment splitConditional : splitConditionals) { - new GeneralTreeMatcher(splitConditionalRefactoring.getOriginalConditional(), splitConditional). - match(srcTree,dstTree,mappingStore); + Tree dstSubTree = TreeUtilFunctions.findByLocationInfo(dstTree,splitConditional.getLocationInfo()); + new GeneralMatcher(splitConditionalRefactoring.getOriginalConditional(), splitConditional). + match(srcSubTree,dstSubTree,mappingStore); } } else if (refactoring instanceof MergeConditionalRefactoring) { MergeConditionalRefactoring mergeConditionalRefactoring = (MergeConditionalRefactoring) refactoring; + Tree dstSubTree = TreeUtilFunctions.findByLocationInfo(dstTree,mergeConditionalRefactoring.getNewConditional().getLocationInfo()); Set mergedConditionals = mergeConditionalRefactoring.getMergedConditionals(); for (AbstractCodeFragment eachMerged : mergedConditionals) { - new GeneralTreeMatcher(eachMerged, mergeConditionalRefactoring.getNewConditional()) - .match(srcTree,dstTree,mappingStore); + Tree srcSubTree = TreeUtilFunctions.findByLocationInfo(srcTree,eachMerged.getLocationInfo()); + new GeneralMatcher(eachMerged, mergeConditionalRefactoring.getNewConditional()) + .match(srcSubTree,dstSubTree,mappingStore); } } else if (refactoring instanceof MergeCatchRefactoring) { MergeCatchRefactoring mergeCatchRefactoring = (MergeCatchRefactoring) refactoring; + Tree dstSubTree = TreeUtilFunctions.findByLocationInfo(dstTree,mergeCatchRefactoring.getNewCatchBlock().getLocationInfo()); for (AbstractCodeFragment eachMerged : mergeCatchRefactoring.getMergedCatchBlocks()) { - new GeneralTreeMatcher(eachMerged, mergeCatchRefactoring.getNewCatchBlock()) - .match(srcTree,dstTree,mappingStore); + Tree srcSubTree = TreeUtilFunctions.findByLocationInfo(srcTree,eachMerged.getLocationInfo()); + new GeneralMatcher(eachMerged, mergeCatchRefactoring.getNewCatchBlock()) + .match(srcSubTree,dstSubTree,mappingStore); } } else if (refactoring instanceof RenameVariableRefactoring)