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);
}
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);
}
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));
}
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());
}
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;
}
Aggregations