use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class ContextTest method resolveLambdaType.
@Test
public void resolveLambdaType() throws ParseException, IOException {
CompilationUnit cu = parseSample("Navigator");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Navigator");
MethodDeclaration method = Navigator.demandMethod(clazz, "findType");
MethodCallExpr callToFilter = Navigator.findMethodCall(method, "filter").get();
Expression lambdaExpr = callToFilter.getArguments().get(0);
String pathToJar = adaptPath("src/test/resources/javaparser-core-2.1.0.jar");
TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(), new JarTypeSolver(pathToJar));
ResolvedType typeOfLambdaExpr = JavaParserFacade.get(typeSolver).getType(lambdaExpr);
assertEquals("java.util.function.Predicate<? super com.github.javaparser.ast.body.TypeDeclaration>", typeOfLambdaExpr.describe());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class ContextTest method resolveInheritedMethodFromInterface.
@Test
public void resolveInheritedMethodFromInterface() {
CompilationUnit cu = parseSample("InterfaceInheritance");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Test");
MethodDeclaration method = Navigator.demandMethod(clazz, "test");
MethodCallExpr call = Navigator.findMethodCall(method, "foobar").get();
File src = adaptPath(new File("src/test/resources"));
TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(), new JavaParserTypeSolver(src));
ResolvedType type = JavaParserFacade.get(typeSolver).getType(call);
assertEquals("double", type.describe());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class EnumResolutionTest method enumAndStaticInitializer.
@Test
public void enumAndStaticInitializer() {
CompilationUnit cu = parseSample("EnumAndStaticInitializer");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MyClass");
MethodCallExpr call = Navigator.findMethodCall(clazz, "put").get();
ResolvedType ref = JavaParserFacade.get(new ReflectionTypeSolver()).getType(call);
assertEquals("MyClass.Primitive", ref.describe());
}
use of com.github.javaparser.resolution.types.ResolvedType 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.resolution.types.ResolvedType 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());
}
Aggregations