8007279: Rename javax.l.model.element.Element.getAnnotations(Class) to getAnnotationsByType(Class)

Wed, 13 Feb 2013 10:33:13 +0100

author
jfranck
date
Wed, 13 Feb 2013 10:33:13 +0100
changeset 1564
aeadaf905d78
parent 1563
bc456436c613
child 1565
d04960f05593

8007279: Rename javax.l.model.element.Element.getAnnotations(Class) to getAnnotationsByType(Class)
Reviewed-by: darcy, abuckley

src/share/classes/com/sun/tools/javac/code/Symbol.java file | annotate | diff | comparison | revisions
src/share/classes/javax/lang/model/element/Element.java file | annotate | diff | comparison | revisions
test/tools/javac/processing/model/element/repeatingAnnotations/ElementRepAnnoTester.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java	Tue Feb 12 17:15:29 2013 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java	Wed Feb 13 10:33:13 2013 +0100
     1.3 @@ -479,7 +479,7 @@
     1.4      }
     1.5  
     1.6      // This method is part of the javax.lang.model API, do not use this in javac code.
     1.7 -    public <A extends java.lang.annotation.Annotation> A[] getAnnotations(Class<A> annoType) {
     1.8 +    public <A extends java.lang.annotation.Annotation> A[] getAnnotationsByType(Class<A> annoType) {
     1.9          return JavacElements.getAnnotations(this, annoType);
    1.10      }
    1.11  
     2.1 --- a/src/share/classes/javax/lang/model/element/Element.java	Tue Feb 12 17:15:29 2013 -0800
     2.2 +++ b/src/share/classes/javax/lang/model/element/Element.java	Wed Feb 13 10:33:13 2013 +0100
     2.3 @@ -149,12 +149,15 @@
     2.4      <A extends Annotation> A getAnnotation(Class<A> annotationType);
     2.5  
     2.6      /**
     2.7 -     * Returns an array of all of this element's annotation for the
     2.8 -     * specified type if such annotations are present, else an empty
     2.9 -     * array.  The annotation may be either inherited or directly
    2.10 -     * present on this element. This method will look through a container
    2.11 -     * annotation (if present) if the supplied annotation type is
    2.12 -     * repeatable.
    2.13 +     * Returns annotations that are <em>present</em> on this element.
    2.14 +     *
    2.15 +     * If there are no annotations <em>present</em> on this element, the return
    2.16 +     * value is an array of length 0.
    2.17 +     *
    2.18 +     * The difference between this method and {@link #getAnnotation(Class)}
    2.19 +     * is that this method detects if its argument is a <em>repeatable
    2.20 +     * annotation type</em> (JLS 9.6), and if so, attempts to find one or more
    2.21 +     * annotations of that type by "looking through" a container annotation.
    2.22       *
    2.23       * <p> The annotations returned by this method could contain an element
    2.24       * whose value is of type {@code Class}.
    2.25 @@ -189,14 +192,14 @@
    2.26       *
    2.27       * @see #getAnnotationMirrors()
    2.28       * @see #getAnnotation(java.lang.Class)
    2.29 -     * @see java.lang.reflect.AnnotatedElement#getAnnotations
    2.30 +     * @see java.lang.reflect.AnnotatedElement#getAnnotationsByType
    2.31       * @see EnumConstantNotPresentException
    2.32       * @see AnnotationTypeMismatchException
    2.33       * @see IncompleteAnnotationException
    2.34       * @see MirroredTypeException
    2.35       * @see MirroredTypesException
    2.36       */
    2.37 -    <A extends Annotation> A[] getAnnotations(Class<A> annotationType);
    2.38 +    <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType);
    2.39  
    2.40      /**
    2.41       * Returns the modifiers of this element, excluding annotations.
     3.1 --- a/test/tools/javac/processing/model/element/repeatingAnnotations/ElementRepAnnoTester.java	Tue Feb 12 17:15:29 2013 -0800
     3.2 +++ b/test/tools/javac/processing/model/element/repeatingAnnotations/ElementRepAnnoTester.java	Wed Feb 13 10:33:13 2013 +0100
     3.3 @@ -366,7 +366,7 @@
     3.4                  e.getEnclosingElement().toString())
     3.5                  || unofficialAnno.contains(
     3.6                  e.getSimpleName().toString())) {
     3.7 -            actualAnnosArgs = e.getAnnotations(Foo.class);
     3.8 +            actualAnnosArgs = e.getAnnotationsByType(Foo.class);
     3.9          }
    3.10          if (singularInheritedAnno.contains(
    3.11                  e.getEnclosingElement().toString())
    3.12 @@ -376,25 +376,25 @@
    3.13                  e.getEnclosingElement().toString())
    3.14                  || unofficialInheritedAnno.contains(
    3.15                  e.getSimpleName().toString())) {
    3.16 -            actualAnnosArgs = e.getAnnotations(FooInherited.class);
    3.17 +            actualAnnosArgs = e.getAnnotationsByType(FooInherited.class);
    3.18          }
    3.19          if (repeatableAnno.contains(
    3.20                  e.getEnclosingElement().toString())
    3.21                  || repeatableAnno.contains(
    3.22                  e.getSimpleName().toString())) {
    3.23 -            actualAnnosArgs = e.getAnnotations(Bar.class);
    3.24 +            actualAnnosArgs = e.getAnnotationsByType(Bar.class);
    3.25          }
    3.26          if (repeatableInheritedAnno.contains(
    3.27                  e.getEnclosingElement().toString())
    3.28                  || repeatableInheritedAnno.contains(
    3.29                  e.getSimpleName().toString())) {
    3.30 -            actualAnnosArgs = e.getAnnotations(BarInherited.class);
    3.31 +            actualAnnosArgs = e.getAnnotationsByType(BarInherited.class);
    3.32          }
    3.33          if (repeatableContainerInheritedAnno.contains(
    3.34                  e.getEnclosingElement().toString())
    3.35                  || repeatableContainerInheritedAnno.contains(
    3.36                  e.getSimpleName().toString())) {
    3.37 -            actualAnnosArgs = e.getAnnotations(BarInheritedContainer.class);
    3.38 +            actualAnnosArgs = e.getAnnotationsByType(BarInheritedContainer.class);
    3.39          }
    3.40          return actualAnnosArgs;
    3.41      }
    3.42 @@ -406,31 +406,31 @@
    3.43                  e.getEnclosingElement().toString())
    3.44                  || repeatableAnnoContainer.contains(
    3.45                  e.getSimpleName().toString())) {
    3.46 -            actualAnnosArgs = e.getAnnotations(BarContainer.class);
    3.47 +            actualAnnosArgs = e.getAnnotationsByType(BarContainer.class);
    3.48          }
    3.49          if (repeatableInheritedAnnoContainer.contains(
    3.50                  e.getEnclosingElement().toString())
    3.51                  || repeatableInheritedAnnoContainer.contains(
    3.52                  e.getSimpleName().toString())) {
    3.53 -            actualAnnosArgs = e.getAnnotations(BarInheritedContainer.class);
    3.54 +            actualAnnosArgs = e.getAnnotationsByType(BarInheritedContainer.class);
    3.55          }
    3.56          if (repeatableContainerInheritedAnnoContainer.contains(
    3.57                  e.getEnclosingElement().toString())
    3.58                  || repeatableContainerInheritedAnnoContainer.contains(
    3.59                  e.getSimpleName().toString())) {
    3.60 -            actualAnnosArgs = e.getAnnotations(BarInheritedContainerContainer.class);
    3.61 +            actualAnnosArgs = e.getAnnotationsByType(BarInheritedContainerContainer.class);
    3.62          }
    3.63          if (unofficialAnnoContainer.contains(
    3.64                  e.getEnclosingElement().toString())
    3.65                  || unofficialAnnoContainer.contains(
    3.66                  e.getSimpleName().toString())) {
    3.67 -            actualAnnosArgs = e.getAnnotations(UnofficialContainer.class);
    3.68 +            actualAnnosArgs = e.getAnnotationsByType(UnofficialContainer.class);
    3.69          }
    3.70          if (unofficialInheritedAnnoContainer.contains(
    3.71                  e.getEnclosingElement().toString())
    3.72                  || unofficialInheritedAnnoContainer.contains(
    3.73                  e.getSimpleName().toString())) {
    3.74 -            actualAnnosArgs = e.getAnnotations(UnofficialInheritedContainer.class);
    3.75 +            actualAnnosArgs = e.getAnnotationsByType(UnofficialInheritedContainer.class);
    3.76          }
    3.77          return actualAnnosArgs;
    3.78      }

mercurial