use of com.github.javaparser.ast.body.ClassOrInterfaceDeclaration in project javaparser by javaparser.
the class GenericsResolutionTest method typeParamOnReturnTypeStep1.
@Test
public void typeParamOnReturnTypeStep1() {
CompilationUnit cu = parseSample("TypeParamOnReturnType");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "TypeParamOnReturnType");
MethodDeclaration method = Navigator.demandMethod(clazz, "nodeEquals");
ThisExpr thisExpr = Navigator.findNodeOfGivenClass(method, ThisExpr.class);
ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver()).getType(thisExpr);
assertEquals(false, type.isTypeVariable());
assertEquals("TypeParamOnReturnType", type.describe());
}
use of com.github.javaparser.ast.body.ClassOrInterfaceDeclaration in project javaparser by javaparser.
the class GenericsResolutionTest method typeParamOnReturnTypeStep2.
@Test
public void typeParamOnReturnTypeStep2() {
CompilationUnit cu = parseSample("TypeParamOnReturnType");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "TypeParamOnReturnType");
MethodDeclaration method = Navigator.demandMethod(clazz, "nodeEquals");
NameExpr n1 = Navigator.findNameExpression(method, "n1").get();
ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver()).getType(n1);
assertEquals(true, type.isTypeVariable());
assertEquals("T", type.describe());
}
use of com.github.javaparser.ast.body.ClassOrInterfaceDeclaration in project javaparser by javaparser.
the class VariadicResolutionTest method resolveVariadicMethodWithGenericArgument.
@Test
public void resolveVariadicMethodWithGenericArgument() {
CompilationUnit cu = parseSample("MethodCalls");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MethodCalls");
MethodDeclaration method = Navigator.demandMethod(clazz, "genericMethodTest");
MethodCallExpr callExpr = Navigator.findMethodCall(method, "variadicWithGenericArg").get();
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
MethodUsage callee = javaParserFacade.solveMethodAsUsage(callExpr);
assertEquals("variadicWithGenericArg", callee.getName());
}
use of com.github.javaparser.ast.body.ClassOrInterfaceDeclaration in project javaparser by javaparser.
the class VariadicResolutionTest method issue7.
@Test
public void issue7() {
CompilationUnit cu = parseSample("Generics_issue7");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "SomeCollection");
MethodDeclaration method = Navigator.demandMethod(clazz, "foo3");
ReturnStmt stmt = (ReturnStmt) method.getBody().get().getStatements().get(0);
Expression expression = stmt.getExpression().get();
JavaParserFacade javaParserFacade = JavaParserFacade.get(new ReflectionTypeSolver());
ResolvedType type = javaParserFacade.getType(expression);
assertEquals(true, type.isReferenceType());
assertEquals(List.class.getCanonicalName(), type.asReferenceType().getQualifiedName());
assertEquals("java.util.List<java.lang.Long>", type.describe());
}
use of com.github.javaparser.ast.body.ClassOrInterfaceDeclaration in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method solveSymbolAsValueReferringToDeclaredInstanceField.
@Test
public void solveSymbolAsValueReferringToDeclaredInstanceField() {
CompilationUnit cu = parseSample("ClassWithSymbols");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
Optional<Value> ref = context.solveSymbolAsValue("i", new MemoryTypeSolver());
assertEquals(true, ref.isPresent());
assertEquals("int", ref.get().getType().describe());
}
Aggregations