use of com.github.javaparser.symbolsolver.model.resolution.Value 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.symbolsolver.model.resolution.Value in project javaparser by javaparser.
the class GenericsResolutionTest method resolveFieldOfGenericReferringToVariableType.
@Test
public void resolveFieldOfGenericReferringToVariableType() {
CompilationUnit cu = parseSample("Generics");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "SomeCollection");
VariableDeclarator field = Navigator.demandField(clazz, "as");
SymbolSolver symbolSolver = new SymbolSolver(new ReflectionTypeSolver());
Optional<Value> symbolReference = symbolSolver.solveSymbolAsValue("as", field);
assertEquals(true, symbolReference.isPresent());
assertEquals("as", symbolReference.get().getName());
ResolvedType type = symbolReference.get().getType();
assertEquals(false, type.isTypeVariable());
assertEquals("java.util.List<A>", type.describe());
assertEquals(1, type.asReferenceType().typeParametersValues().size());
ResolvedType typeParam = type.asReferenceType().typeParametersValues().get(0);
assertEquals(true, typeParam.isTypeVariable());
assertEquals("A", typeParam.describe());
}
use of com.github.javaparser.symbolsolver.model.resolution.Value in project javaparser by javaparser.
the class GenericsResolutionTest method resolveFieldOfVariableType.
@Test
public void resolveFieldOfVariableType() {
CompilationUnit cu = parseSample("Generics");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "SomeCollection");
VariableDeclarator field = Navigator.demandField(clazz, "a");
SymbolSolver symbolSolver = new SymbolSolver(new ReflectionTypeSolver());
Optional<Value> symbolReference = symbolSolver.solveSymbolAsValue("a", field);
assertEquals(true, symbolReference.isPresent());
assertEquals("a", symbolReference.get().getName());
ResolvedType type = symbolReference.get().getType();
assertEquals(true, type.isTypeVariable());
assertEquals("A", type.describe());
}
use of com.github.javaparser.symbolsolver.model.resolution.Value in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method solveSymbolAsValueReferringToDeclaredInstanceField.
@Test
public void solveSymbolAsValueReferringToDeclaredInstanceField() {
CompilationUnit cu = parseSample("ClassWithSymbols");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, 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.model.resolution.Value in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method solveSymbolAsValueReferringToUnknownElement.
@Test
public void solveSymbolAsValueReferringToUnknownElement() {
CompilationUnit cu = parseSample("ClassWithSymbols");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
Optional<Value> ref = context.solveSymbolAsValue("zzz", new MemoryTypeSolver());
assertEquals(false, ref.isPresent());
}
Aggregations