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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations