8008425: Remove interim new javax.lang.model API for type-annotations
Reviewed-by: darcy
This commit is contained in:
parent
1e91824535
commit
0e8a3df6c7
@ -246,6 +246,10 @@ public class Type implements PrimitiveType {
|
||||
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 class Type implements PrimitiveType {
|
||||
}
|
||||
|
||||
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 @@ public class Type implements PrimitiveType {
|
||||
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 @@ public class Type implements PrimitiveType {
|
||||
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
|
||||
@ -1576,11 +1590,6 @@ public class Type implements PrimitiveType {
|
||||
return typeAnnotations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeMirror getUnderlyingType() {
|
||||
return underlyingType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type unannotatedType() {
|
||||
return underlyingType;
|
||||
@ -1593,7 +1602,7 @@ public class Type implements PrimitiveType {
|
||||
|
||||
@Override
|
||||
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
|
||||
return v.visitAnnotated(this, p);
|
||||
return underlyingType.accept(v, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -233,7 +233,7 @@ public class TypeAnnotations {
|
||||
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 @@ public class TypeAnnotations {
|
||||
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;
|
||||
|
@ -2091,7 +2091,7 @@ public class Types {
|
||||
@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
|
||||
|
@ -3362,7 +3362,7 @@ public class Attr extends JCTree.Visitor {
|
||||
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
|
||||
|
@ -333,28 +333,4 @@ public class JavacTypes implements javax.lang.model.util.Types {
|
||||
|
||||
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);
|
||||
}*/
|
||||
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ public abstract class ExecutableMemberDocImpl
|
||||
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;
|
||||
|
@ -65,11 +65,11 @@ public class TypeMaker {
|
||||
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 @@ public class TypeMaker {
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ public class TypeVariableImpl extends AbstractTypeImpl implements TypeVariable {
|
||||
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 @@ public class TypeVariableImpl extends AbstractTypeImpl implements TypeVariable {
|
||||
* 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;
|
||||
|
@ -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();
|
||||
}
|
@ -77,14 +77,6 @@ public interface ExecutableType extends TypeMirror {
|
||||
*/
|
||||
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.
|
||||
|
@ -151,14 +151,7 @@ public enum TypeKind {
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
INTERSECTION,
|
||||
|
||||
/**
|
||||
* An annotated type.
|
||||
*
|
||||
* @since 1.8
|
||||
*/
|
||||
ANNOTATED;
|
||||
INTERSECTION;
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this kind corresponds to a primitive
|
||||
|
@ -194,14 +194,4 @@ public interface TypeVisitor<R, P> {
|
||||
* @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);
|
||||
}
|
||||
|
@ -133,23 +133,6 @@ public abstract class AbstractTypeVisitor6<R, P> implements TypeVisitor<R, P> {
|
||||
return visitUnknown(t, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*
|
||||
|
@ -301,116 +301,4 @@ public interface Types {
|
||||
* 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);
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user