Search in sources :

Example 6 with AltAnnotation

use of org.glassfish.hk2.xml.internal.alt.AltAnnotation in project glassfish-hk2 by eclipse-ee4j.

the class Generator method createAnnotationCopy.

private static void createAnnotationCopy(ConstPool parent, AltAnnotation javaAnnotation, AnnotationsAttribute retVal) throws Throwable {
    Annotation addMe = createAnnotationCopyOnly(parent, javaAnnotation);
    retVal.addAnnotation(addMe);
}
Also used : Annotation(javassist.bytecode.annotation.Annotation) AltAnnotation(org.glassfish.hk2.xml.internal.alt.AltAnnotation)

Example 7 with AltAnnotation

use of org.glassfish.hk2.xml.internal.alt.AltAnnotation in project glassfish-hk2 by eclipse-ee4j.

the class Utilities method getAdapterInformation.

private static AdapterInformation getAdapterInformation(AltMethod method) {
    AltAnnotation adapterAnnotation = isSpecifiedAdapted(method);
    if (adapterAnnotation == null)
        return null;
    AltClass adapter = adapterAnnotation.getClassValue("value");
    AltClass valueType = adapter.getSuperParameterizedType(ClassAltClassImpl.XML_ADAPTER, 0);
    AltClass boundType = adapter.getSuperParameterizedType(ClassAltClassImpl.XML_ADAPTER, 1);
    return new AdapterInformationImpl(adapter, valueType, boundType);
}
Also used : AltAnnotation(org.glassfish.hk2.xml.internal.alt.AltAnnotation) AltClass(org.glassfish.hk2.xml.internal.alt.AltClass)

Example 8 with AltAnnotation

use of org.glassfish.hk2.xml.internal.alt.AltAnnotation in project glassfish-hk2 by eclipse-ee4j.

the class MethodAltMethodImpl method getAnnotations.

/* (non-Javadoc)
     * @see org.glassfish.hk2.xml.internal.alt.AltMethod#getAnnotations()
     */
@Override
public synchronized List<AltAnnotation> getAnnotations() {
    if (altAnnotations != null)
        return altAnnotations;
    Annotation[] annotations = method.getAnnotations();
    ArrayList<AltAnnotation> retVal = new ArrayList<AltAnnotation>(annotations.length);
    for (Annotation annotation : annotations) {
        retVal.add(new AnnotationAltAnnotationImpl(annotation, helper));
    }
    altAnnotations = Collections.unmodifiableList(retVal);
    return altAnnotations;
}
Also used : AltAnnotation(org.glassfish.hk2.xml.internal.alt.AltAnnotation) ArrayList(java.util.ArrayList) AltAnnotation(org.glassfish.hk2.xml.internal.alt.AltAnnotation) Annotation(java.lang.annotation.Annotation)

Example 9 with AltAnnotation

use of org.glassfish.hk2.xml.internal.alt.AltAnnotation in project glassfish-hk2 by eclipse-ee4j.

the class AnnotationAltAnnotationImpl method getAnnotationValues.

/* (non-Javadoc)
     * @see org.glassfish.hk2.xml.internal.alt.AltAnnotation#getAnnotationValues()
     */
