Search in sources :

Example 1 with Kind

use of org.jboss.jandex.Type.Kind in project smallrye-graphql by smallrye.

the class JandexAnnotationsLoader method onMethod.

@Override
public Annotations onMethod(Class<?> type, String methodName, Class<?>... argTypes) {
    ClassInfo classInfo = getClassInfo(type);
    Type[] jandexArgTypes = Stream.of(argTypes).map(Class::getName).map(JandexAnnotationsLoader::createClassType).toArray(Type[]::new);
    MethodInfo methodInfo = classInfo.method(methodName, jandexArgTypes);
    if (methodInfo == null) {
        String[] argTypeNames = Stream.of(argTypes).map(Class::getName).toArray(String[]::new);
        throw new RuntimeException("no method " + signature(methodName, argTypeNames) + " in class " + classInfo.name());
    }
    // noinspection DuplicatedCode
    return new Annotations() {

        @Override
        public Stream<Annotation> all() {
            return methodInfo.annotations().stream().filter(// not params
            annotationInstance -> annotationInstance.target().kind() == METHOD).flatMap(JandexAnnotationsLoader::resolveRepeatableAnnotations).map(JandexAnnotationsLoader::proxy);
        }

        @Override
        public <T extends Annotation> Optional<T> get(Class<T> type) {
            return all(type).collect(toOptionalOrThrow());
        }

        @Override
        public <T extends Annotation> Stream<T> all(Class<T> type) {
            DotName typeName = toDotName(type);
            return methodInfo.annotations().stream().flatMap(JandexAnnotationsLoader::resolveRepeatableAnnotations).filter(annotationInstance -> annotationInstance.name().equals(typeName)).map(JandexAnnotationsLoader::proxy);
        }
    };
}
Also used : Kind(org.jboss.jandex.Type.Kind) CommonUtils.toDotName(com.github.t1.powerannotations.common.CommonUtils.toDotName) CommonUtils.signature(com.github.t1.powerannotations.common.CommonUtils.signature) DotName(org.jboss.jandex.DotName) Type(org.jboss.jandex.Type) ClassInfo(org.jboss.jandex.ClassInfo) FieldInfo(org.jboss.jandex.FieldInfo) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) IndexBuilder(com.github.t1.powerannotations.scanner.IndexBuilder) List(java.util.List) MethodInfo(org.jboss.jandex.MethodInfo) Stream(java.util.stream.Stream) METHOD(org.jboss.jandex.AnnotationTarget.Kind.METHOD) AnnotationInstance(org.jboss.jandex.AnnotationInstance) Annotation(java.lang.annotation.Annotation) AmbiguousAnnotationResolutionException(com.github.t1.annotations.AmbiguousAnnotationResolutionException) Optional(java.util.Optional) Jandex(com.github.t1.powerannotations.common.Jandex) Collector(java.util.stream.Collector) Annotations(com.github.t1.annotations.Annotations) Index(org.jboss.jandex.Index) AnnotationsLoader(com.github.t1.annotations.AnnotationsLoader) CommonUtils.toDotName(com.github.t1.powerannotations.common.CommonUtils.toDotName) DotName(org.jboss.jandex.DotName) Annotation(java.lang.annotation.Annotation) Type(org.jboss.jandex.Type) Annotations(com.github.t1.annotations.Annotations) MethodInfo(org.jboss.jandex.MethodInfo) ClassInfo(org.jboss.jandex.ClassInfo)

Aggregations

AmbiguousAnnotationResolutionException (com.github.t1.annotations.AmbiguousAnnotationResolutionException)1 Annotations (com.github.t1.annotations.Annotations)1 AnnotationsLoader (com.github.t1.annotations.AnnotationsLoader)1 CommonUtils.signature (com.github.t1.powerannotations.common.CommonUtils.signature)1 CommonUtils.toDotName (com.github.t1.powerannotations.common.CommonUtils.toDotName)1 Jandex (com.github.t1.powerannotations.common.Jandex)1 IndexBuilder (com.github.t1.powerannotations.scanner.IndexBuilder)1 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Supplier (java.util.function.Supplier)1 Collector (java.util.stream.Collector)1 Stream (java.util.stream.Stream)1 AnnotationInstance (org.jboss.jandex.AnnotationInstance)1 METHOD (org.jboss.jandex.AnnotationTarget.Kind.METHOD)1 ClassInfo (org.jboss.jandex.ClassInfo)1 DotName (org.jboss.jandex.DotName)1 FieldInfo (org.jboss.jandex.FieldInfo)1 Index (org.jboss.jandex.Index)1