Reputation: 91
I am using inria Spoon to parse Java projects, and then extract information about classes, Interfaces, fields, and methods and all their references.
I am using the below code to build model of an input project.
SpoonAPI spoonAPI = new Launcher();
spoonAPI.addInputResource(projectDirectory);
spoonAPI.buildModel();
CtModel ctModel = spoonAPI.getModel();
However, buildModel() is very time consuming in big projects.
PS: I used JavaParser using the below code and it is more faster than Spoon.
Path pathToSource = Paths.get(projectDirectory);
SourceRoot sourceRoot = new SourceRoot(pathToSource);
sourceRoot.tryToParse();
List<CompilationUnit> compilations = sourceRoot.getCompilationUnits();
I was wondering if there is any faster way to create the CtModel in Spoon.
Upvotes: 3
Views: 348
Reputation: 2051
Instead of parsing the full source directory, you can build the model only for the files you need to analyze or transform:
spoonAPI.addInputResource("path/Foo.java");
spoonAPI.addInputResource("path/Bar.java");
Upvotes: 0