You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public static void main(String[] args) throws IOException {
String code = """
import java.util.ArrayList;
import java.util.List;
public class Lambda {
interface MyInterface {
void doSomething(int a);
}
void test(){
MyInterface myInterface;
ArrayList<Integer> list = new ArrayList<>();
list.forEach(val -> System.out.println(val));
myInterface = arg -> System.out.println(arg);
}
}
""";
JavaParser javaParser = new JavaParser();
TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver());
JavaSymbolSolver symbolSolver = new JavaSymbolSolver(typeSolver);
javaParser.getParserConfiguration().setSymbolResolver(symbolSolver);
javaParser.getParserConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_17);
ParseResult<CompilationUnit> result = javaParser.parse(code);
ModifierVisitor<Void> visit = new ModifierVisitor<>(){
public Visitable visit(MethodCallExpr n, Void arg) {
ResolvedMethodDeclaration resolve = n.resolve();
System.out.println(resolve.getQualifiedSignature());
return super.visit(n, arg);
}
};
visit.visit(result.getResult().get(), null);
System.out.println(result.getResult().get());
}
Hi, I'm trying to get the QualifiedSignature of MethodCallExpr but I'm getting a parsing error when MethodCallEcpr is in the lambda expression. In the above example, the lambda in the foreach does not give an error, but when it is used as the value of the assignment statement, the following error occurs. Is my usage wrong? Thank you.
Exception in thread "main" java.lang.UnsupportedOperationException: Unknown node type: AssignExpr
at com.github.javaparser.symbolsolver.javaparsermodel.contexts.LambdaExprContext.solveSymbolAsValue(LambdaExprContext.java:198)
at com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserParameterDeclaration.getType(JavaParserParameterDeclaration.java:63)
at com.github.javaparser.resolution.model.Value.from(Value.java:45)
at com.github.javaparser.resolution.Context.solveSymbolAsValueInParentContext(Context.java:199)
at com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext.solveSymbolAsValue(MethodCallExprContext.java:145)
at com.github.javaparser.symbolsolver.resolution.SymbolSolver.solveSymbolAsValue(SymbolSolver.java:76)
at com.github.javaparser.symbolsolver.resolution.SymbolSolver.solveSymbolAsValue(SymbolSolver.java:82)
at com.github.javaparser.symbolsolver.javaparsermodel.TypeExtractor.visit(TypeExtractor.java:334)
at com.github.javaparser.symbolsolver.javaparsermodel.TypeExtractor.visit(TypeExtractor.java:64)
at com.github.javaparser.ast.expr.NameExpr.accept(NameExpr.java:81)
The text was updated successfully, but these errors were encountered:
This is not trivial, because to resolve the println(..) method Javaparser has to resolve the type of the parameter, which is undefined at this stage. I don't see any precision on this point in the JLS. If you can clarify what needs to be done, I can try to resolve this bug quickly.
Hi, I'm trying to get the QualifiedSignature of MethodCallExpr but I'm getting a parsing error when MethodCallEcpr is in the lambda expression. In the above example, the lambda in the foreach does not give an error, but when it is used as the value of the assignment statement, the following error occurs. Is my usage wrong? Thank you.
The text was updated successfully, but these errors were encountered: