use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver 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.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class JavaSymbolSolverTest method resolveMethodDeclaration.
@Test
public void resolveMethodDeclaration() {
TypeSolver typeSolver = new ReflectionTypeSolver();
CompilationUnit cu = parseSample("SymbolResolverExample");
new JavaSymbolSolver(typeSolver).inject(cu);
MethodDeclaration methodDeclaration = cu.getClassByName("A").get().getMethods().get(0);
ResolvedMethodDeclaration resolvedMethodDeclaration = methodDeclaration.resolve();
assertEquals("foo", resolvedMethodDeclaration.getName());
assertEquals("A[]", resolvedMethodDeclaration.getReturnType().describe());
assertEquals("java.lang.String[]", resolvedMethodDeclaration.getParam(0).getType().describe());
assertEquals("int[]", resolvedMethodDeclaration.getParam(1).getType().describe());
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class JavaParserClassDeclarationTest method testHasDirectlyAnnotation.
// /
// / Assignability
// /
// boolean isAssignableBy(Type type);
// boolean canBeAssignedTo(TypeDeclaration other)
// boolean isAssignableBy(TypeDeclaration other);
// /
// / Annotations
// /
// hasDirectlyAnnotation
@Test
public void testHasDirectlyAnnotation() throws IOException, ParseException {
TypeSolver typeSolver = new ReflectionTypeSolver();
CompilationUnit cu = JavaParser.parse(adaptPath(new File("src/test/resources/Annotations.java.txt")));
JavaParserClassDeclaration ca = new JavaParserClassDeclaration(Navigator.demandClass(cu, "CA"), typeSolver);
assertEquals(true, ca.hasDirectlyAnnotation("foo.bar.MyAnnotation"));
assertEquals(false, ca.hasDirectlyAnnotation("foo.bar.MyAnnotation2"));
assertEquals(false, ca.hasDirectlyAnnotation("MyAnnotation"));
assertEquals(false, ca.hasDirectlyAnnotation("foo.bar.MyUnexistingAnnotation"));
JavaParserClassDeclaration cb = new JavaParserClassDeclaration(Navigator.demandClass(cu, "CB"), typeSolver);
assertEquals(false, cb.hasDirectlyAnnotation("foo.bar.MyAnnotation"));
assertEquals(true, cb.hasDirectlyAnnotation("foo.bar.MyAnnotation2"));
assertEquals(false, cb.hasDirectlyAnnotation("MyAnnotation"));
assertEquals(false, cb.hasDirectlyAnnotation("foo.bar.MyUnexistingAnnotation"));
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class JavaParserClassDeclarationTest method setup.
@Before
public void setup() {
File src = adaptPath(new File("src/test/test_sourcecode/javaparser_src/proper_source"));
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new ReflectionTypeSolver());
combinedTypeSolver.add(new JavaParserTypeSolver(src));
combinedTypeSolver.add(new JavaParserTypeSolver(adaptPath(new File("src/test/test_sourcecode/javaparser_src/generated"))));
typeSolver = combinedTypeSolver;
File srcNewCode = adaptPath(new File("src/test/test_sourcecode/javaparser_new_src/javaparser-core"));
CombinedTypeSolver combinedTypeSolverNewCode = new CombinedTypeSolver();
combinedTypeSolverNewCode.add(new ReflectionTypeSolver());
combinedTypeSolverNewCode.add(new JavaParserTypeSolver(srcNewCode));
combinedTypeSolverNewCode.add(new JavaParserTypeSolver(adaptPath(new File("src/test/test_sourcecode/javaparser_new_src/javaparser-generated-sources"))));
typeSolverNewCode = combinedTypeSolverNewCode;
TypeSolver ts = new ReflectionTypeSolver();
string = new ReferenceTypeImpl(ts.solveType(String.class.getCanonicalName()), ts);
ResolvedReferenceType booleanC = new ReferenceTypeImpl(ts.solveType(Boolean.class.getCanonicalName()), ts);
listOfBoolean = new ReferenceTypeImpl(ts.solveType(List.class.getCanonicalName()), ImmutableList.of(booleanC), ts);
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class JavaParserClassDeclarationTest method testGetAllGenericFields.
@Test
public void testGetAllGenericFields() throws IOException, ParseException {
TypeSolver typeSolver = new ReflectionTypeSolver();
CompilationUnit cu = JavaParser.parse(adaptPath(new File("src/test/resources/GenericFields.java.txt")));
JavaParserClassDeclaration classDeclaration = new JavaParserClassDeclaration(Navigator.demandClass(cu, "CB"), typeSolver);
assertEquals(3, classDeclaration.getAllFields().size());
ReferenceTypeImpl rtClassDeclaration = new ReferenceTypeImpl(classDeclaration, typeSolver);
assertEquals("s", classDeclaration.getAllFields().get(0).getName());
assertEquals(string, classDeclaration.getAllFields().get(0).getType());
assertEquals(string, rtClassDeclaration.getFieldType("s").get());
assertEquals("t", classDeclaration.getAllFields().get(1).getName());
assertEquals("java.util.List<java.lang.Boolean>", classDeclaration.getAllFields().get(1).getType().describe());
assertEquals(listOfBoolean, rtClassDeclaration.getFieldType("t").get());
assertEquals("i", classDeclaration.getAllFields().get(2).getName());
assertEquals(ResolvedPrimitiveType.INT, classDeclaration.getAllFields().get(2).getType());
assertEquals(ResolvedPrimitiveType.INT, rtClassDeclaration.getFieldType("i").get());
}
Aggregations