From 31104a30235f0b0526ebe028cb3baa49dadca167 Mon Sep 17 00:00:00 2001 From: Ladislav Thon Date: Fri, 30 Jul 2021 13:44:44 +0200 Subject: [PATCH 1/2] remove AnnotationMember --- .../enterprise/lang/model/AnnotationInfo.java | 10 ++-- .../lang/model/AnnotationMember.java | 24 -------- .../lang/model/AnnotationMemberValue.java | 59 +++++++++---------- 3 files changed, 34 insertions(+), 59 deletions(-) delete mode 100644 api/src/main/java/jakarta/enterprise/lang/model/AnnotationMember.java diff --git a/api/src/main/java/jakarta/enterprise/lang/model/AnnotationInfo.java b/api/src/main/java/jakarta/enterprise/lang/model/AnnotationInfo.java index 8223170d..f6d68180 100644 --- a/api/src/main/java/jakarta/enterprise/lang/model/AnnotationInfo.java +++ b/api/src/main/java/jakarta/enterprise/lang/model/AnnotationInfo.java @@ -4,7 +4,7 @@ import java.lang.annotation.Annotation; import java.lang.annotation.Repeatable; -import java.util.Collection; +import java.util.Map; /** * An annotation instance, typically obtained from an {@link AnnotationTarget}. @@ -82,10 +82,10 @@ default AnnotationMemberValue value() { } /** - * Returns all members of this annotation. Returns an empty collection - * if this annotation has no members. + * Returns all members of this annotation as a map, where the key is the member name + * and the value is the member value. Returns an empty map if this annotation has no members. * - * @return an immutable collection of all members of this annotation, never {@code null} + * @return an immutable map of all members of this annotation, never {@code null} */ - Collection members(); + Map members(); } diff --git a/api/src/main/java/jakarta/enterprise/lang/model/AnnotationMember.java b/api/src/main/java/jakarta/enterprise/lang/model/AnnotationMember.java deleted file mode 100644 index d7222d51..00000000 --- a/api/src/main/java/jakarta/enterprise/lang/model/AnnotationMember.java +++ /dev/null @@ -1,24 +0,0 @@ -package jakarta.enterprise.lang.model; - -/** - * An annotation member: name and {@link AnnotationMemberValue value}. - * - * @see #name() - * @see #value() - */ -// TODO maybe remove this and let AnnotationInfo.members() return Map? -public interface AnnotationMember { - /** - * Returns the name of this annotation member. - * - * @return the name of this annotation member, never {@code null} - */ - String name(); - - /** - * Returns the {@link AnnotationMemberValue value} of this annotation member. - * - * @return the value of this annotation member, never {@code null} - */ - AnnotationMemberValue value(); -} diff --git a/api/src/main/java/jakarta/enterprise/lang/model/AnnotationMemberValue.java b/api/src/main/java/jakarta/enterprise/lang/model/AnnotationMemberValue.java index 8afc19f3..d3d4bd3a 100644 --- a/api/src/main/java/jakarta/enterprise/lang/model/AnnotationMemberValue.java +++ b/api/src/main/java/jakarta/enterprise/lang/model/AnnotationMemberValue.java @@ -6,7 +6,7 @@ import java.util.List; /** - * The value of an {@link AnnotationMember}. Annotation member values are of several kinds: + * The value of an annotation member. Annotation member values are of several kinds: *
    *
  • primitive types;
  • *
  • {@link String}s;
  • @@ -34,35 +34,35 @@ public interface AnnotationMemberValue { */ enum Kind { /** - * A primitive {@code boolean}. + * A primitive {@code boolean} value. */ BOOLEAN, /** - * A primitive {@code byte}. + * A primitive {@code byte} value. */ BYTE, /** - * A primitive {@code short}. + * A primitive {@code short} value. */ SHORT, /** - * A primitive {@code int}. + * A primitive {@code int} value. */ INT, /** - * A primitive {@code long}. + * A primitive {@code long} value. */ LONG, /** - * A primitive {@code float}. + * A primitive {@code float} value. */ FLOAT, /** - * A primitive {@code double}. + * A primitive {@code double} value. */ DOUBLE, /** - * A primitive {@code char}. + * A primitive {@code char} value. */ CHAR, /** @@ -74,7 +74,7 @@ enum Kind { */ ENUM, /** - * A {@link Class} value. Represented as {@link jakarta.enterprise.lang.model.types.Type}. + * A {@link Class} value. Represented as {@link Type}. */ CLASS, /** @@ -89,9 +89,9 @@ enum Kind { } /** - * Returns the kind of the annotation member value. + * Returns the kind of this annotation member value. * - * @return the kind of the annotation member value, never {@code null} + * @return the kind of this annotation member value, never {@code null} */ Kind kind(); @@ -187,7 +187,7 @@ default boolean isArray() { } /** - * Returns the value as a boolean. + * Returns this value as a boolean. * * @return the boolean value * @throws IllegalStateException if this annotation member value is not a boolean @@ -195,7 +195,7 @@ default boolean isArray() { boolean asBoolean(); /** - * Returns the value as a byte. + * Returns this value as a byte. * * @return the byte value * @throws IllegalStateException if the value cannot be represented as a byte @@ -203,7 +203,7 @@ default boolean isArray() { byte asByte(); /** - * Returns the value as a short. + * Returns this value as a short. * * @return the short value * @throws IllegalStateException if the value cannot be represented as a short. @@ -211,7 +211,7 @@ default boolean isArray() { short asShort(); /** - * Returns the value as an int. + * Returns this value as an int. * * @return the int value * @throws IllegalStateException if the value cannot be represented as an int. @@ -219,7 +219,7 @@ default boolean isArray() { int asInt(); /** - * Returns the value as a long. + * Returns this value as a long. * * @return the long value * @throws IllegalStateException if the value cannot be represented as a long. @@ -227,7 +227,7 @@ default boolean isArray() { long asLong(); /** - * Returns the value as a float. + * Returns this value as a float. * * @return the float value * @throws IllegalStateException if the value cannot be represented as a float. @@ -235,7 +235,7 @@ default boolean isArray() { float asFloat(); /** - * Returns the value as a double. + * Returns this value as a double. * * @return the double value * @throws IllegalStateException if the value cannot be represented as a double. @@ -243,7 +243,7 @@ default boolean isArray() { double asDouble(); /** - * Returns the value as a char. + * Returns this value as a char. * * @return the char value * @throws IllegalStateException if this annotation member value is not a char @@ -251,7 +251,7 @@ default boolean isArray() { char asChar(); /** - * Returns the value as a String. + * Returns this value as a String. * * @return the String value * @throws IllegalStateException if this annotation member value is not a String @@ -259,7 +259,7 @@ default boolean isArray() { String asString(); /** - * Returns the value as an enum instance. + * Returns this enum value as an instance of the enum type. * * @param enumType the enum type * @param the enum generic type @@ -267,11 +267,10 @@ default boolean isArray() { * @throws IllegalArgumentException if given {@code enumType} is not an enum type * @throws IllegalStateException if this annotation member value is not an enum value */ - // TODO we should be able to remove the Class parameter > E asEnum(Class enumType); /** - * Returns the enum type of the annotation member value. + * Returns the type of this enum value. * * @return a {@link ClassInfo} representing the enum type * @throws IllegalStateException if this annotation member value is not an enum value @@ -279,7 +278,7 @@ default boolean isArray() { ClassInfo asEnumClass(); /** - * Returns the enum constant of the annotation member value. + * Returns the name (also known as enum constant) of this enum value. * * @return the enum constant * @throws IllegalStateException if this annotation member value is not an enum value @@ -287,13 +286,13 @@ default boolean isArray() { String asEnumConstant(); /** - * Returns the class value, represented as a {@link Type}. It can possibly be: + * Returns this class value as a {@link Type}. It can possibly be: *
      *
    • the {@link jakarta.enterprise.lang.model.types.VoidType void} type;
    • *
    • a {@link jakarta.enterprise.lang.model.types.PrimitiveType primitive} type;
    • *
    • a {@link jakarta.enterprise.lang.model.types.ClassType class} type;
    • *
    • an {@link jakarta.enterprise.lang.model.types.ArrayType array} type, whose component type - * is one of the previously mentioned types.
    • + * is a primitive type or a class type. *
    * * @return the class value, as a {@link Type} @@ -302,7 +301,7 @@ default boolean isArray() { Type asType(); /** - * Returns the nested annotation value as an {@link AnnotationInfo}. + * Returns this nested annotation value as an {@link AnnotationInfo}. * * @return an {@link AnnotationInfo} instance * @throws IllegalStateException if this annotation member value is not a nested annotation @@ -310,8 +309,8 @@ default boolean isArray() { AnnotationInfo asNestedAnnotation(); /** - * Returns the array value as an immutable {@link List} of {@link AnnotationMemberValue}s. - * Returns an empty list if the array value is an empty array. + * Returns this array value as an immutable {@link List} of {@link AnnotationMemberValue}s. + * Returns an empty list if the array is empty. * * @return an immutable list of {@link AnnotationMemberValue}s * @throws IllegalStateException if this annotation member value is not an array From 84f4fd590835f5f95e34941f248d65a503746144 Mon Sep 17 00:00:00 2001 From: Ladislav Thon Date: Fri, 30 Jul 2021 13:45:36 +0200 Subject: [PATCH 2/2] rename AnnotationMemberValue to AnnotationMember --- .../inject/build/compatible/spi/AnnotationBuilder.java | 6 +++--- .../jakarta/enterprise/lang/model/AnnotationInfo.java | 10 +++++----- ...nnotationMemberValue.java => AnnotationMember.java} | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) rename api/src/main/java/jakarta/enterprise/lang/model/{AnnotationMemberValue.java => AnnotationMember.java} (98%) diff --git a/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/AnnotationBuilder.java b/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/AnnotationBuilder.java index 457179f9..cdd19154 100644 --- a/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/AnnotationBuilder.java +++ b/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/AnnotationBuilder.java @@ -1,7 +1,7 @@ package jakarta.enterprise.inject.build.compatible.spi; import jakarta.enterprise.lang.model.AnnotationInfo; -import jakarta.enterprise.lang.model.AnnotationMemberValue; +import jakarta.enterprise.lang.model.AnnotationMember; import jakarta.enterprise.lang.model.declarations.ClassInfo; import jakarta.enterprise.lang.model.types.Type; @@ -45,7 +45,7 @@ static AnnotationBuilder of(ClassInfo annotationType) { * @param value value of the annotation member * @return this {@code AnnotationBuilder} */ - default AnnotationBuilder value(AnnotationMemberValue value) { + default AnnotationBuilder value(AnnotationMember value) { return member(AnnotationInfo.MEMBER_VALUE, value); } @@ -420,7 +420,7 @@ default AnnotationBuilder value(Annotation... values) { * @param value value of the annotation member, must not be {@code null} * @return this {@code AnnotationBuilder} */ - AnnotationBuilder member(String name, AnnotationMemberValue value); + AnnotationBuilder member(String name, AnnotationMember value); /** * Adds a boolean-valued annotation member with given {@code name}. diff --git a/api/src/main/java/jakarta/enterprise/lang/model/AnnotationInfo.java b/api/src/main/java/jakarta/enterprise/lang/model/AnnotationInfo.java index f6d68180..c42b9078 100644 --- a/api/src/main/java/jakarta/enterprise/lang/model/AnnotationInfo.java +++ b/api/src/main/java/jakarta/enterprise/lang/model/AnnotationInfo.java @@ -56,12 +56,12 @@ default boolean isRepeatable() { boolean hasMember(String name); /** - * Returns the {@link AnnotationMemberValue value} of this annotation's member with given {@code name}. + * Returns the {@link AnnotationMember value} of this annotation's member with given {@code name}. * * @param name member name, must not be {@code null} * @return value of this annotation's member with given {@code name} or {@code null} if such member doesn't exist */ - AnnotationMemberValue member(String name); + AnnotationMember member(String name); /** * Returns whether this annotation has the {@link #MEMBER_VALUE value} member. @@ -73,11 +73,11 @@ default boolean hasValue() { } /** - * Returns the {@link AnnotationMemberValue value} of this annotation's {@link #MEMBER_VALUE value} member. + * Returns the {@link AnnotationMember value} of this annotation's {@link #MEMBER_VALUE value} member. * * @return value of this annotation's {@link #MEMBER_VALUE value} member or {@code null} if the member doesn't exist */ - default AnnotationMemberValue value() { + default AnnotationMember value() { return member(MEMBER_VALUE); } @@ -87,5 +87,5 @@ default AnnotationMemberValue value() { * * @return an immutable map of all members of this annotation, never {@code null} */ - Map members(); + Map members(); } diff --git a/api/src/main/java/jakarta/enterprise/lang/model/AnnotationMemberValue.java b/api/src/main/java/jakarta/enterprise/lang/model/AnnotationMember.java similarity index 98% rename from api/src/main/java/jakarta/enterprise/lang/model/AnnotationMemberValue.java rename to api/src/main/java/jakarta/enterprise/lang/model/AnnotationMember.java index d3d4bd3a..db298bb3 100644 --- a/api/src/main/java/jakarta/enterprise/lang/model/AnnotationMemberValue.java +++ b/api/src/main/java/jakarta/enterprise/lang/model/AnnotationMember.java @@ -28,7 +28,7 @@ * needs more discussion. I personally don't like coercion here and would always * throw if the type mismatches. */ -public interface AnnotationMemberValue { +public interface AnnotationMember { /** * The kind of the annotation member value. */ @@ -309,11 +309,11 @@ default boolean isArray() { AnnotationInfo asNestedAnnotation(); /** - * Returns this array value as an immutable {@link List} of {@link AnnotationMemberValue}s. + * Returns this array value as an immutable {@link List} of {@link AnnotationMember}s. * Returns an empty list if the array is empty. * - * @return an immutable list of {@link AnnotationMemberValue}s + * @return an immutable list of {@link AnnotationMember}s * @throws IllegalStateException if this annotation member value is not an array */ - List asArray(); + List asArray(); }