com.github.javaparser.ast.nodeTypes.NodeWithAnnotations Java Examples

The following examples show how to use com.github.javaparser.ast.nodeTypes.NodeWithAnnotations. 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: CDIDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withConfigInjection(T node, String configKey, String defaultValue) {
    node.addAnnotation(new NormalAnnotationExpr(
            new Name("org.eclipse.microprofile.config.inject.ConfigProperty"),
            NodeList.nodeList(
                    new MemberValuePair("name", new StringLiteralExpr(configKey)),
                    new MemberValuePair("defaultValue", new StringLiteralExpr(defaultValue))
            )
    ));
    return node;
}
 
Example #2
Source File: DependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
/**
 * Annotates given node with set of roles to enforce security
 *
 * @param node  node to be annotated
 * @param roles roles that are allowed
 */
default <T extends NodeWithAnnotations<?>> T withSecurityRoles(T node, String[] roles) {
    if (roles != null && roles.length > 0) {
        List<Expression> rolesExpr = new ArrayList<>();

        for (String role : roles) {
            rolesExpr.add(new StringLiteralExpr(role.trim()));
        }

        node.addAnnotation(new SingleMemberAnnotationExpr(new Name("javax.annotation.security.RolesAllowed"), new ArrayInitializerExpr(NodeList.nodeList(rolesExpr))));
    }
    return node;
}
 
Example #3
Source File: CDIDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withConfigInjection(T node, String configKey) {
    node.addAnnotation(new NormalAnnotationExpr(
            new Name("org.eclipse.microprofile.config.inject.ConfigProperty"),
            NodeList.nodeList(
                    new MemberValuePair("name", new StringLiteralExpr(configKey))
            )
    ));
    return node;
}
 
Example #4
Source File: AnnotationHelper.java    From apigcc with MIT License 5 votes vote down vote up
/**
 * 是否存在任意一个注解
 * @param node
 * @param annotationNames
 * @return
 */
public static boolean any(NodeWithAnnotations node, Iterable<String> annotationNames) {
    for (String annotationName : annotationNames) {
        if (node.isAnnotationPresent(annotationName)) {
            return true;
        }
    }
    return false;
}
 
Example #5
Source File: AnnotationHelper.java    From apigcc with MIT License 5 votes vote down vote up
/**
 * 获取注解的属性String类型的值
 * @param node
 * @param annotation
 * @param keys
 * @return
 */
@SuppressWarnings("unchecked")
public static Optional<String> string(NodeWithAnnotations node, String annotation, String ... keys) {
    Optional<AnnotationExpr> optional = node.getAnnotationByName(annotation);
    if (optional.isPresent()) {
        Optional<Expression> expr = AnnotationHelper.attr(optional.get(), keys);
        if (expr.isPresent()) {
            return Optional.of(ExpressionHelper.getStringValue(expr.get()));
        }
    }
    return Optional.empty();
}
 
Example #6
Source File: SpringDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withOptionalInjection(T node) {
    node.addAnnotation(new NormalAnnotationExpr(new Name("org.springframework.beans.factory.annotation.Autowired"), NodeList.nodeList(new MemberValuePair("required", new BooleanLiteralExpr(false)))));
    return node;
}
 
Example #7
Source File: ClassExplorer.java    From jeddict with Apache License 2.0 4 votes vote down vote up
@Override
protected NodeWithAnnotations getAnnotatedMember() {
    return type;
}
 
Example #8
Source File: SpringDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withNamed(T node, String name) {
    node.addAnnotation(new SingleMemberAnnotationExpr(new Name("org.springframework.beans.factory.annotation.Qualifier"), new StringLiteralExpr(name)));
    return node;
}
 
Example #9
Source File: SpringDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withApplicationComponent(T node) {
    node.addAnnotation("org.springframework.stereotype.Component");
    return node;
}
 
Example #10
Source File: SpringDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withNamedApplicationComponent(T node, String name) {
    node.addAnnotation(new SingleMemberAnnotationExpr(new Name("org.springframework.stereotype.Component"), new StringLiteralExpr(name)));
    return node;
}
 
Example #11
Source File: SpringDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withSingletonComponent(T node) {
    return withApplicationComponent(node);
}
 
Example #12
Source File: SpringDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withNamedSingletonComponent(T node, String name) {
    return withNamedApplicationComponent(node, name);
}
 
Example #13
Source File: SpringDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withInjection(T node) {
    node.addAnnotation("org.springframework.beans.factory.annotation.Autowired");
    return node;
}
 
Example #14
Source File: SpringDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withNamedInjection(T node, String name) {
    return withNamed(withInjection(node), name);
}
 
Example #15
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 #16
Source File: SpringDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withIncomingMessage(T node, String channel) {
    node.addAnnotation(new NormalAnnotationExpr(new Name("org.springframework.kafka.annotation.KafkaListener"), NodeList.nodeList(new MemberValuePair("topics", new StringLiteralExpr(channel)))));
    return node;
}
 
Example #17
Source File: CDIDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withApplicationComponent(T node) {
    node.addAnnotation("javax.enterprise.context.ApplicationScoped");
    return node;
}
 
Example #18
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)));
    }
}
 
Example #19
Source File: SpringDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withOutgoingMessage(T node, String channel) {
    // currently no-op
    return node;
}
 
Example #20
Source File: SpringDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withConfigInjection(T node, String configKey) {
    node.addAnnotation(new SingleMemberAnnotationExpr(new Name("org.springframework.beans.factory.annotation.Value"), new StringLiteralExpr("${" + configKey + ":#{null}}")));
    return node;
}
 
Example #21
Source File: SpringDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withConfigInjection(T node, String configKey, String defaultValue) {
    node.addAnnotation(new SingleMemberAnnotationExpr(new Name("org.springframework.beans.factory.annotation.Value"), new StringLiteralExpr("${" + configKey + ":" + defaultValue + "}")));
    return node;
}
 
Example #22
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 #23
Source File: CDIDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withNamed(T node, String name) {
    node.addAnnotation(new SingleMemberAnnotationExpr(new Name("javax.inject.Named"), new StringLiteralExpr(name)));
    return node;
}
 
Example #24
Source File: CDIDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withNamedApplicationComponent(T node, String name) {
    return withNamed(withApplicationComponent(node), name);
}
 
Example #25
Source File: CDIDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withSingletonComponent(T node) {
    node.addAnnotation("javax.inject.Singleton");
    return node;
}
 
Example #26
Source File: CDIDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withNamedSingletonComponent(T node, String name) {
    return withNamed(withSingletonComponent(node), name);
}
 
Example #27
Source File: CDIDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withInjection(T node) {
    node.addAnnotation("javax.inject.Inject");
    return node;
}
 
Example #28
Source File: CDIDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withNamedInjection(T node, String name) {
    return withNamed(withInjection(node), name);
}
 
Example #29
Source File: CDIDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withOptionalInjection(T node) {
    return withInjection(node);
}
 
Example #30
Source File: CDIDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withIncomingMessage(T node, String channel) {
    node.addAnnotation(new SingleMemberAnnotationExpr(new Name("org.eclipse.microprofile.reactive.messaging.Incoming"), new StringLiteralExpr(channel)));
    return node;
}