use of java.lang.reflect.AccessibleObject in project OpenAttestation by OpenAttestation.
the class ValidationUtil method validateObjectArray.
/**
*
* @param object instance to validate
* @param context is the Field or Method from which we obtained the object
* instance; we look for
* @Unchecked and
* @Validator annotations
* @param contextName is the name of the Field or Method from which we
* obtained the object instance
* @param parent is the instance containing the Field or Method from which
* we obtained the object instance
*/
private static void validateObjectArray(Object[] array, AccessibleObject context, String contextName, Object parent, ArrayList<Object> visited) {
if (context.isAnnotationPresent(Unchecked.class)) {
log.debug("Object array of class {} in {} of {} is unchecked", array.getClass().getName(), contextName, parent.getClass().getName());
return;
}
log.debug("validateObjectArray of length {}", array.length);
// validate each item in the array
for (int i = 0; i < array.length; i++) {
Object object = array[i];
validateObject(object, context, String.format("%s[%d]", contextName, i), parent, visited);
}
}
use of java.lang.reflect.AccessibleObject in project OpenAttestation by OpenAttestation.
the class ValidationUtil method validateObjectCollection.
/**
*
* @param object instance to validate
* @param context is the Field or Method from which we obtained the object
* instance; we look for
* @Unchecked and
* @Validator annotations
* @param contextName is the name of the Field or Method from which we
* obtained the object instance
* @param parent is the instance containing the Field or Method from which
* we obtained the object instance
*/
private static void validateObjectCollection(Collection<Object> collection, AccessibleObject context, String contextName, Object parent, ArrayList<Object> visited) {
if (context.isAnnotationPresent(Unchecked.class)) {
log.debug("Object collection of class {} in {} of {} is unchecked", collection.getClass().getName(), contextName, parent.getClass().getName());
return;
}
log.debug("validateObjectCollection of size {}", collection.size());
// TODO: if it's an array and annotated with a specific @ArrayValidator , use it directly
/*
if( context.isAnnotationPresent(Validator.class)) {
Class validatorClass = context.getAnnotation(Validator.class).value();
validateWithValidatorClass(object, validatorClass);
return;
}
*/
// validate each item in the collection
/*
ParameterizedType stringListType = (ParameterizedType) field.getGenericType();
Class<?> stringListClass = (Class<?>) stringListType.getActualTypeArguments()[0];
stringReturn = stringListClass.isAssignableFrom(String.class);
*
*/
int i = 0;
for (Object object : collection) {
validateObject(object, context, String.format("%s[%d]", contextName, i), parent, visited);
i++;
}
}
use of java.lang.reflect.AccessibleObject in project XobotOS by xamarin.
the class ViewDebug method getExportedPropertyFields.
private static Field[] getExportedPropertyFields(Class<?> klass) {
if (sFieldsForClasses == null) {
sFieldsForClasses = new HashMap<Class<?>, Field[]>();
}
if (sAnnotations == null) {
sAnnotations = new HashMap<AccessibleObject, ExportedProperty>(512);
}
final HashMap<Class<?>, Field[]> map = sFieldsForClasses;
Field[] fields = map.get(klass);
if (fields != null) {
return fields;
}
final ArrayList<Field> foundFields = new ArrayList<Field>();
fields = klass.getDeclaredFields();
int count = fields.length;
for (int i = 0; i < count; i++) {
final Field field = fields[i];
if (field.isAnnotationPresent(ExportedProperty.class)) {
field.setAccessible(true);
foundFields.add(field);
sAnnotations.put(field, field.getAnnotation(ExportedProperty.class));
}
}
fields = foundFields.toArray(new Field[foundFields.size()]);
map.put(klass, fields);
return fields;
}
use of java.lang.reflect.AccessibleObject in project wildfly by wildfly.
the class WSRefAnnotationProcessor method elementForInjectionTarget.
private static AnnotatedElement elementForInjectionTarget(final DeploymentUnit unit, final InjectionTarget injectionTarget) throws DeploymentUnitProcessingException {
final Module module = unit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
final DeploymentReflectionIndex deploymentReflectionIndex = unit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
final String injectionTargetClassName = injectionTarget.getClassName();
final String injectionTargetName = getInjectionTargetName(injectionTarget);
final AccessibleObject fieldOrMethod = getInjectionTarget(injectionTargetClassName, injectionTargetName, module.getClassLoader(), deploymentReflectionIndex);
return fieldOrMethod;
}
use of java.lang.reflect.AccessibleObject in project android_frameworks_base by AOSPA.
the class ViewDebug method getExportedPropertyMethods.
private static Method[] getExportedPropertyMethods(Class<?> klass) {
if (sMethodsForClasses == null) {
sMethodsForClasses = new HashMap<Class<?>, Method[]>(100);
}
if (sAnnotations == null) {
sAnnotations = new HashMap<AccessibleObject, ExportedProperty>(512);
}
final HashMap<Class<?>, Method[]> map = sMethodsForClasses;
Method[] methods = map.get(klass);
if (methods != null) {
return methods;
}
methods = klass.getDeclaredMethodsUnchecked(false);
final ArrayList<Method> foundMethods = new ArrayList<Method>();
for (final Method method : methods) {
// Ensure the method return and parameter types can be resolved.
try {
method.getReturnType();
method.getParameterTypes();
} catch (NoClassDefFoundError e) {
continue;
}
if (method.getParameterTypes().length == 0 && method.isAnnotationPresent(ExportedProperty.class) && method.getReturnType() != Void.class) {
method.setAccessible(true);
foundMethods.add(method);
sAnnotations.put(method, method.getAnnotation(ExportedProperty.class));
}
}
methods = foundMethods.toArray(new Method[foundMethods.size()]);
map.put(klass, methods);
return methods;
}
Aggregations