Eclipse JDT AST Parser does not resolve type in Java lambda Expression

落爺英雄遲暮 提交于 2019-12-08 05:34:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!