8007279: Rename javax.l.model.element.Element.getAnnotations(Class) to getAnnotationsByType(Class)
authorjfranck
Wed, 13 Feb 2013 10:33:13 +0100
changeset 15719 6b64cf96346b
parent 15718 8e54c8e43d38
child 15720 e61b2f7a5148
8007279: Rename javax.l.model.element.Element.getAnnotations(Class) to getAnnotationsByType(Class) Reviewed-by: darcy, abuckley
langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java
langtools/src/share/classes/javax/lang/model/element/Element.java
langtools/test/tools/javac/processing/model/element/repeatingAnnotations/ElementRepAnnoTester.java
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java	Tue Feb 12 17:15:29 2013 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java	Wed Feb 13 10:33:13 2013 +0100
@@ -479,7 +479,7 @@
     }
 
     // This method is part of the javax.lang.model API, do not use this in javac code.
-    public <A extends java.lang.annotation.Annotation> A[] getAnnotations(Class<A> annoType) {
+    public <A extends java.lang.annotation.Annotation> A[] getAnnotationsByType(Class<A> annoType) {
         return JavacElements.getAnnotations(this, annoType);
     }
 
--- a/langtools/src/share/classes/javax/lang/model/element/Element.java	Tue Feb 12 17:15:29 2013 -0800
+++ b/langtools/src/share/classes/javax/lang/model/element/Element.java	Wed Feb 13 10:33:13 2013 +0100
@@ -149,12 +149,15 @@
     <A extends Annotation> A getAnnotation(Class<A> annotationType);
 
     /**
-     * Returns an array of all of this element's annotation for the
-     * specified type if such annotations are present, else an empty
-     * array.  The annotation may be either inherited or directly
-     * present on this element. This method will look through a container
-     * annotation (if present) if the supplied annotation type is
-     * repeatable.
+     * Returns annotations that are <em>present</em> on this element.
+     *
+     * If there are no annotations <em>present</em> on this element, the return
+     * value is an array of length 0.
+     *
+     * The difference between this method and {@link #getAnnotation(Class)}
+     * is that this method detects if its argument is a <em>repeatable
+     * annotation type</em> (JLS 9.6), and if so, attempts to find one or more
+     * annotations of that type by "looking through" a container annotation.
      *
      * <p> The annotations returned by this method could contain an element
      * whose value is of type {@code Class}.
@@ -189,14 +192,14 @@
      *
      * @see #getAnnotationMirrors()
      * @see #getAnnotation(java.lang.Class)
-     * @see java.lang.reflect.AnnotatedElement#getAnnotations
+     * @see java.lang.reflect.AnnotatedElement#getAnnotationsByType
      * @see EnumConstantNotPresentException
      * @see AnnotationTypeMismatchException
      * @see IncompleteAnnotationException
      * @see MirroredTypeException
      * @see MirroredTypesException
      */
-    <A extends Annotation> A[] getAnnotations(Class<A> annotationType);
+    <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType);
 
     /**
      * Returns the modifiers of this element, excluding annotations.
--- a/langtools/test/tools/javac/processing/model/element/repeatingAnnotations/ElementRepAnnoTester.java	Tue Feb 12 17:15:29 2013 -0800
+++ b/langtools/test/tools/javac/processing/model/element/repeatingAnnotations/ElementRepAnnoTester.java	Wed Feb 13 10:33:13 2013 +0100
@@ -366,7 +366,7 @@
                 e.getEnclosingElement().toString())
                 || unofficialAnno.contains(
                 e.getSimpleName().toString())) {
-            actualAnnosArgs = e.getAnnotations(Foo.class);
+            actualAnnosArgs = e.getAnnotationsByType(Foo.class);
         }
         if (singularInheritedAnno.contains(
                 e.getEnclosingElement().toString())
@@ -376,25 +376,25 @@
                 e.getEnclosingElement().toString())
                 || unofficialInheritedAnno.contains(
                 e.getSimpleName().toString())) {
-            actualAnnosArgs = e.getAnnotations(FooInherited.class);
+            actualAnnosArgs = e.getAnnotationsByType(FooInherited.class);
         }
         if (repeatableAnno.contains(
                 e.getEnclosingElement().toString())
                 || repeatableAnno.contains(
                 e.getSimpleName().toString())) {
-            actualAnnosArgs = e.getAnnotations(Bar.class);
+            actualAnnosArgs = e.getAnnotationsByType(Bar.class);
         }
         if (repeatableInheritedAnno.contains(
                 e.getEnclosingElement().toString())
                 || repeatableInheritedAnno.contains(
                 e.getSimpleName().toString())) {
-            actualAnnosArgs = e.getAnnotations(BarInherited.class);
+            actualAnnosArgs = e.getAnnotationsByType(BarInherited.class);
         }
         if (repeatableContainerInheritedAnno.contains(
                 e.getEnclosingElement().toString())
                 || repeatableContainerInheritedAnno.contains(
                 e.getSimpleName().toString())) {
-            actualAnnosArgs = e.getAnnotations(BarInheritedContainer.class);
+            actualAnnosArgs = e.getAnnotationsByType(BarInheritedContainer.class);
         }
         return actualAnnosArgs;
     }
@@ -406,31 +406,31 @@
                 e.getEnclosingElement().toString())
                 || repeatableAnnoContainer.contains(
                 e.getSimpleName().toString())) {
-            actualAnnosArgs = e.getAnnotations(BarContainer.class);
+            actualAnnosArgs = e.getAnnotationsByType(BarContainer.class);
         }
         if (repeatableInheritedAnnoContainer.contains(
                 e.getEnclosingElement().toString())
                 || repeatableInheritedAnnoContainer.contains(
                 e.getSimpleName().toString())) {
-            actualAnnosArgs = e.getAnnotations(BarInheritedContainer.class);
+            actualAnnosArgs = e.getAnnotationsByType(BarInheritedContainer.class);
         }
         if (repeatableContainerInheritedAnnoContainer.contains(
                 e.getEnclosingElement().toString())
                 || repeatableContainerInheritedAnnoContainer.contains(
                 e.getSimpleName().toString())) {
-            actualAnnosArgs = e.getAnnotations(BarInheritedContainerContainer.class);
+            actualAnnosArgs = e.getAnnotationsByType(BarInheritedContainerContainer.class);
         }
         if (unofficialAnnoContainer.contains(
                 e.getEnclosingElement().toString())
                 || unofficialAnnoContainer.contains(
                 e.getSimpleName().toString())) {
-            actualAnnosArgs = e.getAnnotations(UnofficialContainer.class);
+            actualAnnosArgs = e.getAnnotationsByType(UnofficialContainer.class);
         }
         if (unofficialInheritedAnnoContainer.contains(
                 e.getEnclosingElement().toString())
                 || unofficialInheritedAnnoContainer.contains(
                 e.getSimpleName().toString())) {
-            actualAnnosArgs = e.getAnnotations(UnofficialInheritedContainer.class);
+            actualAnnosArgs = e.getAnnotationsByType(UnofficialInheritedContainer.class);
         }
         return actualAnnosArgs;
     }