diff options
author | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-01-09 19:58:05 +0000 |
---|---|---|
committer | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-01-09 19:58:05 +0000 |
commit | 65bf3316cf384588453604be6b4f0ed3751a8b0f (patch) | |
tree | 996a5f57d4a68c53473382e45cb22f574cb3e4db /libjava/classpath/sun/reflect/annotation/AnnotationInvocationHandler.java | |
parent | 8fc56618a84446beccd45b80381cdfe0e94050df (diff) | |
download | gcc-65bf3316cf384588453604be6b4f0ed3751a8b0f.tar.gz |
Merged gcj-eclipse branch to trunk.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@120621 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/sun/reflect/annotation/AnnotationInvocationHandler.java')
-rw-r--r-- | libjava/classpath/sun/reflect/annotation/AnnotationInvocationHandler.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/libjava/classpath/sun/reflect/annotation/AnnotationInvocationHandler.java b/libjava/classpath/sun/reflect/annotation/AnnotationInvocationHandler.java index ab9ad13d853..f132d81bad8 100644 --- a/libjava/classpath/sun/reflect/annotation/AnnotationInvocationHandler.java +++ b/libjava/classpath/sun/reflect/annotation/AnnotationInvocationHandler.java @@ -39,11 +39,13 @@ exception statement from your version. */ package sun.reflect.annotation; import java.io.Serializable; +import java.lang.annotation.Annotation; import java.lang.annotation.AnnotationTypeMismatchException; import java.lang.annotation.IncompleteAnnotationException; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.lang.reflect.Proxy; import java.util.Arrays; import java.util.Iterator; import java.util.Map; @@ -74,6 +76,24 @@ public final class AnnotationInvocationHandler this.memberValues = memberValues; } + public static Annotation create(Class type, Map memberValues) + { + for (Method m : type.getDeclaredMethods()) + { + String name = m.getName(); + if (! memberValues.containsKey(name)) + { + // FIXME: what to do about exceptions here? + memberValues.put(name, m.getDefaultValue()); + } + } + AnnotationInvocationHandler handler + = new AnnotationInvocationHandler(type, memberValues); + return (Annotation) Proxy.newProxyInstance(type.getClassLoader(), + new Class[] { type }, + handler); + } + /** * Compare an instance of AnnotationInvocationHandler with another object. * Note that the other object does not have to be an @@ -295,6 +315,38 @@ public final class AnnotationInvocationHandler return returnType; } + private Object arrayClone(Object obj) + { + if (obj instanceof boolean[]) + return ((boolean[]) obj).clone(); + + if (obj instanceof byte[]) + return ((byte[]) obj).clone(); + + if (obj instanceof char[]) + return ((char[]) obj).clone(); + + if (obj instanceof short[]) + return ((short[]) obj).clone(); + + if (obj instanceof int[]) + return ((int[]) obj).clone(); + + if (obj instanceof float[]) + return ((float[]) obj).clone(); + + if (obj instanceof long[]) + return ((long[]) obj).clone(); + + if (obj instanceof double[]) + return ((double[]) obj).clone(); + + if (obj instanceof Object[]) + return ((Object[]) obj).clone(); + + return obj; + } + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { @@ -325,6 +377,10 @@ public final class AnnotationInvocationHandler throw new AnnotationTypeMismatchException(method, val.getClass().getName()); } + if (val.getClass().isArray()) + { + val = arrayClone(val); + } return val; } } |