Search in sources :

Example 1 with MethodDeclaration

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

the class SieASTVisitor method visit.

@Override
public void visit(final NormalAnnotationExpr expr, final Void arg) {
    final String fqcn = expr.getName().toString();
    if (fqcn.equals(Description.class.getCanonicalName())) {
        final Node parent = expr.getParentNode();
        final String value = expr.getPairs().get(0).toString();
        if (parent instanceof ClassOrInterfaceDeclaration) {
            descriptionAnotValue = value;
        } else if (parent instanceof MethodDeclaration) {
            methodDescriptions.put(((MethodDeclaration) parent).getName(), value);
        }
    } else if (fqcn.equals(ServiceInterfaceAnnotation.class.getCanonicalName())) {
        String text1 = expr.getPairs().get(0).toString();
        String text2 = expr.getPairs().get(1).toString();
        if (text1.contains("value")) {
            sieAnnotValue = text1;
            sieAnnotOsgiRegistrationType = text2;
        } else {
            sieAnnotValue = text2;
            sieAnnotOsgiRegistrationType = text1;
        }
    }
    super.visit(expr, arg);
}
Also used : Description(org.opendaylight.controller.config.api.annotations.Description) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Node(com.github.javaparser.ast.Node)

Example 2 with MethodDeclaration

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

the class ManipulationSteps method whenHelloWorldIsAddedToTheBodyOfMethodInClass.

@When("$className.$fieldName.$methodName(\"$stringValue\"); is added to the body of method $methodPosition in class $classPosition")
public void whenHelloWorldIsAddedToTheBodyOfMethodInClass(String className, String fieldName, String methodName, String stringValue, int methodPosition, int classPosition) {
    CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
    MethodDeclaration method = getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
    NameExpr clazz = new NameExpr(className);
    FieldAccessExpr field = new FieldAccessExpr(clazz, fieldName);
    MethodCallExpr call = new MethodCallExpr(field, methodName);
    call.addArgument(new StringLiteralExpr(stringValue));
    method.getBody().get().addStatement(call);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) When(org.jbehave.core.annotations.When)

Example 3 with MethodDeclaration

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

the class ManipulationSteps method thenMethodInClassHasTheName.

@Then("method $methodPosition in class $classPosition has the name \"$expectedName\"")
public void thenMethodInClassHasTheName(int methodPosition, int classPosition, String expectedName) {
    CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
    MethodDeclaration method = getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
    assertThat(method.getNameAsString(), is(expectedName));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Then(org.jbehave.core.annotations.Then)

Example 4 with MethodDeclaration

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

the class ManipulationSteps method whenMethodInClassHasItsNameConvertedToUppercase.

@When("method $methodPosition in class $classPosition has it's name converted to uppercase")
public void whenMethodInClassHasItsNameConvertedToUppercase(int methodPosition, int classPosition) {
    CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
    MethodDeclaration method = getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
    method.setName(method.getNameAsString().toUpperCase());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) When(org.jbehave.core.annotations.When)

Example 5 with MethodDeclaration

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

the class CloneVisitor method visit.

@Override
public Node visit(MethodDeclaration _n, Object _arg) {
    JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg);
    List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
    List<TypeParameter> typeParameters = visit(_n.getTypeParameters(), _arg);
    Type type_ = cloneNodes(_n.getType(), _arg);
    List<Parameter> parameters = visit(_n.getParameters(), _arg);
    List<NameExpr> throws_ = visit(_n.getThrows(), _arg);
    BlockStmt block = cloneNodes(_n.getBody(), _arg);
    Comment comment = cloneNodes(_n.getComment(), _arg);
    MethodDeclaration r = new MethodDeclaration(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), _n.getModifiers(), annotations, typeParameters, type_, _n.getName(), parameters, _n.getArrayCount(), throws_, block);
    r.setComment(comment);
    return r;
}
Also used : JavadocComment(com.github.javaparser.ast.comments.JavadocComment) BlockComment(com.github.javaparser.ast.comments.BlockComment) LineComment(com.github.javaparser.ast.comments.LineComment) Comment(com.github.javaparser.ast.comments.Comment) TypeParameter(com.github.javaparser.ast.TypeParameter) MultiTypeParameter(com.github.javaparser.ast.body.MultiTypeParameter) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) JavadocComment(com.github.javaparser.ast.comments.JavadocComment) Parameter(com.github.javaparser.ast.body.Parameter) TypeParameter(com.github.javaparser.ast.TypeParameter) MultiTypeParameter(com.github.javaparser.ast.body.MultiTypeParameter)

Aggregations

MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)324 Test (org.junit.Test)166 CompilationUnit (com.github.javaparser.ast.CompilationUnit)142 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