Java Code Examples for org.jboss.jandex.Index#getAnnotations()

The following examples show how to use org.jboss.jandex.Index#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: QuarkusSecurityJpaProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private AnnotationTarget getSingleAnnotatedElement(Index index, DotName annotation) {
    List<AnnotationInstance> annotations = index.getAnnotations(annotation);
    if (annotations.isEmpty()) {
        return null;
    } else if (annotations.size() > 1) {
        throw new RuntimeException("You can only annotate one field or method with @" + annotation);
    }
    return annotations.get(0).target();
}
 
Example 2
Source File: CompositeIndex.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @see {@link Index#getAnnotations(org.jboss.jandex.DotName)}
 */
public List<AnnotationInstance> getAnnotations(final DotName annotationName) {
    final List<AnnotationInstance> allInstances = new ArrayList<AnnotationInstance>();
    for (Index index : indexes) {
        final List<AnnotationInstance> list = index.getAnnotations(annotationName);
        if (list != null) {
            allInstances.addAll(list);
        }
    }
    return Collections.unmodifiableList(allInstances);
}
 
Example 3
Source File: Main.java    From hibernate-demos with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    try (InputStream input = Main.class.getResourceAsStream( "/META-INF/jandex.idx" ) ) {
        IndexReader reader = new IndexReader( input );
        Index index = reader.read();

        List<AnnotationInstance> entityInstances = index.getAnnotations(
                DotName.createSimple( "com.example.a.Entity" )
        );

        for (AnnotationInstance annotationInstance : entityInstances) {
            System.out.println( annotationInstance.target().asClass().name() );
        }
    }
}