use of com.github.javaparser.resolution.types.ResolvedType 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.resolution.types.ResolvedType in project javaparser by javaparser.
the class ArrayExprTest method verifyAnArrayAccessExprTypeIsCalculatedProperly.
@Test
public void verifyAnArrayAccessExprTypeIsCalculatedProperly() {
String code = "class A { String[] arrSQL; String toExamine = arrSQL[1]; }";
FieldDeclaration field = JavaParser.parse(code).getClassByName("A").get().getFieldByName("toExamine").get();
ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver()).getType(field.getVariables().get(0).getInitializer().get());
assertEquals(true, type.isReferenceType());
assertEquals("java.lang.String", type.asReferenceType().getQualifiedName());
}
use of com.github.javaparser.resolution.types.ResolvedType 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.resolution.types.ResolvedType in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method solveMethodWithPrimitiveParameters.
@Test
public void solveMethodWithPrimitiveParameters() {
CompilationUnit cu = parseSample("ClassWithMethods");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
ResolvedType intType = ResolvedPrimitiveType.INT;
SymbolReference<ResolvedMethodDeclaration> ref = context.solveMethod("foo3", ImmutableList.of(intType), false, new ReflectionTypeSolver());
assertEquals(true, ref.isSolved());
assertEquals("A", ref.getCorrespondingDeclaration().declaringType().getName());
assertEquals(1, ref.getCorrespondingDeclaration().getNumberOfParams());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method solveMethodAsUsageWithMoreSpecializedParameter.
@Test
public void solveMethodAsUsageWithMoreSpecializedParameter() {
CompilationUnit cu = parseSample("ClassWithMethods");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
ResolvedType stringType = new ReferenceTypeImpl(new ReflectionClassDeclaration(String.class, typeSolver), typeSolver);
Optional<MethodUsage> ref = context.solveMethodAsUsage("foo4", ImmutableList.of(stringType), new ReflectionTypeSolver());
assertEquals(true, ref.isPresent());
assertEquals("A", ref.get().declaringType().getName());
assertEquals(1, ref.get().getNoParams());
}
Aggregations