use of java.lang.reflect.AccessibleObject in project platform_frameworks_base by android.
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;
}
try {
final Field[] declaredFields = klass.getDeclaredFieldsUnchecked(false);
final ArrayList<Field> foundFields = new ArrayList<Field>();
for (final Field field : declaredFields) {
// Fields which can't be resolved have a null type.
if (field.getType() != null && 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);
} catch (NoClassDefFoundError e) {
throw new AssertionError(e);
}
return fields;
}
use of java.lang.reflect.AccessibleObject in project j2objc by google.
the class AccessibleObjectTest method test_getDeclaredAnnotations.
public void test_getDeclaredAnnotations() throws Exception {
AccessibleObject ao = SubTestClass.class.getMethod("annotatedMethod");
Annotation[] annotations = ao.getDeclaredAnnotations();
assertEquals(2, annotations.length);
Set<Class<?>> ignoreOrder = new HashSet<Class<?>>();
ignoreOrder.add(annotations[0].annotationType());
ignoreOrder.add(annotations[1].annotationType());
assertTrue("Missing @AnnotationRuntime0", ignoreOrder.contains(AnnotationRuntime0.class));
assertTrue("Missing @AnnotationRuntime1", ignoreOrder.contains(AnnotationRuntime1.class));
}
use of java.lang.reflect.AccessibleObject in project j2objc by google.
the class AccessibleObjectTest method test_getAnnotation.
public void test_getAnnotation() throws Exception {
AccessibleObject ao = SubTestClass.class.getMethod("annotatedMethod");
//test error case
boolean npeThrown = false;
try {
ao.getAnnotation(null);
fail("NPE expected");
} catch (NullPointerException e) {
npeThrown = true;
}
assertTrue("NPE expected", npeThrown);
//test inherited on method has no effect
InheritedRuntime ir = ao.getAnnotation(InheritedRuntime.class);
assertNull("Inherited Annotations should have no effect", ir);
//test ordinary runtime annotation
AnnotationRuntime0 rt0 = ao.getAnnotation(AnnotationRuntime0.class);
assertNotNull("AnnotationRuntime0 instance expected", rt0);
}
use of java.lang.reflect.AccessibleObject in project j2objc by google.
the class AccessibleObjectTest method test_setAccessible$Ljava_lang_reflect_AccessibleObjectZ.
/**
* java.lang.reflect.AccessibleObject#setAccessible(java.lang.reflect.AccessibleObject[],
* boolean)
*/
public void test_setAccessible$Ljava_lang_reflect_AccessibleObjectZ() {
try {
AccessibleObject ao = TestClass.class.getField("aField");
AccessibleObject[] aoa = new AccessibleObject[] { ao };
AccessibleObject.setAccessible(aoa, true);
assertTrue("Returned false to isAccessible", ao.isAccessible());
AccessibleObject.setAccessible(aoa, false);
assertTrue("Returned true to isAccessible", !ao.isAccessible());
} catch (Exception e) {
fail("Exception during test : " + e.getMessage());
}
}
use of java.lang.reflect.AccessibleObject in project j2objc by google.
the class AccessibleObjectTest method test_getAnnotations.
public void test_getAnnotations() throws Exception {
AccessibleObject ao = SubTestClass.class.getMethod("annotatedMethod");
Annotation[] annotations = ao.getAnnotations();
assertEquals(2, annotations.length);
Set<Class<?>> ignoreOrder = new HashSet<Class<?>>();
ignoreOrder.add(annotations[0].annotationType());
ignoreOrder.add(annotations[1].annotationType());
assertTrue("Missing @AnnotationRuntime0", ignoreOrder.contains(AnnotationRuntime0.class));
assertTrue("Missing @AnnotationRuntime1", ignoreOrder.contains(AnnotationRuntime1.class));
}
Aggregations