# HG changeset patch # User jjg # Date 1363642832 25200 # Node ID 40adaf938847a5e256017261aa826e4ade8977c4 # Parent 1f8c28134ffc97a72f6f60a68c08847df08da79e 8008425: Remove interim new javax.lang.model API for type-annotations Reviewed-by: darcy diff -r 1f8c28134ffc -r 40adaf938847 src/share/classes/com/sun/tools/javac/code/Type.java --- a/src/share/classes/com/sun/tools/javac/code/Type.java Mon Mar 18 08:46:09 2013 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java Mon Mar 18 14:40:32 2013 -0700 @@ -246,6 +246,10 @@ return this; } + public boolean isAnnotated() { + return false; + } + /** * If this is an annotated type, return the underlying type. * Otherwise, return the type itself. @@ -1539,7 +1543,12 @@ } public static class AnnotatedType extends Type - implements javax.lang.model.type.AnnotatedType { + implements + javax.lang.model.type.ArrayType, + javax.lang.model.type.DeclaredType, + javax.lang.model.type.PrimitiveType, + javax.lang.model.type.TypeVariable, + javax.lang.model.type.WildcardType { /** The type annotations on this type. */ public List typeAnnotations; @@ -1552,7 +1561,7 @@ super(underlyingType.tag, underlyingType.tsym); this.typeAnnotations = List.nil(); this.underlyingType = underlyingType; - Assert.check(underlyingType.getKind() != TypeKind.ANNOTATED, + Assert.check(!underlyingType.isAnnotated(), "Can't annotate already annotated type: " + underlyingType); } @@ -1561,14 +1570,19 @@ super(underlyingType.tag, underlyingType.tsym); this.typeAnnotations = typeAnnotations; this.underlyingType = underlyingType; - Assert.check(underlyingType.getKind() != TypeKind.ANNOTATED, + Assert.check(!underlyingType.isAnnotated(), "Can't annotate already annotated type: " + underlyingType + "; adding: " + typeAnnotations); } @Override + public boolean isAnnotated() { + return true; + } + + @Override public TypeKind getKind() { - return TypeKind.ANNOTATED; + return underlyingType.getKind(); } @Override @@ -1577,11 +1591,6 @@ } @Override - public TypeMirror getUnderlyingType() { - return underlyingType; - } - - @Override public Type unannotatedType() { return underlyingType; } @@ -1593,7 +1602,7 @@ @Override public R accept(TypeVisitor v, P p) { - return v.visitAnnotated(this, p); + return underlyingType.accept(v, p); } @Override diff -r 1f8c28134ffc -r 40adaf938847 src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java --- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Mon Mar 18 08:46:09 2013 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Mon Mar 18 14:40:32 2013 -0700 @@ -233,7 +233,7 @@ Type.ArrayType arType; { Type touse = type; - if (type.getKind() == TypeKind.ANNOTATED) { + if (type.isAnnotated()) { Type.AnnotatedType atype = (Type.AnnotatedType)type; toreturn = new Type.AnnotatedType(atype.underlyingType); ((Type.AnnotatedType)toreturn).typeAnnotations = atype.typeAnnotations; @@ -252,7 +252,7 @@ ListBuffer depth = ListBuffer.lb(); depth = depth.append(TypePathEntry.ARRAY); while (arType.elemtype.hasTag(TypeTag.ARRAY)) { - if (arType.elemtype.getKind() == TypeKind.ANNOTATED) { + if (arType.elemtype.isAnnotated()) { Type.AnnotatedType aelemtype = (Type.AnnotatedType) arType.elemtype; Type.AnnotatedType newAT = new Type.AnnotatedType(aelemtype.underlyingType); tomodify.elemtype = newAT; diff -r 1f8c28134ffc -r 40adaf938847 src/share/classes/com/sun/tools/javac/code/Types.java --- a/src/share/classes/com/sun/tools/javac/code/Types.java Mon Mar 18 08:46:09 2013 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Mon Mar 18 14:40:32 2013 -0700 @@ -2091,7 +2091,7 @@ @Override public Type visitAnnotatedType(AnnotatedType t, Boolean recurse) { Type erased = erasure(t.underlyingType, recurse); - if (erased.getKind() == TypeKind.ANNOTATED) { + if (erased.isAnnotated()) { // This can only happen when the underlying type is a // type variable and the upper bound of it is annotated. // The annotation on the type variable overrides the one diff -r 1f8c28134ffc -r 40adaf938847 src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Mar 18 08:46:09 2013 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Mar 18 14:40:32 2013 -0700 @@ -3362,7 +3362,7 @@ Type normOuter = site; if (normOuter.hasTag(CLASS)) { normOuter = types.asEnclosingSuper(site, ownOuter.tsym); - if (site.getKind() == TypeKind.ANNOTATED) { + if (site.isAnnotated()) { // Propagate any type annotations. // TODO: should asEnclosingSuper do this? // Note that the type annotations in site will be updated diff -r 1f8c28134ffc -r 40adaf938847 src/share/classes/com/sun/tools/javac/model/JavacTypes.java --- a/src/share/classes/com/sun/tools/javac/model/JavacTypes.java Mon Mar 18 08:46:09 2013 -0700 +++ b/src/share/classes/com/sun/tools/javac/model/JavacTypes.java Mon Mar 18 14:40:32 2013 -0700 @@ -333,28 +333,4 @@ return results; } - - public List typeAnnotationsOf(TypeMirror type) { - // TODO: these methods can be removed. - return null; // ((Type)type).typeAnnotations; - } - - public A typeAnnotationOf(TypeMirror type, - Class annotationType) { - // TODO: these methods can be removed. - return null; // JavacElements.getAnnotation(((Type)type).typeAnnotations, annotationType); - } - - public TypeMirror receiverTypeOf(ExecutableType type) { - return ((Type)type).asMethodType().recvtype; - } - - /* - public A receiverTypeAnnotationOf( - ExecutableType type, Class annotationType) { - return JavacElements.getAnnotation( - ((Type)type).asMethodType().receiverTypeAnnotations, - annotationType); - }*/ - } diff -r 1f8c28134ffc -r 40adaf938847 src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java --- a/src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java Mon Mar 18 08:46:09 2013 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java Mon Mar 18 14:40:32 2013 -0700 @@ -205,7 +205,7 @@ if (recvtype == null) { return new AnnotationDesc[0]; } - if (recvtype.getKind() != TypeKind.ANNOTATED) { + if (!recvtype.isAnnotated()) { return new AnnotationDesc[0]; } List typeAnnos = ((com.sun.tools.javac.code.Type.AnnotatedType)recvtype).typeAnnotations; diff -r 1f8c28134ffc -r 40adaf938847 src/share/classes/com/sun/tools/javadoc/TypeMaker.java --- a/src/share/classes/com/sun/tools/javadoc/TypeMaker.java Mon Mar 18 08:46:09 2013 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/TypeMaker.java Mon Mar 18 14:40:32 2013 -0700 @@ -65,11 +65,11 @@ t = env.types.erasure(t); } if (considerAnnotations - && t.getKind() == TypeKind.ANNOTATED) { + && t.isAnnotated()) { return new AnnotatedTypeImpl(env, (com.sun.tools.javac.code.Type.AnnotatedType) t); } - if (t.getKind() == TypeKind.ANNOTATED) { + if (t.isAnnotated()) { Type.AnnotatedType at = (Type.AnnotatedType) t; return new AnnotatedTypeImpl(env, at); } @@ -147,7 +147,7 @@ */ static String getTypeString(DocEnv env, Type t, boolean full) { // TODO: should annotations be included here? - if (t.getKind() == TypeKind.ANNOTATED) { + if (t.isAnnotated()) { Type.AnnotatedType at = (Type.AnnotatedType)t; t = at.underlyingType; } diff -r 1f8c28134ffc -r 40adaf938847 src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java --- a/src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java Mon Mar 18 08:46:09 2013 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java Mon Mar 18 14:40:32 2013 -0700 @@ -127,7 +127,7 @@ final Type upperBound = v.getUpperBound(); Name boundname = upperBound.tsym.getQualifiedName(); if (boundname == boundname.table.names.java_lang_Object - && upperBound.getKind() != TypeKind.ANNOTATED) { + && !upperBound.isAnnotated()) { return List.nil(); } else { return env.types.getBounds(v); @@ -139,7 +139,7 @@ * Return an empty array if there are none. */ public AnnotationDesc[] annotations() { - if (type.getKind() != TypeKind.ANNOTATED) { + if (!type.isAnnotated()) { return new AnnotationDesc[0]; } List tas = ((com.sun.tools.javac.code.Type.AnnotatedType) type).typeAnnotations; diff -r 1f8c28134ffc -r 40adaf938847 src/share/classes/javax/lang/model/type/AnnotatedType.java --- a/src/share/classes/javax/lang/model/type/AnnotatedType.java Mon Mar 18 08:46:09 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2012, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javax.lang.model.type; - -import java.util.List; - -import javax.lang.model.element.AnnotationMirror; - -/** - * Represents an annotated type. - * - * As of the {@link javax.lang.model.SourceVersion#RELEASE_8 - * RELEASE_8} source version, annotated types can appear for all - * type uses. - * - * @author Werner Dietl - * @since 1.8 - */ -public interface AnnotatedType extends TypeMirror, - DeclaredType, TypeVariable, WildcardType, - PrimitiveType, ArrayType { - - List getAnnotations(); - TypeMirror getUnderlyingType(); -} diff -r 1f8c28134ffc -r 40adaf938847 src/share/classes/javax/lang/model/type/ExecutableType.java --- a/src/share/classes/javax/lang/model/type/ExecutableType.java Mon Mar 18 08:46:09 2013 -0700 +++ b/src/share/classes/javax/lang/model/type/ExecutableType.java Mon Mar 18 14:40:32 2013 -0700 @@ -78,14 +78,6 @@ List getParameterTypes(); /** - * Returns the type of this executable's receiver parameter. - * - * @return the type of this executable's receiver parameter - * TODO: null if none specified or always a valid value? - */ - TypeMirror getReceiverType(); - - /** * Returns the exceptions and other throwables listed in this * executable's {@code throws} clause. * diff -r 1f8c28134ffc -r 40adaf938847 src/share/classes/javax/lang/model/type/TypeKind.java --- a/src/share/classes/javax/lang/model/type/TypeKind.java Mon Mar 18 08:46:09 2013 -0700 +++ b/src/share/classes/javax/lang/model/type/TypeKind.java Mon Mar 18 14:40:32 2013 -0700 @@ -151,14 +151,7 @@ * * @since 1.8 */ - INTERSECTION, - - /** - * An annotated type. - * - * @since 1.8 - */ - ANNOTATED; + INTERSECTION; /** * Returns {@code true} if this kind corresponds to a primitive diff -r 1f8c28134ffc -r 40adaf938847 src/share/classes/javax/lang/model/type/TypeVisitor.java --- a/src/share/classes/javax/lang/model/type/TypeVisitor.java Mon Mar 18 08:46:09 2013 -0700 +++ b/src/share/classes/javax/lang/model/type/TypeVisitor.java Mon Mar 18 14:40:32 2013 -0700 @@ -194,14 +194,4 @@ * @since 1.8 */ R visitIntersection(IntersectionType t, P p); - - /** - * Visits an annotated type. - * - * @param t the type to visit - * @param p a visitor-specified parameter - * @return a visitor-specified result - * @since 1.8 - */ - R visitAnnotated(AnnotatedType t, P p); } diff -r 1f8c28134ffc -r 40adaf938847 src/share/classes/javax/lang/model/util/AbstractTypeVisitor6.java --- a/src/share/classes/javax/lang/model/util/AbstractTypeVisitor6.java Mon Mar 18 08:46:09 2013 -0700 +++ b/src/share/classes/javax/lang/model/util/AbstractTypeVisitor6.java Mon Mar 18 14:40:32 2013 -0700 @@ -134,23 +134,6 @@ } /** - * Visits an {@code AnnotatedType} element by calling {@code - * visit} on the underlying type. - - * @param t {@inheritDoc} - * @param p {@inheritDoc} - * @return the result of calling {@code visit} on the underlying type - * - * @since 1.8 - * - * TODO: should xxxVisitor8 subclasses override this and call - * the defaultAction? - */ - public R visitAnnotated(AnnotatedType t, P p) { - return visit(t.getUnderlyingType(), p); - } - - /** * {@inheritDoc} * *

