Search in sources :

Example 36 with AnnotationInstance

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

the class JandexHelper method getAnnotation.

public static AnnotationInstance getAnnotation(DeploymentUnit unit, String endpoint, String annotationClassName) {
    final List<AnnotationInstance> annotations = ASHelper.getAnnotations(unit, DotName.createSimple(annotationClassName));
    for (AnnotationInstance annotationInstance : annotations) {
        Object target = annotationInstance.target();
        if (target instanceof ClassInfo) {
            final ClassInfo classInfo = (ClassInfo) target;
            final String endpointClass = classInfo.name().toString();
            if (endpointClass.equals(endpoint)) {
                return annotationInstance;
            }
        } else if (target instanceof MethodInfo) {
            final MethodInfo methodInfo = (MethodInfo) target;
            final String endpointClass = methodInfo.declaringClass().name().toString();
            if (endpointClass.equals(endpoint)) {
                return annotationInstance;
            }
        }
    }
    return null;
}
Also used : MethodInfo(org.jboss.jandex.MethodInfo) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 37 with AnnotationInstance

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

the class WSRefAnnotationProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit unit = phaseContext.getDeploymentUnit();
    // Process @WebServiceRef annotations
    final List<AnnotationInstance> webServiceRefAnnotations = getAnnotations(unit, WEB_SERVICE_REF_ANNOTATION);
    for (final AnnotationInstance annotation : webServiceRefAnnotations) {
        final AnnotationTarget annotationTarget = annotation.target();
        final WSRefAnnotationWrapper annotationWrapper = new WSRefAnnotationWrapper(annotation);
        if (annotationTarget instanceof FieldInfo) {
            processFieldRef(unit, annotationWrapper, (FieldInfo) annotationTarget);
        } else if (annotationTarget instanceof MethodInfo) {
            processMethodRef(unit, annotationWrapper, (MethodInfo) annotationTarget);
        } else if (annotationTarget instanceof ClassInfo) {
            processClassRef(unit, annotationWrapper, (ClassInfo) annotationTarget);
        }
    }
    // Process @WebServiceRefs annotations
    final List<AnnotationInstance> webServiceRefsAnnotations = getAnnotations(unit, WEB_SERVICE_REFS_ANNOTATION);
    for (final AnnotationInstance outerAnnotation : webServiceRefsAnnotations) {
        final AnnotationTarget annotationTarget = outerAnnotation.target();
        if (annotationTarget instanceof ClassInfo) {
            final AnnotationInstance[] values = outerAnnotation.value("value").asNestedArray();
            for (final AnnotationInstance annotation : values) {
                final WSRefAnnotationWrapper annotationWrapper = new WSRefAnnotationWrapper(annotation);
                processClassRef(unit, annotationWrapper, (ClassInfo) annotationTarget);
            }
        }
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) 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 38 with AnnotationInstance

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

the class ClassAnnotationInformationFactory method createAnnotationInformation.

