use of com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade in project javaparser by javaparser.
the class LambdaResolutionTest method typeOfVoidLambda.
@Test
public void typeOfVoidLambda() {
CompilationUnit cu = parseSample("LambdaVoid");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Agenda");
MethodDeclaration method = Navigator.demandMethod(clazz, "lambdaEmpty");
ReturnStmt returnStmt = Navigator.findReturnStmt(method);
Expression expression = returnStmt.getExpression().get();
LambdaExpr lambdaExpr = Navigator.findNodeOfGivenClass(expression, LambdaExpr.class);
JavaParserFacade javaParserFacade = JavaParserFacade.get(new ReflectionTypeSolver());
ResolvedType type = javaParserFacade.getType(lambdaExpr);
assertEquals("void", type.describe());
}
use of com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade in project javaparser by javaparser.
the class JavaParserTypeParameterResolutionTest method declaredOnMethodPositiveCase.
@Test
public void declaredOnMethodPositiveCase() {
CompilationUnit cu = parseSample("MethodTypeParameter");
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
ClassOrInterfaceDeclaration classDecl = Navigator.demandClass(cu, "Foo");
MethodDeclaration methodDecl = Navigator.demandMethod(classDecl, "usage");
MethodCallExpr callToFoo = (MethodCallExpr) Navigator.findReturnStmt(methodDecl).getExpression().get();
ResolvedMethodDeclaration methodDeclaration = javaParserFacade.solve(callToFoo).getCorrespondingDeclaration();
for (ResolvedTypeParameterDeclaration tp : methodDeclaration.getTypeParameters()) {
assertTrue(tp instanceof JavaParserTypeParameter);
assertEquals("C", tp.getName());
assertEquals(true, tp.declaredOnMethod());
assertEquals(false, tp.declaredOnType());
}
}
use of com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade in project javaparser by javaparser.
the class Widget method main.
public static void main(String[] args) throws IOException, ParseException {
File src = new File(JAVA_ROOT);
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new ReflectionTypeSolver(true));
combinedTypeSolver.add(new JavaParserTypeSolver(src));
CompilationUnit compilationUnit = JavaParser.parse(new File(CLASS));
JavaParserFacade parserFacade = JavaParserFacade.get(combinedTypeSolver);
MethodDeclaration methodDeclaration = compilationUnit.getNodesByType(MethodDeclaration.class).stream().filter(node -> node.getName().equals("doSomething")).findAny().orElse(null);
methodDeclaration.getNodesByType(MethodCallExpr.class).forEach(parserFacade::solve);
}
use of com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade in project javaparser by javaparser.
the class Issue232 method issue232.
@Test
public void issue232() {
CompilationUnit cu = parseSample("Issue232");
ClassOrInterfaceDeclaration cls = Navigator.demandClassOrInterface(cu, "OfDouble");
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
Context context = JavaParserFactory.getContext(cls, typeSolver);
SymbolReference<ResolvedTypeDeclaration> reference = context.solveType("OfPrimitive<Double, DoubleConsumer, OfDouble>", typeSolver);
}
use of com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade in project javaparser by javaparser.
the class Issue251 method testSolveStaticallyImportedMemberType.
@Test
public void testSolveStaticallyImportedMemberType() {
CompilationUnit cu = parseSample("Issue251");
ClassOrInterfaceDeclaration cls = Navigator.demandClassOrInterface(cu, "Main");
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
MethodDeclaration m = Navigator.demandMethod(cls, "bar");
ExpressionStmt stmt = (ExpressionStmt) m.getBody().get().getStatements().get(1);
MethodCallExpr expression = (MethodCallExpr) stmt.getExpression();
Assert.assertNotNull(javaParserFacade.solve(expression));
}
Aggregations