Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Abstract Syntax Tree Diff

Given the following code in Eclipse:

import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.CompilationUnit;

public class Question {
    public static void main(String[] args) {
        String source = "class Bob {}";
        ASTParser parser = ASTParser.newParser(AST.JLS3); 
        parser.setSource(source.toCharArray());
        CompilationUnit result = (CompilationUnit) parser.createAST(null);

        String source2 = "class Bob {public void MyMethod(){}}";
        ASTParser parser2 = ASTParser.newParser(AST.JLS3); 
        parser2.setSource(source2.toCharArray());
        CompilationUnit result2 = (CompilationUnit) parser2.createAST(null);
    }
}

How do you use the Eclipse Compare API (org.eclipse.compare) to find the AST difference? (And can this be done outside of a plugin?)

I'm looking at the following APIs

http://kickjava.com/src/org/eclipse/compare/structuremergeviewer/Differencer.java.htm http://kickjava.com/src/org/eclipse/jdt/internal/ui/compare/JavaStructureCreator.java.htm http://kickjava.com/src/org/eclipse/compare/CompareUI.java.htm

Can anyone point to example code (or an API - but the code is preferred).

like image 209
hawkeye Avatar asked Jan 23 '23 13:01

hawkeye


1 Answers

GumTree does the job, for free :)

It also supports other languages such as javascript.

like image 95
cdmihai Avatar answered Jan 31 '23 04:01

cdmihai