public Map<String, ClassAnnotationInformation<A, T>> createAnnotationInformation(final CompositeIndex index, final PropertyReplacer propertyReplacer) {
    final List<TargetAnnotation> annotations = new ArrayList<TargetAnnotation>();
    if (multiAnnotationDotName != null) {
        for (AnnotationInstance multiInstance : index.getAnnotations(multiAnnotationDotName)) {
            annotations.addAll(fromMultiAnnotation(multiInstance));
        }
    }
    final List<AnnotationInstance> simpleAnnotations = index.getAnnotations(annotationDotName);
    if (simpleAnnotations != null) {
        for (AnnotationInstance annotation : simpleAnnotations) {
            annotations.add(new TargetAnnotation(annotation, annotation.target()));
        }
    }
    final Map<DotName, List<TargetAnnotation>> classLevel = new HashMap<DotName, List<TargetAnnotation>>();
    final Map<DotName, List<TargetAnnotation>> methodLevel = new HashMap<DotName, List<TargetAnnotation>>();
    final Map<DotName, List<TargetAnnotation>> fieldLevel = new HashMap<DotName, List<TargetAnnotation>>();
    for (TargetAnnotation instance : annotations) {
        final DotName targetClass = getAnnotationClass(instance.target()).name();
        if (instance.target() instanceof ClassInfo) {
            List<TargetAnnotation> data = classLevel.get(targetClass);
            if (data == null)
                classLevel.put(targetClass, data = new ArrayList<TargetAnnotation>(1));
            data.add(instance);
        } else if (instance.target() instanceof MethodInfo) {
            List<TargetAnnotation> data = methodLevel.get(targetClass);
            if (data == null)
                methodLevel.put(targetClass, data = new ArrayList<TargetAnnotation>(1));
            data.add(instance);
        } else if (instance.target() instanceof FieldInfo) {
            List<TargetAnnotation> data = fieldLevel.get(targetClass);
            if (data == null)
                fieldLevel.put(targetClass, data = new ArrayList<TargetAnnotation>(1));
            data.add(instance);
        } else if (instance.target() instanceof MethodParameterInfo) {
        //ignore for now
        } else {
            throw EeLogger.ROOT_LOGGER.unknownAnnotationTargetType(instance.target());
        }
    }
    final Map<String, ClassAnnotationInformation<A, T>> ret = new HashMap<String, ClassAnnotationInformation<A, T>>();
    final Set<DotName> allClasses = new HashSet<DotName>(classLevel.keySet());
    allClasses.addAll(methodLevel.keySet());
    allClasses.addAll(fieldLevel.keySet());
    for (DotName clazz : allClasses) {
        final List<TargetAnnotation> classAnnotations = classLevel.get(clazz);
        final List<T> classData;
        if (classAnnotations == null) {
            classData = Collections.emptyList();
        } else {
            classData = new ArrayList<T>(classAnnotations.size());
            for (TargetAnnotation instance : classAnnotations) {
                classData.add(fromAnnotation(instance.instance(), propertyReplacer));
            }
        }
        final List<TargetAnnotation> fieldAnnotations = fieldLevel.get(clazz);
        final Map<String, List<T>> fieldData;
        //field level annotations
        if (fieldAnnotations == null) {
            fieldData = Collections.emptyMap();
        } else {
            fieldData = new HashMap<String, List<T>>();
            for (TargetAnnotation instance : fieldAnnotations) {
                final String name = ((FieldInfo) instance.target()).name();
                List<T> data = fieldData.get(name);
                if (data == null) {
                    fieldData.put(name, data = new ArrayList<T>(1));
                }
                data.add(fromAnnotation(instance.instance(), propertyReplacer));
            }
        }
        final List<TargetAnnotation> methodAnnotations = methodLevel.get(clazz);
        final Map<MethodIdentifier, List<T>> methodData;
        //method level annotations
        if (methodAnnotations == null) {
            methodData = Collections.emptyMap();
        } else {
            methodData = new HashMap<MethodIdentifier, List<T>>();
            for (TargetAnnotation instance : methodAnnotations) {
                final MethodIdentifier identifier = getMethodIdentifier(instance.target());
                List<T> data = methodData.get(identifier);
                if (data == null) {
                    methodData.put(identifier, data = new ArrayList<T>(1));
                }
                data.add(fromAnnotation(instance.instance(), propertyReplacer));
            }
        }
        ClassAnnotationInformation<A, T> information = new ClassAnnotationInformation<A, T>(annotationType, classData, methodData, fieldData);
        ret.put(clazz.toString(), information);
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DotName(org.jboss.jandex.DotName) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) MethodInfo(org.jboss.jandex.MethodInfo) MethodParameterInfo(org.jboss.jandex.MethodParameterInfo) AnnotationInstance(org.jboss.jandex.AnnotationInstance) FieldInfo(org.jboss.jandex.FieldInfo) ClassInfo(org.jboss.jandex.ClassInfo)

Example 39 with AnnotationInstance

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

the class JBossPersistenceMetaDataFactory method findPersistenceTypeNames.

private Set<String> findPersistenceTypeNames(PersistenceUnitMetadata pu) {
    synchronized (CACHED_TYPENAMES) {
        Set<String> typeNames = CACHED_TYPENAMES.get(pu);
        if (typeNames != null) {
            return typeNames;
        }
    }
    Set<String> persistenceTypeNames = new HashSet<String>();
    for (Map.Entry<URL, Index> entry : pu.getAnnotationIndex().entrySet()) {
        List<AnnotationInstance> instances = entry.getValue().getAnnotations(DotName.createSimple(Entity.class.getName()));
        for (AnnotationInstance instance : instances) {
            AnnotationTarget target = instance.target();
            if (target instanceof ClassInfo) {
                ClassInfo classInfo = (ClassInfo) target;
                persistenceTypeNames.add(classInfo.name().toString());
            }
        }
    }
    synchronized (CACHED_TYPENAMES) {
        CACHED_TYPENAMES.put(pu, persistenceTypeNames);
    }
    return persistenceTypeNames;
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) Index(org.jboss.jandex.Index) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL) AnnotationInstance(org.jboss.jandex.AnnotationInstance) HashSet(java.util.HashSet) ClassInfo(org.jboss.jandex.ClassInfo)

Example 40 with AnnotationInstance

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

the class TransactionDependenciesProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit unit = phaseContext.getDeploymentUnit();
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    final ModuleSpecification moduleSpec = unit.getAttachment(Attachments.MODULE_SPECIFICATION);
    moduleSpec.addSystemDependency(new ModuleDependency(moduleLoader, TRANSACTION_API, false, false, true, false));
    moduleSpec.addSystemDependency(new ModuleDependency(moduleLoader, ModuleIdentifier.fromString("org.wildfly.transaction.client"), false, false, true, false));
    final CompositeIndex compositeIndex = unit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    if (compositeIndex == null) {
        return;
    }
    final List<AnnotationInstance> transactionalAnnotations = compositeIndex.getAnnotations(DotName.createSimple(Transactional.class.getName()));
    final List<AnnotationInstance> transactionScopedAnnotations = compositeIndex.getAnnotations(DotName.createSimple(TransactionScoped.class.getName()));
    if (transactionalAnnotations.size() > 0 || transactionScopedAnnotations.size() > 0) {
        addJTSModuleDependencyToDeployment(unit);
    }
}
Also used : ModuleLoader(org.jboss.modules.ModuleLoader) ModuleDependency(org.jboss.as.server.deployment.module.ModuleDependency) ModuleSpecification(org.jboss.as.server.deployment.module.ModuleSpecification) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance)

Aggregations

AnnotationInstance (org.jboss.jandex.AnnotationInstance)40 ClassInfo (org.jboss.jandex.ClassInfo)26 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)17 AnnotationTarget (org.jboss.jandex.AnnotationTarget)16 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)15 AnnotationValue (org.jboss.jandex.AnnotationValue)11 MethodInfo (org.jboss.jandex.MethodInfo)11 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)9 HashSet (java.util.HashSet)8 DotName (org.jboss.jandex.DotName)7 FieldInfo (org.jboss.jandex.FieldInfo)7 ArrayList (java.util.ArrayList)5 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)5 PropertyReplacer (org.jboss.metadata.property.PropertyReplacer)5 HashMap (java.util.HashMap)4 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)4 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)3 Module (org.jboss.modules.Module)3 PersistenceUnitMetadata (org.jipijapa.plugin.spi.PersistenceUnitMetadata)3 URL (java.net.URL)2