I am working with Spoon Inria to parse and analyze Java applications. Currently, I am using the below code to create input project model. This code works when project files are saved in the disk.
Launcher spoonAPI = new Launcher();
spoonAPI.addInputResource(projectDirectory); //The path to the project root directory
spoonAPI.buildModel();
CtModel ctModel = spoonAPI.getModel();
However, currently I have contents of Java files (classes) in the memory and I do not want to write them in the disk as it takes ages. I was wondering if there is a way using Spoon that I can pass file contents to the parser. For example, a code as below.
//Key is name of class and value is its content
Map<String, String> JavafileContents= new HashMap<String, String>();
for (String filePath : JavafileContents.keySet()) {
spoonAPI.parse(JavafileContents.get(filePath ));
}
CtModel ctModel = spoonAPI.getModel(); //The extracted model should contains all parsed files.
Like a similar solution provided in JDT.
ASTParser parser = ASTParser.newParser(AST.JLS14);
parser.setSource(javaFileContents.get(filePath).toCharArray());
CompilationUnit compilationUnit = (CompilationUnit)parser.createAST(null);