问题
I am using the Eclipse JDT AST Parser (3.10.0) to parse various source code Files.
This is how i initalize the parser:
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setBindingsRecovery(true);
parser.setResolveBindings(true);
parser.setStatementsRecovery(true);
parser.setSource(source.toCharArray());
parser.setUnitName(filename);
parser.setEnvironment(classPath.toArray(new String[classPath.size()]), sources, new String[]{"UTF-8"}, true);
final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
The classpath is created by maven dependency plugin.
This works very well for most Expressions, but it seems to have problems with lambda Expressions
Optional<Address> first = adr.stream().filter(
a -> a.getId().longValue() == contactAddress.getAddressId().longValue()
).findFirst();
Evaluating both sides of the comparison each type resolves to null. Parsing the same code without the surrounding lambda Expression results in long on each side.
Is there any way to as well resolve bindngs in lambda Expressions?
来源:https://stackoverflow.com/questions/39452906/eclipse-jdt-ast-parser-does-not-resolve-type-in-java-lambda-expression