Search in sources :

Example 11 with MethodDeclaration

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

the class MethodDeclarationTransformationsTest method removingLastParameterOfMany.

@Test
public void removingLastParameterOfMany() throws IOException {
    MethodDeclaration it = consider("public void foo(double d, float f){}");
    it.getParameters().remove(1);
    assertTransformedToString("public void foo(double d){}", it);
}
Also used : MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Example 12 with MethodDeclaration

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

the class MethodDeclarationTransformationsTest method addingParameters.

// Parameters
@Test
public void addingParameters() throws IOException {
    MethodDeclaration it = consider("void foo(){}");
    it.addParameter(PrimitiveType.doubleType(), "d");
    assertTransformedToString("void foo(double d){}", it);
}
Also used : MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Example 13 with MethodDeclaration

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

the class TransformationsTest method exampleParam2.

@Test
public void exampleParam2() throws IOException {
    considerExample("Example_param1_original");
    MethodDeclaration md = (MethodDeclaration) cu.getClassByName("A").get().getMember(0).asMethodDeclaration();
    md.addParameter(new ArrayType(PrimitiveType.intType()), "p1");
    md.addParameter("char", "p2");
    assertTransformed("Example_param2", cu);
}
Also used : ArrayType(com.github.javaparser.ast.type.ArrayType) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Test(org.junit.Test)

Example 14 with MethodDeclaration

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

the class TransformationsTest method exampleParam1.

@Test
public void exampleParam1() throws IOException {
    considerExample("Example_param1_original");
    MethodDeclaration md = (MethodDeclaration) cu.getClassByName("A").get().getMember(0).asMethodDeclaration();
    md.addParameter("int", "p1");
    assertTransformed("Example_param1", cu);
}
Also used : MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Test(org.junit.Test)

Example 15 with MethodDeclaration

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

the class TransformationsTest method exampleParam5.

@Test
public void exampleParam5() throws IOException {
    considerExample("Example_param3_original");
    MethodDeclaration md = (MethodDeclaration) cu.getClassByName("A").get().getMember(0).asMethodDeclaration();
    md.setType(PrimitiveType.intType());
    assertTransformed("Example_param5b", cu);
    md.getBody().get().getStatements().add(new ReturnStmt(new NameExpr("p1")));
    assertTransformed("Example_param5", cu);
}
Also used : MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) NameExpr(com.github.javaparser.ast.expr.NameExpr) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) Test(org.junit.Test)

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