use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class EnumResolutionTest method switchOnEnum.
@Test
public void switchOnEnum() {
CompilationUnit cu = parseSample("SwitchOnEnum");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "SwitchOnEnum");
MethodDeclaration method = Navigator.demandMethod(clazz, "foo");
SwitchStmt switchStmt = Navigator.findSwitch(method);
Expression expression = switchStmt.getEntries().get(0).getLabel().get();
SymbolReference<? extends ResolvedValueDeclaration> ref = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
assertTrue(ref.isSolved());
assertEquals("SwitchOnEnum.MyEnum", ref.getCorrespondingDeclaration().getType().asReferenceType().getQualifiedName());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class GenericsResolutionTest method methodWithGenericParameterTypes.
@Test
public void methodWithGenericParameterTypes() {
CompilationUnit cu = parseSample("GenericCollectionWithExtension");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Foo");
MethodDeclaration method = Navigator.demandMethod(clazz, "bar");
MethodCallExpr methodCall = Navigator.findMethodCall(method, "foo").get();
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
MethodUsage methodUsage = javaParserFacade.solveMethodAsUsage(methodCall);
assertEquals("foo", methodUsage.getName());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class GenericsResolutionTest method resolveFieldWithGenericTypeToString.
@Test
public void resolveFieldWithGenericTypeToString() {
CompilationUnit cu = parseSample("Generics");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Generics");
VariableDeclarator fieldS = Navigator.demandField(clazz, "s");
SymbolSolver symbolSolver = new SymbolSolver(new ReflectionTypeSolver());
Optional<Value> symbolReference = symbolSolver.solveSymbolAsValue("s", fieldS);
assertEquals(true, symbolReference.isPresent());
assertEquals("s", symbolReference.get().getName());
ResolvedType type = symbolReference.get().getType();
assertEquals(1, type.asReferenceType().typeParametersValues().size());
assertEquals("java.lang.String", type.asReferenceType().typeParametersValues().get(0).describe());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class GenericsResolutionTest method resolveUsageOfGenericFieldIntermediateCase.
// PRIMA UN TEST CHE DICA CHE IL TIPO DEL CAMPO AS e' LIST<A> NON LIST<E>
@Test
public void resolveUsageOfGenericFieldIntermediateCase() {
CompilationUnit cu = parseSample("Generics");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "SomeCollection");
VariableDeclarator field = Navigator.demandField(clazz, "as");
ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver()).getType(field);
assertEquals(false, type.isTypeVariable());
assertEquals("java.util.List<A>", type.describe());
assertEquals(1, type.asReferenceType().typeParametersValues().size());
assertEquals(true, type.asReferenceType().typeParametersValues().get(0).isTypeVariable());
assertEquals("A", type.asReferenceType().typeParametersValues().get(0).describe());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class GenericsResolutionTest method typeParamOnReturnType.
@Test
public void typeParamOnReturnType() {
CompilationUnit cu = parseSample("TypeParamOnReturnType");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "TypeParamOnReturnType");
MethodDeclaration method = Navigator.demandMethod(clazz, "nodeEquals");
ReturnStmt returnStmt = Navigator.findReturnStmt(method);
ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver()).getType(returnStmt.getExpression().get());
assertEquals(false, type.isTypeVariable());
assertEquals("boolean", type.describe());
}
Aggregations