@Override
public synchronized Map<String, Object> getAnnotationValues() {
    if (values != null)
        return values;
    Map<String, Object> retVal = new TreeMap<String, Object>();
    for (Method javaAnnotationMethod : annotation.annotationType().getMethods()) {
        if (javaAnnotationMethod.getParameterTypes().length != 0)
            continue;
        if (DO_NOT_HANDLE_METHODS.contains(javaAnnotationMethod.getName()))
            continue;
        String key = javaAnnotationMethod.getName();
        Object value;
        try {
            value = ReflectionHelper.invoke(annotation, javaAnnotationMethod, new Object[0], false);
            if (value == null) {
                throw new AssertionError("Recieved null from annotation method " + javaAnnotationMethod.getName());
            }
        } catch (RuntimeException re) {
            throw re;
        } catch (Throwable th) {
            throw new RuntimeException(th);
        }
        if (value instanceof Class) {
            value = new ClassAltClassImpl((Class<?>) value, helper);
        } else if (Enum.class.isAssignableFrom(value.getClass())) {
            value = new EnumAltEnumImpl((Enum<?>) value);
        } else if (value.getClass().isArray() && Class.class.equals(value.getClass().getComponentType())) {
            Class<?>[] cValue = (Class<?>[]) value;
            AltClass[] translatedValue = new AltClass[cValue.length];
            for (int lcv = 0; lcv < cValue.length; lcv++) {
                translatedValue[lcv] = new ClassAltClassImpl(cValue[lcv], helper);
            }
            value = translatedValue;
        } else if (value.getClass().isArray() && Enum.class.isAssignableFrom(value.getClass().getComponentType())) {
            Enum<?>[] eValue = (Enum<?>[]) value;
            AltEnum[] translatedValue = new AltEnum[eValue.length];
            for (int lcv = 0; lcv < eValue.length; lcv++) {
                translatedValue[lcv] = new EnumAltEnumImpl(eValue[lcv]);
            }
            value = translatedValue;
        } else if (value.getClass().isArray() && Annotation.class.isAssignableFrom(value.getClass().getComponentType())) {
            Annotation[] aValue = (Annotation[]) value;
            AltAnnotation[] translatedValue = new AltAnnotation[aValue.length];
            for (int lcv = 0; lcv < aValue.length; lcv++) {
                translatedValue[lcv] = new AnnotationAltAnnotationImpl(aValue[lcv], helper);
            }
            value = translatedValue;
        }
        retVal.put(key, value);
    }
    values = Collections.unmodifiableMap(retVal);
    return values;
}
Also used : AltEnum(org.glassfish.hk2.xml.internal.alt.AltEnum) AltAnnotation(org.glassfish.hk2.xml.internal.alt.AltAnnotation) Method(java.lang.reflect.Method) TreeMap(java.util.TreeMap) AltClass(org.glassfish.hk2.xml.internal.alt.AltClass) AltAnnotation(org.glassfish.hk2.xml.internal.alt.AltAnnotation) Annotation(java.lang.annotation.Annotation) AltClass(org.glassfish.hk2.xml.internal.alt.AltClass)

Example 10 with AltAnnotation

use of org.glassfish.hk2.xml.internal.alt.AltAnnotation in project glassfish-hk2 by eclipse-ee4j.

the class ElementAltMethodImpl method getAnnotations.

/* (non-Javadoc)
     * @see org.glassfish.hk2.xml.internal.alt.AltMethod#getAnnotations()
     */
@Override
public synchronized List<AltAnnotation> getAnnotations() {
    if (annotations != null) {
        return Collections.unmodifiableList(new ArrayList<AltAnnotation>(annotations.values()));
    }
    Map<String, AltAnnotation> retVal = new LinkedHashMap<String, AltAnnotation>();
    for (AnnotationMirror annoMirror : method.getAnnotationMirrors()) {
        AnnotationMirrorAltAnnotationImpl addMe = new AnnotationMirrorAltAnnotationImpl(annoMirror, processingEnv);
        retVal.put(addMe.annotationType(), addMe);
    }
    annotations = Collections.unmodifiableMap(retVal);
    return Collections.unmodifiableList(new ArrayList<AltAnnotation>(annotations.values()));
}
Also used : AltAnnotation(org.glassfish.hk2.xml.internal.alt.AltAnnotation) AnnotationMirror(javax.lang.model.element.AnnotationMirror) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

AltAnnotation (org.glassfish.hk2.xml.internal.alt.AltAnnotation)11 AltClass (org.glassfish.hk2.xml.internal.alt.AltClass)6 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 Annotation (java.lang.annotation.Annotation)3 List (java.util.List)3 Map (java.util.Map)3 AnnotationMirror (javax.lang.model.element.AnnotationMirror)3 AltEnum (org.glassfish.hk2.xml.internal.alt.AltEnum)3 XmlElement (jakarta.xml.bind.annotation.XmlElement)2 XmlElements (jakarta.xml.bind.annotation.XmlElements)2 LinkedHashSet (java.util.LinkedHashSet)2 TreeMap (java.util.TreeMap)2 CtClass (javassist.CtClass)2 Annotation (javassist.bytecode.annotation.Annotation)2 XmlAnyAttribute (jakarta.xml.bind.annotation.XmlAnyAttribute)1 XmlAttribute (jakarta.xml.bind.annotation.XmlAttribute)1 XmlElementWrapper (jakarta.xml.bind.annotation.XmlElementWrapper)1 XmlRootElement (jakarta.xml.bind.annotation.XmlRootElement)1 XmlType (jakarta.xml.bind.annotation.XmlType)1