use of com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration in project javaparser by javaparser.
the class CompilationUnitContextResolutionTest method solveMethodStaticallyImportedWithAsterisk.
@Test
public void solveMethodStaticallyImportedWithAsterisk() throws ParseException, IOException {
CompilationUnit cu = parseSample("CompilationUnitWithImports");
Context context = new CompilationUnitContext(cu, typeSolver);
CombinedTypeSolver typeSolver = new CombinedTypeSolver();
typeSolver.add(new JarTypeSolver(adaptPath("src/test/resources/junit-4.8.1.jar")));
typeSolver.add(new ReflectionTypeSolver());
SymbolReference<ResolvedMethodDeclaration> ref = context.solveMethod("assertFalse", ImmutableList.of(ResolvedPrimitiveType.BOOLEAN), false, typeSolver);
assertEquals(true, ref.isSolved());
assertEquals("assertFalse", ref.getCorrespondingDeclaration().getName());
assertEquals(1, ref.getCorrespondingDeclaration().getNumberOfParams());
assertEquals("boolean", ref.getCorrespondingDeclaration().getParam(0).getType().describe());
assertEquals(true, ref.getCorrespondingDeclaration().getParam(0).getType().isPrimitive());
}
use of com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration in project javaparser by javaparser.
the class CompilationUnitContextResolutionTest method solveMethodStaticallyImportedWithoutAsterisk.
@Test
public void solveMethodStaticallyImportedWithoutAsterisk() throws ParseException, IOException {
CompilationUnit cu = parseSample("CompilationUnitSymbols");
Context context = new CompilationUnitContext(cu, typeSolver);
CombinedTypeSolver typeSolver = new CombinedTypeSolver();
typeSolver.add(new JarTypeSolver(adaptPath("src/test/resources/junit-4.8.1.jar")));
typeSolver.add(new ReflectionTypeSolver());
SymbolReference<ResolvedMethodDeclaration> ref = context.solveMethod("assertEquals", ImmutableList.of(NullType.INSTANCE, NullType.INSTANCE), false, typeSolver);
assertEquals(true, ref.isSolved());
assertEquals("assertEquals", ref.getCorrespondingDeclaration().getName());
assertEquals(2, ref.getCorrespondingDeclaration().getNumberOfParams());
assertEquals("java.lang.Object", ref.getCorrespondingDeclaration().getParam(0).getType().asReferenceType().getQualifiedName());
assertEquals("java.lang.Object", ref.getCorrespondingDeclaration().getParam(1).getType().asReferenceType().getQualifiedName());
}
use of com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration 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.resolution.declarations.ResolvedMethodDeclaration in project javaparser by javaparser.
the class MethodsResolutionTest method solveMethodWithTypePromotionsToByteWithExtraParam.
@Test
public void solveMethodWithTypePromotionsToByteWithExtraParam() {
CompilationUnit cu = parseSample("Issue338");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "TypePromotionsWithExtraParam");
MethodDeclaration method = Navigator.demandMethod(clazz, "callingByte");
{
MethodCallExpr expression = method.getBody().get().getStatements().get(0).asExpressionStmt().getExpression().asMethodCallExpr();
SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
assertEquals(true, reference.isSolved());
assertEquals("byteParam", reference.getCorrespondingDeclaration().getName());
}
{
MethodCallExpr expression = method.getBody().get().getStatements().get(1).asExpressionStmt().getExpression().asMethodCallExpr();
SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
assertEquals(false, reference.isSolved());
}
{
MethodCallExpr expression = method.getBody().get().getStatements().get(2).asExpressionStmt().getExpression().asMethodCallExpr();
SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
assertEquals(false, reference.isSolved());
}
{
MethodCallExpr expression = method.getBody().get().getStatements().get(3).asExpressionStmt().getExpression().asMethodCallExpr();
SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
assertEquals(false, reference.isSolved());
}
}
use of com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration in project javaparser by javaparser.
the class ReflectionMethodDeclarationTest method testGetGenericParameters.
@Test
public void testGetGenericParameters() {
TypeSolver typeResolver = new ReflectionTypeSolver();
ResolvedInterfaceDeclaration map = new ReflectionInterfaceDeclaration(Map.class, typeResolver);
ResolvedMethodDeclaration put = map.getAllMethods().stream().filter(m -> m.getName().equals("put")).findFirst().get().getDeclaration();
assertEquals(true, put.getParam(0).getType().isTypeVariable());
assertEquals(true, put.getParam(0).getType().asTypeParameter().declaredOnType());
assertEquals("java.util.Map.K", put.getParam(0).getType().asTypeParameter().getQualifiedName());
assertEquals(true, put.getParam(1).getType().isTypeVariable());
assertEquals(true, put.getParam(1).getType().asTypeParameter().declaredOnType());
assertEquals("java.util.Map.V", put.getParam(1).getType().asTypeParameter().getQualifiedName());
}
Aggregations