AssertStatement parsing problem [message #1814163] |
Thu, 05 September 2019 03:48  |
Eclipse User |
|
|
|
I use ASTParser to analyze a single Java file.
This is my testing code.
public void method10(int a) {
assert a > 2;
System.out.println("end");
}
And this is my parse code
Collection<File> srcFiles = FileUtils.listFiles(new File(folderPath), new String[] {"java"}, true);
List<String> srcList = new ArrayList<>(srcFiles.size());
for (File file : srcFiles) {
srcList.add(file.getPath());
}
String[] sourceFilePaths = new String[srcList.size()];
srcList.toArray(sourceFilePaths);
ASTParser parser = ASTParser.newParser(AST.JLS8);
String[] sourcepathEntries = {};
parser.setEnvironment(null, sourcepathEntries, null, true);
parser.setResolveBindings(true);
parser.setStatementsRecovery(true);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
ASTRequestor requestor = new ASTRequestor();
String[] bindingKeys = new String[] {};
parser.createASTs(sourceFilePaths, null, bindingKeys, requestor, null);
I collect all CompilationUnit into Requestor and traverse them using visitor pattern.
However, I can not find AssertStatement when I traverse this MethodDeclaratio and the final result is public void method10(int a){
assert a=2;
System.out.println("end");
}
I can not figure out what is the problem.
|
|
|
|
|
|
Re: AssertStatement parsing problem [message #1814644 is a reply to message #1814217] |
Sun, 15 September 2019 14:48  |
Eclipse User |
|
|
|
AST level defines which structure elements in the abstract syntax tree are available. This is a purely technical thing, by which plug-ins can decide their own pace in migrating to newer versions of JDT (supporting newer versions of Java).
For legality of source input only the compiler options COMPILER_SOURCE and COMPILER_COMPLIANCE are relevant.
|
|
|
Powered by
FUDForum. Page generated in 0.04614 seconds