use of com.github.javaparser.symbolsolver.model.resolution.Value in project javaparser by javaparser.
the class CompilationUnitContextResolutionTest method solveSymbolAsValueReferringToStaticallyImportedValue.
@Test
public void solveSymbolAsValueReferringToStaticallyImportedValue() throws ParseException, IOException {
CompilationUnit cu = parseSample("CompilationUnitSymbols");
Context context = new CompilationUnitContext(cu, typeSolver);
CombinedTypeSolver typeSolver = new CombinedTypeSolver();
typeSolver.add(new ReflectionTypeSolver());
typeSolver.add(new JarTypeSolver(adaptPath("src/test/resources/junit-4.8.1.jar")));
Optional<Value> ref = context.solveSymbolAsValue("out", typeSolver);
assertEquals(true, ref.isPresent());
assertEquals("java.io.PrintStream", ref.get().getType().describe());
}
use of com.github.javaparser.symbolsolver.model.resolution.Value in project javaparser by javaparser.
the class EnumDeclarationContextResolutionTest method solveSymbolAsValueReferringToValue.
@Test
public void solveSymbolAsValueReferringToValue() {
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("E1", new MemoryTypeSolver());
assertEquals(true, ref.isPresent());
assertEquals("MyEnum", ref.get().getType().describe());
}
use of com.github.javaparser.symbolsolver.model.resolution.Value in project javaparser by javaparser.
the class EnumDeclarationContextResolutionTest method solveSymbolAsValueReferringToDeclaredStaticField.
@Test
public void solveSymbolAsValueReferringToDeclaredStaticField() {
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("j", new MemoryTypeSolver());
assertEquals(true, ref.isPresent());
assertEquals("long", ref.get().getType().describe());
}
use of com.github.javaparser.symbolsolver.model.resolution.Value in project javaparser by javaparser.
the class GenericsResolutionTest method resolveFieldWithGenericTypeToInteger.
@Test
public void resolveFieldWithGenericTypeToInteger() {
CompilationUnit cu = parseSample("Generics");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Generics");
VariableDeclarator fieldS = Navigator.demandField(clazz, "i");
SymbolSolver symbolSolver = new SymbolSolver(new ReflectionTypeSolver());
Optional<Value> symbolReference = symbolSolver.solveSymbolAsValue("i", fieldS);
assertEquals(true, symbolReference.isPresent());
assertEquals("i", symbolReference.get().getName());
ResolvedType type = symbolReference.get().getType();
assertEquals(1, type.asReferenceType().typeParametersValues().size());
assertEquals("java.lang.Integer", type.asReferenceType().typeParametersValues().get(0).describe());
}
use of com.github.javaparser.symbolsolver.model.resolution.Value in project javaparser by javaparser.
the class GenericsResolutionTest method resolveFieldWithGenericTypeToDeclaredClass.
@Test
public void resolveFieldWithGenericTypeToDeclaredClass() {
CompilationUnit cu = parseSample("Generics");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Generics");
VariableDeclarator fieldS = Navigator.demandField(clazz, "g");
SymbolSolver symbolSolver = new SymbolSolver(new ReflectionTypeSolver());
Optional<Value> symbolReference = symbolSolver.solveSymbolAsValue("g", fieldS);
assertEquals(true, symbolReference.isPresent());
assertEquals("g", symbolReference.get().getName());
ResolvedType type = symbolReference.get().getType();
assertEquals(1, type.asReferenceType().typeParametersValues().size());
assertEquals("me.tomassetti.symbolsolver.javaparser.Generics", type.asReferenceType().typeParametersValues().get(0).describe());
}
Aggregations