Search in sources :

Example 91 with ReflectionTypeSolver

use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.

the class MethodsResolutionTest method solveMethodWithTypePromotionsToInt.

@Test
public void solveMethodWithTypePromotionsToInt() {
    CompilationUnit cu = parseSample("Issue338");
    ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "TypePromotions");
    MethodDeclaration method = Navigator.demandMethod(clazz, "callingInt");
    {
        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("intParam", reference.getCorrespondingDeclaration().getName());
    }
    {
        MethodCallExpr expression = method.getBody().get().getStatements().get(1).asExpressionStmt().getExpression().asMethodCallExpr();
        SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
        assertEquals(true, reference.isSolved());
        assertEquals("intParam", reference.getCorrespondingDeclaration().getName());
    }
    {
        MethodCallExpr expression = method.getBody().get().getStatements().get(2).asExpressionStmt().getExpression().asMethodCallExpr();
        SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
        assertEquals(true, reference.isSolved());
        assertEquals("intParam", reference.getCorrespondingDeclaration().getName());
    }
    {
        MethodCallExpr expression = method.getBody().get().getStatements().get(3).asExpressionStmt().getExpression().asMethodCallExpr();
        SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
        assertEquals(false, reference.isSolved());
    }
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ResolvedMethodDeclaration(com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) SymbolReference(com.github.javaparser.symbolsolver.model.resolution.SymbolReference) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Test(org.junit.Test)

Example 92 with ReflectionTypeSolver

use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.

the class MethodsResolutionTest method solveMethodWithTypePromotionsToShort.

@Test
public void solveMethodWithTypePromotionsToShort() {
    CompilationUnit cu = parseSample("Issue338");
    ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "TypePromotions");
    MethodDeclaration method = Navigator.demandMethod(clazz, "callingShort");
    {
        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("shortParam", reference.getCorrespondingDeclaration().getName());
    }
    {
        MethodCallExpr expression = method.getBody().get().getStatements().get(1).asExpressionStmt().getExpression().asMethodCallExpr();
        SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
        assertEquals(true, reference.isSolved());
        assertEquals("shortParam", reference.getCorrespondingDeclaration().getName());
    }
    {
        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());
    }
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ResolvedMethodDeclaration(com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) SymbolReference(com.github.javaparser.symbolsolver.model.resolution.SymbolReference) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Test(org.junit.Test)

Example 93 with ReflectionTypeSolver

use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.

the class MethodsResolutionTest method callOnThisInAnonymousClass.

@Test
public void callOnThisInAnonymousClass() {
    CompilationUnit cu = parseSample("ThisInAnonymousClass");
    ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Bar");
    MethodCallExpr fooCall = Navigator.findMethodCall(clazz, "foo").get();
    SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(fooCall);
    assertEquals(true, reference.isSolved());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) ResolvedMethodDeclaration(com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration) Test(org.junit.Test)

Example 94 with ReflectionTypeSolver

use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.

the class MethodsResolutionTest method solveMethodWithTypePromotionsToIntWithExtraParam.

@Test
public void solveMethodWithTypePromotionsToIntWithExtraParam() {
    CompilationUnit cu = parseSample("Issue338");
    ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "TypePromotionsWithExtraParam");
    MethodDeclaration method = Navigator.demandMethod(clazz, "callingInt");
    {
        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("intParam", reference.getCorrespondingDeclaration().getName());
    }
    {
        MethodCallExpr expression = method.getBody().get().getStatements().get(1).asExpressionStmt().getExpression().asMethodCallExpr();
        SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
        assertEquals(true, reference.isSolved());
        assertEquals("intParam", reference.getCorrespondingDeclaration().getName());
    }
    {
        MethodCallExpr expression = method.getBody().get().getStatements().get(2).asExpressionStmt().getExpression().asMethodCallExpr();
        SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
        assertEquals(true, reference.isSolved());
        assertEquals("intParam", reference.getCorrespondingDeclaration().getName());
    }
    {
        MethodCallExpr expression = method.getBody().get().getStatements().get(3).asExpressionStmt().getExpression().asMethodCallExpr();
        SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
        assertEquals(false, reference.isSolved());
    }
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ResolvedMethodDeclaration(com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) SymbolReference(com.github.javaparser.symbolsolver.model.resolution.SymbolReference) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Test(org.junit.Test)

Example 95 with ReflectionTypeSolver

use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.

the class MethodsResolutionTest method solveMethodWithTypePromotionsToShortWithExtraParam.

@Test
public void solveMethodWithTypePromotionsToShortWithExtraParam() {
    CompilationUnit cu = parseSample("Issue338");
    ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "TypePromotionsWithExtraParam");
    MethodDeclaration method = Navigator.demandMethod(clazz, "callingShort");
    {
        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("shortParam", reference.getCorrespondingDeclaration().getName());
    }
    {
        MethodCallExpr expression = method.getBody().get().getStatements().get(1).asExpressionStmt().getExpression().asMethodCallExpr();
        SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
        assertEquals(true, reference.isSolved());
        assertEquals("shortParam", reference.getCorrespondingDeclaration().getName());
    }
    {
        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());
    }
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ResolvedMethodDeclaration(com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) SymbolReference(com.github.javaparser.symbolsolver.model.resolution.SymbolReference) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Test(org.junit.Test)

Aggregations

ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)206 Test (org.junit.Test)165 CompilationUnit (com.github.javaparser.ast.CompilationUnit)128 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)81 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)77 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)75 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)57 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)57 CombinedTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)52 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)47 JavaParserFacade (com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade)41 ResolvedMethodDeclaration (com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration)31 JavaParserTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver)28 Expression (com.github.javaparser.ast.expr.Expression)26 Before (org.junit.Before)26 Context (com.github.javaparser.symbolsolver.core.resolution.Context)25 MethodUsage (com.github.javaparser.resolution.MethodUsage)23 File (java.io.File)23 CompilationUnitContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext)22 ReflectionClassDeclaration (com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration)22