This adds a couple of annotation methods that were missing from the original reference versions of Field, Method and Constructor and thus are also missing from the new VM interface.
ChangeLog:
2008-03-04 Andrew John Hughes <[EMAIL PROTECTED]>
* java/lang/reflect/AccessibleObject.java:
(getAnnotation(Class)): Documented.
(getAnnotations()): Likewise.
(getDeclaredAnnotations()): Likewise.
(isAnnotationPresent(Class)): Likewise.
* java/lang/reflect/Constructor.java,
* java/lang/reflect/Field.java,
* java/lang/reflect/Method.java,
* vm/reference/java/lang/reflect/VMConstructor.java,
* vm/reference/java/lang/reflect/VMField.java,
* vm/reference/java/lang/reflect/VMMethod.java:
(getAnnotation(Class)): Added.
(getDeclaredAnnotations()): Likewise.
--
Andrew :)
Support Free Java!
Contribute to GNU Classpath and the OpenJDK
http://www.gnu.org/software/classpath
http://openjdk.java.net
PGP Key: 94EFD9D8 (http://subkeys.pgp.net)
Fingerprint = F8EF F1EA 401E 2E60 15FA 7927 142C 2591 94EF D9D8
Index: java/lang/reflect/AccessibleObject.java
===================================================================
RCS file: /sources/classpath/classpath/java/lang/reflect/AccessibleObject.java,v
retrieving revision 1.9
diff -u -3 -p -u -r1.9 AccessibleObject.java
--- java/lang/reflect/AccessibleObject.java 10 Dec 2006 20:25:45 -0000 1.9
+++ java/lang/reflect/AccessibleObject.java 5 Mar 2008 21:09:43 -0000
@@ -160,21 +160,72 @@ public class AccessibleObject
this.flag = flag;
}
+ /**
+ * <p>
+ * Returns the element's annotation for the specified annotation type,
+ * or <code>null</code> if no such annotation exists.
+ * </p>
+ * <p>
+ * <strong>This method must be overridden by subclasses to provide
+ * appropriate behaviour.</strong>
+ * </p>
+ *
+ * @param annotationClass the type of annotation to look for.
+ * @return this element's annotation for the specified type, or
+ * <code>null</code> if no such annotation exists.
+ * @throws NullPointerException if the annotation class is <code>null</code>.
+ */
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
{
throw new AssertionError("Subclass must override this method");
}
+ /**
+ * Returns all annotations associated with the element. If there are
+ * no annotations associated with the element, then a zero-length array
+ * will be returned. The returned array may be modified by the client
+ * code, but this will have no effect on the annotation content of the
+ * element, and hence no effect on the return value of this method for
+ * future callers.
+ *
+ * @return this element's annotations.
+ */
public Annotation[] getAnnotations()
{
return getDeclaredAnnotations();
}
+ /**
+ * <p>
+ * Returns all annotations directly defined by the element. If there are
+ * no annotations directly associated with the element, then a zero-length
+ * array will be returned. The returned array may be modified by the client
+ * code, but this will have no effect on the annotation content of this
+ * class, and hence no effect on the return value of this method for
+ * future callers.
+ * </p>
+ * <p>
+ * <strong>This method must be overridden by subclasses to provide
+ * appropriate behaviour.</strong>
+ * </p>
+ *
+ * @return the annotations directly defined by the element.
+ * @since 1.5
+ */
public Annotation[] getDeclaredAnnotations()
{
throw new AssertionError("Subclass must override this method");
}
+ /**
+ * Returns true if an annotation for the specified type is associated
+ * with the element. This is primarily a short-hand for using marker
+ * annotations.
+ *
+ * @param annotationClass the type of annotation to look for.
+ * @return true if an annotation exists for the specified type.
+ * @since 1.5
+ */
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
{
return getAnnotation(annotationClass) != null;
Index: java/lang/reflect/Constructor.java
===================================================================
RCS file: /sources/classpath/classpath/java/lang/reflect/Constructor.java,v
retrieving revision 1.7
diff -u -3 -p -u -r1.7 Constructor.java
--- java/lang/reflect/Constructor.java 3 Mar 2008 21:21:32 -0000 1.7
+++ java/lang/reflect/Constructor.java 5 Mar 2008 21:09:43 -0000
@@ -414,4 +414,35 @@ public final class Constructor<T>
return cons.getParameterAnnotations();
}
+ /**
+ * Returns the element's annotation for the specified annotation type,
+ * or <code>null</code> if no such annotation exists.
+ *
+ * @param annotationClass the type of annotation to look for.
+ * @return this element's annotation for the specified type, or
+ * <code>null</code> if no such annotation exists.
+ * @throws NullPointerException if the annotation class is <code>null</code>.
+ */
+ @SuppressWarnings("unchecked")
+ public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
+ {
+ return (T) cons.getAnnotation(annotationClass);
+ }
+
+ /**
+ * Returns all annotations directly defined by the element. If there are
+ * no annotations directly associated with the element, then a zero-length
+ * array will be returned. The returned array may be modified by the client
+ * code, but this will have no effect on the annotation content of this
+ * class, and hence no effect on the return value of this method for
+ * future callers.
+ *
+ * @return the annotations directly defined by the element.
+ * @since 1.5
+ */
+ public Annotation[] getDeclaredAnnotations()
+ {
+ return cons.getDeclaredAnnotations();
+ }
+
}
Index: java/lang/reflect/Field.java
===================================================================
RCS file: /sources/classpath/classpath/java/lang/reflect/Field.java,v
retrieving revision 1.7
diff -u -3 -p -u -r1.7 Field.java
--- java/lang/reflect/Field.java 3 Mar 2008 21:21:32 -0000 1.7
+++ java/lang/reflect/Field.java 5 Mar 2008 21:09:43 -0000
@@ -43,6 +43,8 @@ import gnu.java.lang.CPStringBuilder;
import gnu.java.lang.reflect.FieldSignatureParser;
+import java.lang.annotation.Annotation;
+
/**
* The Field class represents a member variable of a class. It also allows
* dynamic access to a member, via reflection. This works for both
@@ -698,4 +700,35 @@ extends AccessibleObject implements Memb
return p.getFieldType();
}
+ /**
+ * Returns the element's annotation for the specified annotation type,
+ * or <code>null</code> if no such annotation exists.
+ *
+ * @param annotationClass the type of annotation to look for.
+ * @return this element's annotation for the specified type, or
+ * <code>null</code> if no such annotation exists.
+ * @throws NullPointerException if the annotation class is <code>null</code>.
+ */
+ @SuppressWarnings("unchecked")
+ public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
+ {
+ return (T) f.getAnnotation(annotationClass);
+ }
+
+ /**
+ * Returns all annotations directly defined by the element. If there are
+ * no annotations directly associated with the element, then a zero-length
+ * array will be returned. The returned array may be modified by the client
+ * code, but this will have no effect on the annotation content of this
+ * class, and hence no effect on the return value of this method for
+ * future callers.
+ *
+ * @return the annotations directly defined by the element.
+ * @since 1.5
+ */
+ public Annotation[] getDeclaredAnnotations()
+ {
+ return f.getDeclaredAnnotations();
+ }
+
}
Index: java/lang/reflect/Method.java
===================================================================
RCS file: /sources/classpath/classpath/java/lang/reflect/Method.java,v
retrieving revision 1.6
diff -u -3 -p -u -r1.6 Method.java
--- java/lang/reflect/Method.java 3 Mar 2008 21:21:32 -0000 1.6
+++ java/lang/reflect/Method.java 5 Mar 2008 21:09:43 -0000
@@ -464,4 +464,35 @@ extends AccessibleObject implements Memb
return m.getParameterAnnotations();
}
+ /**
+ * Returns the element's annotation for the specified annotation type,
+ * or <code>null</code> if no such annotation exists.
+ *
+ * @param annotationClass the type of annotation to look for.
+ * @return this element's annotation for the specified type, or
+ * <code>null</code> if no such annotation exists.
+ * @throws NullPointerException if the annotation class is <code>null</code>.
+ */
+ @SuppressWarnings("unchecked")
+ public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
+ {
+ return (T) m.getAnnotation(annotationClass);
+ }
+
+ /**
+ * Returns all annotations directly defined by the element. If there are
+ * no annotations directly associated with the element, then a zero-length
+ * array will be returned. The returned array may be modified by the client
+ * code, but this will have no effect on the annotation content of this
+ * class, and hence no effect on the return value of this method for
+ * future callers.
+ *
+ * @return the annotations directly defined by the element.
+ * @since 1.5
+ */
+ public Annotation[] getDeclaredAnnotations()
+ {
+ return m.getDeclaredAnnotations();
+ }
+
}
Index: vm/reference/java/lang/reflect/VMConstructor.java
===================================================================
RCS file: /sources/classpath/classpath/vm/reference/java/lang/reflect/VMConstructor.java,v
retrieving revision 1.2
diff -u -3 -p -u -r1.2 VMConstructor.java
--- vm/reference/java/lang/reflect/VMConstructor.java 3 Mar 2008 21:21:32 -0000 1.2
+++ vm/reference/java/lang/reflect/VMConstructor.java 5 Mar 2008 21:09:51 -0000
@@ -136,4 +136,28 @@ final class VMConstructor
return true;
}
+ /**
+ * Returns the element's annotation for the specified annotation type,
+ * or <code>null</code> if no such annotation exists.
+ *
+ * @param annotationClass the type of annotation to look for.
+ * @return this element's annotation for the specified type, or
+ * <code>null</code> if no such annotation exists.
+ * @throws NullPointerException if the annotation class is <code>null</code>.
+ */
+ native Annotation getAnnotation(Class annotationClass);
+
+ /**
+ * Returns all annotations directly defined by the element. If there are
+ * no annotations directly associated with the element, then a zero-length
+ * array will be returned. The returned array may be modified by the client
+ * code, but this will have no effect on the annotation content of this
+ * class, and hence no effect on the return value of this method for
+ * future callers.
+ *
+ * @return the annotations directly defined by the element.
+ * @since 1.5
+ */
+ native Annotation[] getDeclaredAnnotations();
+
}
Index: vm/reference/java/lang/reflect/VMField.java
===================================================================
RCS file: /sources/classpath/classpath/vm/reference/java/lang/reflect/VMField.java,v
retrieving revision 1.2
diff -u -3 -p -u -r1.2 VMField.java
--- vm/reference/java/lang/reflect/VMField.java 3 Mar 2008 21:21:32 -0000 1.2
+++ vm/reference/java/lang/reflect/VMField.java 5 Mar 2008 21:09:51 -0000
@@ -38,6 +38,8 @@ exception statement from your version. *
package java.lang.reflect;
+import java.lang.annotation.Annotation;
+
final class VMField
{
Class declaringClass;
@@ -514,4 +516,28 @@ final class VMField
return true;
}
+ /**
+ * Returns the element's annotation for the specified annotation type,
+ * or <code>null</code> if no such annotation exists.
+ *
+ * @param annotationClass the type of annotation to look for.
+ * @return this element's annotation for the specified type, or
+ * <code>null</code> if no such annotation exists.
+ * @throws NullPointerException if the annotation class is <code>null</code>.
+ */
+ native Annotation getAnnotation(Class annotationClass);
+
+ /**
+ * Returns all annotations directly defined by the element. If there are
+ * no annotations directly associated with the element, then a zero-length
+ * array will be returned. The returned array may be modified by the client
+ * code, but this will have no effect on the annotation content of this
+ * class, and hence no effect on the return value of this method for
+ * future callers.
+ *
+ * @return the annotations directly defined by the element.
+ * @since 1.5
+ */
+ native Annotation[] getDeclaredAnnotations();
+
}
Index: vm/reference/java/lang/reflect/VMMethod.java
===================================================================
RCS file: /sources/classpath/classpath/vm/reference/java/lang/reflect/VMMethod.java,v
retrieving revision 1.2
diff -u -3 -p -u -r1.2 VMMethod.java
--- vm/reference/java/lang/reflect/VMMethod.java 3 Mar 2008 21:21:33 -0000 1.2
+++ vm/reference/java/lang/reflect/VMMethod.java 5 Mar 2008 21:09:51 -0000
@@ -175,5 +175,29 @@ final class VMMethod
return true;
}
+ /**
+ * Returns the element's annotation for the specified annotation type,
+ * or <code>null</code> if no such annotation exists.
+ *
+ * @param annotationClass the type of annotation to look for.
+ * @return this element's annotation for the specified type, or
+ * <code>null</code> if no such annotation exists.
+ * @throws NullPointerException if the annotation class is <code>null</code>.
+ */
+ native Annotation getAnnotation(Class annotationClass);
+
+ /**
+ * Returns all annotations directly defined by the element. If there are
+ * no annotations directly associated with the element, then a zero-length
+ * array will be returned. The returned array may be modified by the client
+ * code, but this will have no effect on the annotation content of this
+ * class, and hence no effect on the return value of this method for
+ * future callers.
+ *
+ * @return the annotations directly defined by the element.
+ * @since 1.5
+ */
+ native Annotation[] getDeclaredAnnotations();
+
}
signature.asc
Description: Digital signature
