|Analyzing Compilation Unit through a java application [message #918129]
||Thu, 20 September 2012 19:21
| Waths B.
Registered: January 2012
I want to read a java source file to collect all the terms it contains and there bindings to create a vocabulary for them.
Reading following line in a source file:
private void term(String term)
So I should collect 4 words (1 - private, 1 - void, 2 - term, 1 - String) and there AST Node bindings.
So I wrote the following code for that:
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IPath path = new Path(ReadTextInput());
IFile file = workspace.getRoot().getFile(path);
JParser parser = new JParser(JavaCore.createCompilationUnitFrom(file));
CompilationUnit compUnit = parser.getCompilationUnit();
TermVisitor visitor = new TermVisitor();
But when I'm running the application it ways that the workspace is closed ( java.lang.IllegalStateException: Workspace is closed.) So I think that is because I haven't start any workspace yet.
But I don't want to run this analysis as an Eclipse application which opens a new workspace in a separate window. I need to do this without opening any other workspace windows.
So now I'm thinking of creating a new workspace dynamically through the program, create a new project in that workspace and add the source file to that project. Then start the workspace and analyze its compilation unit.
It's really helpful if someone can tell me whether this is possible to implement and if not any suggestion to achieve this task is highly appreciated.
Powered by FUDForum
. Page generated in 0.05960 seconds