This is NOT part of any supported API. + * If you write code that depends on this, you do so at your own + * risk. This code and its internal interfaces are subject to change + * or deletion without notice.
+ */ +public class JavacAnnoConstructs { + + //The annotation returned by this method could contain an element + * whose value is of type {@code Class}. + * This value cannot be returned directly: information necessary to + * locate and load a class (such as the class loader to use) is + * not available, and the class might not be loadable at all. + * Attempting to read a {@code Class} object by invoking the relevant + * method on the returned annotation + * will result in a {@link MirroredTypeException}, + * from which the corresponding {@link TypeMirror} may be extracted. + * Similarly, attempting to read a {@code Class[]}-valued element + * will result in a {@link MirroredTypesException}. + * + *
+ * Note: This method is unlike others in this and related + * interfaces. It operates on runtime reflective information — + * representations of annotation types currently loaded into the + * VM — rather than on the representations defined by and used + * throughout these interfaces. Consequently, calling methods on + * the returned annotation object can throw many of the exceptions + * that can be thrown when calling methods on an annotation object + * returned by core reflection. This method is intended for + * callers that are written to operate on a known, fixed set of + * annotation types. + *+ * + * @param the annotation type + * @param annotationType the {@code Class} object corresponding to + * the annotation type + * @return this element's or type use's annotation for the + * specified annotation type if present on this element, else + * {@code null} + * + * @see #getAnnotationMirrors() + * @see java.lang.reflect.AnnotatedElement#getAnnotation + * @see EnumConstantNotPresentException + * @see AnnotationTypeMismatchException + * @see IncompleteAnnotationException + * @see MirroredTypeException + * @see MirroredTypesException + */ + A getAnnotation(Class annotationType); + + /** + * Returns annotations that are present on this element or type use. + * + * If there are no annotations present on this element or type use, + * 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 repeatable + * annotation type (JLS 9.6), and if so, attempts to find one or more + * annotations of that type by "looking through" a container annotation. + * + *
The annotations returned by this method could contain an element + * whose value is of type {@code Class}. + * This value cannot be returned directly: information necessary to + * locate and load a class (such as the class loader to use) is + * not available, and the class might not be loadable at all. + * Attempting to read a {@code Class} object by invoking the relevant + * method on the returned annotation + * will result in a {@link MirroredTypeException}, + * from which the corresponding {@link TypeMirror} may be extracted. + * Similarly, attempting to read a {@code Class[]}-valued element + * will result in a {@link MirroredTypesException}. + * + *
+ * Note: This method is unlike others in this and related + * interfaces. It operates on runtime reflective information — + * representations of annotation types currently loaded into the + * VM — rather than on the representations defined by and used + * throughout these interfaces. Consequently, calling methods on + * the returned annotation object can throw many of the exceptions + * that can be thrown when calling methods on an annotation object + * returned by core reflection. This method is intended for + * callers that are written to operate on a known, fixed set of + * annotation types. + *+ * + * @param the annotation type + * @param annotationType the {@code Class} object corresponding to + * the annotation type + * @return this element's annotations for the specified annotation + * type if present on this element, else an empty array + * + * @see #getAnnotationMirrors() + * @see #getAnnotation(java.lang.Class) + * @see java.lang.reflect.AnnotatedElement#getAnnotationsByType + * @see EnumConstantNotPresentException + * @see AnnotationTypeMismatchException + * @see IncompleteAnnotationException + * @see MirroredTypeException + * @see MirroredTypesException + */ + A[] getAnnotationsByType(Class annotationType); +} diff -r 40adaf938847 -r 97f6839673d6 src/share/classes/javax/lang/model/element/Element.java --- a/src/share/classes/javax/lang/model/element/Element.java Mon Mar 18 14:40:32 2013 -0700 +++ b/src/share/classes/javax/lang/model/element/Element.java Mon Mar 18 18:33:13 2013 -0700 @@ -60,8 +60,7 @@ * @see TypeMirror * @since 1.6 */ -public interface Element { - +public interface Element extends javax.lang.model.AnnotatedConstruct { /** * Returns the type defined by this element. * @@ -89,119 +88,6 @@ ElementKind getKind(); /** - * Returns the annotations that are directly present on this element. - * - *
To get inherited annotations as well, use - * {@link Elements#getAllAnnotationMirrors(Element) getAllAnnotationMirrors}. - * - * @see ElementFilter - * - * @return the annotations directly present on this element; - * an empty list if there are none - */ - List extends AnnotationMirror> getAnnotationMirrors(); - - /** - * Returns this element's annotation for the specified type if - * such an annotation is present, else {@code null}. The - * annotation may be either inherited or directly present on this - * element. - * - *
The annotation returned by this method could contain an element - * whose value is of type {@code Class}. - * This value cannot be returned directly: information necessary to - * locate and load a class (such as the class loader to use) is - * not available, and the class might not be loadable at all. - * Attempting to read a {@code Class} object by invoking the relevant - * method on the returned annotation - * will result in a {@link MirroredTypeException}, - * from which the corresponding {@link TypeMirror} may be extracted. - * Similarly, attempting to read a {@code Class[]}-valued element - * will result in a {@link MirroredTypesException}. - * - *
- * Note: This method is unlike others in this and related - * interfaces. It operates on runtime reflective information — - * representations of annotation types currently loaded into the - * VM — rather than on the representations defined by and used - * throughout these interfaces. Consequently, calling methods on - * the returned annotation object can throw many of the exceptions - * that can be thrown when calling methods on an annotation object - * returned by core reflection. This method is intended for - * callers that are written to operate on a known, fixed set of - * annotation types. - *- * - * @param the annotation type - * @param annotationType the {@code Class} object corresponding to - * the annotation type - * @return this element's annotation for the specified annotation - * type if present on this element, else {@code null} - * - * @see #getAnnotationMirrors() - * @see java.lang.reflect.AnnotatedElement#getAnnotation - * @see EnumConstantNotPresentException - * @see AnnotationTypeMismatchException - * @see IncompleteAnnotationException - * @see MirroredTypeException - * @see MirroredTypesException - */ - A getAnnotation(Class annotationType); - - /** - * Returns annotations that are present on this element. - * - * If there are no annotations present 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 repeatable - * annotation type (JLS 9.6), and if so, attempts to find one or more - * annotations of that type by "looking through" a container annotation. - * - *
The annotations returned by this method could contain an element - * whose value is of type {@code Class}. - * This value cannot be returned directly: information necessary to - * locate and load a class (such as the class loader to use) is - * not available, and the class might not be loadable at all. - * Attempting to read a {@code Class} object by invoking the relevant - * method on the returned annotation - * will result in a {@link MirroredTypeException}, - * from which the corresponding {@link TypeMirror} may be extracted. - * Similarly, attempting to read a {@code Class[]}-valued element - * will result in a {@link MirroredTypesException}. - * - *
- * Note: This method is unlike others in this and related - * interfaces. It operates on runtime reflective information — - * representations of annotation types currently loaded into the - * VM — rather than on the representations defined by and used - * throughout these interfaces. Consequently, calling methods on - * the returned annotation object can throw many of the exceptions - * that can be thrown when calling methods on an annotation object - * returned by core reflection. This method is intended for - * callers that are written to operate on a known, fixed set of - * annotation types. - *- * - * @param the annotation type - * @param annotationType the {@code Class} object corresponding to - * the annotation type - * @return this element's annotations for the specified annotation - * type if present on this element, else an empty array - * - * @see #getAnnotationMirrors() - * @see #getAnnotation(java.lang.Class) - * @see java.lang.reflect.AnnotatedElement#getAnnotationsByType - * @see EnumConstantNotPresentException - * @see AnnotationTypeMismatchException - * @see IncompleteAnnotationException - * @see MirroredTypeException - * @see MirroredTypesException - */ - A[] getAnnotationsByType(Class annotationType); - - /** * Returns the modifiers of this element, excluding annotations. * Implicit modifiers, such as the {@code public} and {@code static} * modifiers of interface members, are included. @@ -325,6 +211,19 @@ */ int hashCode(); + + /** + * {@inheritDoc} + * + *
To get inherited annotations as well, use {@link + * Elements#getAllAnnotationMirrors(Element) + * getAllAnnotationMirrors}. + * + * @see ElementFilter + * @since 1.6 + */ + @Override + List extends AnnotationMirror> getAnnotationMirrors(); /** * Applies a visitor to this element. * diff -r 40adaf938847 -r 97f6839673d6 src/share/classes/javax/lang/model/element/ExecutableElement.java --- a/src/share/classes/javax/lang/model/element/ExecutableElement.java Mon Mar 18 14:40:32 2013 -0700 +++ b/src/share/classes/javax/lang/model/element/ExecutableElement.java Mon Mar 18 18:33:13 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -69,6 +69,25 @@ List extends VariableElement> getParameters(); /** + * Returns the receiver type of this executable, + * or {@link javax.lang.model.type.NoType NoType} with + * kind {@link javax.lang.model.type.TypeKind#NONE NONE} + * if the executable has no receiver type. + * + * An executable which is an instance method, or a constructor of an + * inner class, has a receiver type derived from the {@linkplain + * #getEnclosingElement declaring type}. + * + * An executable which is a static method, or a constructor of a + * non-inner class, or an initializer (static or instance), has no + * receiver type. + * + * @return the receiver type of this executable + * @since 1.8 + */ + TypeMirror getReceiverType(); + + /** * Returns {@code true} if this method or constructor accepts a variable * number of arguments and returns {@code false} otherwise. * diff -r 40adaf938847 -r 97f6839673d6 src/share/classes/javax/lang/model/type/ExecutableType.java --- a/src/share/classes/javax/lang/model/type/ExecutableType.java Mon Mar 18 14:40:32 2013 -0700 +++ b/src/share/classes/javax/lang/model/type/ExecutableType.java Mon Mar 18 18:33:13 2013 -0700 @@ -78,6 +78,25 @@ List extends TypeMirror> getParameterTypes(); /** + * Returns the receiver type of this executable, + * or {@link javax.lang.model.type.NoType NoType} with + * kind {@link javax.lang.model.type.TypeKind#NONE NONE} + * if the executable has no receiver type. + * + * An executable which is an instance method, or a constructor of an + * inner class, has a receiver type derived from the {@linkplain + * #getEnclosingElement declaring type}. + * + * An executable which is a static method, or a constructor of a + * non-inner class, or an initializer (static or instance), has no + * receiver type. + * + * @return the receiver type of this executable + * @since 1.8 + */ + TypeMirror getReceiverType(); + + /** * Returns the exceptions and other throwables listed in this * executable's {@code throws} clause. * diff -r 40adaf938847 -r 97f6839673d6 src/share/classes/javax/lang/model/type/TypeMirror.java --- a/src/share/classes/javax/lang/model/type/TypeMirror.java Mon Mar 18 14:40:32 2013 -0700 +++ b/src/share/classes/javax/lang/model/type/TypeMirror.java Mon Mar 18 18:33:13 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,8 @@ package javax.lang.model.type; +import java.lang.annotation.Annotation; +import java.util.List; import javax.lang.model.element.*; import javax.lang.model.util.Types; @@ -55,7 +57,7 @@ * @see Types * @since 1.6 */ -public interface TypeMirror { +public interface TypeMirror extends javax.lang.model.AnnotatedConstruct { /** * Returns the {@code kind} of this type. diff -r 40adaf938847 -r 97f6839673d6 src/share/classes/javax/lang/model/util/Types.java --- a/src/share/classes/javax/lang/model/util/Types.java Mon Mar 18 14:40:32 2013 -0700 +++ b/src/share/classes/javax/lang/model/util/Types.java Mon Mar 18 18:33:13 2013 -0700 @@ -59,6 +59,13 @@ /** * Tests whether two {@code TypeMirror} objects represent the same type. * + *
Since annotations are only meta-data associated with a type, + * the set of annotations on either argument is not taken + * into account when computing whether or not two {@code + * TypeMirror} objects are the same type. In particular, two + * {@code TypeMirror} objects can have different annotations and + * still be considered the same. + * *
Caveat: if either of the arguments to this method represents a * wildcard, this method will return false. As a consequence, a wildcard * is not the same type as itself. This might be surprising at first,