Skip to content

Commit 38a57f1

Browse files
committed
ASTDiff: Fixes the annotation processor
1 parent 0d17c3e commit 38a57f1

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.refactoringminer.astDiff.matchers.statement;
2+
3+
import com.github.gumtreediff.matchers.Mapping;
4+
import com.github.gumtreediff.tree.Tree;
5+
import org.refactoringminer.astDiff.models.ExtendedMultiMappingStore;
6+
import org.refactoringminer.astDiff.utils.Constants;
7+
import org.refactoringminer.astDiff.utils.TreeUtilFunctions;
8+
9+
public class IgnoringCommentsLeafMatcher extends LeafMatcher {
10+
@Override
11+
public void match(Tree src, Tree dst, ExtendedMultiMappingStore mappingStore) {
12+
ExtendedMultiMappingStore newMappings = new ExtendedMultiMappingStore(src, dst);
13+
super.match(src, dst, newMappings);
14+
// Remove comment mappings from the mapping store
15+
for (Mapping newMapping : newMappings) {
16+
if (isPartOfComments(newMapping.first) || isPartOfComments(newMapping.second)) {
17+
newMappings.removeMapping(newMapping.first, newMapping.second);
18+
}
19+
}
20+
for (Mapping newMapping : newMappings) {
21+
mappingStore.addMapping(newMapping.first, newMapping.second);
22+
}
23+
}
24+
public static boolean isPartOfComments(Tree tree) {
25+
return TreeUtilFunctions.getParentUntilType(tree, Constants.LINE_COMMENT) != null ||
26+
TreeUtilFunctions.getParentUntilType(tree, Constants.JAVA_DOC) != null ||
27+
TreeUtilFunctions.getParentUntilType(tree, Constants.BLOCK_COMMENT) != null;
28+
}
29+
}

src/main/java/org/refactoringminer/astDiff/matchers/wrappers/MethodMatcher.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import gr.uom.java.xmi.diff.UMLOperationDiff;
88
import gr.uom.java.xmi.diff.UMLTypeParameterListDiff;
99
import org.apache.commons.lang3.tuple.Pair;
10+
import org.refactoringminer.astDiff.matchers.statement.IgnoringCommentsLeafMatcher;
1011
import org.refactoringminer.astDiff.models.ExtendedMultiMappingStore;
1112
import org.refactoringminer.astDiff.models.OptimizationData;
1213
import org.refactoringminer.astDiff.utils.Constants;
13-
import org.refactoringminer.astDiff.matchers.statement.BasicTreeMatcher;
1414
import org.refactoringminer.astDiff.matchers.statement.LeafMatcher;
1515
import org.refactoringminer.astDiff.utils.Helpers;
1616
import org.refactoringminer.astDiff.utils.TreeUtilFunctions;
@@ -139,7 +139,12 @@ private void processOperationDiff(Tree srcTree, Tree dstTree, UMLOperationBodyMa
139139
for (org.apache.commons.lang3.tuple.Pair<UMLAnnotation, UMLAnnotation> umlAnnotationUMLAnnotationPair : umlOperationDiff.getAnnotationListDiff().getCommonAnnotations()) {
140140
Tree srcClassAnnotationTree = TreeUtilFunctions.findByLocationInfo(srcTree , umlAnnotationUMLAnnotationPair.getLeft().getLocationInfo());
141141
Tree dstClassAnnotationTree = TreeUtilFunctions.findByLocationInfo(dstTree, umlAnnotationUMLAnnotationPair.getRight().getLocationInfo());
142-
mappingStore.addMappingRecursively(srcClassAnnotationTree,dstClassAnnotationTree);
142+
if (srcClassAnnotationTree == null || dstClassAnnotationTree == null) continue;
143+
if (srcClassAnnotationTree.isIsoStructuralTo(dstClassAnnotationTree))
144+
mappingStore.addMappingRecursively(srcClassAnnotationTree, dstClassAnnotationTree);
145+
else {
146+
new IgnoringCommentsLeafMatcher().match(srcClassAnnotationTree, dstClassAnnotationTree, mappingStore);
147+
}
143148
}
144149
Set<org.apache.commons.lang3.tuple.Pair<UMLType, UMLType>> commonExceptionTypes = umlOperationDiff.getCommonExceptionTypes();
145150
new KeywordMatcher(Constants.THROWS_KEYWORD, THROWS_KEYWORD_LABEL).match(srcTree, dstTree, mappingStore);

0 commit comments

Comments
 (0)