use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class FieldsResolutionTest method accessClassFieldThroughThis.
@Test
public void accessClassFieldThroughThis() {
CompilationUnit cu = parseSample("AccessClassMemberThroughThis");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "AccessClassMemberThroughThis");
MethodDeclaration method = Navigator.demandMethod(clazz, "getLabel2");
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());
}
use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class FieldsResolutionTest method accessEnumMethodThroughThis.
@Test
public void accessEnumMethodThroughThis() {
CompilationUnit cu = parseSample("AccessEnumMemberThroughThis");
com.github.javaparser.ast.body.EnumDeclaration enumDecl = Navigator.demandEnum(cu, "AccessEnumMemberThroughThis");
MethodDeclaration method = Navigator.demandMethod(enumDecl, "getLabel2");
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());
}
use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class FieldsResolutionTest method accessEnumFieldThroughThis.
@Test
public void accessEnumFieldThroughThis() {
CompilationUnit cu = parseSample("AccessEnumMemberThroughThis");
com.github.javaparser.ast.body.EnumDeclaration enumDecl = Navigator.demandEnum(cu, "AccessEnumMemberThroughThis");
MethodDeclaration method = Navigator.demandMethod(enumDecl, "getLabel");
SimpleName expression = Navigator.findSimpleName(method, "label").get();
SymbolReference ref = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
assertTrue(ref.isSolved());
assertEquals("label", ref.getCorrespondingDeclaration().getName());
}
use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class FieldsResolutionTest method accessFieldThroughSuper.
@Test
public void accessFieldThroughSuper() {
CompilationUnit cu = parseSample("AccessThroughSuper");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "AccessThroughSuper.SubClass");
MethodDeclaration method = Navigator.demandMethod(clazz, "fieldTest");
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());
}
use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class LambdaResolutionTest method lambdaReduce.
@Test
public void lambdaReduce() {
CompilationUnit cu = parseSample("Lambda");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Agenda");
MethodDeclaration method = Navigator.demandMethod(clazz, "reduce");
ReturnStmt returnStmt = Navigator.findReturnStmt(method);
Expression expr = returnStmt.getExpression().get();
JavaParserFacade javaParserFacade = JavaParserFacade.get(new ReflectionTypeSolver());
ResolvedType type1 = javaParserFacade.getType(expr);
assertEquals("java.util.Optional<java.lang.Integer>", type1.describe());
}
Aggregations