use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class GenericsResolutionTest method typeParamOnReturnTypeStep3.
@Test
public void typeParamOnReturnTypeStep3() {
CompilationUnit cu = parseSample("TypeParamOnReturnType");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "TypeParamOnReturnType");
MethodDeclaration method = Navigator.demandMethod(clazz, "nodeEquals");
MethodCallExpr call = Navigator.findMethodCall(method, "accept").get();
JavaParserFacade javaParserFacade = JavaParserFacade.get(new ReflectionTypeSolver());
ResolvedType type = javaParserFacade.getType(call);
assertEquals(false, type.isTypeVariable());
assertEquals("java.lang.Boolean", type.describe());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class GenericsResolutionTest method classCastScope.
@Test
public void classCastScope() {
CompilationUnit cu = parseSample("ClassCast");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "ClassCast");
MethodDeclaration method = Navigator.demandMethod(clazz, "getNodesByType");
MethodCallExpr call = Navigator.findMethodCall(method, "cast").get();
TypeSolver typeSolver = new ReflectionTypeSolver();
Expression scope = call.getScope().get();
ResolvedType type = JavaParserFacade.get(typeSolver).getType(scope);
// System.out.println(typeUsage);
assertEquals(false, type.isTypeVariable());
assertEquals("java.lang.Class<N>", type.describe());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class GenericsResolutionTest method classCast.
@Test
public void classCast() {
CompilationUnit cu = parseSample("ClassCast");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "ClassCast");
MethodDeclaration method = Navigator.demandMethod(clazz, "getNodesByType");
ReturnStmt returnStmt = Navigator.findReturnStmt(method);
ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver()).getType(returnStmt.getExpression().get());
assertEquals(true, type.isTypeVariable());
assertEquals("N", type.describe());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver 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.symbolsolver.resolution.typesolvers.ReflectionTypeSolver 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());
}
Aggregations