8008425: Remove interim new javax.lang.model API for type-annotations
Reviewed-by: darcy
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Type.java Mon Mar 18 08:46:09 2013 -0700
+++ b/langtools/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<Attribute.TypeCompound> 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, P> R accept(TypeVisitor<R, P> v, P p) {
- return v.visitAnnotated(this, p);
+ return underlyingType.accept(v, p);
}
@Override
--- a/langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Mon Mar 18 08:46:09 2013 -0700
+++ b/langtools/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<TypePathEntry> 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;
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java Mon Mar 18 08:46:09 2013 -0700
+++ b/langtools/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
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Mar 18 08:46:09 2013 -0700
+++ b/langtools/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
--- a/langtools/src/share/classes/com/sun/tools/javac/model/JavacTypes.java Mon Mar 18 08:46:09 2013 -0700
+++ b/langtools/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<? extends AnnotationMirror> typeAnnotationsOf(TypeMirror type) {
- // TODO: these methods can be removed.
- return null; // ((Type)type).typeAnnotations;
- }
-
- public <A extends Annotation> A typeAnnotationOf(TypeMirror type,
- Class<A> 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 extends Annotation> A receiverTypeAnnotationOf(
- ExecutableType type, Class<A> annotationType) {
- return JavacElements.getAnnotation(
- ((Type)type).asMethodType().receiverTypeAnnotations,
- annotationType);
- }*/
-
}
--- a/langtools/src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java Mon Mar 18 08:46:09 2013 -0700
+++ b/langtools/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<? extends Compound> typeAnnos = ((com.sun.tools.javac.code.Type.AnnotatedType)recvtype).typeAnnotations;
--- a/langtools/src/share/classes/com/sun/tools/javadoc/TypeMaker.java Mon Mar 18 08:46:09 2013 -0700
+++ b/langtools/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;
}
--- a/langtools/src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java Mon Mar 18 08:46:09 2013 -0700
+++ b/langtools/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<TypeCompound> tas = ((com.sun.tools.javac.code.Type.AnnotatedType) type).typeAnnotations;
--- a/langtools/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<? extends AnnotationMirror> getAnnotations();
- TypeMirror getUnderlyingType();
-}
--- a/langtools/src/share/classes/javax/lang/model/type/ExecutableType.java Mon Mar 18 08:46:09 2013 -0700
+++ b/langtools/src/share/classes/javax/lang/model/type/ExecutableType.java Mon Mar 18 14:40:32 2013 -0700
@@ -78,14 +78,6 @@
List<? extends TypeMirror> 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.
*
--- a/langtools/src/share/classes/javax/lang/model/type/TypeKind.java Mon Mar 18 08:46:09 2013 -0700
+++ b/langtools/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
--- a/langtools/src/share/classes/javax/lang/model/type/TypeVisitor.java Mon Mar 18 08:46:09 2013 -0700
+++ b/langtools/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);
}
--- a/langtools/src/share/classes/javax/lang/model/util/AbstractTypeVisitor6.java Mon Mar 18 08:46:09 2013 -0700
+++ b/langtools/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}
*
* <p> The default implementation of this method in {@code
--- a/langtools/src/share/classes/javax/lang/model/util/Types.java Mon Mar 18 08:46:09 2013 -0700
+++ b/langtools/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<? extends AnnotationMirror> 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.
- *
- * <p> 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}.
- *
- * <blockquote>
- * <i>Note:</i> 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.
- * </blockquote>
- *
- * @param <A> 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 extends Annotation> A typeAnnotationOf(TypeMirror type, Class<A> 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.
- *
- * <p> 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}.
- *
- * <blockquote>
- * <i>Note:</i> 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.
- * </blockquote>
- *
- * @param <A> 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 extends Annotation> A receiverTypeAnnotationOf(ExecutableType type, Class<A> annotationType);
-
}