8336754: Remodel TypeAnnotation to "has" instead of "be" an Annotation

Co-authored-by: Alex Buckley <abuckley@openjdk.org>
Reviewed-by: asotona
This commit is contained in:
Chen Liang 2024-08-16 15:48:54 +00:00
parent 07352c6744
commit 961e944fa7
20 changed files with 260 additions and 243 deletions

View file

@ -41,7 +41,11 @@ import java.util.List;
import jdk.internal.javac.PreviewFeature;
/**
* Models the value of a key-value pair of an annotation.
* Models an {@code element_value} structure, or a value of an element-value
* pair of an annotation, as defined in JVMS {@jvms 4.7.16.1}.
* <p>
* Two {@code AnnotationValue} objects should be compared using the {@link
* Object#equals(Object) equals} method.
*
* @see Annotation
* @see AnnotationElement
@ -53,8 +57,8 @@ import jdk.internal.javac.PreviewFeature;
public sealed interface AnnotationValue {
/**
* Models an annotation-valued element.
* The {@linkplain #tag tag} of this element is {@value ClassFile#AEV_ANNOTATION}.
* Models an annotation value of an element-value pair.
* The {@linkplain #tag tag} of this value is {@value ClassFile#AEV_ANNOTATION}.
*
* @since 22
*/
@ -66,8 +70,8 @@ public sealed interface AnnotationValue {
}
/**
* Models an array-valued element.
* The {@linkplain #tag tag} of this element is {@value ClassFile#AEV_ARRAY}.
* Models an array value of an element-value pair.
* The {@linkplain #tag tag} of this value is {@value ClassFile#AEV_ARRAY}.
*
* @since 22
*/
@ -79,13 +83,15 @@ public sealed interface AnnotationValue {
*
* @apiNote
* All array elements derived from Java source code have the same type,
* which must not be an array type. ({@jls 9.6.1})
* which must not be an array type. (JLS {@jls 9.6.1}) If such elements are
* annotations, they have the same annotation interface; if such elements
* are enum, they belong to the same enum class.
*/
List<AnnotationValue> values();
}
/**
* Models a constant-valued element.
* Models a constant value of an element-value pair.
*
* @sealedGraph
* @since 22
@ -123,8 +129,8 @@ public sealed interface AnnotationValue {
}
/**
* Models a string-valued element.
* The {@linkplain #tag tag} of this element is {@value ClassFile#AEV_STRING}.
* Models a string value of an element-value pair.
* The {@linkplain #tag tag} of this value is {@value ClassFile#AEV_STRING}.
*
* @since 22
*/
@ -151,8 +157,8 @@ public sealed interface AnnotationValue {
}
/**
* Models a double-valued element.
* The {@linkplain #tag tag} of this element is {@value ClassFile#AEV_DOUBLE}.
* Models a double value of an element-value pair.
* The {@linkplain #tag tag} of this value is {@value ClassFile#AEV_DOUBLE}.
*
* @since 22
*/
@ -179,8 +185,8 @@ public sealed interface AnnotationValue {
}
/**
* Models a float-valued element.
* The {@linkplain #tag tag} of this element is {@value ClassFile#AEV_FLOAT}.
* Models a float value of an element-value pair.
* The {@linkplain #tag tag} of this value is {@value ClassFile#AEV_FLOAT}.
*
* @since 22
*/
@ -207,8 +213,8 @@ public sealed interface AnnotationValue {
}
/**
* Models a long-valued element.
* The {@linkplain #tag tag} of this element is {@value ClassFile#AEV_LONG}.
* Models a long value of an element-value pair.
* The {@linkplain #tag tag} of this value is {@value ClassFile#AEV_LONG}.
*
* @since 22
*/
@ -235,8 +241,8 @@ public sealed interface AnnotationValue {
}
/**
* Models an int-valued element.
* The {@linkplain #tag tag} of this element is {@value ClassFile#AEV_INT}.
* Models an int value of an element-value pair.
* The {@linkplain #tag tag} of this value is {@value ClassFile#AEV_INT}.
*
* @since 22
*/
@ -263,8 +269,8 @@ public sealed interface AnnotationValue {
}
/**
* Models a short-valued element.
* The {@linkplain #tag tag} of this element is {@value ClassFile#AEV_SHORT}.
* Models a short value of an element-value pair.
* The {@linkplain #tag tag} of this value is {@value ClassFile#AEV_SHORT}.
*
* @since 22
*/
@ -294,8 +300,8 @@ public sealed interface AnnotationValue {
}
/**
* Models a char-valued element.
* The {@linkplain #tag tag} of this element is {@value ClassFile#AEV_CHAR}.
* Models a char value of an element-value pair.
* The {@linkplain #tag tag} of this value is {@value ClassFile#AEV_CHAR}.
*
* @since 22
*/
@ -325,8 +331,8 @@ public sealed interface AnnotationValue {
}
/**
* Models a byte-valued element.
* The {@linkplain #tag tag} of this element is {@value ClassFile#AEV_BYTE}.
* Models a byte value of an element-value pair.
* The {@linkplain #tag tag} of this value is {@value ClassFile#AEV_BYTE}.
*
* @since 22
*/
@ -356,8 +362,8 @@ public sealed interface AnnotationValue {
}
/**
* Models a boolean-valued element.
* The {@linkplain #tag tag} of this element is {@value ClassFile#AEV_BOOLEAN}.
* Models a boolean value of an element-value pair.
* The {@linkplain #tag tag} of this value is {@value ClassFile#AEV_BOOLEAN}.
*
* @since 22
*/
@ -387,8 +393,8 @@ public sealed interface AnnotationValue {
}
/**
* Models a class-valued element.
* The {@linkplain #tag tag} of this element is {@value ClassFile#AEV_CLASS}.
* Models a class value of an element-value pair.
* The {@linkplain #tag tag} of this value is {@value ClassFile#AEV_CLASS}.
*
* @since 22
*/
@ -405,8 +411,8 @@ public sealed interface AnnotationValue {
}
/**
* Models an enum-valued element.
* The {@linkplain #tag tag} of this element is {@value ClassFile#AEV_ENUM}.
* Models an enum value of an element-value pair.
* The {@linkplain #tag tag} of this value is {@value ClassFile#AEV_ENUM}.
*
* @since 22
*/
@ -426,12 +432,13 @@ public sealed interface AnnotationValue {
}
/**
* {@return the tag character for this type as per JVMS {@jvms 4.7.16.1}}
* {@return the tag character for this value as per JVMS {@jvms 4.7.16.1}}
* The tag characters have a one-to-one mapping to the types of annotation element values.
*/
char tag();
/**
* {@return an annotation element for a enum-valued element}
* {@return an enum value for an element-value pair}
* @param className the descriptor string of the enum class
* @param constantName the name of the enum constant
*/
@ -441,7 +448,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a enum-valued element}
* {@return an enum value for an element-value pair}
* @param className the descriptor of the enum class
* @param constantName the name of the enum constant
*/
@ -451,7 +458,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a class-valued element}
* {@return a class value for an element-value pair}
* @param className the descriptor string of the class
*/
static OfClass ofClass(Utf8Entry className) {
@ -459,7 +466,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a class-valued element}
* {@return a class value for an element-value pair}
* @param className the descriptor of the class
*/
static OfClass ofClass(ClassDesc className) {
@ -467,7 +474,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a string-valued element}
* {@return a string value for an element-value pair}
* @param value the string
*/
static OfString ofString(Utf8Entry value) {
@ -475,7 +482,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a string-valued element}
* {@return a string value for an element-value pair}
* @param value the string
*/
static OfString ofString(String value) {
@ -483,7 +490,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a double-valued element}
* {@return a double value for an element-value pair}
* @param value the double value
*/
static OfDouble ofDouble(DoubleEntry value) {
@ -491,7 +498,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a double-valued element}
* {@return a double value for an element-value pair}
* @param value the double value
*/
static OfDouble ofDouble(double value) {
@ -499,7 +506,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a float-valued element}
* {@return a float value for an element-value pair}
* @param value the float value
*/
static OfFloat ofFloat(FloatEntry value) {
@ -507,7 +514,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a float-valued element}
* {@return a float value for an element-value pair}
* @param value the float value
*/
static OfFloat ofFloat(float value) {
@ -515,7 +522,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a long-valued element}
* {@return a long value for an element-value pair}
* @param value the long value
*/
static OfLong ofLong(LongEntry value) {
@ -523,7 +530,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a long-valued element}
* {@return a long value for an element-value pair}
* @param value the long value
*/
static OfLong ofLong(long value) {
@ -531,7 +538,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for an int-valued element}
* {@return an int value for an element-value pair}
* @param value the int value
*/
static OfInt ofInt(IntegerEntry value) {
@ -539,7 +546,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for an int-valued element}
* {@return an int value for an element-value pair}
* @param value the int value
*/
static OfInt ofInt(int value) {
@ -547,7 +554,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a short-valued element}
* {@return a short value for an element-value pair}
* @param value the short value
*/
static OfShort ofShort(IntegerEntry value) {
@ -555,7 +562,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a short-valued element}
* {@return a short value for an element-value pair}
* @param value the short value
*/
static OfShort ofShort(short value) {
@ -563,7 +570,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a char-valued element}
* {@return a char value for an element-value pair}
* @param value the char value
*/
static OfChar ofChar(IntegerEntry value) {
@ -571,7 +578,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a char-valued element}
* {@return a char value for an element-value pair}
* @param value the char value
*/
static OfChar ofChar(char value) {
@ -579,7 +586,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a byte-valued element}
* {@return a byte value for an element-value pair}
* @param value the byte value
*/
static OfByte ofByte(IntegerEntry value) {
@ -587,7 +594,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a byte-valued element}
* {@return a byte value for an element-value pair}
* @param value the byte value
*/
static OfByte ofByte(byte value) {
@ -595,7 +602,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a boolean-valued element}
* {@return a boolean value for an element-value pair}
* @param value the boolean value
*/
static OfBoolean ofBoolean(IntegerEntry value) {
@ -603,7 +610,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for a boolean-valued element}
* {@return a boolean value for an element-value pair}
* @param value the boolean value
*/
static OfBoolean ofBoolean(boolean value) {
@ -612,7 +619,7 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for an annotation-valued element}
* {@return an annotation value for an element-value pair}
* @param value the annotation
*/
static OfAnnotation ofAnnotation(Annotation value) {
@ -620,7 +627,12 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for an array-valued element}
* {@return an array value for an element-value pair}
*
* @apiNote
* See {@link AnnotationValue.OfArray#values() values()} for conventions
* on array values derived from Java source code.
*
* @param values the array elements
*/
static OfArray ofArray(List<AnnotationValue> values) {
@ -628,7 +640,12 @@ public sealed interface AnnotationValue {
}
/**
* {@return an annotation element for an array-valued element}
* {@return an array value for an element-value pair}
*
* @apiNote
* See {@link AnnotationValue.OfArray#values() values()} for conventions
* on array values derived from Java source code.
*
* @param values the array elements
*/
static OfArray ofArray(AnnotationValue... values) {