use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class MethodsResolutionTest method solveMethodWithTypePromotionsToLong.
@Test
public void solveMethodWithTypePromotionsToLong() {
CompilationUnit cu = parseSample("Issue338");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "TypePromotions");
MethodDeclaration method = Navigator.demandMethod(clazz, "callingLong");
{
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("longParam", 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("longParam", 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("longParam", reference.getCorrespondingDeclaration().getName());
}
{
MethodCallExpr expression = method.getBody().get().getStatements().get(3).asExpressionStmt().getExpression().asMethodCallExpr();
SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
assertEquals(true, reference.isSolved());
assertEquals("longParam", reference.getCorrespondingDeclaration().getName());
}
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class MethodsResolutionTest method solveMethodWithTypePromotionsToLongWithExtraParam.
@Test
public void solveMethodWithTypePromotionsToLongWithExtraParam() {
CompilationUnit cu = parseSample("Issue338");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "TypePromotionsWithExtraParam");
MethodDeclaration method = Navigator.demandMethod(clazz, "callingLong");
{
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("longParam", 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("longParam", 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("longParam", reference.getCorrespondingDeclaration().getName());
}
{
MethodCallExpr expression = method.getBody().get().getStatements().get(3).asExpressionStmt().getExpression().asMethodCallExpr();
SymbolReference<ResolvedMethodDeclaration> reference = JavaParserFacade.get(new ReflectionTypeSolver()).solve(expression);
assertEquals(true, reference.isSolved());
assertEquals("longParam", reference.getCorrespondingDeclaration().getName());
}
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class StatementContextResolutionTest method resolveMethodOnGenericClass.
@Test
public void resolveMethodOnGenericClass() {
CompilationUnit cu = parseSample("LocalVariableInParent");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration referencesToField = Navigator.demandClass(cu, "LocalVariableInParent");
MethodDeclaration method = Navigator.demandMethod(referencesToField, "foo5");
MethodCallExpr call = Navigator.findMethodCall(method, "add").get();
TypeSolver typeSolver = new ReflectionTypeSolver();
SymbolReference<? extends ResolvedValueDeclaration> ref = JavaParserFacade.get(typeSolver).solve(call.getScope().get());
assertTrue(ref.isSolved());
assertEquals("java.util.List<Comment>", ref.getCorrespondingDeclaration().getType().describe());
MethodUsage methodUsage = JavaParserFacade.get(typeSolver).solveMethodAsUsage(call);
assertEquals("add", methodUsage.getName());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class StatementContextResolutionTest method resolveLocalVariableInSameParent.
@Test
public void resolveLocalVariableInSameParent() {
CompilationUnit cu = parseSample("LocalVariableInParent");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration referencesToField = Navigator.demandClass(cu, "LocalVariableInParent");
MethodDeclaration method = Navigator.demandMethod(referencesToField, "foo2");
NameExpr nameExpr = Navigator.findNameExpression(method, "s").get();
SymbolReference<? extends ResolvedValueDeclaration> ref = JavaParserFacade.get(new ReflectionTypeSolver()).solve(nameExpr);
assertTrue(ref.isSolved());
assertEquals("java.lang.String", ref.getCorrespondingDeclaration().getType().asReferenceType().getQualifiedName());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class StatementContextResolutionTest method resolveLocalVariableInParentOfParent.
@Test
public void resolveLocalVariableInParentOfParent() {
CompilationUnit cu = parseSample("LocalVariableInParent");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration referencesToField = Navigator.demandClass(cu, "LocalVariableInParent");
MethodDeclaration method = Navigator.demandMethod(referencesToField, "foo1");
NameExpr nameExpr = Navigator.findNameExpression(method, "s").get();
SymbolReference<? extends ResolvedValueDeclaration> ref = JavaParserFacade.get(new ReflectionTypeSolver()).solve(nameExpr);
assertTrue(ref.isSolved());
assertEquals("java.lang.String", ref.getCorrespondingDeclaration().getType().asReferenceType().getQualifiedName());
}
Aggregations