use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.
the class DefaultBeanInfo method getGetter.
@Override
public Method getGetter(final String propertyName, final Class<?> type) {
final boolean isBoolean = Boolean.TYPE.equals(type);
final String name = ((isBoolean) ? "is" : "get") + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
final Method result = lookup(new Lookup<Method>() {
@Override
public Method lookup(ClassReflectionIndex index) {
Collection<Method> methods = index.getAllMethods(name, 0);
if (type == null) {
if (methods.size() == 1)
return methods.iterator().next();
else
return null;
}
for (Method m : methods) {
Class<?> pt = m.getReturnType();
if (pt.isAssignableFrom(type))
return m;
}
return null;
}
}, 0, Integer.MAX_VALUE);
if (result == null)
throw PojoLogger.ROOT_LOGGER.getterNotFound(type, beanClass.getName());
return result;
}
use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.
the class DefaultBeanInfo method getSetter.
@Override
public Method getSetter(final String propertyName, final Class<?> type) {
final String name = "set" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
final Method result = lookup(new Lookup<Method>() {
@Override
public Method lookup(ClassReflectionIndex index) {
Collection<Method> methods = index.getAllMethods(name, 1);
if (type == null) {
if (methods.size() == 1)
return methods.iterator().next();
else
return null;
}
for (Method m : methods) {
Class<?> pt = m.getParameterTypes()[0];
if (pt.isAssignableFrom(type))
return m;
}
return null;
}
}, 0, Integer.MAX_VALUE);
if (result == null)
throw PojoLogger.ROOT_LOGGER.setterNotFound(type, beanClass.getName());
return result;
}
use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.
the class DefaultBeanInfo method lookup.
/**
* Do lazy lookup.
*
* @param lookup the lookup
* @param start the start
* @param depth the depth
* @return reflection index result
*/
protected <U> U lookup(Lookup<U> lookup, int start, int depth) {
int size;
synchronized (indexes) {
size = indexes.size();
for (int i = start; i < depth && i < size; i++) {
U result = lookup.lookup(indexes.get(i));
if (result != null)
return result;
}
}
if (currentClass == null)
return null;
synchronized (indexes) {
ClassReflectionIndex cri = index.getClassIndex(currentClass);
indexes.add(cri);
currentClass = currentClass.getSuperclass();
}
return lookup(lookup, size, depth);
}
use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.
the class MethodAnnotationAggregator method runtimeAnnotationInformation.
public static <A extends Annotation, T> RuntimeAnnotationInformation<T> runtimeAnnotationInformation(final Class<?> componentClass, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex index, final Class<A> annotationType) {
final HashSet<MethodIdentifier> methodIdentifiers = new HashSet<MethodIdentifier>();
final Map<Method, List<T>> methods = new HashMap<Method, List<T>>();
final Map<String, List<T>> classAnnotations = new HashMap<String, List<T>>();
Class<?> c = componentClass;
while (c != null && c != Object.class) {
final ClassReflectionIndex classIndex = index.getClassIndex(c);
final EEModuleClassDescription description = applicationClasses.getClassByName(c.getName());
if (description != null) {
ClassAnnotationInformation<A, T> annotationData = description.getAnnotationInformation(annotationType);
if (annotationData != null) {
if (!annotationData.getClassLevelAnnotations().isEmpty()) {
classAnnotations.put(c.getName(), annotationData.getClassLevelAnnotations());
}
for (Map.Entry<MethodIdentifier, List<T>> entry : annotationData.getMethodLevelAnnotations().entrySet()) {
final Method method = classIndex.getMethod(entry.getKey());
if (method != null) {
//we do not have to worry about private methods being overridden
if (Modifier.isPrivate(method.getModifiers()) || !methodIdentifiers.contains(entry.getKey())) {
methods.put(method, entry.getValue());
}
} else {
//but if it does, we give some info
throw EeLogger.ROOT_LOGGER.cannotResolveMethod(entry.getKey(), c, entry.getValue());
}
}
}
}
//so we can check if a method is overriden
for (Method method : (Iterable<Method>) classIndex.getMethods()) {
//we do not have to worry about private methods being overridden
if (!Modifier.isPrivate(method.getModifiers())) {
methodIdentifiers.add(MethodIdentifier.getIdentifierForMethod(method));
}
}
c = c.getSuperclass();
}
return new RuntimeAnnotationInformation<T>(classAnnotations, methods);
}
Aggregations