Search in sources :

Example 1 with MethodWrapper

use of org.glassfish.hk2.utilities.reflection.MethodWrapper in project glassfish-hk2 by eclipse-ee4j.

the class ModelImpl method getJavaNameFromKey.

public synchronized String getJavaNameFromKey(String key, ClassReflectionHelper reflectionHelper) {
    if (keyToJavaNameMap == null) {
        keyToJavaNameMap = new LinkedHashMap<String, String>();
    }
    String result = keyToJavaNameMap.get(key);
    if (result != null)
        return result;
    if (reflectionHelper == null)
        return null;
    Class<?> originalInterface = getOriginalInterfaceAsClass();
    for (MethodWrapper wrapper : reflectionHelper.getAllMethods(originalInterface)) {
        Method m = wrapper.getMethod();
        String xmlName;
        XmlElement element = m.getAnnotation(XmlElement.class);
        if (element == null) {
            XmlAttribute attribute = m.getAnnotation(XmlAttribute.class);
            if (attribute == null)
                continue;
            xmlName = attribute.name();
        } else {
            xmlName = element.name();
        }
        String keyName;
        String javaName = getJavaNameFromGetterOrSetter(m, reflectionHelper);
        if ("##default".equals(xmlName)) {
            keyName = javaName;
        } else {
            keyName = xmlName;
        }
        if (!key.equals(keyName))
            continue;
        // Found it!
        keyToJavaNameMap.put(key, javaName);
        return javaName;
    }
    return null;
}
Also used : XmlAttribute(jakarta.xml.bind.annotation.XmlAttribute) XmlElement(jakarta.xml.bind.annotation.XmlElement) MethodWrapper(org.glassfish.hk2.utilities.reflection.MethodWrapper) AltMethod(org.glassfish.hk2.xml.internal.alt.AltMethod) Method(java.lang.reflect.Method)

Example 2 with MethodWrapper

use of org.glassfish.hk2.utilities.reflection.MethodWrapper in project glassfish-hk2 by eclipse-ee4j.

the class ClassAltClassImpl method getMethods.

/* (non-Javadoc)
     * @see org.glassfish.hk2.xml.internal.alt.AltClass#getMethods()
     */
@Override
public synchronized List<AltMethod> getMethods() {
    if (methods != null)
        return methods;
    Set<MethodWrapper> wrappers = helper.getAllMethods(clazz);
    ArrayList<AltMethod> retVal = new ArrayList<AltMethod>(wrappers.size());
    for (MethodWrapper method : wrappers) {
        retVal.add(new MethodAltMethodImpl(method.getMethod(), helper));
    }
    methods = Collections.unmodifiableList(retVal);
    return methods;
}
Also used : AltMethod(org.glassfish.hk2.xml.internal.alt.AltMethod) ArrayList(java.util.ArrayList) MethodWrapper(org.glassfish.hk2.utilities.reflection.MethodWrapper)

Example 3 with MethodWrapper

use of org.glassfish.hk2.utilities.reflection.MethodWrapper in project glassfish-hk2 by eclipse-ee4j.

the class PBUtilities method getAllMethodsWithName.

private static Set<Method> getAllMethodsWithName(Class<?> oInterface, String methodName) {
    HashSet<Method> retVal = new HashSet<Method>();
    Set<MethodWrapper> allMethods = reflectionHelper.getAllMethods(oInterface);
    for (MethodWrapper wrapper : allMethods) {
        if (methodName.equals(wrapper.getMethod().getName())) {
            retVal.add(wrapper.getMethod());
        }
    }
    return retVal;
}
Also used : Method(java.lang.reflect.Method) MethodWrapper(org.glassfish.hk2.utilities.reflection.MethodWrapper) HashSet(java.util.HashSet)

Example 4 with MethodWrapper

use of org.glassfish.hk2.utilities.reflection.MethodWrapper in project glassfish-hk2 by eclipse-ee4j.

the class ClassReflectionHelperUtilities method getDeclaredMethodWrappers.

/**
 * Gets the EXACT set of MethodWrappers on this class only.  No subclasses.  So
 * this set should be considered RAW and has not taken into account any subclasses
 *
 * @param clazz The class to examine
 * @return
 */
private static Set<MethodWrapper> getDeclaredMethodWrappers(final Class<?> clazz) {
    Method[] declaredMethods = secureGetDeclaredMethods(clazz);
    Set<MethodWrapper> retVal = new LinkedHashSet<MethodWrapper>();
    for (Method method : declaredMethods) {
        retVal.add(new MethodWrapperImpl(method));
    }
    return retVal;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Method(java.lang.reflect.Method) MethodWrapper(org.glassfish.hk2.utilities.reflection.MethodWrapper)

Example 5 with MethodWrapper

use of org.glassfish.hk2.utilities.reflection.MethodWrapper in project glassfish-hk2 by eclipse-ee4j.

the class ClassReflectionHelperUtilities method getAllMethodWrappers.

/**
 * Returns methods of a class, including those in superclasses and interfaces.
 * @param clazz Class to get methods of
 * @return
 */
static Set<MethodWrapper> getAllMethodWrappers(Class<?> clazz) {
    if (clazz == null)
        return Collections.emptySet();
    if (Object.class.equals(clazz))
        return OBJECT_METHODS;
    Set<MethodWrapper> retVal = new LinkedHashSet<MethodWrapper>();
    if (clazz.isInterface()) {
        for (Method m : clazz.getDeclaredMethods()) {
            MethodWrapper wrapper = new MethodWrapperImpl(m);
            retVal.add(wrapper);
        }
        for (Class<?> extendee : clazz.getInterfaces()) {
            retVal.addAll(getAllMethodWrappers(extendee));
        }
    } else {
        retVal.addAll(getDeclaredMethodWrappers(clazz));
        retVal.addAll(getAllMethodWrappers(clazz.getSuperclass()));
    }
    return retVal;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MethodWrapper(org.glassfish.hk2.utilities.reflection.MethodWrapper) Method(java.lang.reflect.Method)

Aggregations

MethodWrapper (org.glassfish.hk2.utilities.reflection.MethodWrapper)10 Method (java.lang.reflect.Method)9 LinkedHashSet (java.util.LinkedHashSet)3 ArrayList (java.util.ArrayList)2 ClassReflectionHelper (org.glassfish.hk2.utilities.reflection.ClassReflectionHelper)2 AltMethod (org.glassfish.hk2.xml.internal.alt.AltMethod)2 XmlAttribute (jakarta.xml.bind.annotation.XmlAttribute)1 XmlElement (jakarta.xml.bind.annotation.XmlElement)1 Annotation (java.lang.annotation.Annotation)1 GenericArrayType (java.lang.reflect.GenericArrayType)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 WildcardType (java.lang.reflect.WildcardType)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ConstructorInterceptor (org.aopalliance.intercept.ConstructorInterceptor)1 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)1 AOPProxyCtl (org.glassfish.hk2.api.AOPProxyCtl)1