EN JP
This is a AST Generator of GumTree for .mjava
file.
.mjava
is extracted method as a single file.
build.gradle
repositories {
....
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/a-fujimt/gen.mjava")
credentials {
username = project.hasProperty("GITHUB_USER") ? GITHUB_USER : ''
password = project.hasProperty("GITHUB_TOKEN") ? GITHUB_TOKEN : ''
}
}
}
dependencies {
implementation 'com.fujimotoakira:gen.mjava:1.0-SNAPSHOT'
implementation 'com.github.gumtreediff:core:version' // GumTree
implementation 'com.github.gumtreediff:client:version' // GumTree
....
}
gradle.properties
GITHUB_USER = XXXXXX
GUTHUB_TOKEN = YYYYYY
Add GitHub authentication in gradle.properties
because this project is published in Github Package. If you want to know detail about GitHub authentication, see this page.
Using the generator registry (ref)
Run.initGenerators(); // registers the available parsers
String file = "myfile.mjava";
TreeContext tc = TreeGenerators.getInstance().getTree(file); // retrieves and applies the default parser for the file
Tree t = tc.getRoot(); // retrieves the root of the tree
System.out.println(t.toTreeString()); // displays the tree in our ad-hoc format
Using mjava JDT generator (ref)
String file = "myfile.mjava";
Tree tree = new MJdtTreeGenerator().generateFrom().file(file).getRoot(); // instantiates and applies the MJDT generator