Skip to content

Commit

Permalink
Initial Fix for #77
Browse files Browse the repository at this point in the history
Modify the matchers to enable the matching of composite and non-composite with GeneralMatcher

Better naming for the method
  • Loading branch information
pouryafard75 committed Apr 29, 2023
1 parent b4fe6ce commit c834dc4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}. <br>
* @author Pourya Alikhani Fard [email protected]
*/
public class CompositeMatcher extends BasicTreeMatcher implements TreeMatcher {
Expand Down Expand Up @@ -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<Tree, Tree> cpyMap) {
Tree cpy = TreeUtilFunctions.makeDefaultTree(tree);
cpyMap.put(cpy,tree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. <br>
* If you know that both fragments are composite, use {@link org.refactoringminer.astDiff.matchers.CompositeMatcher} instead. <br>
* @author Pourya Alikhani Fard [email protected]
*/
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;
}
Expand All @@ -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);
}

}

Expand Down
2 changes: 1 addition & 1 deletion src/org/refactoringminer/astDiff/matchers/LeafMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 12 additions & 6 deletions src/org/refactoringminer/astDiff/matchers/ProjectASTDiffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<AbstractCodeFragment> 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<AbstractCodeFragment> 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)
Expand Down

0 comments on commit c834dc4

Please sign in to comment.