use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class MethodsResolutionTest method solveMethodAccessThroughSuper.
@Test
public void solveMethodAccessThroughSuper() {
CompilationUnit cu = parseSample("AccessThroughSuper");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "AccessThroughSuper.SubClass");
MethodDeclaration method = Navigator.demandMethod(clazz, "methodTest");
ReturnStmt returnStmt = (ReturnStmt) method.getBody().get().getStatements().get(0);
Expression expression = returnStmt.getExpression().get();
ResolvedType ref = JavaParserFacade.get(new ReflectionTypeSolver()).getType(expression);
assertEquals("java.lang.String", ref.describe());
}
use of com.github.javaparser.ast.body.MethodDeclaration 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());
}
}
use of com.github.javaparser.ast.body.MethodDeclaration 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());
}
}
use of com.github.javaparser.ast.body.MethodDeclaration 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());
}
}
use of com.github.javaparser.ast.body.MethodDeclaration 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());
}
}
Aggregations