use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method solveMethodAsUsageWithPrimitiveParameters.
@Test
public void solveMethodAsUsageWithPrimitiveParameters() {
CompilationUnit cu = parseSample("ClassWithMethods");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
ResolvedType intType = ResolvedPrimitiveType.INT;
Optional<MethodUsage> ref = context.solveMethodAsUsage("foo3", ImmutableList.of(intType), new ReflectionTypeSolver());
assertEquals(true, ref.isPresent());
assertEquals("A", ref.get().declaringType().getName());
assertEquals(1, ref.get().getNoParams());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class CompilationUnitContextResolutionTest method solveExistingGenericType.
@Test
public void solveExistingGenericType() {
CompilationUnit cu = parseSample("ClassWithTypeVariables");
Context context = new CompilationUnitContext(cu, typeSolver);
Optional<ResolvedType> a = context.solveGenericType("A", new MemoryTypeSolver());
Optional<ResolvedType> b = context.solveGenericType("B", new MemoryTypeSolver());
Optional<ResolvedType> c = context.solveGenericType("C", new MemoryTypeSolver());
assertEquals(false, a.isPresent());
assertEquals(false, b.isPresent());
assertEquals(false, c.isPresent());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class JavaSymbolSolverTest method resolveArrayType.
@Test
public void resolveArrayType() {
TypeSolver typeSolver = new ReflectionTypeSolver();
CompilationUnit cu = parseSample("SymbolResolverExample");
new JavaSymbolSolver(typeSolver).inject(cu);
MethodDeclaration methodDeclaration = cu.getClassByName("A").get().getMethods().get(0);
ResolvedType resolvedType = methodDeclaration.getType().resolve();
assertEquals("A[]", resolvedType.describe());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class DefaultPackageTest method aClassInDefaultPackageCanBeAccessedFromOutsideTheDefaultPackageWithoutImportingIt.
@Test(expected = UnsolvedSymbolException.class)
public void aClassInDefaultPackageCanBeAccessedFromOutsideTheDefaultPackageWithoutImportingIt() {
String code = "package myPackage; class A extends B {}";
MemoryTypeSolver memoryTypeSolver = new MemoryTypeSolver();
memoryTypeSolver.addDeclaration("B", new MyClassDeclaration("B"));
ResolvedType resolvedType = JavaParserFacade.get(memoryTypeSolver).convertToUsage(JavaParser.parse(code).getClassByName("A").get().getExtendedTypes(0));
assertEquals("B", resolvedType.asReferenceType().getQualifiedName());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class JavaParserFacadeResolutionTest method solvingReferenceToAnAncestorInternalClass.
// See issue 47
@Test
public void solvingReferenceToAnAncestorInternalClass() {
String code = "public class Foo {\n" + " public class Base {\n" + " public class X {\n" + " }\n" + " }\n" + "\n" + " public class Derived extends Base {\n" + " public X x = null;\n" + " }\n" + "}";
FieldDeclaration fieldDeclaration = Navigator.findNodeOfGivenClass(JavaParser.parse(code), FieldDeclaration.class);
Type jpType = fieldDeclaration.getCommonType();
ResolvedType jssType = JavaParserFacade.get(new ReflectionTypeSolver()).convertToUsage(jpType);
assertEquals("Foo.Base.X", jssType.asReferenceType().getQualifiedName());
}
Aggregations