Search in sources :

Example 11 with Type

use of org.jboss.jandex.Type in project wildfly-swarm by wildfly-swarm.

the class SpecialCaseTests method testCollection_DataObjectList.

@Test
public void testCollection_DataObjectList() throws IOException, JSONException {
    String name = SpecialCaseTestContainer.class.getName();
    Type pType = getFieldFromKlazz(name, "ccList").type();
    OpenApiDataObjectScanner scanner = new OpenApiDataObjectScanner(index, pType);
    Schema result = scanner.process();
    printToConsole(name, result);
    assertJsonEquals(name, "special.dataObjectList.expected.json", result);
}
Also used : Type(org.jboss.jandex.Type) Schema(org.eclipse.microprofile.openapi.models.media.Schema) Test(org.junit.Test)

Example 12 with Type

use of org.jboss.jandex.Type in project wildfly-swarm by wildfly-swarm.

the class SpecialCaseTests method testCollection_WildcardWithSuperBound.

@Test
public void testCollection_WildcardWithSuperBound() throws IOException, JSONException {
    String name = SpecialCaseTestContainer.class.getName();
    Type pType = getFieldFromKlazz(name, "listSuperFlight").type();
    OpenApiDataObjectScanner scanner = new OpenApiDataObjectScanner(index, pType);
    Schema result = scanner.process();
    printToConsole(name, result);
    assertJsonEquals(name, "special.wildcardWithSuperBound.expected.json", result);
}
Also used : Type(org.jboss.jandex.Type) Schema(org.eclipse.microprofile.openapi.models.media.Schema) Test(org.junit.Test)

Example 13 with Type

use of org.jboss.jandex.Type in project wildfly by wildfly.

the class JandexAnnotationRepositoryImpl method getAnnotation.

@Override
public Collection<Annotation> getAnnotation(Class<?> annotationClass) {
    List<AnnotationInstance> instances = backingRepository.getAnnotations(DotName.createSimple(annotationClass.getName()));
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(instances.size());
    for (AnnotationInstance instance : instances) {
        AnnotationTarget target = instance.target();
        Annotation annotation = null;
        if (target instanceof MethodInfo) {
            MethodInfo m = (MethodInfo) target;
            List<String> parameterTypes = new ArrayList<String>(m.args().length);
            for (Type type : m.args()) {
                parameterTypes.add(type.toString());
            }
            String declaringClass = m.declaringClass().name().toString();
            annotation = new AnnotationImpl(declaringClass, cl, parameterTypes, m.name(), true, false, annotationClass);
        }
        if (target instanceof FieldInfo) {
            FieldInfo f = (FieldInfo) target;
            String declaringClass = f.declaringClass().name().toString();
            annotation = new AnnotationImpl(declaringClass, cl, null, f.name(), false, true, annotationClass);
        }
        if (target instanceof ClassInfo) {
            ClassInfo c = (ClassInfo) target;
            annotation = new AnnotationImpl(c.name().toString(), cl, null, null, false, false, annotationClass);
        }
        if (annotation != null) {
            annotations.add(annotation);
        }
    }
    annotations.trimToSize();
    if (annotations.isEmpty()) {
        return null;
    } else {
        return Collections.unmodifiableList(annotations);
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) ArrayList(java.util.ArrayList) Annotation(org.jboss.jca.common.spi.annotations.repository.Annotation) Type(org.jboss.jandex.Type) MethodInfo(org.jboss.jandex.MethodInfo) AnnotationInstance(org.jboss.jandex.AnnotationInstance) FieldInfo(org.jboss.jandex.FieldInfo) ClassInfo(org.jboss.jandex.ClassInfo)

Example 14 with Type

use of org.jboss.jandex.Type in project wildfly by wildfly.

the class LifecycleAnnotationParsingProcessor method processLifeCycle.

private void processLifeCycle(final EEModuleDescription eeModuleDescription, final AnnotationTarget target, final DotName annotationType, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException {
    if (!(target instanceof MethodInfo)) {
        throw EeLogger.ROOT_LOGGER.methodOnlyAnnotation(annotationType);
    }
    final MethodInfo methodInfo = MethodInfo.class.cast(target);
    final ClassInfo classInfo = methodInfo.declaringClass();
    final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
    final Type[] args = methodInfo.args();
    if (args.length > 1) {
        ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidNumberOfArguments(methodInfo.name(), annotationType, classInfo.name()));
        return;
    } else if (args.length == 1 && !args[0].name().toString().equals(InvocationContext.class.getName())) {
        ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidSignature(methodInfo.name(), annotationType, classInfo.name(), "void methodName(InvocationContext ctx)"));
        return;
    }
    final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(classDescription.getInterceptorClassDescription());
    if (annotationType == POST_CONSTRUCT_ANNOTATION) {
        builder.setPostConstruct(getMethodIdentifier(args, methodInfo));
    } else if (annotationType == PRE_DESTROY_ANNOTATION) {
        builder.setPreDestroy(getMethodIdentifier(args, methodInfo));
    } else if (annotationType == AROUND_CONSTRUCT_ANNOTATION) {
        builder.setAroundConstruct(getMethodIdentifier(args, methodInfo));
    }
    classDescription.setInterceptorClassDescription(builder.build());
}
Also used : Type(org.jboss.jandex.Type) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) MethodInfo(org.jboss.jandex.MethodInfo) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription) ClassInfo(org.jboss.jandex.ClassInfo)

