use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class CompilationUnitContextResolutionTest method solveUnexistingGenericType.
@Test
public void solveUnexistingGenericType() {
CompilationUnit cu = parseSample("ClassWithTypeVariables");
Context context = new CompilationUnitContext(cu, typeSolver);
Optional<ResolvedType> d = context.solveGenericType("D", new MemoryTypeSolver());
assertEquals(false, d.isPresent());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class DefaultPackageTest method aClassInDefaultPackageCanBeAccessedFromOutsideTheDefaultPackageImportingIt.
@Test(expected = UnsolvedSymbolException.class)
public void aClassInDefaultPackageCanBeAccessedFromOutsideTheDefaultPackageImportingIt() {
String code = "package myPackage; import B; class A extends B {}";
MemoryTypeSolver memoryTypeSolver = new MemoryTypeSolver();
memoryTypeSolver.addDeclaration("B", new MyClassDeclaration("B"));
ClassOrInterfaceType jpType = JavaParser.parse(code).getClassByName("A").get().getExtendedTypes(0);
ResolvedType resolvedType = JavaParserFacade.get(memoryTypeSolver).convertToUsage(jpType);
assertEquals("B", resolvedType.asReferenceType().getQualifiedName());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class DefaultPackageTest method aClassInDefaultPackageCanBeAccessedFromTheDefaultPackage.
@Test
public void aClassInDefaultPackageCanBeAccessedFromTheDefaultPackage() {
String code = "class A extends B {}";
MemoryTypeSolver memoryTypeSolver = new MemoryTypeSolver();
memoryTypeSolver.addDeclaration("B", new MyClassDeclaration("B"));
ClassOrInterfaceType jpType = JavaParser.parse(code).getClassByName("A").get().getExtendedTypes(0);
ResolvedType resolvedType = JavaParserFacade.get(memoryTypeSolver).convertToUsage(jpType);
assertEquals("B", resolvedType.asReferenceType().getQualifiedName());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class FieldsResolutionTest method accessClassFieldThroughThis.
@Test
public void accessClassFieldThroughThis() {
CompilationUnit cu = parseSample("AccessClassMemberThroughThis");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "AccessClassMemberThroughThis");
MethodDeclaration method = Navigator.demandMethod(clazz, "getLabel2");
ReturnStmt returnStmt = (ReturnStmt) method.getBody().get().getStatements().get(0);
Expression expression = returnStmt.getExpression().get();
ResolvedType ref = JavaParserFacade.get(new ReflectionTypeSolver()).getType(expression);
assertEquals("java.lang.String", ref.describe());
}
use of com.github.javaparser.resolution.types.ResolvedType in project javaparser by javaparser.
the class FieldsResolutionTest method accessEnumMethodThroughThis.
@Test
public void accessEnumMethodThroughThis() {
CompilationUnit cu = parseSample("AccessEnumMemberThroughThis");
com.github.javaparser.ast.body.EnumDeclaration enumDecl = Navigator.demandEnum(cu, "AccessEnumMemberThroughThis");
MethodDeclaration method = Navigator.demandMethod(enumDecl, "getLabel2");
ReturnStmt returnStmt = (ReturnStmt) method.getBody().get().getStatements().get(0);
Expression expression = returnStmt.getExpression().get();
ResolvedType ref = JavaParserFacade.get(new ReflectionTypeSolver()).getType(expression);
assertEquals("java.lang.String", ref.describe());
}
Aggregations