use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class ReflectionMethodDeclarationTest method testGetSignature.
@Test
public void testGetSignature() {
TypeSolver typeResolver = new ReflectionTypeSolver();
ResolvedClassDeclaration object = new ReflectionClassDeclaration(Object.class, typeResolver);
ResolvedInterfaceDeclaration list = new ReflectionInterfaceDeclaration(List.class, typeResolver);
ResolvedMethodDeclaration hashCode = object.getAllMethods().stream().filter(m -> m.getName().equals("hashCode")).findFirst().get().getDeclaration();
ResolvedMethodDeclaration equals = object.getAllMethods().stream().filter(m -> m.getName().equals("equals")).findFirst().get().getDeclaration();
ResolvedMethodDeclaration containsAll = list.getAllMethods().stream().filter(m -> m.getName().equals("containsAll")).findFirst().get().getDeclaration();
ResolvedMethodDeclaration subList = list.getAllMethods().stream().filter(m -> m.getName().equals("subList")).findFirst().get().getDeclaration();
assertEquals("hashCode()", hashCode.getSignature());
assertEquals("equals(java.lang.Object)", equals.getSignature());
assertEquals("containsAll(java.util.Collection<? extends java.lang.Object>)", containsAll.getSignature());
assertEquals("subList(int, int)", subList.getSignature());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class AnalyseJavaParserTest method getSourceFileInfoExtractor.
private SourceFileInfoExtractor getSourceFileInfoExtractor() {
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"))));
SourceFileInfoExtractor sourceFileInfoExtractor = new SourceFileInfoExtractor();
sourceFileInfoExtractor.setTypeSolver(combinedTypeSolver);
sourceFileInfoExtractor.setPrintFileName(false);
return sourceFileInfoExtractor;
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class AnalyseNewJavaParserHelpersTest method typeSolver.
private static TypeSolver typeSolver() {
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_new_src/javaparser-generated-sources"))));
return combinedTypeSolver;
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class ArrayExprTest method verifyAnArrayAccessExprTypeIsCalculatedProperly.
@Test
public void verifyAnArrayAccessExprTypeIsCalculatedProperly() {
String code = "class A { String[] arrSQL; String toExamine = arrSQL[1]; }";
FieldDeclaration field = JavaParser.parse(code).getClassByName("A").get().getFieldByName("toExamine").get();
ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver()).getType(field.getVariables().get(0).getInitializer().get());
assertEquals(true, type.isReferenceType());
assertEquals("java.lang.String", type.asReferenceType().getQualifiedName());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class VariadicResolutionTest method resolveVariadicMethodWithGenericArgument.
@Test
public void resolveVariadicMethodWithGenericArgument() {
CompilationUnit cu = parseSample("MethodCalls");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MethodCalls");
MethodDeclaration method = Navigator.demandMethod(clazz, "genericMethodTest");
MethodCallExpr callExpr = Navigator.findMethodCall(method, "variadicWithGenericArg").get();
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
MethodUsage callee = javaParserFacade.solveMethodAsUsage(callExpr);
assertEquals("variadicWithGenericArg", callee.getName());
}
Aggregations