|
Re: Tracking JDT Compiler Error Messages (IProblem) [message #1052934 is a reply to message #1052865] |
Wed, 01 May 2013 13:20 |
Stephan Herrmann Messages: 1853 Registered: July 2009 |
Senior Member |
|
|
First, if AST creation yields fewer problems than you expect, have you checked if these problems are
- configurable problems that just need to be enabled via the options used by the ASTParser?
- reported against secondary files, i.e., not the being passed to the parser? (Have you seen ASTParser.createASTs(..) - the plural version?)
- problems that are not necessarily detected by parsing alone (i.e., semantic problems that may be detected as late as during code generation)? Does requesting resolved bindings make a difference?
That said, using the concept of Java projects indeed depends on a workspace. Note, that this doesn't necessarily require to fire up the entire IDE, it's not the workbench that's needed but a workspace. The latter can in principle be initialized in a standalone application, too, but I don't have a HowTo at hand for this scenario.
HTH,
Stephan
|
|
|
|
Re: Tracking JDT Compiler Error Messages (IProblem) [message #1052975 is a reply to message #1052936] |
Wed, 01 May 2013 16:57 |
David Boulanger Messages: 5 Registered: April 2013 |
Junior Member |
|
|
Hello Stephan,
Just to let you know that your third hint brings me to the solution I sought. I needed finally to resolve the bindings between the char[] source code and its environment (setEnvironment) and set the name of the compilation unit. Setting the environment enables us to bypass the workspace and create our own "virtual" project by importing the proper libraries (classpath) and the source code (sourcepath). If somebody would like to retrieve also syntax errors, he has only to enable the recovery of statements. Thus we are able to parse an external Java file in a standalone Java application and retrieve the same amount of errors as it would in a real Eclipse project (except for the package declaration error). Here is the code fragment I used:
File file = new File("");
String srcCode = Files.toString(file, Charsets.UTF_8);
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setSource(srcCode.toCharArray());
parser.setKind(ASTParser.K_COMPILATION_UNIT);
Map options = JavaCore.getOptions();
JavaCore.setComplianceOptions(JavaCore.VERSION_1_5, options);
parser.setCompilerOptions(options);
String[] classpath = {"", "", ""};
String[] sourcepath = {""};
parser.setEnvironment(classpath, sourcepath, null, true);
parser.setUnitName("");
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
parser.setStatementsRecovery(true);
CompilationUnit cu = (CompilationUnit) parser.createAST(null);
cu.accept(new ASTVisitor2(cu));
Again, thanks for having taken the time to provide me with those hints. It is really appreciated.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03118 seconds