use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class LambdaResolutionTest method lambdaBlockExplicitReturn.
@Test
public void lambdaBlockExplicitReturn() {
CompilationUnit cu = parseSample("LambdaMulti");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Agenda");
MethodDeclaration method = Navigator.demandMethod(clazz, "lambdaSingleReturn");
ReturnStmt returnStmt = Navigator.findReturnStmt(method);
Expression expression = returnStmt.getExpression().get();
JavaParserFacade javaParserFacade = JavaParserFacade.get(new ReflectionTypeSolver());
ResolvedType type = javaParserFacade.getType(expression);
assertEquals("java.lang.String", type.describe());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class LambdaResolutionTest method lambdaMap.
@Test
public void lambdaMap() {
CompilationUnit cu = parseSample("Lambda");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Agenda");
MethodDeclaration m1 = Navigator.demandMethod(clazz, "lambdaMap");
MethodDeclaration m2 = Navigator.demandMethod(clazz, "lambdaMap2");
ReturnStmt returnStmt1 = Navigator.findReturnStmt(m1);
ReturnStmt returnStmt2 = Navigator.findReturnStmt(m2);
Expression e1 = returnStmt1.getExpression().get();
Expression e2 = returnStmt2.getExpression().get();
JavaParserFacade javaParserFacade = JavaParserFacade.get(new ReflectionTypeSolver());
ResolvedType type1 = javaParserFacade.getType(e1);
ResolvedType type2 = javaParserFacade.getType(e2);
assertEquals("java.util.stream.Stream<java.lang.String>", type1.describe());
assertEquals("java.util.stream.Stream<java.util.stream.IntStream>", type2.describe());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class LambdaResolutionTest method lambdaBlockMultiLineReturn.
@Test
public void lambdaBlockMultiLineReturn() {
CompilationUnit cu = parseSample("LambdaMulti");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Agenda");
MethodDeclaration method = Navigator.demandMethod(clazz, "multiLineReturn");
ReturnStmt returnStmt = Navigator.findReturnStmt(method);
Expression expression = returnStmt.getExpression().get();
JavaParserFacade javaParserFacade = JavaParserFacade.get(new ReflectionTypeSolver());
ResolvedType type = javaParserFacade.getType(expression);
assertEquals("java.lang.String", type.describe());
}
use of com.github.javaparser.resolution.types.ResolvedType 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.resolution.types.ResolvedType in project javaparser by javaparser.
the class MethodsResolutionTest method solveMethodAccessThroughSuper.
@Test
public void solveMethodAccessThroughSuper() {
CompilationUnit cu = parseSample("AccessThroughSuper");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "AccessThroughSuper.SubClass");
MethodDeclaration method = Navigator.demandMethod(clazz, "methodTest");
ReturnStmt returnStmt = (ReturnStmt) method.getBody().get().getStatements().get(0);
Expression expression = returnStmt.getExpression().get();
ResolvedType ref = JavaParserFacade.get(new ReflectionTypeSolver()).getType(expression);
assertEquals("java.lang.String", ref.describe());
}
Aggregations