Java Code Examples for com.github.javaparser.ast.body.MethodDeclaration#getAnnotations()

The following examples show how to use com.github.javaparser.ast.body.MethodDeclaration#getAnnotations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegistryMethodVisitor.java    From gauge-java with Apache License 2.0 6 votes vote down vote up
@Override
public void visit(MethodDeclaration methodDeclaration, Object arg) {
    List<AnnotationExpr> annotations = methodDeclaration.getAnnotations();
    if (annotations.isEmpty()) {
        return;
    }

    for (AnnotationExpr annotationExpr : annotations) {
        if (!(annotationExpr instanceof SingleMemberAnnotationExpr)) {
            continue;
        }
        SingleMemberAnnotationExpr annotation = (SingleMemberAnnotationExpr) annotationExpr;
        if (annotation.getMemberValue() instanceof ArrayInitializerExpr) {
            ArrayInitializerExpr memberValue = (ArrayInitializerExpr) annotation.getMemberValue();
            for (Expression expression : memberValue.getValues()) {
                addStepToRegistry(expression, methodDeclaration, annotation);
            }
        } else {
            addStepToRegistry(annotation.getMemberValue(), methodDeclaration, annotation);
        }
    }
}
 
Example 2
Source File: AddOverrideAnnotation.java    From Refactoring-Bot with MIT License 5 votes vote down vote up
/**
 * @param declaration
 * @return true if given declaration already has an @Override annotation, false
 *         otherwise
 */
private boolean isOverrideAnnotationExisting(MethodDeclaration declaration) {
	List<AnnotationExpr> annotations = declaration.getAnnotations();
	for (AnnotationExpr annotation : annotations) {
		if (annotation.getNameAsString().equals(OVERRIDE_ANNOTATION_NAME)) {
			return true;
		}
	}

	return false;
}
 
Example 3
Source File: DSN.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void visit(MethodDeclaration n, Void arg) {
    for (AnnotationExpr a : n.getAnnotations()) {
        if (!a.getNameAsString().equals("CstrTest")) {
            return;
        }
    }
    System.out.println(n.getName());
    n.getRange().ifPresent(r -> l.add(r.end.line - r.begin.line));
    super.visit(n, arg);
}