Example 15 with Type

use of org.jboss.jandex.Type in project wildfly by wildfly.

the class PassivationAnnotationParsingProcessor method processPassivation.

private void processPassivation(final EEModuleDescription eeModuleDescription, final AnnotationTarget target, final DotName annotationType) throws DeploymentUnitProcessingException {
    if (!(target instanceof MethodInfo)) {
        throw EeLogger.ROOT_LOGGER.methodOnlyAnnotation(annotationType);
    }
    final MethodInfo methodInfo = MethodInfo.class.cast(target);
    final ClassInfo classInfo = methodInfo.declaringClass();
    final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
    final Type[] args = methodInfo.args();
    if (args.length > 1) {
        ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidNumberOfArguments(methodInfo.name(), annotationType, classInfo.name()));
        return;
    } else if (args.length == 1 && !args[0].name().toString().equals(InvocationContext.class.getName())) {
        ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidSignature(methodInfo.name(), annotationType, classInfo.name(), "void methodName(InvocationContext ctx)"));
        return;
    }
    final MethodIdentifier methodIdentifier;
    if (args.length == 0) {
        methodIdentifier = MethodIdentifier.getIdentifier(Void.TYPE, methodInfo.name());
    } else {
        methodIdentifier = MethodIdentifier.getIdentifier(Void.TYPE, methodInfo.name(), InvocationContext.class);
    }
    final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(classDescription.getInterceptorClassDescription());
    if (annotationType == POST_ACTIVATE) {
        builder.setPostActivate(methodIdentifier);
    } else {
        builder.setPrePassivate(methodIdentifier);
    }
    classDescription.setInterceptorClassDescription(builder.build());
}
Also used : Type(org.jboss.jandex.Type) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) MethodInfo(org.jboss.jandex.MethodInfo) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) InvocationContext(javax.interceptor.InvocationContext) ClassInfo(org.jboss.jandex.ClassInfo)

Aggregations

Type (org.jboss.jandex.Type)28 Schema (org.eclipse.microprofile.openapi.models.media.Schema)15 Test (org.junit.Test)11 ClassType (org.jboss.jandex.ClassType)10 ClassInfo (org.jboss.jandex.ClassInfo)9 ParameterizedType (org.jboss.jandex.ParameterizedType)7 PrimitiveType (org.jboss.jandex.PrimitiveType)6 ArrayType (org.jboss.jandex.ArrayType)5 MethodInfo (org.jboss.jandex.MethodInfo)4 TypeUtil (org.wildfly.swarm.microprofile.openapi.runtime.util.TypeUtil)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)3 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)3 InterceptorClassDescription (org.jboss.as.ee.component.interceptors.InterceptorClassDescription)3 MethodIdentifier (org.jboss.invocation.proxy.MethodIdentifier)3 FieldInfo (org.jboss.jandex.FieldInfo)3 RefType (org.wildfly.swarm.microprofile.openapi.runtime.util.JandexUtil.RefType)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2