Search in sources :

Example 6 with MethodDeclaration

use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.

the class DifferentiateDotExpressionTest method staticMethodCallsFromInnerClasses.

@Test
public void staticMethodCallsFromInnerClasses() {
    ClassOrInterfaceDeclaration clazz = ((JavaParserClassDeclaration) typeSolver.solveType("InnerClassDotExpressions")).getWrappedNode();
    MethodDeclaration mainMethod = Navigator.demandMethod(clazz, "main");
    JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
    MethodCallExpr methodCall = Navigator.findMethodCall(mainMethod, "methodCall").get();
    MethodCallExpr innerMethodCall = Navigator.findMethodCall(mainMethod, "innerMethodCall").get();
    MethodCallExpr innerInnerMethodCall = Navigator.findMethodCall(mainMethod, "innerInnerMethodCall").get();
    assertEquals(true, javaParserFacade.solve(methodCall).isSolved());
    assertEquals(true, javaParserFacade.solve(innerMethodCall).isSolved());
    assertEquals(true, javaParserFacade.solve(innerInnerMethodCall).isSolved());
}
Also used : JavaParserClassDeclaration(com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 7 with MethodDeclaration

use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.

the class DifferentiateDotExpressionTest method staticFieldCallsFromInnerClasses.

@Test
public void staticFieldCallsFromInnerClasses() {
    ClassOrInterfaceDeclaration clazz = ((JavaParserClassDeclaration) typeSolver.solveType("InnerStaticClassFieldDotExpressions")).getWrappedNode();
    MethodDeclaration mainMethod = Navigator.demandMethod(clazz, "main");
    JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
    MethodCallExpr methodCallWithNestedStaticFieldParam = Navigator.findMethodCall(mainMethod, "parseInt").get();
    assertEquals(true, javaParserFacade.solve(methodCallWithNestedStaticFieldParam).isSolved());
}
Also used : JavaParserClassDeclaration(com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 8 with MethodDeclaration

use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.

the class JavaParserAnonymousClassDeclarationTest method callingSuperClassInnerClassMethod.

@Test
public void callingSuperClassInnerClassMethod() {
    CompilationUnit cu = parseSample("AnonymousClassDeclarations");
    ClassOrInterfaceDeclaration aClass = Navigator.demandClass(cu, "AnonymousClassDeclarations");
    MethodDeclaration method = Navigator.demandMethod(aClass, "fooBar2");
    MethodCallExpr methodCall = Navigator.findMethodCall(method, "innerClassMethod").get();
    CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
    combinedTypeSolver.add(new ReflectionTypeSolver());
    MethodUsage methodUsage = JavaParserFacade.get(combinedTypeSolver).solveMethodAsUsage(methodCall);
    assertThat(methodUsage.getQualifiedSignature(), is("AnonymousClassDeclarations.DoFn.ProcessContext.innerClassMethod()"));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) MethodUsage(com.github.javaparser.resolution.MethodUsage) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 9 with MethodDeclaration

use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.

the class MethodDeclarationTransformationsTest method removingModifiers.

@Test
public void removingModifiers() throws IOException {
    MethodDeclaration it = consider("public void A(){}");
    it.setModifiers(EnumSet.noneOf(Modifier.class));
    assertTransformedToString("void A(){}", it);
}
Also used : MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Modifier(com.github.javaparser.ast.Modifier) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Example 10 with MethodDeclaration

use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.

the class MethodDeclarationTransformationsTest method addingModifiers.

// JavaDoc
// Modifiers
@Test
public void addingModifiers() throws IOException {
    MethodDeclaration it = consider("void A(){}");
    it.setModifiers(EnumSet.of(Modifier.PUBLIC));
    assertTransformedToString("public void A(){}", it);
}
Also used : MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Aggregations

MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)325 Test (org.junit.Test)166 CompilationUnit (com.github.javaparser.ast.CompilationUnit)143 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)107 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)100 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)84 Expression (com.github.javaparser.ast.expr.Expression)82 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)77 NameExpr (com.github.javaparser.ast.expr.NameExpr)58 ReturnStmt (com.github.javaparser.ast.stmt.ReturnStmt)57 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)47 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)46 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)41 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)41 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)40 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)38 JavaParserFacade (com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade)35 CommonCodegenUtils.getVariableDeclarator (org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.getVariableDeclarator)35 NodeList (com.github.javaparser.ast.NodeList)32 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)27