Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to the new visitor (Part1) #817

Merged
merged 123 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
81765ea
ASTDiff: Prepare the migration to the new visitor
pouryafard75 Nov 30, 2024
93de354
ASTDiff: Test result migration
pouryafard75 Dec 1, 2024
b9a52d7
ASTDiff: Test result migration
pouryafard75 Dec 1, 2024
531e67f
ASTDiff: Test result migration
pouryafard75 Dec 1, 2024
1355114
ASTDiff: Test result migration
pouryafard75 Dec 1, 2024
b141fe8
ASTDiff: Test result migration
pouryafard75 Dec 1, 2024
710f464
ASTDiff: Test result migration
pouryafard75 Dec 1, 2024
afe1915
ASTDiff: Test result migration
pouryafard75 Dec 1, 2024
65ed5bb
ASTDiff: Test result migration
pouryafard75 Dec 1, 2024
4283ce7
ASTDiff: Test result migration
pouryafard75 Dec 1, 2024
56b8a25
ASTDiff: Test result migration
pouryafard75 Dec 1, 2024
6c04eef
ASTDiff: Test result migration
pouryafard75 Dec 1, 2024
860fb60
ASTDiff: Test result migration
pouryafard75 Dec 1, 2024
6a0a3f0
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
6911ced
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
a10b41b
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
d23b750
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
2e0d27e
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
8584efa
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
242d1ba
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
37b642d
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
8a6d0ce
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
0484db2
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
7a9fa66
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
d3f4394
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
ee700d5
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
e2fe4d8
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
e2eb65f
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
ca52beb
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
3f13852
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
0b3ad36
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
5aad7e1
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
bdcd908
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
134f22c
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
a23f1ff
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
c4e5d7d
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
c186c52
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
41d9bc2
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
8d93ad5
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
4d29f9c
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
1748f3a
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
86da2a0
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
392eb45
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
df25205
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
732db76
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
d23b831
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
f6ce15f
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
8919431
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
c54fb3a
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
48730b7
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
aa8d80f
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
32ee443
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
bdb1e41
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
e9cbe01
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
34e1921
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
912363b
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
7b2849b
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
b240d34
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
e3a800c
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
51bd76e
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
66f3402
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
fd5251f
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
946cb3b
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
9bdbf60
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
7e433be
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
05acbcc
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
6275fe6
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
d465b31
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
1adc90b
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
72ef76f
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
0afb47d
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
a38fc4b
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
90ab03d
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
95abb3f
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
611b59c
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
332bd9f
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
b41d248
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
9cb66ef
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
3cd35ab
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
26dadb4
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
cda2331
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
d012260
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
371194a
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
20473ff
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
c645386
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
214d3e8
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
6df4928
ASTDiff: Test result migration
pouryafard75 Dec 2, 2024
64fdd96
ASTDiff: Fix whitespace in a test result (https://github.com/Cellular…
pouryafard75 Dec 4, 2024
4ed2f93
ASTDiff: Test result migration
pouryafard75 Dec 4, 2024
311d78c
ASTDiff: Test result migration
pouryafard75 Dec 4, 2024
2abad71
ASTDiff: Disable tests temporarily
pouryafard75 Dec 4, 2024
b9a5016
ASTDiff: Modify the utility tool temporarily for the migration
pouryafard75 Dec 3, 2024
4faf27b
ASTDiff: Test result migration
pouryafard75 Dec 5, 2024
1c78b1f
ASTDiff: Test result migration
pouryafard75 Dec 5, 2024
4aea2ee
ASTDiff: Test result migration
pouryafard75 Dec 5, 2024
21849b9
ASTDiff: Test result migration
pouryafard75 Dec 5, 2024
340975f
ASTDiff: Test result migration
pouryafard75 Dec 5, 2024
4e0c14f
ASTDiff: Test result migration
pouryafard75 Dec 5, 2024
0bdb75b
ASTDiff: Test result migration
pouryafard75 Dec 5, 2024
80c38db
ASTDiff: Test result migration
pouryafard75 Dec 5, 2024
04e64d3
ASTDiff: Test result migration
pouryafard75 Dec 5, 2024
2166a93
ASTDiff: Test result migration
pouryafard75 Dec 5, 2024
aaf1c66
ASTDiff: Test result migration
pouryafard75 Dec 5, 2024
51f0530
ASTDiff: Test result migration
pouryafard75 Dec 5, 2024
caa9dea
ASTDiff: TreeUtilFunction look ahead bug fix
pouryafard75 Dec 6, 2024
c2bf1cc
ASTDiff: Fix for the attr annotations
pouryafard75 Dec 9, 2024
87dabe9
ASTDiff: Test result migration
pouryafard75 Dec 9, 2024
397b405
ASTDiff: Test result migration
pouryafard75 Dec 9, 2024
e81fdcd
ASTDiff: Remove unnecessary logs
pouryafard75 Dec 9, 2024
94d9c28
JUnit test execution parallelization changed to class level
pouryafard75 Dec 9, 2024
ad7cf00
ASTDiff: Run tests with/without comments at the same time
pouryafard75 Dec 9, 2024
51a8dfe
ASTDiff: Test result migration
pouryafard75 Dec 9, 2024
9813af2
ASTDiff: Test result migration
pouryafard75 Dec 9, 2024
12e9f04
ASTDiff: Test result migration
pouryafard75 Dec 9, 2024
50ef4b7
ASTDiff: RefactoringsOracle tests consider comments
pouryafard75 Dec 9, 2024
6a8f52b
ASTDiff: Test result migration
pouryafard75 Dec 9, 2024
4ad055b
ASTDiff: Test result migration
pouryafard75 Dec 9, 2024
cdc2fea
ASTDiff: Fix for inter-file optimizations
pouryafard75 Dec 9, 2024
04dc94e
ASTDiff: Test result migration
pouryafard75 Dec 9, 2024
ee8f1f6
ASTDiff: Finalize BenchmarkUtilityRunner
pouryafard75 Dec 9, 2024
82e1cd2
ASTDiff: More bug fixes
pouryafard75 Dec 9, 2024
42c558f
ASTDiff: Test result migration
pouryafard75 Dec 9, 2024
280a3ee
ASTDiff: Test result migration
pouryafard75 Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 7 additions & 3 deletions src/main/java/gr/uom/java/xmi/UMLModelASTReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;

import com.github.gumtreediff.gen.jdt.AbstractJdtVisitor;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.ToolFactory;
import org.eclipse.jdt.core.compiler.IProblem;
Expand Down Expand Up @@ -62,17 +63,17 @@
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;

import com.github.gumtreediff.gen.jdt.JdtVisitor;
import com.github.gumtreediff.tree.TreeContext;

import gr.uom.java.xmi.LocationInfo.CodeElementType;
import gr.uom.java.xmi.decomposition.AbstractExpression;
import gr.uom.java.xmi.decomposition.OperationBody;
import gr.uom.java.xmi.decomposition.VariableDeclaration;
import org.refactoringminer.astDiff.visitors.JdtVisitor;
import org.refactoringminer.astDiff.visitors.JdtWithCommentsVisitor;

public class UMLModelASTReader {
private static final boolean VISIT_JDT_COMMENTS = Boolean.parseBoolean(System.getProperty("rm.jdt.comments", "true"));
private boolean VISIT_JDT_COMMENTS = Boolean.parseBoolean(System.getProperty("rm.jdt.comments", "true"));
private static final String FREE_MARKER_GENERATED = "generated using freemarker";
private static final String FREE_MARKER_GENERATED_2 = "generated using FreeMarker";
private static final String ANTLR_GENERATED = "// $ANTLR";
Expand Down Expand Up @@ -137,7 +138,10 @@ private void processJavaFileContents(Map<String, String> javaFileContents, boole
if(astDiff) {
IScanner scanner = ToolFactory.createScanner(true, false, false, false);
scanner.setSource(charArray);
JdtVisitor visitor = (VISIT_JDT_COMMENTS) ? new JdtWithCommentsVisitor(scanner) : new JdtVisitor(scanner);
AbstractJdtVisitor visitor = (VISIT_JDT_COMMENTS) ?
new JdtWithCommentsVisitor(scanner) :
new com.github.gumtreediff.gen.jdt.JdtVisitor(scanner);
// JdtVisitor visitor = new JdtWithCommentsVisitor(scanner);
compilationUnit.accept(visitor);
TreeContext treeContext = visitor.getTreeContext();
this.umlModel.getTreeContextMap().put(filePath, treeContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public GeneralMatcher(AbstractCodeFragment st1, AbstractCodeFragment st2) {
}
@Override
public void match(Tree src, Tree dst, ExtendedMultiMappingStore mappingStore) {
if (src == null || dst == null) return;
if ((st1 instanceof CompositeStatementObject) && (st2 instanceof CompositeStatementObject)) {
new CompositeMatcher((CompositeStatementObject) st1, (CompositeStatementObject) st2)
.match(src, dst, mappingStore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ private static void processOptimization(ASTDiff input, OptimizationData optimiza
}
else {
//Inter-file optimizations
TreeContext tc1 = parentContextMap.get(lastStepMapping.getFragment1().getLocationInfo().getFilePath());
Tree t1 = TreeUtilFunctions.findByLocationInfo(tc1.getRoot(), lastStepMapping.getFragment1().getLocationInfo());
TreeContext tc2 = childContextMap.get(lastStepMapping.getFragment2().getLocationInfo().getFilePath());
Tree t2 = TreeUtilFunctions.findByLocationInfo(tc2.getRoot(), lastStepMapping.getFragment2().getLocationInfo());
if (t1 == null || t2 == null) continue;
new LeafMatcher().match(t1, t2, input.getAllMappings());
}
}
ExtendedMultiMappingStore allMappings = input.getAllMappings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import gr.uom.java.xmi.UMLEnumConstant;
import gr.uom.java.xmi.diff.UMLCommentListDiff;
import gr.uom.java.xmi.diff.UMLJavadocDiff;
import org.apache.commons.lang3.tuple.Pair;
import org.refactoringminer.astDiff.models.OptimizationData;
import org.refactoringminer.astDiff.utils.Constants;
import org.refactoringminer.astDiff.models.ExtendedMultiMappingStore;
Expand Down Expand Up @@ -113,9 +114,16 @@ private void matchFieldAllModifiers(Tree srcFieldDeclaration, Tree dstFieldDecla
}

private void matchFieldAnnotations(Tree srcFieldDeclaration, Tree dstFieldDeclaration, ExtendedMultiMappingStore mappingStore) {
Tree srcField = TreeUtilFunctions.findFirstByType(srcFieldDeclaration, Constants.MARKER_ANNOTATION);
Tree dstField = TreeUtilFunctions.findFirstByType(dstFieldDeclaration, Constants.MARKER_ANNOTATION);
new LeafMatcher().match(srcField, dstField, mappingStore);
//TODO: add test for all the annotations
Pair<Tree, Tree> srcAndDst = TreeUtilFunctions.populateLeftAndRightBasedOnTheFirstChildOfType(
srcFieldDeclaration, dstFieldDeclaration,
new String[]{
Constants.MARKER_ANNOTATION,
Constants.SINGLE_MEMBER_ANNOTATION,
Constants.NORMAL_ANNOTATION,
}
);
new LeafMatcher().match(srcAndDst.getLeft(), srcAndDst.getRight(), mappingStore);
}

private void matchModifiersForField(Tree srcFieldDeclaration, Tree dstFieldDeclaration, String srcModifier, String dstModifier, ExtendedMultiMappingStore mappingStore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,11 @@ private void processRefactorings(Tree srcTree, Tree dstTree, List<Refactoring> r
eligible = !renameVariableRefactoring.isInsideExtractedOrInlinedMethod();
if (!eligible)
break;
while (!TreeUtilFunctions.isStatement(dstInput.getType().name)) {
while (dstInput != null && !TreeUtilFunctions.isStatement(dstInput.getType().name) ) {
if (dstInput.getType() == null) break;
dstInput = dstInput.getParent();
}
if (dstInput == null) return;
if (TreeUtilFunctions.isStatement(dstInput.getType().name)){
new LeafMatcher().match(srcInput,dstInput,mappingStore);
}
Expand Down Expand Up @@ -391,7 +392,7 @@ private List<Refactoring> getClassDiffRefactorings(UMLClassBaseDiff classDiff) {
ImmutablePair<String, String> refactoringClassBefore = involvedClassesBeforeRefactoring.iterator().next();
ImmutablePair<String, String> refactoringClassAfter = involvedClassesAfterRefactoring.iterator().next();
if (umlClassBefore.getLocationInfo().getFilePath().equals(refactoringClassBefore.getLeft())
&& umlClassAfter.getLocationInfo().getFilePath().equals(refactoringClassAfter.getLeft())) {
|| umlClassAfter.getLocationInfo().getFilePath().equals(refactoringClassAfter.getLeft())) {
String refactoringClassNameBefore = refactoringClassBefore.getRight();
String refactoringClassNameAfter = refactoringClassAfter.getRight();
// Relied on || in order to ascertain at least one class involves (handling move to anonymous and vice versa)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ public class Constants {
public static final String NUMBER_LITERAL = "NumberLiteral";
public static final String BOOLEAN_LITERAL = "BooleanLiteral";

public static final String SINGLE_MEMBER_ANNOTATION = "SingleMemberAnnotation";
public static final String MARKER_ANNOTATION = "MarkerAnnotation";
public static final String SINGLE_MEMBER_ANNOTATION = "SingleMemberAnnotation"; //@type(Expression), for instance
public static final String MARKER_ANNOTATION = "MarkerAnnotation"; //@Deprecated for instance
public static final String NORMAL_ANNOTATION = "NormalAnnotation"; //@Author("John Doe", "") for instance

public static final String COMPILATION_UNIT = "CompilationUnit";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class TreeUtilFunctions {

public static Tree findByLocationInfo(Tree tree, LocationInfo locationInfo){
int start_offset = locationInfo.getStartOffset();
if (tree.getPos() > start_offset) return (tree.getParent() != null) ? findByLocationInfo(tree.getParent(),locationInfo) : null;
int end_offset = locationInfo.getEndOffset();
if (tree.getPos() > start_offset || tree.getEndPos() < end_offset) return (tree.getParent() != null) ? findByLocationInfo(tree.getParent(),locationInfo) : null;
return findByLocationInfoNoLookAhead(tree, locationInfo);
}

Expand Down Expand Up @@ -152,6 +153,23 @@ public static Tree deepCopyWithMap(Tree tree,Map<Tree,Tree> cpyMap) {
return copy;
}

public static org.apache.commons.lang3.tuple.Pair<Tree, Tree> populateLeftAndRightBasedOnTheFirstChildOfType(Tree srcTree, Tree dstTree, String[] types)
{
Tree srcRes = null;
Tree dstRes = null;
for (String type : types) {
srcRes = TreeUtilFunctions.findFirstByType(srcTree, type);
dstRes = TreeUtilFunctions.findFirstByType(dstTree, type);
if (srcRes != null && dstRes != null)
break;
else {
//In case, only one of them is null. We want to avoid this scenario (unless we get more examples)
srcRes = null;
dstRes = null;
}
}
return org.apache.commons.lang3.tuple.Pair.of(srcRes,dstRes);
}
public static FakeTree getFakeTreeInstance()
{
if (_instance == null)
Expand Down
Loading
Loading