Search in sources :

Example 6 with MethodInfo

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

the class ResourceInjectionAnnotationParsingProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
    final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    final PropertyReplacer replacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
    if (module == null) {
        return;
    }
    final List<AnnotationInstance> resourceAnnotations = index.getAnnotations(RESOURCE_ANNOTATION_NAME);
    for (AnnotationInstance annotation : resourceAnnotations) {
        final AnnotationTarget annotationTarget = annotation.target();
        final AnnotationValue nameValue = annotation.value("name");
        final String name = (nameValue != null) ? replacer.replaceProperties(nameValue.asString()) : null;
        final AnnotationValue typeValue = annotation.value("type");
        final String type = typeValue != null ? typeValue.asClass().name().toString() : null;
        if (annotationTarget instanceof FieldInfo) {
            final FieldInfo fieldInfo = (FieldInfo) annotationTarget;
            final ClassInfo classInfo = fieldInfo.declaringClass();
            EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
            processFieldResource(phaseContext, fieldInfo, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer);
        } else if (annotationTarget instanceof MethodInfo) {
            final MethodInfo methodInfo = (MethodInfo) annotationTarget;
            ClassInfo classInfo = methodInfo.declaringClass();
            EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
            processMethodResource(phaseContext, methodInfo, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer);
        } else if (annotationTarget instanceof ClassInfo) {
            final ClassInfo classInfo = (ClassInfo) annotationTarget;
            EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
            processClassResource(phaseContext, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer);
        }
    }
    final List<AnnotationInstance> resourcesAnnotations = index.getAnnotations(RESOURCES_ANNOTATION_NAME);
    for (AnnotationInstance outerAnnotation : resourcesAnnotations) {
        final AnnotationTarget annotationTarget = outerAnnotation.target();
        if (annotationTarget instanceof ClassInfo) {
            final ClassInfo classInfo = (ClassInfo) annotationTarget;
            final AnnotationInstance[] values = outerAnnotation.value("value").asNestedArray();
            for (AnnotationInstance annotation : values) {
                final AnnotationValue nameValue = annotation.value("name");
                final String name = (nameValue != null) ? replacer.replaceProperties(nameValue.asString()) : null;
                final AnnotationValue typeValue = annotation.value("type");
                final String type = (typeValue != null) ? typeValue.asClass().name().toString() : null;
                EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
                processClassResource(phaseContext, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer);
            }
        }
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) AnnotationValue(org.jboss.jandex.AnnotationValue) PropertyReplacer(org.jboss.metadata.property.PropertyReplacer) MethodInfo(org.jboss.jandex.MethodInfo) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance) FieldInfo(org.jboss.jandex.FieldInfo) ClassInfo(org.jboss.jandex.ClassInfo)

Example 7 with MethodInfo

use of org.jboss.jandex.MethodInfo 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 8 with MethodInfo

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

the class EjbResourceInjectionAnnotationProcessor method deploy.

public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
    final List<AnnotationInstance> resourceAnnotations = index.getAnnotations(EJB_ANNOTATION_NAME);
    PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
    for (AnnotationInstance annotation : resourceAnnotations) {
        final AnnotationTarget annotationTarget = annotation.target();
        final EJBResourceWrapper annotationWrapper = new EJBResourceWrapper(annotation, propertyReplacer);
        if (annotationTarget instanceof FieldInfo) {
            processField(deploymentUnit, annotationWrapper, (FieldInfo) annotationTarget, moduleDescription);
        } else if (annotationTarget instanceof MethodInfo) {
            processMethod(deploymentUnit, annotationWrapper, (MethodInfo) annotationTarget, moduleDescription);
        } else if (annotationTarget instanceof ClassInfo) {
            processClass(deploymentUnit, annotationWrapper, (ClassInfo) annotationTarget, moduleDescription);
        }
    }
    final List<AnnotationInstance> ejbsAnnotations = index.getAnnotations(EJBS_ANNOTATION_NAME);
    for (AnnotationInstance annotation : ejbsAnnotations) {
        final AnnotationTarget annotationTarget = annotation.target();
        if (annotationTarget instanceof ClassInfo) {
            final AnnotationValue annotationValue = annotation.value();
            final AnnotationInstance[] ejbAnnotations = annotationValue.asNestedArray();
            for (AnnotationInstance ejbAnnotation : ejbAnnotations) {
                final EJBResourceWrapper annotationWrapper = new EJBResourceWrapper(ejbAnnotation, propertyReplacer);
                processClass(deploymentUnit, annotationWrapper, (ClassInfo) annotationTarget, moduleDescription);
            }
        } else {
            throw EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(EJBs.class.getName(), annotation.target());
        }
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EJBs(javax.ejb.EJBs) AnnotationValue(org.jboss.jandex.AnnotationValue) PropertyReplacer(org.jboss.metadata.property.PropertyReplacer) MethodInfo(org.jboss.jandex.MethodInfo) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance) FieldInfo(org.jboss.jandex.FieldInfo) ClassInfo(org.jboss.jandex.ClassInfo)

Example 9 with MethodInfo

use of org.jboss.jandex.MethodInfo 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)

Example 10 with MethodInfo

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

the class XTSHandlerDeploymentProcessor method addEndpointsToList.

private void addEndpointsToList(Set<String> endpoints, List<AnnotationInstance> annotations) {
    for (AnnotationInstance annotationInstance : annotations) {
        Object target = annotationInstance.target();
        if (target instanceof ClassInfo) {
            final ClassInfo classInfo = (ClassInfo) annotationInstance.target();
            final String endpointClass = classInfo.name().toString();
            endpoints.add(endpointClass);
        } else if (target instanceof MethodInfo) {
            final MethodInfo methodInfo = (MethodInfo) target;
            final String endpointClass = methodInfo.declaringClass().name().toString();
            endpoints.add(endpointClass);
        }
    }
}
Also used : MethodInfo(org.jboss.jandex.MethodInfo) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Aggregations

MethodInfo (org.jboss.jandex.MethodInfo)24 AnnotationInstance (org.jboss.jandex.AnnotationInstance)18 ClassInfo (org.jboss.jandex.ClassInfo)18 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)7 FieldInfo (org.jboss.jandex.FieldInfo)7 AnnotationTarget (org.jboss.jandex.AnnotationTarget)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 InterceptorClassDescription (org.jboss.as.ee.component.interceptors.InterceptorClassDescription)5 InvocationContext (javax.interceptor.InvocationContext)4 AnnotationValue (org.jboss.jandex.AnnotationValue)4 Type (org.jboss.jandex.Type)4 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)3 MethodIdentifier (org.jboss.invocation.proxy.MethodIdentifier)3 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)2 DotName (org.jboss.jandex.DotName)2 MethodParameterInfo (org.jboss.jandex.MethodParameterInfo)2 PropertyReplacer (org.jboss.metadata.property.PropertyReplacer)2 JBossWebContainer (org.wildfly.swarm.undertow.descriptors.JBossWebContainer)2