The default implementation of this method in {@code diff -r 1f8c28134ffc -r 40adaf938847 src/share/classes/javax/lang/model/util/Types.java --- a/src/share/classes/javax/lang/model/util/Types.java Mon Mar 18 08:46:09 2013 -0700 +++ b/src/share/classes/javax/lang/model/util/Types.java Mon Mar 18 14:40:32 2013 -0700 @@ -301,116 +301,4 @@ * for the given type */ TypeMirror asMemberOf(DeclaredType containing, Element element); - - /** - * Returns the annotations targeting the type. - * - * @param type the targeted type - * @return the type annotations targeting the type - */ - List typeAnnotationsOf(TypeMirror type); - - /** - * Returns the type's annotation for the specified type if - * such an annotation is present, else {@code null}. The - * annotation has to be 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 type the targeted type - * @param annotationType the {@code Class} object corresponding to - * the annotation type - * @return the type's annotation for the specified annotation - * type if present on the type, else {@code null} - * - * @see Element#getAnnotationMirrors() - * @see EnumConstantNotPresentException - * @see AnnotationTypeMismatchException - * @see IncompleteAnnotationException - * @see MirroredTypeException - * @see MirroredTypesException - */ - A typeAnnotationOf(TypeMirror type, Class annotationType); - - /** - * Returns the annotations targeting the method receiver type. - * - * @param type the targeted type - * @return the receiver type of the executable type - */ - TypeMirror receiverTypeOf(ExecutableType type); - - /** - * Returns the type's annotation for the specified executable type - * receiver if such an annotation is present, else {@code null}. The - * annotation has to be 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 type the method type - * @param annotationType the {@code Class} object corresponding to - * the annotation type - * @return the type's annotation for the specified annotation - * type if present on the type, else {@code null} - * - * @see Element#getAnnotationMirrors() - * @see EnumConstantNotPresentException - * @see AnnotationTypeMismatchException - * @see IncompleteAnnotationException - * @see MirroredTypeException - * @see MirroredTypesException - */ - // TODO: no longer needed? - // A receiverTypeAnnotationOf(ExecutableType type, Class annotationType); - }