mirror of
https://github.com/corda/corda.git
synced 2025-06-12 20:28:18 +00:00
support runtime-visible annotations and java.lang.reflect.Proxy
This commit is contained in:
@ -10,6 +10,10 @@
|
||||
|
||||
package java.lang.reflect;
|
||||
|
||||
import avian.AnnotationInvocationHandler;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
public class Field<T> extends AccessibleObject {
|
||||
private static final int VoidField = 0;
|
||||
private static final int ByteField = 1;
|
||||
@ -27,7 +31,8 @@ public class Field<T> extends AccessibleObject {
|
||||
private short flags;
|
||||
private short offset;
|
||||
private byte[] name;
|
||||
private byte[] spec;
|
||||
public byte[] spec;
|
||||
public Addendum addendum;
|
||||
private Class<T> class_;
|
||||
|
||||
private Field() { }
|
||||
@ -195,6 +200,45 @@ public class Field<T> extends AccessibleObject {
|
||||
}
|
||||
}
|
||||
|
||||
private Annotation getAnnotation(Object[] a) {
|
||||
if (a[0] == null) {
|
||||
a[0] = Proxy.newProxyInstance
|
||||
(class_.getClassLoader(), new Class[] { (Class) a[1] },
|
||||
new AnnotationInvocationHandler(a));
|
||||
}
|
||||
return (Annotation) a[0];
|
||||
}
|
||||
|
||||
public <T extends Annotation> T getAnnotation(Class<T> class_) {
|
||||
if (addendum != null && addendum.annotationTable != null) {
|
||||
Object[] table = addendum.annotationTable;
|
||||
for (int i = 0; i < table.length; ++i) {
|
||||
Object[] a = (Object[]) table[i];
|
||||
if (a[1] == class_) {
|
||||
return (T) getAnnotation(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Annotation[] getAnnotations() {
|
||||
if (addendum != null && addendum.annotationTable != null) {
|
||||
Object[] table = addendum.annotationTable;
|
||||
Annotation[] array = new Annotation[table.length];
|
||||
for (int i = 0; i < table.length; ++i) {
|
||||
array[i] = getAnnotation((Object[]) table[i]);
|
||||
}
|
||||
return array;
|
||||
} else {
|
||||
return new Annotation[0];
|
||||
}
|
||||
}
|
||||
|
||||
public Annotation[] getDeclaredAnnotations() {
|
||||
return getAnnotations();
|
||||
}
|
||||
|
||||
public boolean isEnumConstant() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@ -210,4 +254,8 @@ public class Field<T> extends AccessibleObject {
|
||||
|
||||
private static native void setObject
|
||||
(Object instance, int offset, Object value);
|
||||
|
||||
public static class Addendum {
|
||||
public Object[] annotationTable;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user