Skip to content

Commit 4dd5f23

Browse files
committed
rename: eagerResolution -> allowEnumClinit
1 parent 0037aa7 commit 4dd5f23

File tree

8 files changed

+95
-48
lines changed

8 files changed

+95
-48
lines changed

src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java

Lines changed: 60 additions & 31 deletions
Large diffs are not rendered by default.

src/java.base/share/classes/sun/reflect/annotation/AnnotationType.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ private AnnotationType(final Class<? extends Annotation> annotationClass) {
125125

126126
byte[] annotationDefault = SharedSecrets.getJavaLangReflectAccess().getAnnotationDefaultBytes(method);
127127
if (annotationDefault != null) {
128-
// Pass eagerResolution==false to support the
129-
// context where eager resolution is not desired.
130-
// All uses of defaultValue will use
128+
// Pass allowEnumClinit == false to avoid
129+
// enum class initialization.
130+
// All accesses of defaultValue use
131131
// sun.reflect.annotation.ResolvableValue.resolved
132-
// to ensure only resolved values are seen by
133-
// users of the standard annotation API.
132+
// to ensure enum constants values are seen via
133+
// the standard annotation API.
134134
Object defaultValue = AnnotationParser.parseAnnotationDefault(method, annotationDefault, false);
135135
if (defaultValue != null) {
136136
memberDefaults.put(name, defaultValue);

src/java.base/share/classes/sun/reflect/annotation/EnumValue.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
* An instance of this class is stored in an AnnotationInvocationHandler's
3030
* "memberValues" map to defer reification of an enum constant until the
3131
* dynamic proxy is queried for the enum member.
32+
* <p>
33+
* Instances of this object are created when the {@code allowEnumClinit}
34+
* argument to {@link AnnotationParser#parseEnumValue} is {@code false}.
3235
*/
3336
public final class EnumValue implements java.io.Serializable, ResolvableValue {
3437

@@ -44,7 +47,7 @@ public final class EnumValue implements java.io.Serializable, ResolvableValue {
4447
public final String constName;
4548

4649
/**
47-
* The lazily retrived value of the enum constant.
50+
* The lazily resolved value of the enum constant.
4851
*/
4952
transient Object constValue;
5053

src/java.base/share/classes/sun/reflect/annotation/EnumValueArray.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727

2828
import java.io.Serializable;
2929
import java.lang.reflect.Array;
30-
import java.util.Arrays;
3130
import java.util.List;
32-
import java.util.Objects;
3331

3432
/**
3533
* An instance of this class is stored in an AnnotationInvocationHandler's
3634
* "memberValues" map to defer reification of an enum constant until the
3735
* dynamic proxy is queried for the enum member.
36+
* <p>
37+
* Instances of this object are created when the {@code allowEnumClinit}
38+
* argument to {@link AnnotationParser#parseEnumArray} is {@code false}.
3839
*/
3940
public final class EnumValueArray implements java.io.Serializable, ResolvableValue {
4041

src/java.base/share/classes/sun/reflect/annotation/ResolvableValue.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
/**
2929
* Denotes a parsed annotation element value that is not fully resolved to the
3030
* value returned by the annotation interface method for the element.
31-
* This is used for example to defer resolving enum constants which is important
32-
* in contexts where class initialization of the enum types should not be
33-
* triggered by annotation parsing.
31+
* This is used, for example, to avoid enum class initialization when
32+
* parsing enum annotation elements.
3433
*/
3534
public interface ResolvableValue {
3635

src/java.base/share/classes/sun/reflect/annotation/TypeAnnotationParser.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,15 @@ static TypeAnnotation[] parseAllTypeAnnotations(AnnotatedElement decl) {
345345
decl, false, container);
346346
}
347347

348-
/* Parse type annotations encoded as an array of bytes */
348+
/**
349+
* Parses types annotations encoded as an array of bytes.
350+
*
351+
* @param allowEnumClinit described in {@link AnnotationParser}
352+
*/
349353
public static TypeAnnotation[] parseTypeAnnotations(byte[] rawAnnotations,
350354
ConstantPool cp,
351355
AnnotatedElement baseDecl,
352-
boolean eagerResolution,
356+
boolean allowEnumClinit,
353357
Class<?> container) {
354358
if (rawAnnotations == null)
355359
return EMPTY_TYPE_ANNOTATION_ARRAY;
@@ -360,7 +364,7 @@ public static TypeAnnotation[] parseTypeAnnotations(byte[] rawAnnotations,
360364

361365
// Parse each TypeAnnotation
362366
for (int i = 0; i < annotationCount; i++) {
363-
TypeAnnotation ta = parseTypeAnnotation(buf, cp, baseDecl, eagerResolution, container);
367+
TypeAnnotation ta = parseTypeAnnotation(buf, cp, baseDecl, allowEnumClinit, container);
364368
if (ta != null)
365369
typeAnnotations.add(ta);
366370
}
@@ -414,15 +418,18 @@ static Map<Class<? extends Annotation>, Annotation> mapTypeAnnotations(TypeAnnot
414418
private static final byte CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT = (byte)0x4A;
415419
private static final byte METHOD_REFERENCE_TYPE_ARGUMENT = (byte)0x4B;
416420

421+
/**
422+
* @param allowEnumClinit described in {@link AnnotationParser}
423+
*/
417424
public static TypeAnnotation parseTypeAnnotation(ByteBuffer buf,
418425
ConstantPool cp,
419426
AnnotatedElement baseDecl,
420-
boolean eagerResolution,
427+
boolean allowEnumClinit,
421428
Class<?> container) {
422429
try {
423430
TypeAnnotationTargetInfo ti = parseTargetInfo(buf);
424431
LocationInfo locationInfo = LocationInfo.parseLocationInfo(buf);
425-
Annotation a = AnnotationParser.parseAnnotation(buf, cp, container, eagerResolution, false);
432+
Annotation a = AnnotationParser.parseAnnotation(buf, cp, container, allowEnumClinit, false);
426433
if (ti == null) // Inside a method for example
427434
return null;
428435
return new TypeAnnotation(ti, locationInfo, a, baseDecl);

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/annotation/AnnotationValue.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ public <V> V get(String name, Class<V> elementType) {
157157
return elementType.cast(val);
158158
}
159159

160+
/**
161+
* Gets an unmodifiable view of the elements in this annotation value.
162+
* The type for each value in the returned map is specified by {@link #get(String, Class)}.
163+
*/
164+
public Map<String, Object> getElements() {
165+
return elements;
166+
}
167+
160168
@Override
161169
public String toString() {
162170
return "@" + type.toClassName() + "(" + elements + ")";

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/annotation/ElementTypeMismatch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* <p>
3131
* Similar to {@code AnnotationTypeMismatchExceptionProxy}.
3232
*/
33-
public final class ElementTypeMismatch {
33+
public final class ElementTypeMismatch extends ErrorElement {
3434
private final String foundType;
3535

3636
/**

0 commit comments

Comments
 (0)