-
Notifications
You must be signed in to change notification settings - Fork 174
GumTree API
Jean-Rémy Falleri edited this page Feb 1, 2021
·
14 revisions
You can use GumTree directly from Java code. Here are some examples (it should compatible with the version at the latest commit):
Run.initGenerators();
String file = "myfile.java";
TreeContext tc = Generators.getInstance().getTree(file); // retrieve the default generator for the file
Tree t = tc.getRoot(); // return the root of the tree
System.out.println(TreeIoUtils.toLisp(tc).toString()); // displays the tree in LISP syntax
String file = "myfile.java";
Tree tree = new JdtTreeGenerator().generateFrom().file(file).getRoot();
Run.initGenerators();
String srcFile = "file_v0.java";
String dstFile = "file_v1.java";
Tree src = Generators.getInstance().getTree(srcFile).getRoot();
Tree dst = Generators.getInstance().getTree(dstFile).getRoot();
Matcher defaultMatcher = Matchers.getInstance().getMatcher();
MappingStore mappings = defaultMatcher.match(src, dst);
Run.initGenerators();
String srcFile = "file_v0.java";
String dstFile = "file_v1.java";
Tree src = Generators.getInstance().getTree(srcFile).getRoot();
Tree dst = Generators.getInstance().getTree(dstFile).getRoot();
Matcher defaultMatcher = Matchers.getInstance().getMatcher();
MappingStore mappings = defaultMatcher.match(src, dst);
EditScriptGenerator editScriptGenerator = new SimplifiedChawatheScriptGenerator();
EditScript actions = editScriptGenerator.computeActions(mappings);