mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-13 11:55:38 +00:00
8345319: Fix the tag type in PoolEntry and AnnotationValue
Reviewed-by: asotona
This commit is contained in:
parent
e9f6ba0526
commit
76e874c08e
@ -456,9 +456,11 @@ public sealed interface AnnotationValue {
|
||||
*
|
||||
* @apiNote
|
||||
* {@code TAG_}-prefixed constants in this class, such as {@link #TAG_INT},
|
||||
* describe the possible return values of this method.
|
||||
* describe the possible return values of this method. The return type is
|
||||
* {@code int} for consistency with union indicator items in other union
|
||||
* structures in the {@code class} file format.
|
||||
*/
|
||||
char tag();
|
||||
int tag();
|
||||
|
||||
/**
|
||||
* {@return an enum value for an element-value pair}
|
||||
|
||||
@ -98,7 +98,7 @@ public sealed interface PoolEntry
|
||||
* {@code TAG_}-prefixed constants in this class, such as {@link #TAG_UTF8},
|
||||
* describe the possible return values of this method.
|
||||
*/
|
||||
byte tag();
|
||||
int tag();
|
||||
|
||||
/**
|
||||
* {@return the index within the constant pool corresponding to this entry}
|
||||
|
||||
@ -104,7 +104,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public abstract byte tag();
|
||||
public abstract int tag();
|
||||
|
||||
public int width() {
|
||||
return 1;
|
||||
@ -181,7 +181,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte tag() {
|
||||
public int tag() {
|
||||
return TAG_UTF8;
|
||||
}
|
||||
|
||||
@ -522,7 +522,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte tag() {
|
||||
public int tag() {
|
||||
return TAG_CLASS;
|
||||
}
|
||||
|
||||
@ -582,7 +582,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte tag() {
|
||||
public int tag() {
|
||||
return TAG_PACKAGE;
|
||||
}
|
||||
|
||||
@ -613,7 +613,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte tag() {
|
||||
public int tag() {
|
||||
return TAG_MODULE;
|
||||
}
|
||||
|
||||
@ -645,7 +645,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte tag() {
|
||||
public int tag() {
|
||||
return TAG_NAME_AND_TYPE;
|
||||
}
|
||||
|
||||
@ -719,7 +719,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte tag() {
|
||||
public int tag() {
|
||||
return TAG_FIELDREF;
|
||||
}
|
||||
|
||||
@ -737,7 +737,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte tag() {
|
||||
public int tag() {
|
||||
return TAG_METHODREF;
|
||||
}
|
||||
|
||||
@ -755,7 +755,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte tag() {
|
||||
public int tag() {
|
||||
return TAG_INTERFACE_METHODREF;
|
||||
}
|
||||
|
||||
@ -849,7 +849,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte tag() {
|
||||
public int tag() {
|
||||
return TAG_INVOKE_DYNAMIC;
|
||||
}
|
||||
|
||||
@ -874,7 +874,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte tag() {
|
||||
public int tag() {
|
||||
return TAG_DYNAMIC;
|
||||
}
|
||||
|
||||
@ -905,7 +905,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte tag() {
|
||||
public int tag() {
|
||||
return TAG_METHOD_HANDLE;
|
||||
}
|
||||
|
||||
@ -964,7 +964,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte tag() {
|
||||
public int tag() {
|
||||
return TAG_METHOD_TYPE;
|
||||
}
|
||||
|
||||
@ -1002,7 +1002,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte tag() {
|
||||
public int tag() {
|
||||
return TAG_STRING;
|
||||
}
|
||||
|
||||
@ -1054,7 +1054,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte tag() {
|
||||
public int tag() {
|
||||
return TAG_INTEGER;
|
||||
}
|
||||
|
||||
@ -1100,7 +1100,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte tag() {
|
||||
public int tag() {
|
||||
return TAG_FLOAT;
|
||||
}
|
||||
|
||||
@ -1145,7 +1145,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte tag() {
|
||||
public int tag() {
|
||||
return TAG_LONG;
|
||||
}
|
||||
|
||||
@ -1195,7 +1195,7 @@ public abstract sealed class AbstractPoolEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte tag() {
|
||||
public int tag() {
|
||||
return TAG_DOUBLE;
|
||||
}
|
||||
|
||||
|
||||
@ -72,7 +72,7 @@ public record AnnotationImpl(Utf8Entry className, List<AnnotationElement> elemen
|
||||
public record OfStringImpl(Utf8Entry constant)
|
||||
implements AnnotationValue.OfString {
|
||||
@Override
|
||||
public char tag() {
|
||||
public int tag() {
|
||||
return TAG_STRING;
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ public record AnnotationImpl(Utf8Entry className, List<AnnotationElement> elemen
|
||||
public record OfDoubleImpl(DoubleEntry constant)
|
||||
implements AnnotationValue.OfDouble {
|
||||
@Override
|
||||
public char tag() {
|
||||
public int tag() {
|
||||
return TAG_DOUBLE;
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ public record AnnotationImpl(Utf8Entry className, List<AnnotationElement> elemen
|
||||
public record OfFloatImpl(FloatEntry constant)
|
||||
implements AnnotationValue.OfFloat {
|
||||
@Override
|
||||
public char tag() {
|
||||
public int tag() {
|
||||
return TAG_FLOAT;
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ public record AnnotationImpl(Utf8Entry className, List<AnnotationElement> elemen
|
||||
public record OfLongImpl(LongEntry constant)
|
||||
implements AnnotationValue.OfLong {
|
||||
@Override
|
||||
public char tag() {
|
||||
public int tag() {
|
||||
return TAG_LONG;
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ public record AnnotationImpl(Utf8Entry className, List<AnnotationElement> elemen
|
||||
public record OfIntImpl(IntegerEntry constant)
|
||||
implements AnnotationValue.OfInt {
|
||||
@Override
|
||||
public char tag() {
|
||||
public int tag() {
|
||||
return TAG_INT;
|
||||
}
|
||||
|
||||
@ -137,7 +137,7 @@ public record AnnotationImpl(Utf8Entry className, List<AnnotationElement> elemen
|
||||
public record OfShortImpl(IntegerEntry constant)
|
||||
implements AnnotationValue.OfShort {
|
||||
@Override
|
||||
public char tag() {
|
||||
public int tag() {
|
||||
return TAG_SHORT;
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ public record AnnotationImpl(Utf8Entry className, List<AnnotationElement> elemen
|
||||
public record OfCharImpl(IntegerEntry constant)
|
||||
implements AnnotationValue.OfChar {
|
||||
@Override
|
||||
public char tag() {
|
||||
public int tag() {
|
||||
return TAG_CHAR;
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ public record AnnotationImpl(Utf8Entry className, List<AnnotationElement> elemen
|
||||
public record OfByteImpl(IntegerEntry constant)
|
||||
implements AnnotationValue.OfByte {
|
||||
@Override
|
||||
public char tag() {
|
||||
public int tag() {
|
||||
return TAG_BYTE;
|
||||
}
|
||||
|
||||
@ -176,7 +176,7 @@ public record AnnotationImpl(Utf8Entry className, List<AnnotationElement> elemen
|
||||
public record OfBooleanImpl(IntegerEntry constant)
|
||||
implements AnnotationValue.OfBoolean {
|
||||
@Override
|
||||
public char tag() {
|
||||
public int tag() {
|
||||
return TAG_BOOLEAN;
|
||||
}
|
||||
|
||||
@ -193,7 +193,7 @@ public record AnnotationImpl(Utf8Entry className, List<AnnotationElement> elemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public char tag() {
|
||||
public int tag() {
|
||||
return TAG_ARRAY;
|
||||
}
|
||||
}
|
||||
@ -201,7 +201,7 @@ public record AnnotationImpl(Utf8Entry className, List<AnnotationElement> elemen
|
||||
public record OfEnumImpl(Utf8Entry className, Utf8Entry constantName)
|
||||
implements AnnotationValue.OfEnum {
|
||||
@Override
|
||||
public char tag() {
|
||||
public int tag() {
|
||||
return TAG_ENUM;
|
||||
}
|
||||
}
|
||||
@ -209,7 +209,7 @@ public record AnnotationImpl(Utf8Entry className, List<AnnotationElement> elemen
|
||||
public record OfAnnotationImpl(Annotation annotation)
|
||||
implements AnnotationValue.OfAnnotation {
|
||||
@Override
|
||||
public char tag() {
|
||||
public int tag() {
|
||||
return TAG_ANNOTATION;
|
||||
}
|
||||
}
|
||||
@ -217,7 +217,7 @@ public record AnnotationImpl(Utf8Entry className, List<AnnotationElement> elemen
|
||||
public record OfClassImpl(Utf8Entry className)
|
||||
implements AnnotationValue.OfClass {
|
||||
@Override
|
||||
public char tag() {
|
||||
public int tag() {
|
||||
return TAG_CLASS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -354,7 +354,7 @@ public final class AnnotationReader {
|
||||
public static void writeAnnotationValue(BufWriterImpl buf, AnnotationValue value) {
|
||||
var tag = value.tag();
|
||||
buf.writeU1(tag);
|
||||
switch (value.tag()) {
|
||||
switch (tag) {
|
||||
case TAG_BOOLEAN, TAG_BYTE, TAG_CHAR, TAG_DOUBLE, TAG_FLOAT, TAG_INT, TAG_LONG, TAG_SHORT, TAG_STRING ->
|
||||
buf.writeIndex(((AnnotationValue.OfConstant) value).constant());
|
||||
case TAG_CLASS -> buf.writeIndex(((AnnotationValue.OfClass) value).className());
|
||||
|
||||
@ -225,11 +225,12 @@ public class AnnotationWriter extends BasicWriter {
|
||||
}
|
||||
|
||||
public void write(AnnotationValue value, boolean resolveIndices) {
|
||||
var tagChar = (char) value.tag();
|
||||
switch (value) {
|
||||
case AnnotationValue.OfConstant ev -> {
|
||||
if (resolveIndices) {
|
||||
var entry = ev.constant();
|
||||
switch (ev.tag()) {
|
||||
switch (tagChar) {
|
||||
case 'B':
|
||||
print("(byte) ");
|
||||
print(constantWriter.stringValue(entry));
|
||||
@ -258,11 +259,11 @@ public class AnnotationWriter extends BasicWriter {
|
||||
print("\"");
|
||||
break;
|
||||
default:
|
||||
print(ev.tag() + "#" + entry.index());
|
||||
print(tagChar + "#" + entry.index());
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
print(ev.tag() + "#" + ev.constant().index());
|
||||
print(tagChar + "#" + ev.constant().index());
|
||||
}
|
||||
}
|
||||
case AnnotationValue.OfEnum ev -> {
|
||||
@ -271,7 +272,7 @@ public class AnnotationWriter extends BasicWriter {
|
||||
print(".");
|
||||
writeIndex(ev.constantName(), resolveIndices);
|
||||
} else {
|
||||
print(ev.tag() + "#" + ev.className().index() + ".#"
|
||||
print(tagChar + "#" + ev.className().index() + ".#"
|
||||
+ ev.constantName().index());
|
||||
}
|
||||
}
|
||||
@ -280,11 +281,11 @@ public class AnnotationWriter extends BasicWriter {
|
||||
print("class ");
|
||||
writeIndex(ev.className(), resolveIndices);
|
||||
} else {
|
||||
print(ev.tag() + "#" + ev.className().index());
|
||||
print(tagChar + "#" + ev.className().index());
|
||||
}
|
||||
}
|
||||
case AnnotationValue.OfAnnotation ev -> {
|
||||
print(ev.tag());
|
||||
print(tagChar);
|
||||
AnnotationWriter.this.write(ev.annotation(), resolveIndices);
|
||||
}
|
||||
case AnnotationValue.OfArray ev -> {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2024, 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
|
||||
@ -26,7 +26,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ExpectedValues {
|
||||
char tag();
|
||||
int tag();
|
||||
String name();
|
||||
String[] values();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user