use of com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver 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.symbolsolver.resolution.typesolvers.MemoryTypeSolver in project javaparser by javaparser.
the class EnumDeclarationContextResolutionTest method solveSymbolAsValueReferringToDeclaredInstanceField.
@Test
public void solveSymbolAsValueReferringToDeclaredInstanceField() {
CompilationUnit cu = parseSample("AnEnum");
com.github.javaparser.ast.body.EnumDeclaration enumDeclaration = Navigator.demandEnum(cu, "MyEnum");
Context context = new EnumDeclarationContext(enumDeclaration, typeSolver);
Optional<Value> ref = context.solveSymbolAsValue("i", new MemoryTypeSolver());
assertEquals(true, ref.isPresent());
assertEquals("int", ref.get().getType().describe());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver 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.symbolsolver.resolution.typesolvers.MemoryTypeSolver 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.symbolsolver.resolution.typesolvers.MemoryTypeSolver in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method solveSymbolReferringToInterfaceInheritedInstanceField.
@Test
public void solveSymbolReferringToInterfaceInheritedInstanceField() {
CompilationUnit cu = parseSample("ClassWithSymbols");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
SymbolReference<? extends ResolvedValueDeclaration> ref = context.solveSymbol("o", new MemoryTypeSolver());
assertEquals(true, ref.isSolved());
assertEquals("int", ref.getCorrespondingDeclaration().getType().describe());
}
Aggregations