Java Code Examples for com.github.javaparser.ast.nodeTypes.NodeWithAnnotations#getAnnotations()

The following examples show how to use com.github.javaparser.ast.nodeTypes.NodeWithAnnotations#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: ParseHelper.java    From genDoc with Apache License 2.0 4 votes vote down vote up
static List<Annotation> parseAnnotation(NodeWithAnnotations<? extends Node> nodeWithAnnotations, Member member) {
    NodeList<AnnotationExpr> annotationExprs = nodeWithAnnotations.getAnnotations();

    if (annotationExprs != null && annotationExprs.size() > 0) {
        List<Annotation> annotations = new ArrayList<Annotation>();

        for (AnnotationExpr annotationExpr : annotationExprs) {
            Annotation annotation = null;

            if (annotationExpr instanceof MarkerAnnotationExpr) {
                annotation = new MarkerAnnotation();
            } else if (annotationExpr instanceof SingleMemberAnnotationExpr) {
                SingleMemberAnnotationExpr singleMemberAnnotationExpr = (SingleMemberAnnotationExpr) annotationExpr;

                annotation = new SingleAnnotation();


                SingleAnnotation singleAnnotation = (SingleAnnotation) annotation;
                singleAnnotation.setValue(annotationValueTrim(singleMemberAnnotationExpr.getMemberValue().toString()));
            } else if (annotationExpr instanceof NormalAnnotationExpr) {
                NormalAnnotationExpr normalAnnotationExpr = (NormalAnnotationExpr) annotationExpr;

                annotation = new NormalAnnotation();

                NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;

                List<NormalAnnotation.Pair> pairList = new ArrayList<NormalAnnotation.Pair>();

                for (MemberValuePair memberValuePair : normalAnnotationExpr.getPairs()) {
                    NormalAnnotation.Pair pair = new NormalAnnotation.Pair();
                    pair.setName(memberValuePair.getNameAsString());
                    pair.setValue(annotationValueTrim(memberValuePair.getValue().toString()));
                    pairList.add(pair);
                }
                normalAnnotation.setPairList(pairList);
            }

            if (annotation != null) {
                annotation.setName(annotationExpr.getNameAsString());
                annotation.setMember(member);
                annotations.add(annotation);
            }
        }

        return annotations;
    }
    return null;
}
 
Example 2
Source File: GroovydocJavaVisitor.java    From groovy with Apache License 2.0 4 votes vote down vote up
private void processAnnotations(SimpleGroovyProgramElementDoc element, NodeWithAnnotations<?> n) {
    for (AnnotationExpr an : n.getAnnotations()) {
        element.addAnnotationRef(new SimpleGroovyAnnotationRef(an.getNameAsString(), getAnnotationText(an)));
    }
}
 
Example 3
Source File: GroovydocJavaVisitor.java    From groovy with Apache License 2.0 4 votes vote down vote up
private void processAnnotations(SimpleGroovyParameter param, NodeWithAnnotations<?> n) {
    for (AnnotationExpr an : n.getAnnotations()) {
        param.addAnnotationRef(new SimpleGroovyAnnotationRef(an.getNameAsString(), getAnnotationText(an)));
    }
}