use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class ReflectionClassDeclarationTest method testGetAllInterfaces.
@Test
public void testGetAllInterfaces() {
TypeSolver typeResolver = new ReflectionTypeSolver();
ResolvedClassDeclaration arraylist = new ReflectionClassDeclaration(ArrayList.class, typeResolver);
// Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess
assertEquals(ImmutableSet.of(Serializable.class.getCanonicalName(), Cloneable.class.getCanonicalName(), List.class.getCanonicalName(), RandomAccess.class.getCanonicalName(), Collection.class.getCanonicalName(), Iterable.class.getCanonicalName()), arraylist.getAllInterfaces().stream().map(i -> i.getQualifiedName()).collect(Collectors.toSet()));
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class ReflectionClassDeclarationTest method testGetSuperclassSimpleImplicit.
@Test
public void testGetSuperclassSimpleImplicit() {
class Foo<E> {
E field;
}
TypeSolver typeResolver = new ReflectionTypeSolver();
ResolvedClassDeclaration foo = new ReflectionClassDeclaration(Foo.class, typeResolver);
assertEquals(Object.class.getCanonicalName(), foo.getSuperClass().getQualifiedName());
assertEquals(Collections.emptyList(), foo.getSuperClass().typeParametersValues());
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class Issue1364 method setup.
@Before
public void setup() {
ClassOrInterfaceDeclaration fakeObject = new ClassOrInterfaceDeclaration();
fakeObject.setName(new SimpleName("java.lang.Object"));
TypeSolver typeSolver = new TypeSolver() {
@Override
public TypeSolver getParent() {
return null;
}
@Override
public void setParent(TypeSolver parent) {
}
@Override
public SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveType(String name) {
if ("java.lang.Object".equals(name)) {
// custom handling
return SymbolReference.solved(new JavaParserClassDeclaration(fakeObject, this));
}
return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class);
}
};
ParserConfiguration config = new ParserConfiguration();
config.setSymbolResolver(new JavaSymbolSolver(typeSolver));
javaParser = new JavaParser(config);
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class Issue186 method lambdaPrimitivesIssue.
@Test
public void lambdaPrimitivesIssue() {
CompilationUnit cu = parseSample("Issue186");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "JavaTest");
MethodDeclaration methodDeclaration = Navigator.demandMethod(clazz, "bar");
List<LambdaExpr> lambdas = methodDeclaration.findAll(LambdaExpr.class);
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
assertEquals("java.util.function.Predicate<? super java.lang.String>", javaParserFacade.getType(lambdas.get(0)).describe());
assertEquals("java.util.function.Function<? super java.lang.String, ? extends java.lang.Integer>", javaParserFacade.getType(lambdas.get(1)).describe());
assertEquals("java.util.function.Predicate<? super java.lang.Integer>", javaParserFacade.getType(lambdas.get(2)).describe());
}
use of com.github.javaparser.symbolsolver.model.resolution.TypeSolver in project javaparser by javaparser.
the class Issue200 method issue200.
@Test
public void issue200() {
CompilationUnit cu = parseSample("Issue200");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "JavaTest");
MethodDeclaration methodDeclaration = Navigator.demandMethod(clazz, "foo");
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
List<ReturnStmt> nodesByType = methodDeclaration.findAll(ReturnStmt.class);
assertEquals("java.util.stream.Stream<JavaTest.Solved>", javaParserFacade.getType((nodesByType.get(0)).getExpression().get()).describe());
}
Aggregations