diff --git a/src/java.base/share/classes/java/lang/classfile/Attributes.java b/src/java.base/share/classes/java/lang/classfile/Attributes.java
index 75e06e7c3f31e..1e91090f8afda 100644
--- a/src/java.base/share/classes/java/lang/classfile/Attributes.java
+++ b/src/java.base/share/classes/java/lang/classfile/Attributes.java
@@ -24,77 +24,74 @@
*/
package java.lang.classfile;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import java.lang.classfile.attribute.AnnotationDefaultAttribute;
-import java.lang.classfile.attribute.BootstrapMethodsAttribute;
-import java.lang.classfile.attribute.CharacterRangeInfo;
-import java.lang.classfile.attribute.CharacterRangeTableAttribute;
-import java.lang.classfile.attribute.CodeAttribute;
-import java.lang.classfile.attribute.CompilationIDAttribute;
-import java.lang.classfile.attribute.ConstantValueAttribute;
-import java.lang.classfile.attribute.DeprecatedAttribute;
-import java.lang.classfile.attribute.EnclosingMethodAttribute;
-import java.lang.classfile.attribute.ExceptionsAttribute;
-import java.lang.classfile.attribute.InnerClassInfo;
-import java.lang.classfile.attribute.InnerClassesAttribute;
-import java.lang.classfile.attribute.LineNumberInfo;
-import java.lang.classfile.attribute.LineNumberTableAttribute;
-import java.lang.classfile.attribute.LocalVariableInfo;
-import java.lang.classfile.attribute.LocalVariableTableAttribute;
-import java.lang.classfile.attribute.LocalVariableTypeInfo;
-import java.lang.classfile.attribute.LocalVariableTypeTableAttribute;
-import java.lang.classfile.attribute.MethodParameterInfo;
-import java.lang.classfile.attribute.MethodParametersAttribute;
-import java.lang.classfile.attribute.ModuleAttribute;
-import java.lang.classfile.attribute.ModuleExportInfo;
-import java.lang.classfile.attribute.ModuleHashInfo;
-import java.lang.classfile.attribute.ModuleHashesAttribute;
-import java.lang.classfile.attribute.ModuleMainClassAttribute;
-import java.lang.classfile.attribute.ModuleOpenInfo;
-import java.lang.classfile.attribute.ModulePackagesAttribute;
-import java.lang.classfile.attribute.ModuleProvideInfo;
-import java.lang.classfile.attribute.ModuleRequireInfo;
-import java.lang.classfile.attribute.ModuleResolutionAttribute;
-import java.lang.classfile.attribute.ModuleTargetAttribute;
-import java.lang.classfile.attribute.NestHostAttribute;
-import java.lang.classfile.attribute.NestMembersAttribute;
-import java.lang.classfile.attribute.PermittedSubclassesAttribute;
-import java.lang.classfile.attribute.RecordAttribute;
-import java.lang.classfile.attribute.RecordComponentInfo;
-import java.lang.classfile.attribute.RuntimeInvisibleAnnotationsAttribute;
-import java.lang.classfile.attribute.RuntimeInvisibleParameterAnnotationsAttribute;
-import java.lang.classfile.attribute.RuntimeInvisibleTypeAnnotationsAttribute;
-import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
-import java.lang.classfile.attribute.RuntimeVisibleParameterAnnotationsAttribute;
-import java.lang.classfile.attribute.RuntimeVisibleTypeAnnotationsAttribute;
-import java.lang.classfile.attribute.SignatureAttribute;
-import java.lang.classfile.attribute.SourceDebugExtensionAttribute;
-import java.lang.classfile.attribute.SourceFileAttribute;
-import java.lang.classfile.attribute.SourceIDAttribute;
-import java.lang.classfile.attribute.StackMapTableAttribute;
-import java.lang.classfile.attribute.SyntheticAttribute;
-import java.lang.classfile.constantpool.Utf8Entry;
-import jdk.internal.classfile.impl.AbstractAttributeMapper;
-import jdk.internal.classfile.impl.BoundAttribute;
-import jdk.internal.classfile.impl.CodeImpl;
-import jdk.internal.classfile.impl.AbstractPoolEntry;
-import jdk.internal.classfile.impl.StackMapDecoder;
+import java.lang.classfile.AttributeMapper.AttributeStability;
+import java.lang.classfile.attribute.*;
+import jdk.internal.classfile.impl.AbstractAttributeMapper.*;
import jdk.internal.javac.PreviewFeature;
/**
* Attribute mappers for standard classfile attributes.
+ *
+ * Unless otherwise specified, mappers returned by each method
+ * do not permit multiple attribute instances in a given location.
+ *
+ * The most stable {@link AttributeStability#STATELESS STATELESS} mappers are:
+ *
+ * - {@link #deprecated()}
+ *
- {@link #moduleResolution()}
+ *
- {@link #sourceDebugExtension()}
+ *
- {@link #synthetic()}
+ *
+ *
+ * The mappers with {@link AttributeStability#CP_REFS CP_REFS} stability are:
+ *
+ * - {@link #annotationDefault()}
+ *
- {@link #bootstrapMethods()}
+ *
- {@link #code()}
+ *
- {@link #compilationId()}
+ *
- {@link #constantValue()}
+ *
- {@link #enclosingMethod()}
+ *
- {@link #exceptions()}
+ *
- {@link #innerClasses()}
+ *
- {@link #methodParameters()}
+ *
- {@link #module()}
+ *
- {@link #moduleHashes()}
+ *
- {@link #moduleMainClass()}
+ *
- {@link #modulePackages()}
+ *
- {@link #moduleTarget()}
+ *
- {@link #nestHost()}
+ *
- {@link #nestMembers()}
+ *
- {@link #permittedSubclasses()}
+ *
- {@link #record()}
+ *
- {@link #runtimeInvisibleAnnotations()}
+ *
- {@link #runtimeInvisibleParameterAnnotations()}
+ *
- {@link #runtimeVisibleAnnotations()}
+ *
- {@link #runtimeVisibleParameterAnnotations()}
+ *
- {@link #signature()}
+ *
- {@link #sourceFile()}
+ *
- {@link #sourceId()}
+ *
+ *
+ * The mappers with {@link AttributeStability#LABELS LABELS} stability are:
+ *
+ * - {@link #characterRangeTable()}
+ *
- {@link #lineNumberTable()}
+ *
- {@link #localVariableTable()}
+ *
- {@link #localVariableTypeTable()}
+ *
+ *
+ * The {@link AttributeStability#UNSTABLE UNSTABLE} mappers are:
+ *
+ * - {@link #runtimeInvisibleTypeAnnotations()}
+ *
- {@link #runtimeVisibleTypeAnnotations()}
+ *
*
* @see AttributeMapper
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
-public class Attributes {
+public final class Attributes {
/** AnnotationDefault */
public static final String NAME_ANNOTATION_DEFAULT = "AnnotationDefault";
@@ -207,836 +204,297 @@ public class Attributes {
private Attributes() {
}
- /** Attribute mapper for the {@code AnnotationDefault} attribute */
- public static final AttributeMapper
- ANNOTATION_DEFAULT = new AbstractAttributeMapper<>(NAME_ANNOTATION_DEFAULT) {
- @Override
- public AnnotationDefaultAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundAnnotationDefaultAttr(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, AnnotationDefaultAttribute attr) {
- attr.defaultValue().writeTo(buf);
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code BootstrapMethods} attribute */
- public static final AttributeMapper
- BOOTSTRAP_METHODS = new AbstractAttributeMapper<>(NAME_BOOTSTRAP_METHODS) {
- @Override
- public BootstrapMethodsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundBootstrapMethodsAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, BootstrapMethodsAttribute attr) {
- buf.writeList(attr.bootstrapMethods());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code CharacterRangeTable} attribute */
- public static final AttributeMapper
- CHARACTER_RANGE_TABLE = new AbstractAttributeMapper<>(NAME_CHARACTER_RANGE_TABLE, true) {
- @Override
- public CharacterRangeTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundCharacterRangeTableAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, CharacterRangeTableAttribute attr) {
- List ranges = attr.characterRangeTable();
- buf.writeU2(ranges.size());
- for (CharacterRangeInfo info : ranges) {
- buf.writeU2(info.startPc());
- buf.writeU2(info.endPc());
- buf.writeInt(info.characterRangeStart());
- buf.writeInt(info.characterRangeEnd());
- buf.writeU2(info.flags());
- }
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.LABELS;
- }
- };
-
- /** Attribute mapper for the {@code Code} attribute */
- public static final AttributeMapper
- CODE = new AbstractAttributeMapper<>(NAME_CODE) {
- @Override
- public CodeAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new CodeImpl(e, cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, CodeAttribute attr) {
- throw new UnsupportedOperationException("Code attribute does not support direct write");
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
-
- /** Attribute mapper for the {@code CompilationID} attribute */
- public static final AttributeMapper
- COMPILATION_ID = new AbstractAttributeMapper<>(NAME_COMPILATION_ID, true) {
- @Override
- public CompilationIDAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundCompilationIDAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, CompilationIDAttribute attr) {
- buf.writeIndex(attr.compilationId());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code ConstantValue} attribute */
- public static final AttributeMapper
- CONSTANT_VALUE = new AbstractAttributeMapper<>(NAME_CONSTANT_VALUE) {
- @Override
- public ConstantValueAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundConstantValueAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, ConstantValueAttribute attr) {
- buf.writeIndex(attr.constant());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code Deprecated} attribute */
- public static final AttributeMapper
- DEPRECATED = new AbstractAttributeMapper<>(NAME_DEPRECATED, true) {
- @Override
- public DeprecatedAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundDeprecatedAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, DeprecatedAttribute attr) {
- // empty
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.STATELESS;
- }
- };
-
- /** Attribute mapper for the {@code EnclosingMethod} attribute */
- public static final AttributeMapper
- ENCLOSING_METHOD = new AbstractAttributeMapper<>(NAME_ENCLOSING_METHOD) {
- @Override
- public EnclosingMethodAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundEnclosingMethodAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, EnclosingMethodAttribute attr) {
- buf.writeIndex(attr.enclosingClass());
- buf.writeIndexOrZero(attr.enclosingMethod().orElse(null));
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code Exceptions} attribute */
- public static final AttributeMapper
- EXCEPTIONS = new AbstractAttributeMapper<>(NAME_EXCEPTIONS) {
- @Override
- public ExceptionsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundExceptionsAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, ExceptionsAttribute attr) {
- buf.writeListIndices(attr.exceptions());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code InnerClasses} attribute */
- public static final AttributeMapper
- INNER_CLASSES = new AbstractAttributeMapper<>(NAME_INNER_CLASSES) {
- @Override
- public InnerClassesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundInnerClassesAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, InnerClassesAttribute attr) {
- List classes = attr.classes();
- buf.writeU2(classes.size());
- for (InnerClassInfo ic : classes) {
- buf.writeIndex(ic.innerClass());
- buf.writeIndexOrZero(ic.outerClass().orElse(null));
- buf.writeIndexOrZero(ic.innerName().orElse(null));
- buf.writeU2(ic.flagsMask());
- }
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code LineNumberTable} attribute */
- public static final AttributeMapper
- LINE_NUMBER_TABLE = new AbstractAttributeMapper<>(NAME_LINE_NUMBER_TABLE, true) {
- @Override
- public LineNumberTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundLineNumberTableAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, LineNumberTableAttribute attr) {
- List lines = attr.lineNumbers();
- buf.writeU2(lines.size());
- for (LineNumberInfo line : lines) {
- buf.writeU2(line.startPc());
- buf.writeU2(line.lineNumber());
- }
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.LABELS;
- }
- };
-
- /** Attribute mapper for the {@code LocalVariableTable} attribute */
- public static final AttributeMapper
- LOCAL_VARIABLE_TABLE = new AbstractAttributeMapper<>(NAME_LOCAL_VARIABLE_TABLE, true) {
- @Override
- public LocalVariableTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundLocalVariableTableAttribute(e, cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, LocalVariableTableAttribute attr) {
- List infos = attr.localVariables();
- buf.writeU2(infos.size());
- for (LocalVariableInfo info : infos) {
- buf.writeU2(info.startPc());
- buf.writeU2(info.length());
- buf.writeIndex(info.name());
- buf.writeIndex(info.type());
- buf.writeU2(info.slot());
- }
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.LABELS;
- }
- };
-
- /** Attribute mapper for the {@code LocalVariableTypeTable} attribute */
- public static final AttributeMapper
- LOCAL_VARIABLE_TYPE_TABLE = new AbstractAttributeMapper<>(NAME_LOCAL_VARIABLE_TYPE_TABLE, true) {
- @Override
- public LocalVariableTypeTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundLocalVariableTypeTableAttribute(e, cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, LocalVariableTypeTableAttribute attr) {
- List infos = attr.localVariableTypes();
- buf.writeU2(infos.size());
- for (LocalVariableTypeInfo info : infos) {
- buf.writeU2(info.startPc());
- buf.writeU2(info.length());
- buf.writeIndex(info.name());
- buf.writeIndex(info.signature());
- buf.writeU2(info.slot());
- }
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.LABELS;
- }
- };
-
- /** Attribute mapper for the {@code MethodParameters} attribute */
- public static final AttributeMapper
- METHOD_PARAMETERS = new AbstractAttributeMapper<>(NAME_METHOD_PARAMETERS) {
- @Override
- public MethodParametersAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundMethodParametersAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, MethodParametersAttribute attr) {
- List parameters = attr.parameters();
- buf.writeU1(parameters.size());
- for (MethodParameterInfo info : parameters) {
- buf.writeIndexOrZero(info.name().orElse(null));
- buf.writeU2(info.flagsMask());
- }
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code Module} attribute */
- public static final AttributeMapper
- MODULE = new AbstractAttributeMapper<>(NAME_MODULE) {
- @Override
- public ModuleAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundModuleAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, ModuleAttribute attr) {
- buf.writeIndex(attr.moduleName());
- buf.writeU2(attr.moduleFlagsMask());
- buf.writeIndexOrZero(attr.moduleVersion().orElse(null));
- buf.writeU2(attr.requires().size());
- for (ModuleRequireInfo require : attr.requires()) {
- buf.writeIndex(require.requires());
- buf.writeU2(require.requiresFlagsMask());
- buf.writeIndexOrZero(require.requiresVersion().orElse(null));
- }
- buf.writeU2(attr.exports().size());
- for (ModuleExportInfo export : attr.exports()) {
- buf.writeIndex(export.exportedPackage());
- buf.writeU2(export.exportsFlagsMask());
- buf.writeListIndices(export.exportsTo());
- }
- buf.writeU2(attr.opens().size());
- for (ModuleOpenInfo open : attr.opens()) {
- buf.writeIndex(open.openedPackage());
- buf.writeU2(open.opensFlagsMask());
- buf.writeListIndices(open.opensTo());
- }
- buf.writeListIndices(attr.uses());
- buf.writeU2(attr.provides().size());
- for (ModuleProvideInfo provide : attr.provides()) {
- buf.writeIndex(provide.provides());
- buf.writeListIndices(provide.providesWith());
- }
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code ModuleHashes} attribute */
- public static final AttributeMapper
- MODULE_HASHES = new AbstractAttributeMapper<>(NAME_MODULE_HASHES) {
- @Override
- public ModuleHashesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundModuleHashesAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, ModuleHashesAttribute attr) {
- buf.writeIndex(attr.algorithm());
- List hashes = attr.hashes();
- buf.writeU2(hashes.size());
- for (ModuleHashInfo hash : hashes) {
- buf.writeIndex(hash.moduleName());
- buf.writeU2(hash.hash().length);
- buf.writeBytes(hash.hash());
- }
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code ModuleMainClass} attribute */
- public static final AttributeMapper
- MODULE_MAIN_CLASS = new AbstractAttributeMapper<>(NAME_MODULE_MAIN_CLASS) {
- @Override
- public ModuleMainClassAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundModuleMainClassAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, ModuleMainClassAttribute attr) {
- buf.writeIndex(attr.mainClass());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code ModulePackages} attribute */
- public static final AttributeMapper
- MODULE_PACKAGES = new AbstractAttributeMapper<>(NAME_MODULE_PACKAGES) {
- @Override
- public ModulePackagesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundModulePackagesAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, ModulePackagesAttribute attr) {
- buf.writeListIndices(attr.packages());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code ModuleResolution} attribute */
- public static final AttributeMapper
- MODULE_RESOLUTION = new AbstractAttributeMapper<>(NAME_MODULE_RESOLUTION) {
- @Override
- public ModuleResolutionAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundModuleResolutionAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, ModuleResolutionAttribute attr) {
- buf.writeU2(attr.resolutionFlags());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.STATELESS;
- }
- };
-
- /** Attribute mapper for the {@code ModuleTarget} attribute */
- public static final AttributeMapper
- MODULE_TARGET = new AbstractAttributeMapper<>(NAME_MODULE_TARGET) {
- @Override
- public ModuleTargetAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundModuleTargetAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, ModuleTargetAttribute attr) {
- buf.writeIndex(attr.targetPlatform());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code NestHost} attribute */
- public static final AttributeMapper
- NEST_HOST = new AbstractAttributeMapper<>(NAME_NEST_HOST) {
- @Override
- public NestHostAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundNestHostAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, NestHostAttribute attr) {
- buf.writeIndex(attr.nestHost());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code NestMembers} attribute */
- public static final AttributeMapper
- NEST_MEMBERS = new AbstractAttributeMapper<>(NAME_NEST_MEMBERS) {
- @Override
- public NestMembersAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundNestMembersAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, NestMembersAttribute attr) {
- buf.writeListIndices(attr.nestMembers());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code PermittedSubclasses} attribute */
- public static final AttributeMapper
- PERMITTED_SUBCLASSES = new AbstractAttributeMapper<>(NAME_PERMITTED_SUBCLASSES) {
- @Override
- public PermittedSubclassesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundPermittedSubclassesAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, PermittedSubclassesAttribute attr) {
- buf.writeListIndices(attr.permittedSubclasses());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code Record} attribute */
- public static final AttributeMapper
- RECORD = new AbstractAttributeMapper<>(NAME_RECORD) {
- @Override
- public RecordAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundRecordAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, RecordAttribute attr) {
- List components = attr.components();
- buf.writeU2(components.size());
- for (RecordComponentInfo info : components) {
- buf.writeIndex(info.name());
- buf.writeIndex(info.descriptor());
- buf.writeList(info.attributes());
- }
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code RuntimeInvisibleAnnotations} attribute */
- public static final AttributeMapper
- RUNTIME_INVISIBLE_ANNOTATIONS = new AbstractAttributeMapper<>(NAME_RUNTIME_INVISIBLE_ANNOTATIONS) {
- @Override
- public RuntimeInvisibleAnnotationsAttribute readAttribute(AttributedElement enclosing, ClassReader cf, int pos) {
- return new BoundAttribute.BoundRuntimeInvisibleAnnotationsAttribute(cf, pos);
- }
-
- @Override
- protected void writeBody(BufWriter buf, RuntimeInvisibleAnnotationsAttribute attr) {
- buf.writeList(attr.annotations());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code RuntimeInvisibleParameterAnnotations} attribute */
- public static final AttributeMapper
- RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS = new AbstractAttributeMapper<>(NAME_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS) {
- @Override
- public RuntimeInvisibleParameterAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundRuntimeInvisibleParameterAnnotationsAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, RuntimeInvisibleParameterAnnotationsAttribute attr) {
- List> lists = attr.parameterAnnotations();
- buf.writeU1(lists.size());
- for (List list : lists)
- buf.writeList(list);
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code RuntimeInvisibleTypeAnnotations} attribute */
- public static final AttributeMapper
- RUNTIME_INVISIBLE_TYPE_ANNOTATIONS = new AbstractAttributeMapper<>(NAME_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS) {
- @Override
- public RuntimeInvisibleTypeAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundRuntimeInvisibleTypeAnnotationsAttribute(e, cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, RuntimeInvisibleTypeAnnotationsAttribute attr) {
- buf.writeList(attr.annotations());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.UNSTABLE;
- }
- };
-
- /** Attribute mapper for the {@code RuntimeVisibleAnnotations} attribute */
- public static final AttributeMapper
- RUNTIME_VISIBLE_ANNOTATIONS = new AbstractAttributeMapper<>(NAME_RUNTIME_VISIBLE_ANNOTATIONS) {
- @Override
- public RuntimeVisibleAnnotationsAttribute readAttribute(AttributedElement enclosing, ClassReader cf, int pos) {
- return new BoundAttribute.BoundRuntimeVisibleAnnotationsAttribute(cf, pos);
- }
-
- @Override
- protected void writeBody(BufWriter buf, RuntimeVisibleAnnotationsAttribute attr) {
- buf.writeList(attr.annotations());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code RuntimeVisibleParameterAnnotations} attribute */
- public static final AttributeMapper
- RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS = new AbstractAttributeMapper<>(NAME_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS) {
- @Override
- public RuntimeVisibleParameterAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundRuntimeVisibleParameterAnnotationsAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, RuntimeVisibleParameterAnnotationsAttribute attr) {
- List> lists = attr.parameterAnnotations();
- buf.writeU1(lists.size());
- for (List list : lists)
- buf.writeList(list);
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code RuntimeVisibleTypeAnnotations} attribute */
- public static final AttributeMapper
- RUNTIME_VISIBLE_TYPE_ANNOTATIONS = new AbstractAttributeMapper<>(NAME_RUNTIME_VISIBLE_TYPE_ANNOTATIONS) {
- @Override
- public RuntimeVisibleTypeAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundRuntimeVisibleTypeAnnotationsAttribute(e, cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, RuntimeVisibleTypeAnnotationsAttribute attr) {
- buf.writeList(attr.annotations());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.UNSTABLE;
- }
- };
-
- /** Attribute mapper for the {@code Signature} attribute */
- public static final AttributeMapper
- SIGNATURE = new AbstractAttributeMapper<>(NAME_SIGNATURE) {
- @Override
- public SignatureAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundSignatureAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, SignatureAttribute attr) {
- buf.writeIndex(attr.signature());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code SourceDebugExtension} attribute */
- public static final AttributeMapper
- SOURCE_DEBUG_EXTENSION = new AbstractAttributeMapper<>(NAME_SOURCE_DEBUG_EXTENSION) {
- @Override
- public SourceDebugExtensionAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundSourceDebugExtensionAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, SourceDebugExtensionAttribute attr) {
- buf.writeBytes(attr.contents());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.STATELESS;
- }
- };
-
- /** Attribute mapper for the {@code SourceFile} attribute */
- public static final AttributeMapper
- SOURCE_FILE = new AbstractAttributeMapper<>(NAME_SOURCE_FILE) {
- @Override
- public SourceFileAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundSourceFileAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, SourceFileAttribute attr) {
- buf.writeIndex(attr.sourceFile());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code SourceID} attribute */
- public static final AttributeMapper
- SOURCE_ID = new AbstractAttributeMapper<>(NAME_SOURCE_ID) {
- @Override
- public SourceIDAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundSourceIDAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, SourceIDAttribute attr) {
- buf.writeIndex(attr.sourceId());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.CP_REFS;
- }
- };
-
- /** Attribute mapper for the {@code StackMapTable} attribute */
- public static final AttributeMapper
- STACK_MAP_TABLE = new AbstractAttributeMapper<>(NAME_STACK_MAP_TABLE) {
- @Override
- public StackMapTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundStackMapTableAttribute((CodeImpl)e, cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter b, StackMapTableAttribute attr) {
- StackMapDecoder.writeFrames(b, attr.entries());
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.LABELS;
- }
- };
-
-
- /** Attribute mapper for the {@code Synthetic} attribute */
- public static final AttributeMapper
- SYNTHETIC = new AbstractAttributeMapper<>(NAME_SYNTHETIC, true) {
- @Override
- public SyntheticAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
- return new BoundAttribute.BoundSyntheticAttribute(cf, this, p);
- }
-
- @Override
- protected void writeBody(BufWriter buf, SyntheticAttribute attr) {
- // empty
- }
-
- @Override
- public AttributeMapper.AttributeStability stability() {
- return AttributeStability.STATELESS;
- }
- };
+ /**
+ * {@return Attribute mapper for the {@code AnnotationDefault} attribute}
+ * @since 23
+ */
+ public static AttributeMapper annotationDefault() {
+ return AnnotationDefaultMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code BootstrapMethods} attribute}
+ * @since 23
+ */
+ public static AttributeMapper bootstrapMethods() {
+ return BootstrapMethodsMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code CharacterRangeTable} attribute}
+ * The mapper permits multiple instances in a given location.
+ * @since 23
+ */
+ public static AttributeMapper characterRangeTable() {
+ return CharacterRangeTableMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code Code} attribute}
+ * @since 23
+ */
+ public static AttributeMapper code() {
+ return CodeMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code CompilationID} attribute}
+ * @since 23
+ */
+ public static AttributeMapper compilationId() {
+ return CompilationIDMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code ConstantValue} attribute}
+ * @since 23
+ */
+ public static AttributeMapper constantValue() {
+ return ConstantValueMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code Deprecated} attribute}
+ * The mapper permits multiple instances in a given location.
+ * @since 23
+ */
+ public static AttributeMapper deprecated() {
+ return DeprecatedMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code EnclosingMethod} attribute}
+ * @since 23
+ */
+ public static AttributeMapper enclosingMethod() {
+ return EnclosingMethodMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code Exceptions} attribute}
+ * @since 23
+ */
+ public static AttributeMapper exceptions() {
+ return ExceptionsMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code InnerClasses} attribute}
+ * @since 23
+ */
+ public static AttributeMapper innerClasses() {
+ return InnerClassesMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code LineNumberTable} attribute}
+ * The mapper permits multiple instances in a given location.
+ * @since 23
+ */
+ public static AttributeMapper lineNumberTable() {
+ return LineNumberTableMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code LocalVariableTable} attribute}
+ * The mapper permits multiple instances in a given location.
+ * @since 23
+ */
+ public static AttributeMapper localVariableTable() {
+ return LocalVariableTableMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code LocalVariableTypeTable} attribute}
+ * The mapper permits multiple instances in a given location.
+ * @since 23
+ */
+ public static AttributeMapper localVariableTypeTable() {
+ return LocalVariableTypeTableMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code MethodParameters} attribute}
+ * @since 23
+ */
+ public static AttributeMapper methodParameters() {
+ return MethodParametersMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code Module} attribute}
+ * @since 23
+ */
+ public static AttributeMapper module() {
+ return ModuleMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code ModuleHashes} attribute}
+ * @since 23
+ */
+ public static AttributeMapper moduleHashes() {
+ return ModuleHashesMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code ModuleMainClass} attribute}
+ * @since 23
+ */
+ public static AttributeMapper moduleMainClass() {
+ return ModuleMainClassMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code ModulePackages} attribute}
+ * @since 23
+ */
+ public static AttributeMapper modulePackages() {
+ return ModulePackagesMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code ModuleResolution} attribute}
+ * @since 23
+ */
+ public static AttributeMapper moduleResolution() {
+ return ModuleResolutionMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code ModuleTarget} attribute}
+ * @since 23
+ */
+ public static AttributeMapper moduleTarget() {
+ return ModuleTargetMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code NestHost} attribute}
+ * @since 23
+ */
+ public static AttributeMapper nestHost() {
+ return NestHostMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code NestMembers} attribute}
+ * @since 23
+ */
+ public static AttributeMapper nestMembers() {
+ return NestMembersMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code PermittedSubclasses} attribute}
+ * @since 23
+ */
+ public static AttributeMapper permittedSubclasses() {
+ return PermittedSubclassesMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code Record} attribute}
+ * @since 23
+ */
+ public static AttributeMapper record() {
+ return RecordMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code RuntimeInvisibleAnnotations} attribute}
+ * @since 23
+ */
+ public static AttributeMapper runtimeInvisibleAnnotations() {
+ return RuntimeInvisibleAnnotationsMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code RuntimeInvisibleParameterAnnotations} attribute}
+ * @since 23
+ */
+ public static AttributeMapper runtimeInvisibleParameterAnnotations() {
+ return RuntimeInvisibleParameterAnnotationsMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code RuntimeInvisibleTypeAnnotations} attribute}
+ * @since 23
+ */
+ public static AttributeMapper runtimeInvisibleTypeAnnotations() {
+ return RuntimeInvisibleTypeAnnotationsMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code RuntimeVisibleAnnotations} attribute}
+ * @since 23
+ */
+ public static AttributeMapper runtimeVisibleAnnotations() {
+ return RuntimeVisibleAnnotationsMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code RuntimeVisibleParameterAnnotations} attribute}
+ * @since 23
+ */
+ public static AttributeMapper runtimeVisibleParameterAnnotations() {
+ return RuntimeVisibleParameterAnnotationsMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code RuntimeVisibleTypeAnnotations} attribute}
+ * @since 23
+ */
+ public static AttributeMapper runtimeVisibleTypeAnnotations() {
+ return RuntimeVisibleTypeAnnotationsMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code Signature} attribute}
+ * @since 23
+ */
+ public static AttributeMapper signature() {
+ return SignatureMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code SourceDebugExtension} attribute}
+ * @since 23
+ */
+ public static AttributeMapper sourceDebugExtension() {
+ return SourceDebugExtensionMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code SourceFile} attribute}
+ * @since 23
+ */
+ public static AttributeMapper sourceFile() {
+ return SourceFileMapper.INSTANCE;
+ }
+
+ /**
+ * {@return Attribute mapper for the {@code SourceID} attribute}
+ * @since 23
+ */
+ public static AttributeMapper sourceId() {
+ return SourceIDMapper.INSTANCE;
+ }
/**
- * {@return the attribute mapper for a standard attribute}
- *
- * @param name the name of the attribute to find
+ * {@return Attribute mapper for the {@code StackMapTable} attribute}
+ * @since 23
*/
- public static AttributeMapper> standardAttribute(Utf8Entry name) {
- return _ATTR_MAP.get(name);
+ public static AttributeMapper stackMapTable() {
+ return StackMapTableMapper.INSTANCE;
}
/**
- * All standard attribute mappers.
+ * {@return Attribute mapper for the {@code Synthetic} attribute}
+ * The mapper permits multiple instances in a given location.
+ * @since 23
*/
- public static final Set> PREDEFINED_ATTRIBUTES = Set.of(
- ANNOTATION_DEFAULT,
- BOOTSTRAP_METHODS,
- CHARACTER_RANGE_TABLE,
- CODE,
- COMPILATION_ID,
- CONSTANT_VALUE,
- DEPRECATED,
- ENCLOSING_METHOD,
- EXCEPTIONS,
- INNER_CLASSES,
- LINE_NUMBER_TABLE,
- LOCAL_VARIABLE_TABLE,
- LOCAL_VARIABLE_TYPE_TABLE,
- METHOD_PARAMETERS,
- MODULE,
- MODULE_HASHES,
- MODULE_MAIN_CLASS,
- MODULE_PACKAGES,
- MODULE_RESOLUTION,
- MODULE_TARGET,
- NEST_HOST,
- NEST_MEMBERS,
- PERMITTED_SUBCLASSES,
- RECORD,
- RUNTIME_INVISIBLE_ANNOTATIONS,
- RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS,
- RUNTIME_INVISIBLE_TYPE_ANNOTATIONS,
- RUNTIME_VISIBLE_ANNOTATIONS,
- RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS,
- RUNTIME_VISIBLE_TYPE_ANNOTATIONS,
- SIGNATURE,
- SOURCE_DEBUG_EXTENSION,
- SOURCE_FILE,
- SOURCE_ID,
- STACK_MAP_TABLE,
- SYNTHETIC);
-
- private static final Map> _ATTR_MAP;
- //no lambdas here as this is on critical JDK boostrap path
- static {
- var map = new HashMap>(64);
- for (var am : PREDEFINED_ATTRIBUTES) {
- map.put(AbstractPoolEntry.rawUtf8EntryFromStandardAttributeName(am.name()), am);
- }
- _ATTR_MAP = Collections.unmodifiableMap(map);
+ public static AttributeMapper synthetic() {
+ return SyntheticMapper.INSTANCE;
}
}
diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractAttributeMapper.java b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractAttributeMapper.java
index 861bcd3b6012d..9bb3f275ba1a2 100644
--- a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractAttributeMapper.java
+++ b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractAttributeMapper.java
@@ -24,35 +24,45 @@
*/
package jdk.internal.classfile.impl;
+import java.lang.classfile.Annotation;
import java.lang.classfile.Attribute;
import java.lang.classfile.AttributeMapper;
+import java.lang.classfile.AttributedElement;
import java.lang.classfile.BufWriter;
+import java.lang.classfile.ClassReader;
+import java.lang.classfile.attribute.*;
+import java.util.List;
-public abstract class AbstractAttributeMapper>
+import static java.lang.classfile.Attributes.*;
+
+public sealed abstract class AbstractAttributeMapper>
implements AttributeMapper {
private final String name;
+ private final AttributeMapper.AttributeStability stability;
private final boolean allowMultiple;
protected abstract void writeBody(BufWriter buf, T attr);
- public AbstractAttributeMapper(String name) {
- this(name, false);
+ public AbstractAttributeMapper(String name, AttributeMapper.AttributeStability stability) {
+ this(name, stability, false);
}
public AbstractAttributeMapper(String name,
+ AttributeMapper.AttributeStability stability,
boolean allowMultiple) {
this.name = name;
+ this.stability = stability;
this.allowMultiple = allowMultiple;
}
@Override
- public String name() {
+ public final String name() {
return name;
}
@Override
- public void writeAttribute(BufWriter buf, T attr) {
+ public final void writeAttribute(BufWriter buf, T attr) {
buf.writeIndex(buf.constantPool().utf8Entry(name));
buf.writeInt(0);
int start = buf.size();
@@ -61,6 +71,11 @@ public void writeAttribute(BufWriter buf, T attr) {
buf.patchInt(start - 4, 4, written);
}
+ @Override
+ public AttributeMapper.AttributeStability stability() {
+ return stability;
+ }
+
@Override
public boolean allowMultiple() {
return allowMultiple;
@@ -71,4 +86,739 @@ public String toString() {
return String.format("AttributeMapper[name=%s, allowMultiple=%b, stability=%s]",
name, allowMultiple, stability());
}
+
+ public static final class AnnotationDefaultMapper extends AbstractAttributeMapper {
+ public static final AnnotationDefaultMapper INSTANCE = new AnnotationDefaultMapper();
+
+ private AnnotationDefaultMapper() {
+ super(NAME_ANNOTATION_DEFAULT, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public AnnotationDefaultAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundAnnotationDefaultAttr(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, AnnotationDefaultAttribute attr) {
+ attr.defaultValue().writeTo(buf);
+ }
+ }
+
+ public static final class BootstrapMethodsMapper extends AbstractAttributeMapper {
+ public static final BootstrapMethodsMapper INSTANCE = new BootstrapMethodsMapper();
+
+ private BootstrapMethodsMapper() {
+ super(NAME_BOOTSTRAP_METHODS, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public BootstrapMethodsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundBootstrapMethodsAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, BootstrapMethodsAttribute attr) {
+ buf.writeList(attr.bootstrapMethods());
+ }
+ }
+
+ public static final class CharacterRangeTableMapper extends AbstractAttributeMapper {
+ public static final CharacterRangeTableMapper INSTANCE = new CharacterRangeTableMapper();
+
+ private CharacterRangeTableMapper() {
+ super(NAME_CHARACTER_RANGE_TABLE, AttributeStability.LABELS, true);
+ }
+
+ @Override
+ public CharacterRangeTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundCharacterRangeTableAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, CharacterRangeTableAttribute attr) {
+ List ranges = attr.characterRangeTable();
+ buf.writeU2(ranges.size());
+ for (CharacterRangeInfo info : ranges) {
+ buf.writeU2(info.startPc());
+ buf.writeU2(info.endPc());
+ buf.writeInt(info.characterRangeStart());
+ buf.writeInt(info.characterRangeEnd());
+ buf.writeU2(info.flags());
+ }
+ }
+ }
+
+ public static final class CodeMapper extends AbstractAttributeMapper {
+ public static final CodeMapper INSTANCE = new CodeMapper();
+
+ private CodeMapper() {
+ super(NAME_CODE, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public CodeAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new CodeImpl(e, cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, CodeAttribute attr) {
+ throw new UnsupportedOperationException("Code attribute does not support direct write");
+ }
+ }
+
+ public static final class CompilationIDMapper extends AbstractAttributeMapper {
+ public static final CompilationIDMapper INSTANCE = new CompilationIDMapper();
+
+ private CompilationIDMapper() {
+ super(NAME_COMPILATION_ID, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public CompilationIDAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundCompilationIDAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, CompilationIDAttribute attr) {
+ buf.writeIndex(attr.compilationId());
+ }
+ }
+
+ public static final class ConstantValueMapper extends AbstractAttributeMapper {
+ public static final ConstantValueMapper INSTANCE = new ConstantValueMapper();
+
+ private ConstantValueMapper() {
+ super(NAME_CONSTANT_VALUE, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public ConstantValueAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundConstantValueAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, ConstantValueAttribute attr) {
+ buf.writeIndex(attr.constant());
+ }
+ }
+
+ public static final class DeprecatedMapper extends AbstractAttributeMapper {
+ public static final DeprecatedMapper INSTANCE = new DeprecatedMapper();
+
+ private DeprecatedMapper() {
+ super(NAME_DEPRECATED, AttributeStability.STATELESS, true);
+ }
+
+ @Override
+ public DeprecatedAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundDeprecatedAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, DeprecatedAttribute attr) {
+ // empty
+ }
+ }
+
+ public static final class EnclosingMethodMapper extends AbstractAttributeMapper {
+ public static final EnclosingMethodMapper INSTANCE = new EnclosingMethodMapper();
+
+ private EnclosingMethodMapper() {
+ super(NAME_ENCLOSING_METHOD, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public EnclosingMethodAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundEnclosingMethodAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, EnclosingMethodAttribute attr) {
+ buf.writeIndex(attr.enclosingClass());
+ buf.writeIndexOrZero(attr.enclosingMethod().orElse(null));
+ }
+ }
+
+ public static final class ExceptionsMapper extends AbstractAttributeMapper {
+ public static final ExceptionsMapper INSTANCE = new ExceptionsMapper();
+
+ private ExceptionsMapper() {
+ super(NAME_EXCEPTIONS, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public ExceptionsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundExceptionsAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, ExceptionsAttribute attr) {
+ buf.writeListIndices(attr.exceptions());
+ }
+ }
+
+ public static final class InnerClassesMapper extends AbstractAttributeMapper {
+ public static final InnerClassesMapper INSTANCE = new InnerClassesMapper();
+
+ private InnerClassesMapper() {
+ super(NAME_INNER_CLASSES, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public InnerClassesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundInnerClassesAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, InnerClassesAttribute attr) {
+ List classes = attr.classes();
+ buf.writeU2(classes.size());
+ for (InnerClassInfo ic : classes) {
+ buf.writeIndex(ic.innerClass());
+ buf.writeIndexOrZero(ic.outerClass().orElse(null));
+ buf.writeIndexOrZero(ic.innerName().orElse(null));
+ buf.writeU2(ic.flagsMask());
+ }
+ }
+ }
+
+ public static final class LineNumberTableMapper extends AbstractAttributeMapper {
+ public static final LineNumberTableMapper INSTANCE = new LineNumberTableMapper();
+
+ private LineNumberTableMapper() {
+ super(NAME_LINE_NUMBER_TABLE, AttributeStability.LABELS, true);
+ }
+
+ @Override
+ public LineNumberTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundLineNumberTableAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, LineNumberTableAttribute attr) {
+ List lines = attr.lineNumbers();
+ buf.writeU2(lines.size());
+ for (LineNumberInfo line : lines) {
+ buf.writeU2(line.startPc());
+ buf.writeU2(line.lineNumber());
+ }
+ }
+ }
+
+ public static final class LocalVariableTableMapper extends AbstractAttributeMapper {
+ public static final LocalVariableTableMapper INSTANCE = new LocalVariableTableMapper();
+
+ private LocalVariableTableMapper() {
+ super(NAME_LOCAL_VARIABLE_TABLE, AttributeStability.LABELS, true);
+ }
+
+ @Override
+ public LocalVariableTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundLocalVariableTableAttribute(e, cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, LocalVariableTableAttribute attr) {
+ List infos = attr.localVariables();
+ buf.writeU2(infos.size());
+ for (LocalVariableInfo info : infos) {
+ buf.writeU2(info.startPc());
+ buf.writeU2(info.length());
+ buf.writeIndex(info.name());
+ buf.writeIndex(info.type());
+ buf.writeU2(info.slot());
+ }
+ }
+ }
+
+ public static final class LocalVariableTypeTableMapper extends AbstractAttributeMapper {
+ public static final LocalVariableTypeTableMapper INSTANCE = new LocalVariableTypeTableMapper();
+
+ private LocalVariableTypeTableMapper() {
+ super(NAME_LOCAL_VARIABLE_TYPE_TABLE, AttributeStability.LABELS, true);
+ }
+
+ @Override
+ public LocalVariableTypeTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundLocalVariableTypeTableAttribute(e, cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, LocalVariableTypeTableAttribute attr) {
+ List infos = attr.localVariableTypes();
+ buf.writeU2(infos.size());
+ for (LocalVariableTypeInfo info : infos) {
+ buf.writeU2(info.startPc());
+ buf.writeU2(info.length());
+ buf.writeIndex(info.name());
+ buf.writeIndex(info.signature());
+ buf.writeU2(info.slot());
+ }
+ }
+ }
+
+ public static final class MethodParametersMapper extends AbstractAttributeMapper {
+ public static final MethodParametersMapper INSTANCE = new MethodParametersMapper();
+
+ private MethodParametersMapper() {
+ super(NAME_METHOD_PARAMETERS, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public MethodParametersAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundMethodParametersAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, MethodParametersAttribute attr) {
+ List parameters = attr.parameters();
+ buf.writeU1(parameters.size());
+ for (MethodParameterInfo info : parameters) {
+ buf.writeIndexOrZero(info.name().orElse(null));
+ buf.writeU2(info.flagsMask());
+ }
+ }
+ }
+
+ public static final class ModuleMapper extends AbstractAttributeMapper {
+ public static final ModuleMapper INSTANCE = new ModuleMapper();
+
+ private ModuleMapper() {
+ super(NAME_MODULE, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public ModuleAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundModuleAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, ModuleAttribute attr) {
+ buf.writeIndex(attr.moduleName());
+ buf.writeU2(attr.moduleFlagsMask());
+ buf.writeIndexOrZero(attr.moduleVersion().orElse(null));
+ buf.writeU2(attr.requires().size());
+ for (ModuleRequireInfo require : attr.requires()) {
+ buf.writeIndex(require.requires());
+ buf.writeU2(require.requiresFlagsMask());
+ buf.writeIndexOrZero(require.requiresVersion().orElse(null));
+ }
+ buf.writeU2(attr.exports().size());
+ for (ModuleExportInfo export : attr.exports()) {
+ buf.writeIndex(export.exportedPackage());
+ buf.writeU2(export.exportsFlagsMask());
+ buf.writeListIndices(export.exportsTo());
+ }
+ buf.writeU2(attr.opens().size());
+ for (ModuleOpenInfo open : attr.opens()) {
+ buf.writeIndex(open.openedPackage());
+ buf.writeU2(open.opensFlagsMask());
+ buf.writeListIndices(open.opensTo());
+ }
+ buf.writeListIndices(attr.uses());
+ buf.writeU2(attr.provides().size());
+ for (ModuleProvideInfo provide : attr.provides()) {
+ buf.writeIndex(provide.provides());
+ buf.writeListIndices(provide.providesWith());
+ }
+ }
+ }
+
+ public static final class ModuleHashesMapper extends AbstractAttributeMapper {
+ public static final ModuleHashesMapper INSTANCE = new ModuleHashesMapper();
+
+ private ModuleHashesMapper() {
+ super(NAME_MODULE_HASHES, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public ModuleHashesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundModuleHashesAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, ModuleHashesAttribute attr) {
+ buf.writeIndex(attr.algorithm());
+ List hashes = attr.hashes();
+ buf.writeU2(hashes.size());
+ for (ModuleHashInfo hash : hashes) {
+ buf.writeIndex(hash.moduleName());
+ buf.writeU2(hash.hash().length);
+ buf.writeBytes(hash.hash());
+ }
+ }
+ }
+
+ public static final class ModuleMainClassMapper extends AbstractAttributeMapper {
+ public static final ModuleMainClassMapper INSTANCE = new ModuleMainClassMapper();
+
+ private ModuleMainClassMapper() {
+ super(NAME_MODULE_MAIN_CLASS, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public ModuleMainClassAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundModuleMainClassAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, ModuleMainClassAttribute attr) {
+ buf.writeIndex(attr.mainClass());
+ }
+ }
+
+ public static final class ModulePackagesMapper extends AbstractAttributeMapper {
+ public static final ModulePackagesMapper INSTANCE = new ModulePackagesMapper();
+
+ private ModulePackagesMapper() {
+ super(NAME_MODULE_PACKAGES, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public ModulePackagesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundModulePackagesAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, ModulePackagesAttribute attr) {
+ buf.writeListIndices(attr.packages());
+ }
+ }
+
+ public static final class ModuleResolutionMapper extends AbstractAttributeMapper {
+ public static final ModuleResolutionMapper INSTANCE = new ModuleResolutionMapper();
+
+ private ModuleResolutionMapper() {
+ super(NAME_MODULE_RESOLUTION, AttributeStability.STATELESS);
+ }
+
+ @Override
+ public ModuleResolutionAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundModuleResolutionAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, ModuleResolutionAttribute attr) {
+ buf.writeU2(attr.resolutionFlags());
+ }
+ }
+
+ public static final class ModuleTargetMapper extends AbstractAttributeMapper {
+ public static final ModuleTargetMapper INSTANCE = new ModuleTargetMapper();
+
+ private ModuleTargetMapper() {
+ super(NAME_MODULE_TARGET, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public ModuleTargetAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundModuleTargetAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, ModuleTargetAttribute attr) {
+ buf.writeIndex(attr.targetPlatform());
+ }
+ }
+
+ public static final class NestHostMapper extends AbstractAttributeMapper {
+ public static final NestHostMapper INSTANCE = new NestHostMapper();
+
+ private NestHostMapper() {
+ super(NAME_NEST_HOST, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public NestHostAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundNestHostAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, NestHostAttribute attr) {
+ buf.writeIndex(attr.nestHost());
+ }
+ }
+
+ public static final class NestMembersMapper extends AbstractAttributeMapper {
+ public static final NestMembersMapper INSTANCE = new NestMembersMapper();
+
+ private NestMembersMapper() {
+ super(NAME_NEST_MEMBERS, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public NestMembersAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundNestMembersAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, NestMembersAttribute attr) {
+ buf.writeListIndices(attr.nestMembers());
+ }
+ }
+
+ public static final class PermittedSubclassesMapper extends AbstractAttributeMapper {
+ public static final PermittedSubclassesMapper INSTANCE = new PermittedSubclassesMapper();
+
+ private PermittedSubclassesMapper() {
+ super(NAME_PERMITTED_SUBCLASSES, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public PermittedSubclassesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundPermittedSubclassesAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, PermittedSubclassesAttribute attr) {
+ buf.writeListIndices(attr.permittedSubclasses());
+ }
+ }
+
+ public static final class RecordMapper extends AbstractAttributeMapper {
+ public static final RecordMapper INSTANCE = new RecordMapper();
+
+ private RecordMapper() {
+ super(NAME_RECORD, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public RecordAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundRecordAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, RecordAttribute attr) {
+ List components = attr.components();
+ buf.writeU2(components.size());
+ for (RecordComponentInfo info : components) {
+ buf.writeIndex(info.name());
+ buf.writeIndex(info.descriptor());
+ buf.writeList(info.attributes());
+ }
+ }
+ }
+
+ public static final class RuntimeInvisibleAnnotationsMapper extends AbstractAttributeMapper {
+ public static final RuntimeInvisibleAnnotationsMapper INSTANCE = new RuntimeInvisibleAnnotationsMapper();
+
+ private RuntimeInvisibleAnnotationsMapper() {
+ super(NAME_RUNTIME_INVISIBLE_ANNOTATIONS, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public RuntimeInvisibleAnnotationsAttribute readAttribute(AttributedElement enclosing, ClassReader cf, int pos) {
+ return new BoundAttribute.BoundRuntimeInvisibleAnnotationsAttribute(cf, pos);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, RuntimeInvisibleAnnotationsAttribute attr) {
+ buf.writeList(attr.annotations());
+ }
+ }
+
+ public static final class RuntimeInvisibleParameterAnnotationsMapper extends AbstractAttributeMapper {
+ public static final RuntimeInvisibleParameterAnnotationsMapper INSTANCE = new RuntimeInvisibleParameterAnnotationsMapper();
+
+ private RuntimeInvisibleParameterAnnotationsMapper() {
+ super(NAME_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public RuntimeInvisibleParameterAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundRuntimeInvisibleParameterAnnotationsAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, RuntimeInvisibleParameterAnnotationsAttribute attr) {
+ List> lists = attr.parameterAnnotations();
+ buf.writeU1(lists.size());
+ for (List list : lists)
+ buf.writeList(list);
+ }
+ }
+
+ public static final class RuntimeInvisibleTypeAnnotationsMapper extends AbstractAttributeMapper {
+ public static final RuntimeInvisibleTypeAnnotationsMapper INSTANCE = new RuntimeInvisibleTypeAnnotationsMapper();
+
+ private RuntimeInvisibleTypeAnnotationsMapper() {
+ super(NAME_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, AttributeStability.UNSTABLE);
+ }
+
+ @Override
+ public RuntimeInvisibleTypeAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundRuntimeInvisibleTypeAnnotationsAttribute(e, cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, RuntimeInvisibleTypeAnnotationsAttribute attr) {
+ buf.writeList(attr.annotations());
+ }
+ }
+
+ public static final class RuntimeVisibleAnnotationsMapper extends AbstractAttributeMapper {
+ public static final RuntimeVisibleAnnotationsMapper INSTANCE = new RuntimeVisibleAnnotationsMapper();
+
+ private RuntimeVisibleAnnotationsMapper() {
+ super(NAME_RUNTIME_VISIBLE_ANNOTATIONS, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public RuntimeVisibleAnnotationsAttribute readAttribute(AttributedElement enclosing, ClassReader cf, int pos) {
+ return new BoundAttribute.BoundRuntimeVisibleAnnotationsAttribute(cf, pos);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, RuntimeVisibleAnnotationsAttribute attr) {
+ buf.writeList(attr.annotations());
+ }
+ }
+
+ public static final class RuntimeVisibleParameterAnnotationsMapper extends AbstractAttributeMapper {
+ public static final RuntimeVisibleParameterAnnotationsMapper INSTANCE = new RuntimeVisibleParameterAnnotationsMapper();
+
+ private RuntimeVisibleParameterAnnotationsMapper() {
+ super(NAME_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public RuntimeVisibleParameterAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundRuntimeVisibleParameterAnnotationsAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, RuntimeVisibleParameterAnnotationsAttribute attr) {
+ List> lists = attr.parameterAnnotations();
+ buf.writeU1(lists.size());
+ for (List list : lists)
+ buf.writeList(list);
+ }
+ }
+
+ public static final class RuntimeVisibleTypeAnnotationsMapper extends AbstractAttributeMapper {
+ public static final RuntimeVisibleTypeAnnotationsMapper INSTANCE = new RuntimeVisibleTypeAnnotationsMapper();
+
+ private RuntimeVisibleTypeAnnotationsMapper() {
+ super(NAME_RUNTIME_VISIBLE_TYPE_ANNOTATIONS, AttributeStability.UNSTABLE);
+ }
+
+ @Override
+ public RuntimeVisibleTypeAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundRuntimeVisibleTypeAnnotationsAttribute(e, cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, RuntimeVisibleTypeAnnotationsAttribute attr) {
+ buf.writeList(attr.annotations());
+ }
+ }
+
+ public static final class SignatureMapper extends AbstractAttributeMapper {
+ public static final SignatureMapper INSTANCE = new SignatureMapper();
+
+ private SignatureMapper() {
+ super(NAME_SIGNATURE, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public SignatureAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundSignatureAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, SignatureAttribute attr) {
+ buf.writeIndex(attr.signature());
+ }
+ }
+
+ public static final class SourceDebugExtensionMapper extends AbstractAttributeMapper {
+ public static final SourceDebugExtensionMapper INSTANCE = new SourceDebugExtensionMapper();
+
+ private SourceDebugExtensionMapper() {
+ super(NAME_SOURCE_DEBUG_EXTENSION, AttributeStability.STATELESS);
+ }
+
+ @Override
+ public SourceDebugExtensionAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundSourceDebugExtensionAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, SourceDebugExtensionAttribute attr) {
+ buf.writeBytes(attr.contents());
+ }
+ }
+
+ public static final class SourceFileMapper extends AbstractAttributeMapper {
+ public static final SourceFileMapper INSTANCE = new SourceFileMapper();
+
+ private SourceFileMapper() {
+ super(NAME_SOURCE_FILE, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public SourceFileAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundSourceFileAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, SourceFileAttribute attr) {
+ buf.writeIndex(attr.sourceFile());
+ }
+ }
+
+ public static final class SourceIDMapper extends AbstractAttributeMapper {
+ public static final SourceIDMapper INSTANCE = new SourceIDMapper();
+
+ private SourceIDMapper() {
+ super(NAME_SOURCE_ID, AttributeStability.CP_REFS);
+ }
+
+ @Override
+ public SourceIDAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundSourceIDAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, SourceIDAttribute attr) {
+ buf.writeIndex(attr.sourceId());
+ }
+ }
+
+ public static final class StackMapTableMapper extends AbstractAttributeMapper {
+ public static final StackMapTableMapper INSTANCE = new StackMapTableMapper();
+
+ private StackMapTableMapper() {
+ super(NAME_STACK_MAP_TABLE, AttributeStability.LABELS);
+ }
+
+ @Override
+ public StackMapTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundStackMapTableAttribute((CodeImpl)e, cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter b, StackMapTableAttribute attr) {
+ StackMapDecoder.writeFrames(b, attr.entries());
+ }
+ }
+
+ public static final class SyntheticMapper extends AbstractAttributeMapper {
+ public static final SyntheticMapper INSTANCE = new SyntheticMapper();
+
+ private SyntheticMapper() {
+ super(NAME_SYNTHETIC, AttributeStability.STATELESS, true);
+ }
+
+ @Override
+ public SyntheticAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
+ return new BoundAttribute.BoundSyntheticAttribute(cf, this, p);
+ }
+
+ @Override
+ protected void writeBody(BufWriter buf, SyntheticAttribute attr) {
+ // empty
+ }
+ }
}
diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java b/src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java
index d572e09040eba..69e7f34731f81 100644
--- a/src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java
+++ b/src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java
@@ -43,6 +43,8 @@
import java.lang.classfile.constantpool.Utf8Entry;
import jdk.internal.access.SharedSecrets;
+import static java.lang.classfile.Attributes.*;
+
public abstract sealed class BoundAttribute>
extends AbstractElement
implements Attribute {
@@ -140,7 +142,7 @@ public static List> readAttributes(AttributedElement enclosing, Cla
throw new IllegalArgumentException("attribute " + name.stringValue() + " too big to handle");
}
- var mapper = Attributes.standardAttribute(name);
+ var mapper = standardAttribute(name);
if (mapper == null) {
mapper = customAttributes.apply(name);
}
@@ -889,7 +891,7 @@ public static final class BoundRuntimeInvisibleAnnotationsAttribute
public BoundRuntimeInvisibleAnnotationsAttribute(ClassReader cf,
int payloadStart) {
- super(cf, Attributes.RUNTIME_INVISIBLE_ANNOTATIONS, payloadStart);
+ super(cf, Attributes.runtimeInvisibleAnnotations(), payloadStart);
}
@Override
@@ -907,7 +909,7 @@ public static final class BoundRuntimeVisibleAnnotationsAttribute
public BoundRuntimeVisibleAnnotationsAttribute(ClassReader cf,
int payloadStart) {
- super(cf, Attributes.RUNTIME_VISIBLE_ANNOTATIONS, payloadStart);
+ super(cf, Attributes.runtimeVisibleAnnotations(), payloadStart);
}
@Override
@@ -983,4 +985,88 @@ public byte[] codeArray() {
return classReader.readBytes(payloadStart + 8, codeLength());
}
}
+
+ /**
+ * {@return the attribute mapper for a standard attribute}
+ *
+ * @param name the name of the attribute to find
+ */
+ public static AttributeMapper> standardAttribute(Utf8Entry name) {
+ // critical bootstrap path, so no lambdas nor method handles here
+ return switch (name.hashCode()) {
+ case 0x78147009 ->
+ name.equalsString(NAME_ANNOTATION_DEFAULT) ? annotationDefault() : null;
+ case 0x665e3a3a ->
+ name.equalsString(NAME_BOOTSTRAP_METHODS) ? bootstrapMethods() : null;
+ case 0xcb7e162 ->
+ name.equalsString(NAME_CHARACTER_RANGE_TABLE) ? characterRangeTable() : null;
+ case 0x21e41e7e ->
+ name.equalsString(NAME_CODE) ? code() : null;
+ case 0x5a306b41 ->
+ name.equalsString(NAME_COMPILATION_ID) ? compilationId() : null;
+ case 0x3e191c7c ->
+ name.equalsString(NAME_CONSTANT_VALUE) ? constantValue() : null;
+ case 0x5e88ed0c ->
+ name.equalsString(NAME_DEPRECATED) ? deprecated() : null;
+ case 0x7284695e ->
+ name.equalsString(NAME_ENCLOSING_METHOD) ? enclosingMethod() : null;
+ case 0x21df25db ->
+ name.equalsString(NAME_EXCEPTIONS) ? exceptions() : null;
+ case 0x11392da9 ->
+ name.equalsString(NAME_INNER_CLASSES) ? innerClasses() : null;
+ case 0x167536fc ->
+ name.equalsString(NAME_LINE_NUMBER_TABLE) ? lineNumberTable() : null;
+ case 0x46939abc ->
+ name.equalsString(NAME_LOCAL_VARIABLE_TABLE) ? localVariableTable() : null;
+ case 0x63ee67f4 ->
+ name.equalsString(NAME_LOCAL_VARIABLE_TYPE_TABLE) ? localVariableTypeTable() : null;
+ case 0x2b597e15 ->
+ name.equalsString(NAME_METHOD_PARAMETERS) ? methodParameters() : null;
+ case 0x19f20ade ->
+ name.equalsString(NAME_MODULE) ? module() : null;
+ case 0x47f6395e ->
+ name.equalsString(NAME_MODULE_HASHES) ? moduleHashes() : null;
+ case 0x54db809 ->
+ name.equalsString(NAME_MODULE_MAIN_CLASS) ? moduleMainClass() : null;
+ case 0x1abd1c2c ->
+ name.equalsString(NAME_MODULE_PACKAGES) ? modulePackages() : null;
+ case 0x6ba46dd ->
+ name.equalsString(NAME_MODULE_RESOLUTION) ? moduleResolution() : null;
+ case 0x46f7d91d ->
+ name.equalsString(NAME_MODULE_TARGET) ? moduleTarget() : null;
+ case 0x5137f53 ->
+ name.equalsString(NAME_NEST_HOST) ? nestHost() : null;
+ case 0x4a8fa3b6 ->
+ name.equalsString(NAME_NEST_MEMBERS) ? nestMembers() : null;
+ case 0x55c73cb6 ->
+ name.equalsString(NAME_PERMITTED_SUBCLASSES) ? permittedSubclasses() : null;
+ case 0x3fe76d4e ->
+ name.equalsString(NAME_RECORD) ? record() : null;
+ case 0x180d6925 ->
+ name.equalsString(NAME_RUNTIME_INVISIBLE_ANNOTATIONS) ? runtimeInvisibleAnnotations() : null;
+ case 0x7be22752 ->
+ name.equalsString(NAME_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS) ? runtimeInvisibleParameterAnnotations() : null;
+ case 0x5299824 ->
+ name.equalsString(NAME_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS) ? runtimeInvisibleTypeAnnotations() : null;
+ case 0x3534786e ->
+ name.equalsString(NAME_RUNTIME_VISIBLE_ANNOTATIONS) ? runtimeVisibleAnnotations() : null;
+ case 0xb4b4ac6 ->
+ name.equalsString(NAME_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS) ? runtimeVisibleParameterAnnotations() : null;
+ case 0x6926482 ->
+ name.equalsString(NAME_RUNTIME_VISIBLE_TYPE_ANNOTATIONS) ? runtimeVisibleTypeAnnotations() : null;
+ case 0x16a42b7c ->
+ name.equalsString(NAME_SIGNATURE) ? signature() : null;
+ case 0x400ab245 ->
+ name.equalsString(NAME_SOURCE_DEBUG_EXTENSION) ? sourceDebugExtension() : null;
+ case 0x2af490d4 ->
+ name.equalsString(NAME_SOURCE_FILE) ? sourceFile() : null;
+ case 0x303e0c58 ->
+ name.equalsString(NAME_SOURCE_ID) ? sourceId() : null;
+ case 0x19c7d0cd ->
+ name.equalsString(NAME_STACK_MAP_TABLE) ? stackMapTable() : null;
+ case 0x3dc79b7a ->
+ name.equalsString(NAME_SYNTHETIC) ? synthetic() : null;
+ default -> null;
+ };
+ }
}
diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/ClassImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/ClassImpl.java
index 8604ec5e59711..65e9a26926547 100644
--- a/src/java.base/share/classes/jdk/internal/classfile/impl/ClassImpl.java
+++ b/src/java.base/share/classes/jdk/internal/classfile/impl/ClassImpl.java
@@ -24,32 +24,36 @@
*/
package jdk.internal.classfile.impl;
-import java.util.Collection;
import java.util.List;
import java.util.Optional;
-import java.util.Set;
import java.util.function.Consumer;
-import java.util.stream.Collectors;
-
-import java.lang.classfile.ClassBuilder;
import java.lang.classfile.constantpool.ClassEntry;
import java.lang.reflect.AccessFlag;
import java.lang.classfile.AccessFlags;
import java.lang.classfile.Attribute;
-import java.lang.classfile.AttributeMapper;
import java.lang.classfile.Attributes;
import java.lang.classfile.ClassElement;
import java.lang.classfile.ClassModel;
import java.lang.classfile.ClassReader;
-import java.lang.classfile.ClassTransform;
import java.lang.classfile.ClassFile;
import java.lang.classfile.ClassFileVersion;
+import java.lang.classfile.CustomAttribute;
import java.lang.classfile.constantpool.ConstantPool;
-import java.lang.classfile.constantpool.ConstantPoolBuilder;
import java.lang.classfile.FieldModel;
import java.lang.classfile.Interfaces;
import java.lang.classfile.MethodModel;
import java.lang.classfile.Superclass;
+import java.lang.classfile.attribute.InnerClassesAttribute;
+import java.lang.classfile.attribute.ModuleAttribute;
+import java.lang.classfile.attribute.ModuleHashesAttribute;
+import java.lang.classfile.attribute.ModuleMainClassAttribute;
+import java.lang.classfile.attribute.ModulePackagesAttribute;
+import java.lang.classfile.attribute.ModuleResolutionAttribute;
+import java.lang.classfile.attribute.ModuleTargetAttribute;
+import java.lang.classfile.attribute.RuntimeInvisibleAnnotationsAttribute;
+import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
+import java.lang.classfile.attribute.SourceDebugExtensionAttribute;
+import java.lang.classfile.attribute.SourceFileAttribute;
import jdk.internal.access.SharedSecrets;
public final class ClassImpl
@@ -202,28 +206,21 @@ public String toString() {
}
private boolean verifyModuleAttributes() {
- if (findAttribute(Attributes.MODULE).isEmpty())
+ if (findAttribute(Attributes.module()).isEmpty())
return false;
- Set> found = attributes().stream()
- .map(Attribute::attributeMapper)
- .collect(Collectors.toSet());
-
- found.removeAll(allowedModuleAttributes);
- found.retainAll(Attributes.PREDEFINED_ATTRIBUTES);
- return found.isEmpty();
- }
-
- private static final Set> allowedModuleAttributes
- = Set.of(Attributes.MODULE,
- Attributes.MODULE_HASHES,
- Attributes.MODULE_MAIN_CLASS,
- Attributes.MODULE_PACKAGES,
- Attributes.MODULE_RESOLUTION,
- Attributes.MODULE_TARGET,
- Attributes.INNER_CLASSES,
- Attributes.SOURCE_FILE,
- Attributes.SOURCE_DEBUG_EXTENSION,
- Attributes.RUNTIME_VISIBLE_ANNOTATIONS,
- Attributes.RUNTIME_INVISIBLE_ANNOTATIONS);
+ return attributes().stream().allMatch(a ->
+ a instanceof ModuleAttribute
+ || a instanceof ModulePackagesAttribute
+ || a instanceof ModuleHashesAttribute
+ || a instanceof ModuleMainClassAttribute
+ || a instanceof ModuleResolutionAttribute
+ || a instanceof ModuleTargetAttribute
+ || a instanceof InnerClassesAttribute
+ || a instanceof SourceFileAttribute
+ || a instanceof SourceDebugExtensionAttribute
+ || a instanceof RuntimeVisibleAnnotationsAttribute
+ || a instanceof RuntimeInvisibleAnnotationsAttribute
+ || a instanceof CustomAttribute);
+ }
}
diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/ClassReaderImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/ClassReaderImpl.java
index 4878ad56ae8b8..d7c1f7b28fd33 100644
--- a/src/java.base/share/classes/jdk/internal/classfile/impl/ClassReaderImpl.java
+++ b/src/java.base/share/classes/jdk/internal/classfile/impl/ClassReaderImpl.java
@@ -290,7 +290,7 @@ BootstrapMethodsAttribute bootstrapMethodsAttribute() {
if (bootstrapMethodsAttribute == null) {
bootstrapMethodsAttribute
- = containedClass.findAttribute(Attributes.BOOTSTRAP_METHODS)
+ = containedClass.findAttribute(Attributes.bootstrapMethods())
.orElse(new UnboundAttribute.EmptyBootstrapAttribute());
}
@@ -324,7 +324,7 @@ ClassModel getContainedClass() {
boolean writeBootstrapMethods(BufWriter buf) {
Optional a
- = containedClass.findAttribute(Attributes.BOOTSTRAP_METHODS);
+ = containedClass.findAttribute(Attributes.bootstrapMethods());
if (a.isEmpty())
return false;
a.get().writeTo(buf);
diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/CodeImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/CodeImpl.java
index 4eba39989f62c..ec6ba32801a2d 100644
--- a/src/java.base/share/classes/jdk/internal/classfile/impl/CodeImpl.java
+++ b/src/java.base/share/classes/jdk/internal/classfile/impl/CodeImpl.java
@@ -230,7 +230,7 @@ private void inflateLabel(int bci) {
private void inflateLineNumbers() {
for (Attribute> a : attributes()) {
- if (a.attributeMapper() == Attributes.LINE_NUMBER_TABLE) {
+ if (a.attributeMapper() == Attributes.lineNumberTable()) {
BoundLineNumberTableAttribute attr = (BoundLineNumberTableAttribute) a;
if (lineNumbers == null)
lineNumbers = new int[codeLength + 1];
@@ -252,7 +252,7 @@ private void inflateLineNumbers() {
}
private void inflateJumpTargets() {
- Optional a = findAttribute(Attributes.STACK_MAP_TABLE);
+ Optional a = findAttribute(Attributes.stackMapTable());
if (a.isEmpty()) {
if (classReader.readU2(6) <= ClassFile.JAVA_6_VERSION) {
//fallback to jump targets inflation without StackMapTableAttribute
@@ -325,8 +325,8 @@ else if (frameType < 128) {
}
private void inflateTypeAnnotations() {
- findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).ifPresent(RuntimeVisibleTypeAnnotationsAttribute::annotations);
- findAttribute(Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS).ifPresent(RuntimeInvisibleTypeAnnotationsAttribute::annotations);
+ findAttribute(Attributes.runtimeVisibleTypeAnnotations()).ifPresent(RuntimeVisibleTypeAnnotationsAttribute::annotations);
+ findAttribute(Attributes.runtimeInvisibleTypeAnnotations()).ifPresent(RuntimeInvisibleTypeAnnotationsAttribute::annotations);
}
private void generateCatchTargets(Consumer consumer) {
@@ -345,7 +345,7 @@ public void accept(int s, int e, int h, int c) {
private void generateDebugElements(Consumer consumer) {
for (Attribute> a : attributes()) {
- if (a.attributeMapper() == Attributes.CHARACTER_RANGE_TABLE) {
+ if (a.attributeMapper() == Attributes.characterRangeTable()) {
var attr = (BoundCharacterRangeTableAttribute) a;
int cnt = classReader.readU2(attr.payloadStart);
int p = attr.payloadStart + 2;
@@ -357,7 +357,7 @@ private void generateDebugElements(Consumer consumer) {
consumer.accept(instruction);
}
}
- else if (a.attributeMapper() == Attributes.LOCAL_VARIABLE_TABLE) {
+ else if (a.attributeMapper() == Attributes.localVariableTable()) {
var attr = (BoundLocalVariableTableAttribute) a;
int cnt = classReader.readU2(attr.payloadStart);
int p = attr.payloadStart + 2;
@@ -369,7 +369,7 @@ else if (a.attributeMapper() == Attributes.LOCAL_VARIABLE_TABLE) {
consumer.accept(instruction);
}
}
- else if (a.attributeMapper() == Attributes.LOCAL_VARIABLE_TYPE_TABLE) {
+ else if (a.attributeMapper() == Attributes.localVariableTypeTable()) {
var attr = (BoundLocalVariableTypeTableAttribute) a;
int cnt = classReader.readU2(attr.payloadStart);
int p = attr.payloadStart + 2;
@@ -381,10 +381,10 @@ else if (a.attributeMapper() == Attributes.LOCAL_VARIABLE_TYPE_TABLE) {
consumer.accept(instruction);
}
}
- else if (a.attributeMapper() == Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS) {
+ else if (a.attributeMapper() == Attributes.runtimeVisibleTypeAnnotations()) {
consumer.accept((BoundRuntimeVisibleTypeAnnotationsAttribute) a);
}
- else if (a.attributeMapper() == Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS) {
+ else if (a.attributeMapper() == Attributes.runtimeInvisibleTypeAnnotations()) {
consumer.accept((BoundRuntimeInvisibleTypeAnnotationsAttribute) a);
}
}
diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java b/src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java
index 9f68177351f80..b961a12031f59 100644
--- a/src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java
+++ b/src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java
@@ -230,7 +230,7 @@ private void buildContent() {
if (context.debugElementsOption() == ClassFile.DebugElementsOption.PASS_DEBUG) {
if (!characterRanges.isEmpty()) {
- Attribute> a = new UnboundAttribute.AdHocAttribute<>(Attributes.CHARACTER_RANGE_TABLE) {
+ Attribute> a = new UnboundAttribute.AdHocAttribute<>(Attributes.characterRangeTable()) {
@Override
public void writeBody(BufWriter b) {
@@ -262,7 +262,7 @@ public void writeBody(BufWriter b) {
}
if (!localVariables.isEmpty()) {
- Attribute> a = new UnboundAttribute.AdHocAttribute<>(Attributes.LOCAL_VARIABLE_TABLE) {
+ Attribute> a = new UnboundAttribute.AdHocAttribute<>(Attributes.localVariableTable()) {
@Override
public void writeBody(BufWriter b) {
int pos = b.size();
@@ -285,7 +285,7 @@ public void writeBody(BufWriter b) {
}
if (!localVariableTypes.isEmpty()) {
- Attribute> a = new UnboundAttribute.AdHocAttribute<>(Attributes.LOCAL_VARIABLE_TYPE_TABLE) {
+ Attribute> a = new UnboundAttribute.AdHocAttribute<>(Attributes.localVariableTypeTable()) {
@Override
public void writeBody(BufWriter b) {
int pos = b.size();
@@ -312,7 +312,7 @@ public void writeBody(BufWriter b) {
attributes.withAttribute(lineNumberWriter);
}
- content = new UnboundAttribute.AdHocAttribute<>(Attributes.CODE) {
+ content = new UnboundAttribute.AdHocAttribute<>(Attributes.code()) {
private void writeCounters(boolean codeMatch, BufWriterImpl buf) {
if (codeMatch) {
@@ -368,7 +368,7 @@ public void writeBody(BufWriter b) {
if (codeAndExceptionsMatch(codeLength)) {
switch (context.stackMapsOption()) {
case STACK_MAPS_WHEN_REQUIRED -> {
- attributes.withAttribute(original.findAttribute(Attributes.STACK_MAP_TABLE).orElse(null));
+ attributes.withAttribute(original.findAttribute(Attributes.stackMapTable()).orElse(null));
writeCounters(true, buf);
}
case GENERATE_STACK_MAPS ->
@@ -401,7 +401,7 @@ private static class DedupLineNumberTableAttribute extends UnboundAttribute.AdHo
private int lastPc, lastLine, writtenLine;
public DedupLineNumberTableAttribute(ConstantPoolBuilder constantPool, ClassFileImpl context) {
- super(Attributes.LINE_NUMBER_TABLE);
+ super(Attributes.lineNumberTable());
buf = new BufWriterImpl(constantPool, context);
lastPc = -1;
writtenLine = -1;
diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/MethodImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/MethodImpl.java
index 0baaa5865aec8..9a96e586c5501 100644
--- a/src/java.base/share/classes/jdk/internal/classfile/impl/MethodImpl.java
+++ b/src/java.base/share/classes/jdk/internal/classfile/impl/MethodImpl.java
@@ -118,7 +118,7 @@ public void writeTo(BufWriter b) {
@Override
public Optional code() {
- return findAttribute(Attributes.CODE).map(a -> (CodeModel) a);
+ return findAttribute(Attributes.code()).map(a -> (CodeModel) a);
}
@Override
diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/SplitConstantPool.java b/src/java.base/share/classes/jdk/internal/classfile/impl/SplitConstantPool.java
index db2b4f030a327..8deac9e3f95f8 100644
--- a/src/java.base/share/classes/jdk/internal/classfile/impl/SplitConstantPool.java
+++ b/src/java.base/share/classes/jdk/internal/classfile/impl/SplitConstantPool.java
@@ -144,7 +144,7 @@ public boolean writeBootstrapMethods(BufWriter buf) {
}
else {
Attribute a
- = new UnboundAttribute.AdHocAttribute<>(Attributes.BOOTSTRAP_METHODS) {
+ = new UnboundAttribute.AdHocAttribute<>(Attributes.bootstrapMethods()) {
@Override
public void writeBody(BufWriter b) {
diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java b/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java
index 17fcc5046a15a..4a8677e876f65 100644
--- a/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java
+++ b/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java
@@ -380,7 +380,7 @@ private void removeRangeFromExcTable(int rangeStart, int rangeEnd) {
* @return StackMapTableAttribute
or null if stack map is empty
*/
public Attribute extends StackMapTableAttribute> stackMapTableAttribute() {
- return frames.isEmpty() ? null : new UnboundAttribute.AdHocAttribute<>(Attributes.STACK_MAP_TABLE) {
+ return frames.isEmpty() ? null : new UnboundAttribute.AdHocAttribute<>(Attributes.stackMapTable()) {
@Override
public void writeBody(BufWriter b) {
b.writeU2(frames.size());
diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/UnboundAttribute.java b/src/java.base/share/classes/jdk/internal/classfile/impl/UnboundAttribute.java
index bdb293493bfa1..70b58e423f69a 100644
--- a/src/java.base/share/classes/jdk/internal/classfile/impl/UnboundAttribute.java
+++ b/src/java.base/share/classes/jdk/internal/classfile/impl/UnboundAttribute.java
@@ -149,7 +149,7 @@ public static final class UnboundConstantValueAttribute
private final ConstantValueEntry entry;
public UnboundConstantValueAttribute(ConstantValueEntry entry) {
- super(Attributes.CONSTANT_VALUE);
+ super(Attributes.constantValue());
this.entry = entry;
}
@@ -164,7 +164,7 @@ public static final class UnboundDeprecatedAttribute
extends UnboundAttribute
implements DeprecatedAttribute {
public UnboundDeprecatedAttribute() {
- super(Attributes.DEPRECATED);
+ super(Attributes.deprecated());
}
}
@@ -172,7 +172,7 @@ public static final class UnboundSyntheticAttribute
extends UnboundAttribute
implements SyntheticAttribute {
public UnboundSyntheticAttribute() {
- super(Attributes.SYNTHETIC);
+ super(Attributes.synthetic());
}
}
@@ -182,7 +182,7 @@ public static final class UnboundSignatureAttribute
private final Utf8Entry signature;
public UnboundSignatureAttribute(Utf8Entry signature) {
- super(Attributes.SIGNATURE);
+ super(Attributes.signature());
this.signature = signature;
}
@@ -198,7 +198,7 @@ public static final class UnboundExceptionsAttribute
private final List exceptions;
public UnboundExceptionsAttribute(List exceptions) {
- super(Attributes.EXCEPTIONS);
+ super(Attributes.exceptions());
this.exceptions = List.copyOf(exceptions);
}
@@ -214,7 +214,7 @@ public static final class UnboundAnnotationDefaultAttribute
private final AnnotationValue annotationDefault;
public UnboundAnnotationDefaultAttribute(AnnotationValue annotationDefault) {
- super(Attributes.ANNOTATION_DEFAULT);
+ super(Attributes.annotationDefault());
this.annotationDefault = annotationDefault;
}
@@ -229,7 +229,7 @@ public static final class UnboundSourceFileAttribute extends UnboundAttribute entries;
public UnboundStackMapTableAttribute(List entries) {
- super(Attributes.STACK_MAP_TABLE);
+ super(Attributes.stackMapTable());
this.entries = List.copyOf(entries);
}
@@ -261,7 +261,7 @@ public static final class UnboundInnerClassesAttribute
private final List innerClasses;
public UnboundInnerClassesAttribute(List innerClasses) {
- super(Attributes.INNER_CLASSES);
+ super(Attributes.innerClasses());
this.innerClasses = List.copyOf(innerClasses);
}
@@ -277,7 +277,7 @@ public static final class UnboundRecordAttribute
private final List components;
public UnboundRecordAttribute(List components) {
- super(Attributes.RECORD);
+ super(Attributes.record());
this.components = List.copyOf(components);
}
@@ -294,7 +294,7 @@ public static final class UnboundEnclosingMethodAttribute
private final NameAndTypeEntry method;
public UnboundEnclosingMethodAttribute(ClassEntry classEntry, NameAndTypeEntry method) {
- super(Attributes.ENCLOSING_METHOD);
+ super(Attributes.enclosingMethod());
this.classEntry = classEntry;
this.method = method;
}
@@ -316,7 +316,7 @@ public static final class UnboundMethodParametersAttribute
private final List parameters;
public UnboundMethodParametersAttribute(List parameters) {
- super(Attributes.METHOD_PARAMETERS);
+ super(Attributes.methodParameters());
this.parameters = List.copyOf(parameters);
}
@@ -332,7 +332,7 @@ public static final class UnboundModuleTargetAttribute
final Utf8Entry moduleTarget;
public UnboundModuleTargetAttribute(Utf8Entry moduleTarget) {
- super(Attributes.MODULE_TARGET);
+ super(Attributes.moduleTarget());
this.moduleTarget = moduleTarget;
}
@@ -348,7 +348,7 @@ public static final class UnboundModuleMainClassAttribute
final ClassEntry mainClass;
public UnboundModuleMainClassAttribute(ClassEntry mainClass) {
- super(Attributes.MODULE_MAIN_CLASS);
+ super(Attributes.moduleMainClass());
this.mainClass = mainClass;
}
@@ -365,7 +365,7 @@ public static final class UnboundModuleHashesAttribute
private final List hashes;
public UnboundModuleHashesAttribute(Utf8Entry algorithm, List hashes) {
- super(Attributes.MODULE_HASHES);
+ super(Attributes.moduleHashes());
this.algorithm = algorithm;
this.hashes = List.copyOf(hashes);
}
@@ -387,7 +387,7 @@ public static final class UnboundModulePackagesAttribute
private final Collection packages;
public UnboundModulePackagesAttribute(Collection packages) {
- super(Attributes.MODULE_PACKAGES);
+ super(Attributes.modulePackages());
this.packages = List.copyOf(packages);
}
@@ -403,7 +403,7 @@ public static final class UnboundModuleResolutionAttribute
private final int resolutionFlags;
public UnboundModuleResolutionAttribute(int flags) {
- super(Attributes.MODULE_RESOLUTION);
+ super(Attributes.moduleResolution());
resolutionFlags = flags;
}
@@ -419,7 +419,7 @@ public static final class UnboundPermittedSubclassesAttribute
private final List permittedSubclasses;
public UnboundPermittedSubclassesAttribute(List permittedSubclasses) {
- super(Attributes.PERMITTED_SUBCLASSES);
+ super(Attributes.permittedSubclasses());
this.permittedSubclasses = List.copyOf(permittedSubclasses);
}
@@ -435,7 +435,7 @@ public static final class UnboundNestMembersAttribute
private final List memberEntries;
public UnboundNestMembersAttribute(List memberEntries) {
- super(Attributes.NEST_MEMBERS);
+ super(Attributes.nestMembers());
this.memberEntries = List.copyOf(memberEntries);
}
@@ -451,7 +451,7 @@ public static final class UnboundNestHostAttribute
private final ClassEntry hostEntry;
public UnboundNestHostAttribute(ClassEntry hostEntry) {
- super(Attributes.NEST_HOST);
+ super(Attributes.nestHost());
this.hostEntry = hostEntry;
}
@@ -467,7 +467,7 @@ public static final class UnboundCompilationIDAttribute
private final Utf8Entry idEntry;
public UnboundCompilationIDAttribute(Utf8Entry idEntry) {
- super(Attributes.COMPILATION_ID);
+ super(Attributes.compilationId());
this.idEntry = idEntry;
}
@@ -483,7 +483,7 @@ public static final class UnboundSourceIDAttribute
private final Utf8Entry idEntry;
public UnboundSourceIDAttribute(Utf8Entry idEntry) {
- super(Attributes.SOURCE_ID);
+ super(Attributes.sourceId());
this.idEntry = idEntry;
}
@@ -499,7 +499,7 @@ public static final class UnboundSourceDebugExtensionAttribute
private final byte[] contents;
public UnboundSourceDebugExtensionAttribute(byte[] contents) {
- super(Attributes.SOURCE_DEBUG_EXTENSION);
+ super(Attributes.sourceDebugExtension());
this.contents = contents;
}
@@ -515,7 +515,7 @@ public static final class UnboundCharacterRangeTableAttribute
private final List ranges;
public UnboundCharacterRangeTableAttribute(List ranges) {
- super(Attributes.CHARACTER_RANGE_TABLE);
+ super(Attributes.characterRangeTable());
this.ranges = List.copyOf(ranges);
}
@@ -531,7 +531,7 @@ public static final class UnboundLineNumberTableAttribute
private final List lines;
public UnboundLineNumberTableAttribute(List lines) {
- super(Attributes.LINE_NUMBER_TABLE);
+ super(Attributes.lineNumberTable());
this.lines = List.copyOf(lines);
}
@@ -547,7 +547,7 @@ public static final class UnboundLocalVariableTableAttribute
private final List locals;
public UnboundLocalVariableTableAttribute(List locals) {
- super(Attributes.LOCAL_VARIABLE_TABLE);
+ super(Attributes.localVariableTable());
this.locals = List.copyOf(locals);
}
@@ -563,7 +563,7 @@ public static final class UnboundLocalVariableTypeTableAttribute
private final List locals;
public UnboundLocalVariableTypeTableAttribute(List locals) {
- super(Attributes.LOCAL_VARIABLE_TYPE_TABLE);
+ super(Attributes.localVariableTypeTable());
this.locals = List.copyOf(locals);
}
@@ -579,7 +579,7 @@ public static final class UnboundRuntimeVisibleAnnotationsAttribute
private final List elements;
public UnboundRuntimeVisibleAnnotationsAttribute(List elements) {
- super(Attributes.RUNTIME_VISIBLE_ANNOTATIONS);
+ super(Attributes.runtimeVisibleAnnotations());
this.elements = List.copyOf(elements);
}
@@ -595,7 +595,7 @@ public static final class UnboundRuntimeInvisibleAnnotationsAttribute
private final List elements;
public UnboundRuntimeInvisibleAnnotationsAttribute(List elements) {
- super(Attributes.RUNTIME_INVISIBLE_ANNOTATIONS);
+ super(Attributes.runtimeInvisibleAnnotations());
this.elements = List.copyOf(elements);
}
@@ -611,7 +611,7 @@ public static final class UnboundRuntimeVisibleParameterAnnotationsAttribute
private final List> elements;
public UnboundRuntimeVisibleParameterAnnotationsAttribute(List> elements) {
- super(Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS);
+ super(Attributes.runtimeVisibleParameterAnnotations());
this.elements = List.copyOf(elements);
}
@@ -627,7 +627,7 @@ public static final class UnboundRuntimeInvisibleParameterAnnotationsAttribute
private final List> elements;
public UnboundRuntimeInvisibleParameterAnnotationsAttribute(List> elements) {
- super(Attributes.RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS);
+ super(Attributes.runtimeInvisibleParameterAnnotations());
this.elements = List.copyOf(elements);
}
@@ -643,7 +643,7 @@ public static final class UnboundRuntimeVisibleTypeAnnotationsAttribute
private final List elements;
public UnboundRuntimeVisibleTypeAnnotationsAttribute(List elements) {
- super(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS);
+ super(Attributes.runtimeVisibleTypeAnnotations());
this.elements = List.copyOf(elements);
}
@@ -659,7 +659,7 @@ public static final class UnboundRuntimeInvisibleTypeAnnotationsAttribute
private final List elements;
public UnboundRuntimeInvisibleTypeAnnotationsAttribute(List elements) {
- super(Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS);
+ super(Attributes.runtimeInvisibleTypeAnnotations());
this.elements = List.copyOf(elements);
}
@@ -845,7 +845,7 @@ public UnboundModuleAttribute(ModuleEntry moduleName,
Collection uses,
Collection provides)
{
- super(Attributes.MODULE);
+ super(Attributes.module());
this.moduleName = moduleName;
this.moduleFlags = moduleFlags;
this.moduleVersion = moduleVersion;
@@ -921,7 +921,7 @@ public static final class EmptyBootstrapAttribute
extends UnboundAttribute
implements BootstrapMethodsAttribute {
public EmptyBootstrapAttribute() {
- super(Attributes.BOOTSTRAP_METHODS);
+ super(Attributes.bootstrapMethods());
}
@Override
diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/Util.java b/src/java.base/share/classes/jdk/internal/classfile/impl/Util.java
index 7bff7e6f06dbb..0e969272c4028 100644
--- a/src/java.base/share/classes/jdk/internal/classfile/impl/Util.java
+++ b/src/java.base/share/classes/jdk/internal/classfile/impl/Util.java
@@ -214,7 +214,7 @@ public static void dumpMethod(SplitConstantPool cp,
var cc = ClassFile.of();
var clm = cc.parse(cc.build(cp.classEntry(cls), cp, clb ->
clb.withMethod(methodName, methodDesc, acc, mb ->
- ((DirectMethodBuilder)mb).writeAttribute(new UnboundAttribute.AdHocAttribute(Attributes.CODE) {
+ ((DirectMethodBuilder)mb).writeAttribute(new UnboundAttribute.AdHocAttribute(Attributes.code()) {
@Override
public void writeBody(BufWriter b) {
b.writeU2(-1);//max stack
diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/verifier/VerificationWrapper.java b/src/java.base/share/classes/jdk/internal/classfile/impl/verifier/VerificationWrapper.java
index 6be4a611e975d..fefc6b20cb2b1 100644
--- a/src/java.base/share/classes/jdk/internal/classfile/impl/verifier/VerificationWrapper.java
+++ b/src/java.base/share/classes/jdk/internal/classfile/impl/verifier/VerificationWrapper.java
@@ -142,12 +142,12 @@ List exceptionTable() {
}
List localVariableTable() {
- var attro = c.findAttribute(Attributes.LOCAL_VARIABLE_TABLE);
+ var attro = c.findAttribute(Attributes.localVariableTable());
return attro.map(lvta -> lvta.localVariables()).orElse(List.of());
}
byte[] stackMapTableRawData() {
- var attro = c.findAttribute(Attributes.STACK_MAP_TABLE);
+ var attro = c.findAttribute(Attributes.stackMapTable());
return attro.map(attr -> ((BoundAttribute) attr).contents()).orElse(null);
}
diff --git a/src/jdk.jartool/share/classes/sun/tools/jar/FingerPrint.java b/src/jdk.jartool/share/classes/sun/tools/jar/FingerPrint.java
index a4cfc59eb2098..b28078916c58b 100644
--- a/src/jdk.jartool/share/classes/sun/tools/jar/FingerPrint.java
+++ b/src/jdk.jartool/share/classes/sun/tools/jar/FingerPrint.java
@@ -284,7 +284,7 @@ public void accept(ClassElement cle) {
case MethodModel mm -> {
if (isPublic(mm.flags())) {
Set exceptionSet = new HashSet<>();
- mm.findAttribute(Attributes.EXCEPTIONS).ifPresent(ea ->
+ mm.findAttribute(Attributes.exceptions()).ifPresent(ea ->
ea.exceptions().forEach(e ->
exceptionSet.add(e.asInternalName())));
// treat type descriptor as a proxy for signature because signature
diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java b/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java
index 23bec4e7298f6..839ac2fd041b7 100644
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java
@@ -478,7 +478,7 @@ public void write(Attribute> a, CodeAttribute lr) {
println("Record:");
indent(+1);
for (var componentInfo : attr.components()) {
- var sigAttr = componentInfo.findAttribute(Attributes.SIGNATURE);
+ var sigAttr = componentInfo.findAttribute(Attributes.signature());
print(getJavaName(
new ClassWriter.SignaturePrinter(options.verbose).print(
sigAttr.map(SignatureAttribute::asTypeSignature)
diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java b/src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java
index c5ac15ee7dab9..798d2f2d3a8d2 100644
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java
@@ -141,7 +141,7 @@ public boolean write(ClassModel cm) {
}
}
- cm.findAttribute(Attributes.SOURCE_FILE).ifPresent(sfa ->
+ cm.findAttribute(Attributes.sourceFile()).ifPresent(sfa ->
println("Compiled from \"" + sfa.sourceFile().stringValue() + "\""));
if (options.sysInfo || options.verbose) {
@@ -151,7 +151,7 @@ public boolean write(ClassModel cm) {
writeModifiers(getClassModifiers(cm.flags().flagsMask()));
if ((classModel.flags().flagsMask() & ACC_MODULE) != 0) {
- var attr = classModel.findAttribute(Attributes.MODULE);
+ var attr = classModel.findAttribute(Attributes.module());
if (attr.isPresent()) {
var modAttr = attr.get();
if ((modAttr.moduleFlagsMask() & ACC_OPEN) != 0) {
@@ -178,7 +178,7 @@ public boolean write(ClassModel cm) {
}
try {
- var sigAttr = classModel.findAttribute(Attributes.SIGNATURE).orElse(null);
+ var sigAttr = classModel.findAttribute(Attributes.signature()).orElse(null);
if (sigAttr == null) {
// use info from class file header
if ((classModel.flags().flagsMask() & ACC_INTERFACE) == 0
@@ -399,13 +399,13 @@ protected void writeField(FieldModel f) {
writeModifiers(flags.flags().stream().filter(fl -> fl.sourceModifier())
.map(fl -> Modifier.toString(fl.mask())).toList());
print(() -> sigPrinter.print(
- f.findAttribute(Attributes.SIGNATURE)
+ f.findAttribute(Attributes.signature())
.map(SignatureAttribute::asTypeSignature)
.orElseGet(() -> Signature.of(f.fieldTypeSymbol()))));
print(" ");
print(() -> f.fieldName().stringValue());
if (options.showConstants) {
- var a = f.findAttribute(Attributes.CONSTANT_VALUE);
+ var a = f.findAttribute(Attributes.constantValue());
if (a.isPresent()) {
print(" = ");
var cv = a.get();
@@ -480,7 +480,7 @@ protected void writeMethod(MethodModel m) {
writeModifiers(modifiers);
try {
- var sigAttr = m.findAttribute(Attributes.SIGNATURE);
+ var sigAttr = m.findAttribute(Attributes.signature());
MethodSignature d;
if (sigAttr.isEmpty()) {
d = MethodSignature.parseFrom(m.methodType().stringValue());
@@ -507,7 +507,7 @@ protected void writeMethod(MethodModel m) {
break;
}
- var e_attr = m.findAttribute(Attributes.EXCEPTIONS);
+ var e_attr = m.findAttribute(Attributes.exceptions());
// if there are generic exceptions, there must be erased exceptions
if (e_attr.isPresent()) {
var exceptions = e_attr.get();
@@ -559,9 +559,9 @@ protected void writeMethod(MethodModel m) {
}
if (options.showLineAndLocalVariableTables) {
- code.findAttribute(Attributes.LINE_NUMBER_TABLE)
+ code.findAttribute(Attributes.lineNumberTable())
.ifPresent(a -> attrWriter.write(a, code));
- code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE)
+ code.findAttribute(Attributes.localVariableTable())
.ifPresent(a -> attrWriter.write(a, code));
}
}
@@ -589,7 +589,7 @@ void writeModifiers(Collection items) {
public static final int ACC_STATIC_PHASE = 0x0040;
void writeDirectives() {
- var attr = classModel.findAttribute(Attributes.MODULE);
+ var attr = classModel.findAttribute(Attributes.module());
if (attr.isEmpty())
return;
diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/javap/JavapTask.java b/src/jdk.jdeps/share/classes/com/sun/tools/javap/JavapTask.java
index 1c32fff24e06a..ac8ab164e629b 100644
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/JavapTask.java
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/JavapTask.java
@@ -674,7 +674,7 @@ protected int writeClass(ClassWriter classWriter, String className)
if (options.showInnerClasses) {
ClassModel cm = cfInfo.cm;
- var a = cm.findAttribute(java.lang.classfile.Attributes.INNER_CLASSES);
+ var a = cm.findAttribute(java.lang.classfile.Attributes.innerClasses());
if (a.isPresent()) {
var inners = a.get();
try {
diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/javap/LocalVariableTableWriter.java b/src/jdk.jdeps/share/classes/com/sun/tools/javap/LocalVariableTableWriter.java
index d6b57ca4c48f2..f19d8fce4bbb5 100644
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/LocalVariableTableWriter.java
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/LocalVariableTableWriter.java
@@ -80,7 +80,7 @@ protected LocalVariableTableWriter(Context context) {
public void reset(CodeModel attr) {
codeAttr = attr;
pcMap = new HashMap<>();
- var lvt = attr.findAttribute(Attributes.LOCAL_VARIABLE_TABLE);
+ var lvt = attr.findAttribute(Attributes.localVariableTable());
if (lvt.isEmpty())
return;
diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/javap/LocalVariableTypeTableWriter.java b/src/jdk.jdeps/share/classes/com/sun/tools/javap/LocalVariableTypeTableWriter.java
index f9ac8c70e0f93..04e7b3fd0e0b8 100644
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/LocalVariableTypeTableWriter.java
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/LocalVariableTypeTableWriter.java
@@ -80,7 +80,7 @@ protected LocalVariableTypeTableWriter(Context context) {
public void reset(CodeModel attr) {
codeAttr = attr;
pcMap = new HashMap<>();
- var lvt = attr.findAttribute(Attributes.LOCAL_VARIABLE_TYPE_TABLE);
+ var lvt = attr.findAttribute(Attributes.localVariableTypeTable());
if (lvt.isEmpty())
return;
diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/javap/SourceWriter.java b/src/jdk.jdeps/share/classes/com/sun/tools/javap/SourceWriter.java
index 1d06727ff63a9..884c0fa9f80bc 100644
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/SourceWriter.java
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/SourceWriter.java
@@ -105,7 +105,7 @@ public boolean hasSource() {
private void setLineMap(CodeModel attr) {
SortedMap> map = new TreeMap<>();
SortedSet allLines = new TreeSet<>();
- for (var t : attr.findAttributes(Attributes.LINE_NUMBER_TABLE)) {
+ for (var t : attr.findAttributes(Attributes.lineNumberTable())) {
for (var e: t.lineNumbers()) {
int start_pc = e.startPc();
int line = e.lineNumber();
@@ -145,7 +145,7 @@ private String readSource(ClassModel cf) {
// InnerClasses and EnclosingMethod attributes.
try {
String className = cf.thisClass().asInternalName();
- var sf = cf.findAttribute(Attributes.SOURCE_FILE);
+ var sf = cf.findAttribute(Attributes.sourceFile());
if (sf.isEmpty()) {
report(messages.getMessage("err.no.SourceFile.attribute"));
return null;
diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/javap/StackMapWriter.java b/src/jdk.jdeps/share/classes/com/sun/tools/javap/StackMapWriter.java
index 9a83fddbb87de..a1d939bcc4f23 100644
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/StackMapWriter.java
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/StackMapWriter.java
@@ -62,7 +62,7 @@ public void reset(CodeAttribute code) {
}
void setStackMap(CodeAttribute code) {
- StackMapTableAttribute attr = code.findAttribute(Attributes.STACK_MAP_TABLE)
+ StackMapTableAttribute attr = code.findAttribute(Attributes.stackMapTable())
.orElse(null);
if (attr == null) {
map = null;
diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/javap/TypeAnnotationWriter.java b/src/jdk.jdeps/share/classes/com/sun/tools/javap/TypeAnnotationWriter.java
index a0236955cfca5..d5e19bc4241c2 100644
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/TypeAnnotationWriter.java
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/TypeAnnotationWriter.java
@@ -76,10 +76,10 @@ public void reset(CodeAttribute attr) {
pcMap = new HashMap<>();
codeAttribute = attr;
check(NoteKind.VISIBLE,
- m.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS)
+ m.findAttribute(Attributes.runtimeVisibleTypeAnnotations())
.map(a -> a.annotations()));
check(NoteKind.INVISIBLE,
- m.findAttribute(Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS)
+ m.findAttribute(Attributes.runtimeInvisibleTypeAnnotations())
.map(a -> a.annotations()));
}
diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Dependencies.java b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Dependencies.java
index 422845150f041..c0ac835f4b605 100644
--- a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Dependencies.java
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Dependencies.java
@@ -597,7 +597,7 @@ private void scan(MethodTypeDesc mtd) {
void scanAttributes(AttributedElement attrs) {
try {
- var sa = attrs.findAttribute(Attributes.SIGNATURE).orElse(null);
+ var sa = attrs.findAttribute(Attributes.signature()).orElse(null);
if (sa != null) {
switch (attrs) {
case ClassModel _ -> scan(sa.asClassSignature());
@@ -606,14 +606,14 @@ void scanAttributes(AttributedElement attrs) {
}
}
- var rvaa = attrs.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElse(null);
+ var rvaa = attrs.findAttribute(Attributes.runtimeVisibleAnnotations()).orElse(null);
if (rvaa != null) {
for (var anno : rvaa.annotations()) {
scan(anno.classSymbol());
}
}
- var rvpaa = attrs.findAttribute(Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS).orElse(null);
+ var rvpaa = attrs.findAttribute(Attributes.runtimeVisibleParameterAnnotations()).orElse(null);
if (rvpaa != null) {
for (var parameter : rvpaa.parameterAnnotations()) {
for (var anno : parameter) {
@@ -622,7 +622,7 @@ void scanAttributes(AttributedElement attrs) {
}
}
- var exceptions = attrs.findAttribute(Attributes.EXCEPTIONS).orElse(null);
+ var exceptions = attrs.findAttribute(Attributes.exceptions()).orElse(null);
if (exceptions != null) {
for (var e : exceptions.exceptions()) {
addClass(e);
diff --git a/test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaMethod.java b/test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaMethod.java
index ae077b3b3f44c..00973fd78c29d 100644
--- a/test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaMethod.java
+++ b/test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaMethod.java
@@ -678,7 +678,7 @@ public void getOopMapAtTest() throws Exception {
Map methodMap = buildMethodMap(type);
ClassModel cf = readClassfile(c);
for (MethodModel cm : cf.methods()) {
- cm.findAttribute(Attributes.CODE).ifPresent(codeAttr -> {
+ cm.findAttribute(Attributes.code()).ifPresent(codeAttr -> {
String key = cm.methodName().stringValue() + ":" + cm.methodType().stringValue();
HotSpotResolvedJavaMethod m = (HotSpotResolvedJavaMethod) Objects.requireNonNull(methodMap.get(key));
boolean isMethodWithManyArgs = c == getClass() && m.getName().equals("methodWithManyArgs");
diff --git a/test/jdk/java/lang/StackWalker/TestBCI.java b/test/jdk/java/lang/StackWalker/TestBCI.java
index 3cba0505e9c9b..4d5e6a6eaf473 100644
--- a/test/jdk/java/lang/StackWalker/TestBCI.java
+++ b/test/jdk/java/lang/StackWalker/TestBCI.java
@@ -134,7 +134,7 @@ static class MethodInfo {
this.name = m.methodName().stringValue();
this.desc = m.methodTypeSymbol();
m.code().orElseThrow(() -> new IllegalArgumentException("Missing Code in " + m))
- .findAttribute(Attributes.LINE_NUMBER_TABLE)
+ .findAttribute(Attributes.lineNumberTable())
.orElseThrow(() -> new IllegalArgumentException("Missing LineNumberTable in " + m))
.lineNumbers().forEach(entry ->
bciToLineNumbers.computeIfAbsent(entry.startPc(), _ -> new TreeSet<>())
diff --git a/test/jdk/java/lang/invoke/lambda/LambdaAsm.java b/test/jdk/java/lang/invoke/lambda/LambdaAsm.java
index ebca93d639aa9..8369ea2bcd39b 100644
--- a/test/jdk/java/lang/invoke/lambda/LambdaAsm.java
+++ b/test/jdk/java/lang/invoke/lambda/LambdaAsm.java
@@ -125,7 +125,7 @@ static int checkMethod(ClassModel cf, String mthd) throws Exception {
for (var m : cf.methods()) {
String mname = m.methodName().stringValue();
if (mname.equals(mthd)) {
- for (var a : m.findAttributes(Attributes.CODE)) {
+ for (var a : m.findAttributes(Attributes.code())) {
count++;
checkMethod(cf.thisClass().asInternalName(), mname,
cf.constantPool(), a);
diff --git a/test/jdk/jdk/classfile/AdvancedTransformationsTest.java b/test/jdk/jdk/classfile/AdvancedTransformationsTest.java
index 9b4609fe8bc48..2ef7dca11ae0b 100644
--- a/test/jdk/jdk/classfile/AdvancedTransformationsTest.java
+++ b/test/jdk/jdk/classfile/AdvancedTransformationsTest.java
@@ -120,9 +120,9 @@ void testRemapClass() throws Exception {
ClassDesc.ofDescriptor(RawBytecodeHelper.class.descriptorString()), ClassDesc.of("remapped.RemappedBytecode")))
.orElse(ClassHierarchyResolver.defaultResolver())
)).verify(remapped));
- remapped.fields().forEach(f -> f.findAttribute(Attributes.SIGNATURE).ifPresent(sa ->
+ remapped.fields().forEach(f -> f.findAttribute(Attributes.signature()).ifPresent(sa ->
verifySignature(f.fieldTypeSymbol(), sa.asTypeSignature())));
- remapped.methods().forEach(m -> m.findAttribute(Attributes.SIGNATURE).ifPresent(sa -> {
+ remapped.methods().forEach(m -> m.findAttribute(Attributes.signature()).ifPresent(sa -> {
var md = m.methodTypeSymbol();
var ms = sa.asMethodSignature();
verifySignature(md.returnType(), ms.result());
@@ -173,7 +173,7 @@ void testRemapModule() throws Exception {
cc.parse(
cc.buildModule(
ModuleAttribute.of(ModuleDesc.of("MyModule"), mab ->
- mab.uses(foo).provides(foo, foo)))))).findAttribute(Attributes.MODULE).get();
+ mab.uses(foo).provides(foo, foo)))))).findAttribute(Attributes.module()).get();
assertEquals(ma.uses().get(0).asSymbol(), bar);
var provides = ma.provides().get(0);
assertEquals(provides.provides().asSymbol(), bar);
diff --git a/test/jdk/jdk/classfile/AnnotationModelTest.java b/test/jdk/jdk/classfile/AnnotationModelTest.java
index ed647784219fc..25d02b8172f08 100644
--- a/test/jdk/jdk/classfile/AnnotationModelTest.java
+++ b/test/jdk/jdk/classfile/AnnotationModelTest.java
@@ -54,7 +54,7 @@ class AnnotationModelTest {
@Test
void readAnnos() {
var model = ClassFile.of().parse(fileBytes);
- var annotations = model.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).get().annotations();
+ var annotations = model.findAttribute(Attributes.runtimeVisibleAnnotations()).get().annotations();
assertEquals(annotations.size(), 3);
}
diff --git a/test/jdk/jdk/classfile/AttributesTest.java b/test/jdk/jdk/classfile/AttributesTest.java
new file mode 100644
index 0000000000000..0d156dd586027
--- /dev/null
+++ b/test/jdk/jdk/classfile/AttributesTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+/*
+ * @test
+ * @bug 8331291
+ * @summary Testing Attributes API.
+ * @run junit AttributesTest
+ */
+import java.lang.classfile.AttributeMapper;
+import java.lang.classfile.Attributes;
+import java.lang.classfile.constantpool.Utf8Entry;
+import java.lang.reflect.Field;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import jdk.internal.classfile.impl.BoundAttribute;
+import jdk.internal.classfile.impl.TemporaryConstantPool;
+
+class AttributesTest {
+
+ @Test
+ void testAttributesMapping() throws Exception {
+ var cp = TemporaryConstantPool.INSTANCE;
+ for (Field f : Attributes.class.getDeclaredFields()) {
+ if (f.getName().startsWith("NAME_") && f.getType() == String.class) {
+ Utf8Entry attrName = cp.utf8Entry((String)f.get(null));
+ AttributeMapper> mapper = BoundAttribute.standardAttribute(attrName);
+ assertNotNull(mapper, attrName.stringValue() + " 0x" + Integer.toHexString(attrName.hashCode()));
+ assertEquals(attrName.stringValue(), mapper.name());
+ }
+ }
+ }
+}
diff --git a/test/jdk/jdk/classfile/BoundAttributeTest.java b/test/jdk/jdk/classfile/BoundAttributeTest.java
index 8a25146bab951..103bcffa8987a 100644
--- a/test/jdk/jdk/classfile/BoundAttributeTest.java
+++ b/test/jdk/jdk/classfile/BoundAttributeTest.java
@@ -61,7 +61,7 @@ void testReadMethodParametersAttributeWithoutParameterName() {
});
ClassModel model = cc.parse(raw);
MethodParametersAttribute methodParametersAttribute = model.methods().get(0)
- .findAttribute(Attributes.METHOD_PARAMETERS)
+ .findAttribute(Attributes.methodParameters())
.orElseThrow(() -> new AssertionFailedError("Attribute not present"));
// MethodParametersAttribute#parameters() materializes the parameters
List parameters = assertDoesNotThrow(methodParametersAttribute::parameters);
diff --git a/test/jdk/jdk/classfile/CorpusTest.java b/test/jdk/jdk/classfile/CorpusTest.java
index b13657e207213..21e275a837d84 100644
--- a/test/jdk/jdk/classfile/CorpusTest.java
+++ b/test/jdk/jdk/classfile/CorpusTest.java
@@ -83,7 +83,7 @@ static void splitTableAttributes(String sourceClassFile, String targetClassFile)
var dcob = (DirectCodeBuilder)cob;
var curPc = dcob.curPc();
switch (coe) {
- case LineNumber ln -> dcob.writeAttribute(new UnboundAttribute.AdHocAttribute<>(Attributes.LINE_NUMBER_TABLE) {
+ case LineNumber ln -> dcob.writeAttribute(new UnboundAttribute.AdHocAttribute<>(Attributes.lineNumberTable()) {
@Override
public void writeBody(BufWriter b) {
b.writeU2(1);
@@ -91,14 +91,14 @@ public void writeBody(BufWriter b) {
b.writeU2(ln.line());
}
});
- case LocalVariable lv -> dcob.writeAttribute(new UnboundAttribute.AdHocAttribute<>(Attributes.LOCAL_VARIABLE_TABLE) {
+ case LocalVariable lv -> dcob.writeAttribute(new UnboundAttribute.AdHocAttribute<>(Attributes.localVariableTable()) {
@Override
public void writeBody(BufWriter b) {
b.writeU2(1);
lv.writeTo(b);
}
});
- case LocalVariableType lvt -> dcob.writeAttribute(new UnboundAttribute.AdHocAttribute<>(Attributes.LOCAL_VARIABLE_TYPE_TABLE) {
+ case LocalVariableType lvt -> dcob.writeAttribute(new UnboundAttribute.AdHocAttribute<>(Attributes.localVariableTypeTable()) {
@Override
public void writeBody(BufWriter b) {
b.writeU2(1);
diff --git a/test/jdk/jdk/classfile/FilterDeadLabelsTest.java b/test/jdk/jdk/classfile/FilterDeadLabelsTest.java
index be527d7bc1139..810f02d5f19fb 100644
--- a/test/jdk/jdk/classfile/FilterDeadLabelsTest.java
+++ b/test/jdk/jdk/classfile/FilterDeadLabelsTest.java
@@ -66,9 +66,9 @@ void testFilterDeadLabels() {
}))).methods().get(0).code().get();
assertTrue(code.exceptionHandlers().isEmpty());
- code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE).ifPresent(a -> assertTrue(a.localVariables().isEmpty()));
- code.findAttribute(Attributes.LOCAL_VARIABLE_TYPE_TABLE).ifPresent(a -> assertTrue(a.localVariableTypes().isEmpty()));
- code.findAttribute(Attributes.CHARACTER_RANGE_TABLE).ifPresent(a -> assertTrue(a.characterRangeTable().isEmpty()));
+ code.findAttribute(Attributes.localVariableTable()).ifPresent(a -> assertTrue(a.localVariables().isEmpty()));
+ code.findAttribute(Attributes.localVariableTypeTable()).ifPresent(a -> assertTrue(a.localVariableTypes().isEmpty()));
+ code.findAttribute(Attributes.characterRangeTable()).ifPresent(a -> assertTrue(a.characterRangeTable().isEmpty()));
}
@ParameterizedTest
diff --git a/test/jdk/jdk/classfile/LimitsTest.java b/test/jdk/jdk/classfile/LimitsTest.java
index a94a56ce33ff3..40ae8a5fb1f67 100644
--- a/test/jdk/jdk/classfile/LimitsTest.java
+++ b/test/jdk/jdk/classfile/LimitsTest.java
@@ -127,7 +127,7 @@ void testInvalidLookupSwitch() {
assertThrows(IllegalArgumentException.class, () ->
ClassFile.of().parse(ClassFile.of().build(ClassDesc.of("LookupSwitchClass"), cb -> cb.withMethod(
"lookupSwitchMethod", MethodTypeDesc.of(ConstantDescs.CD_void), 0, mb ->
- ((DirectMethodBuilder)mb).writeAttribute(new UnboundAttribute.AdHocAttribute(Attributes.CODE) {
+ ((DirectMethodBuilder)mb).writeAttribute(new UnboundAttribute.AdHocAttribute(Attributes.code()) {
@Override
public void writeBody(BufWriter b) {
b.writeU2(-1);//max stack
@@ -152,7 +152,7 @@ void testInvalidTableSwitch() {
assertThrows(IllegalArgumentException.class, () ->
ClassFile.of().parse(ClassFile.of().build(ClassDesc.of("TableSwitchClass"), cb -> cb.withMethod(
"tableSwitchMethod", MethodTypeDesc.of(ConstantDescs.CD_void), 0, mb ->
- ((DirectMethodBuilder)mb).writeAttribute(new UnboundAttribute.AdHocAttribute(Attributes.CODE) {
+ ((DirectMethodBuilder)mb).writeAttribute(new UnboundAttribute.AdHocAttribute(Attributes.code()) {
@Override
public void writeBody(BufWriter b) {
b.writeU2(-1);//max stack
diff --git a/test/jdk/jdk/classfile/LowJCovAttributeTest.java b/test/jdk/jdk/classfile/LowJCovAttributeTest.java
index 9bc1e29155ea3..858b9c90416d1 100644
--- a/test/jdk/jdk/classfile/LowJCovAttributeTest.java
+++ b/test/jdk/jdk/classfile/LowJCovAttributeTest.java
@@ -94,8 +94,8 @@ private void testRead0() {
}
}
for (MethodModel m : classLow.methods()) {
- m.findAttribute(Attributes.CODE).ifPresent(code ->
- ((CodeModel) code).findAttribute(Attributes.CHARACTER_RANGE_TABLE).ifPresent(attr -> {
+ m.findAttribute(Attributes.code()).ifPresent(code ->
+ ((CodeModel) code).findAttribute(Attributes.characterRangeTable()).ifPresent(attr -> {
for (CharacterRangeInfo cr : attr.characterRangeTable()) {
printf(" %d-%d -> %d/%d-%d/%d (%x)%n", cr.startPc(), cr.endPc(),
cr.characterRangeStart() >> 10, cr.characterRangeStart() & 0x3FF,
@@ -156,7 +156,7 @@ private void println() {
// }
// writeAndCompareAttributes(classLow, cp);
// for (MethodLow m : classLow.methodsLow()) {
-// m.findAttribute(Attributes.CODE).ifPresent(code ->
+// m.findAttribute(Attributes.code()).ifPresent(code ->
// writeAndCompareAttributes(code, cp));
// }
// }
diff --git a/test/jdk/jdk/classfile/LvtTest.java b/test/jdk/jdk/classfile/LvtTest.java
index 35ec8dfcfa358..7c60d75823af4 100644
--- a/test/jdk/jdk/classfile/LvtTest.java
+++ b/test/jdk/jdk/classfile/LvtTest.java
@@ -174,7 +174,7 @@ void testCreateLoadLVT() throws Exception {
var c = cc.parse(bytes);
var main = c.methods().get(1);
- var lvt = main.code().get().findAttribute(Attributes.LOCAL_VARIABLE_TABLE).get();
+ var lvt = main.code().get().findAttribute(Attributes.localVariableTable()).get();
var lvs = lvt.localVariables();
assertEquals(lvs.size(), 3);
@@ -278,7 +278,7 @@ void testCreateLoadLVTT() throws Exception {
});
var c = cc.parse(bytes);
var main = c.methods().get(1);
- var lvtt = main.code().get().findAttribute(Attributes.LOCAL_VARIABLE_TYPE_TABLE).get();
+ var lvtt = main.code().get().findAttribute(Attributes.localVariableTypeTable()).get();
var lvts = lvtt.localVariableTypes();
/* From javap:
diff --git a/test/jdk/jdk/classfile/MassAdaptCopyPrimitiveMatchCodeTest.java b/test/jdk/jdk/classfile/MassAdaptCopyPrimitiveMatchCodeTest.java
index 825394bff0af7..0ac9de70472ca 100644
--- a/test/jdk/jdk/classfile/MassAdaptCopyPrimitiveMatchCodeTest.java
+++ b/test/jdk/jdk/classfile/MassAdaptCopyPrimitiveMatchCodeTest.java
@@ -120,7 +120,7 @@ void copy(String name, byte[] bytes) throws Exception {
cb.with(e);
});
//TODO: work-around to compiler bug generating multiple constant pool entries within records
- if (cm.findAttribute(Attributes.RECORD).isPresent()) {
+ if (cm.findAttribute(Attributes.record()).isPresent()) {
System.err.printf("MassAdaptCopyPrimitiveMatchCodeTest: Ignored because it is a record%n - %s%n", name);
return;
}
diff --git a/test/jdk/jdk/classfile/ModuleBuilderTest.java b/test/jdk/jdk/classfile/ModuleBuilderTest.java
index 68dd16ab03af4..38e2dfef35a79 100644
--- a/test/jdk/jdk/classfile/ModuleBuilderTest.java
+++ b/test/jdk/jdk/classfile/ModuleBuilderTest.java
@@ -89,7 +89,7 @@ public ModuleBuilderTest() {
.with(ModuleMainClassAttribute.of(ClassDesc.of("overwritten.main.Class"))));
moduleModel = cc.parse(modInfo);
attr = ((ModuleAttribute) moduleModel.attributes().stream()
- .filter(a -> a.attributeMapper() == Attributes.MODULE)
+ .filter(a -> a.attributeMapper() == Attributes.module())
.findFirst()
.orElseThrow());
}
@@ -103,7 +103,7 @@ void testCreateModuleInfo() {
// Verify
var cm = cc.parse(modBytes);
- var attr =cm.findAttribute(Attributes.MODULE).get();
+ var attr =cm.findAttribute(Attributes.module()).get();
assertEquals(attr.moduleName().name().stringValue(), modName.name());
assertEquals(attr.moduleFlagsMask(), 0);
assertEquals(attr.moduleVersion().get().stringValue(), modVsn);
@@ -181,13 +181,13 @@ void testVerifyProvides() {
@Test
void verifyPackages() {
- ModulePackagesAttribute a = moduleModel.findAttribute(Attributes.MODULE_PACKAGES).orElseThrow();
+ ModulePackagesAttribute a = moduleModel.findAttribute(Attributes.modulePackages()).orElseThrow();
assertEquals(a.packages().stream().map(pe -> pe.asSymbol().name()).toList(), List.of("foo.bar.baz", "quux"));
}
@Test
void verifyMainclass() {
- ModuleMainClassAttribute a = moduleModel.findAttribute(Attributes.MODULE_MAIN_CLASS).orElseThrow();
+ ModuleMainClassAttribute a = moduleModel.findAttribute(Attributes.moduleMainClass()).orElseThrow();
assertEquals(a.mainClass().asInternalName(), "overwritten/main/Class");
}
diff --git a/test/jdk/jdk/classfile/SignaturesTest.java b/test/jdk/jdk/classfile/SignaturesTest.java
index f4da2405dcd9f..4bba69735da3d 100644
--- a/test/jdk/jdk/classfile/SignaturesTest.java
+++ b/test/jdk/jdk/classfile/SignaturesTest.java
@@ -133,7 +133,7 @@ void testParseAndPrintSignatures() throws Exception {
.filter(p -> Files.isRegularFile(p) && p.toString().endsWith(".class")).forEach(path -> {
try {
var cm = ClassFile.of().parse(path);
- cm.findAttribute(Attributes.SIGNATURE).ifPresent(csig -> {
+ cm.findAttribute(Attributes.signature()).ifPresent(csig -> {
assertEquals(
ClassSignature.parseFrom(csig.signature().stringValue()).signatureString(),
csig.signature().stringValue(),
@@ -141,7 +141,7 @@ void testParseAndPrintSignatures() throws Exception {
csc.incrementAndGet();
});
for (var m : cm.methods()) {
- m.findAttribute(Attributes.SIGNATURE).ifPresent(msig -> {
+ m.findAttribute(Attributes.signature()).ifPresent(msig -> {
assertEquals(
MethodSignature.parseFrom(msig.signature().stringValue()).signatureString(),
msig.signature().stringValue(),
@@ -150,7 +150,7 @@ void testParseAndPrintSignatures() throws Exception {
});
}
for (var f : cm.fields()) {
- f.findAttribute(Attributes.SIGNATURE).ifPresent(fsig -> {
+ f.findAttribute(Attributes.signature()).ifPresent(fsig -> {
assertEquals(
Signature.parseFrom(fsig.signature().stringValue()).signatureString(),
fsig.signature().stringValue(),
@@ -158,8 +158,8 @@ void testParseAndPrintSignatures() throws Exception {
fsc.incrementAndGet();
});
}
- cm.findAttribute(Attributes.RECORD).ifPresent(reca
- -> reca.components().forEach(rc -> rc.findAttribute(Attributes.SIGNATURE).ifPresent(rsig -> {
+ cm.findAttribute(Attributes.record()).ifPresent(reca
+ -> reca.components().forEach(rc -> rc.findAttribute(Attributes.signature()).ifPresent(rsig -> {
assertEquals(
Signature.parseFrom(rsig.signature().stringValue()).signatureString(),
rsig.signature().stringValue(),
@@ -182,7 +182,7 @@ static class Observer extends ArrayList.Inner>{}
@Test
void testClassSignatureClassDesc() throws IOException {
var observerCf = ClassFile.of().parse(Path.of(System.getProperty("test.classes"), "SignaturesTest$Observer.class"));
- var sig = observerCf.findAttribute(Attributes.SIGNATURE).orElseThrow().asClassSignature();
+ var sig = observerCf.findAttribute(Attributes.signature()).orElseThrow().asClassSignature();
var arrayListSig = sig.superclassSignature(); // ArrayList
var arrayListTypeArg = (TypeArg.Bounded) arrayListSig.typeArgs().getFirst(); // Outer.Inner
assertEquals(TypeArg.Bounded.WildcardIndicator.NONE, arrayListTypeArg.wildcardIndicator());
diff --git a/test/jdk/jdk/classfile/TestRecordComponent.java b/test/jdk/jdk/classfile/TestRecordComponent.java
index a4d173e2c679d..95d56ffae8d08 100644
--- a/test/jdk/jdk/classfile/TestRecordComponent.java
+++ b/test/jdk/jdk/classfile/TestRecordComponent.java
@@ -93,7 +93,7 @@ void testChagne() throws Exception {
cb.with(ce);
};
ClassModel newModel = cc.parse(cc.transform(cm, xform));
- RecordAttribute ra = newModel.findAttribute(Attributes.RECORD).orElseThrow();
+ RecordAttribute ra = newModel.findAttribute(Attributes.record()).orElseThrow();
assertEquals(ra.components().size(), 2, "Should have two components");
assertEquals(ra.components().get(0).name().stringValue(), "fooXYZ");
assertEquals(ra.components().get(1).name().stringValue(), "barXYZ");
@@ -110,7 +110,7 @@ void testOptions() throws Exception {
count.addAndGet(rm.components().size());
}});
assertEquals(count.get(), 2);
- assertEquals(cm.findAttribute(Attributes.RECORD).orElseThrow().components().size(), 2);
+ assertEquals(cm.findAttribute(Attributes.record()).orElseThrow().components().size(), 2);
count.set(0);
}
diff --git a/test/jdk/jdk/classfile/examples/AnnotationsExamples.java b/test/jdk/jdk/classfile/examples/AnnotationsExamples.java
index d9c397489654d..846645d93a941 100644
--- a/test/jdk/jdk/classfile/examples/AnnotationsExamples.java
+++ b/test/jdk/jdk/classfile/examples/AnnotationsExamples.java
@@ -54,8 +54,9 @@ public byte[] addAnno(ClassModel m) {
* Find classes with annotations of a certain type
*/
public void findAnnotation(ClassModel m) {
- if (m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).isPresent()) {
- RuntimeVisibleAnnotationsAttribute a = m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).get();
+ var rvaa = m.findAttribute(Attributes.runtimeVisibleAnnotations());
+ if (rvaa.isPresent()) {
+ RuntimeVisibleAnnotationsAttribute a = rvaa.get();
for (Annotation ann : a.annotations()) {
if (ann.className().stringValue().equals("Ljava/lang/FunctionalInterface;"))
System.out.println(m.thisClass().asInternalName());
@@ -68,9 +69,9 @@ public void findAnnotation(ClassModel m) {
*/
public void swapAnnotation(ClassModel m) {
ClassModel m2 = m;
-
- if (m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).isPresent()) {
- RuntimeVisibleAnnotationsAttribute a = m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).get();
+ var rvaa = m.findAttribute(Attributes.runtimeVisibleAnnotations());
+ if (rvaa.isPresent()) {
+ RuntimeVisibleAnnotationsAttribute a = rvaa.get();
var cc = ClassFile.of();
for (Annotation ann : a.annotations()) {
if (ann.className().stringValue().equals("Ljava/lang/annotation/Documented;")) {
@@ -78,9 +79,9 @@ public void swapAnnotation(ClassModel m) {
}
}
}
-
- if (m2.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).isPresent()) {
- RuntimeVisibleAnnotationsAttribute a = m2.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).get();
+ rvaa = m2.findAttribute(Attributes.runtimeVisibleAnnotations());
+ if (rvaa.isPresent()) {
+ RuntimeVisibleAnnotationsAttribute a = rvaa.get();
for (Annotation ann : a.annotations()) {
if (ann.className().stringValue().equals("Ljava/lang/annotation/Documented;"))
throw new RuntimeException();
@@ -112,9 +113,9 @@ public void swapAnnotation(ClassModel m) {
*/
public void addAnnotation(ClassModel m) {
ClassModel m2 = m;
-
- if (m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).isPresent()) {
- RuntimeVisibleAnnotationsAttribute a = m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).get();
+ var rvaa = m.findAttribute(Attributes.runtimeVisibleAnnotations());
+ if (rvaa.isPresent()) {
+ RuntimeVisibleAnnotationsAttribute a = rvaa.get();
var cc = ClassFile.of();
for (Annotation ann : a.annotations()) {
if (ann.className().stringValue().equals("Ljava/lang/FunctionalInterface;")) {
@@ -135,7 +136,7 @@ public void addAnnotation(ClassModel m) {
}
}
- int size = m2.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElseThrow().annotations().size();
+ int size = m2.findAttribute(Attributes.runtimeVisibleAnnotations()).orElseThrow().annotations().size();
if (size !=2) {
StringBuilder sb = new StringBuilder();
ClassPrinter.toJson(m2, ClassPrinter.Verbosity.TRACE_ALL, sb::append);
diff --git a/test/jdk/jdk/classfile/examples/ModuleExamples.java b/test/jdk/jdk/classfile/examples/ModuleExamples.java
index 69e71aaeb5ce6..d4f4ff9a6958f 100644
--- a/test/jdk/jdk/classfile/examples/ModuleExamples.java
+++ b/test/jdk/jdk/classfile/examples/ModuleExamples.java
@@ -54,14 +54,14 @@ public void examineModule() throws IOException {
ClassModel cm = ClassFile.of().parse(JRT.getPath("modules/java.base/module-info.class"));
System.out.println("Is JVMS $4.7 compatible module-info: " + cm.isModuleInfo());
- ModuleAttribute ma = cm.findAttribute(Attributes.MODULE).orElseThrow();
+ ModuleAttribute ma = cm.findAttribute(Attributes.module()).orElseThrow();
System.out.println("Module name: " + ma.moduleName().name().stringValue());
System.out.println("Exports: " + ma.exports());
- ModuleMainClassAttribute mmca = cm.findAttribute(Attributes.MODULE_MAIN_CLASS).orElse(null);
+ ModuleMainClassAttribute mmca = cm.findAttribute(Attributes.moduleMainClass()).orElse(null);
System.out.println("Does the module have a MainClassAttribute?: " + (mmca != null));
- ModulePackagesAttribute mmp = cm.findAttribute(Attributes.MODULE_PACKAGES).orElseThrow();
+ ModulePackagesAttribute mmp = cm.findAttribute(Attributes.modulePackages()).orElseThrow();
System.out.println("Packages?: " + mmp.packages());
}
diff --git a/test/jdk/jdk/classfile/helpers/ClassRecord.java b/test/jdk/jdk/classfile/helpers/ClassRecord.java
index b348a51f23ef3..a62ef1723677f 100644
--- a/test/jdk/jdk/classfile/helpers/ClassRecord.java
+++ b/test/jdk/jdk/classfile/helpers/ClassRecord.java
@@ -243,75 +243,75 @@ public static AttributesRecord ofStreamingElements(Supplier (Attribute>) e)
.collect(toMap(Attribute::attributeName, e -> e));
return new AttributesRecord(
- mapAttr(attrs, ANNOTATION_DEFAULT, a -> ElementValueRecord.ofElementValue(a.defaultValue())),
+ mapAttr(attrs, annotationDefault(), a -> ElementValueRecord.ofElementValue(a.defaultValue())),
cp == null ? null : IntStream.range(0, cp.bootstrapMethodCount()).mapToObj(i -> BootstrapMethodRecord.ofBootstrapMethodEntry(cp.bootstrapMethodEntry(i))).collect(toSetOrNull()),
- mapAttr(attrs, CODE, a -> CodeRecord.ofStreamingElements(a.maxStack(), a.maxLocals(), a.codeLength(), a::elementStream, a, new CodeNormalizerHelper(a.codeArray()), cf)),
- mapAttr(attrs, COMPILATION_ID, a -> a.compilationId().stringValue()),
- mapAttr(attrs, CONSTANT_VALUE, a -> ConstantPoolEntryRecord.ofCPEntry(a.constant())),
- mapAttr(attrs, DEPRECATED, a -> DefinedValue.DEFINED),
- mapAttr(attrs, ENCLOSING_METHOD, a -> EnclosingMethodRecord.ofEnclosingMethodAttribute(a)),
- mapAttr(attrs, EXCEPTIONS, a -> new HashSet<>(a.exceptions().stream().map(e -> e.asInternalName()).toList())),
- mapAttr(attrs, INNER_CLASSES, a -> a.classes().stream().collect(toMap(ic -> ic.innerClass().asInternalName(), ic -> InnerClassRecord.ofInnerClassInfo(ic)))),
- mapAttr(attrs, METHOD_PARAMETERS, a -> a.parameters().stream().map(mp -> MethodParameterRecord.ofMethodParameter(mp)).toList()),
- mapAttr(attrs, MODULE, a -> ModuleRecord.ofModuleAttribute(a)),
- mapAttr(attrs, MODULE_HASHES, a -> ModuleHashesRecord.ofModuleHashesAttribute(a)),
- mapAttr(attrs, MODULE_MAIN_CLASS, a -> a.mainClass().asInternalName()),
- mapAttr(attrs, MODULE_PACKAGES, a -> a.packages().stream().map(p -> p.name().stringValue()).collect(toSet())),
- mapAttr(attrs, MODULE_RESOLUTION, a -> a.resolutionFlags()),
- mapAttr(attrs, MODULE_TARGET, a -> a.targetPlatform().stringValue()),
- mapAttr(attrs, NEST_HOST, a -> a.nestHost().asInternalName()),
- mapAttr(attrs, NEST_MEMBERS, a -> a.nestMembers().stream().map(m -> m.asInternalName()).collect(toSet())),
- mapAttr(attrs, PERMITTED_SUBCLASSES, a -> new HashSet<>(a.permittedSubclasses().stream().map(e -> e.asInternalName()).toList())),
- mapAttr(attrs, RECORD, a -> a.components().stream().map(rc -> RecordComponentRecord.ofRecordComponent(rc, cf)).toList()),
+ mapAttr(attrs, code(), a -> CodeRecord.ofStreamingElements(a.maxStack(), a.maxLocals(), a.codeLength(), a::elementStream, a, new CodeNormalizerHelper(a.codeArray()), cf)),
+ mapAttr(attrs, compilationId(), a -> a.compilationId().stringValue()),
+ mapAttr(attrs, constantValue(), a -> ConstantPoolEntryRecord.ofCPEntry(a.constant())),
+ mapAttr(attrs, Attributes.deprecated(), a -> DefinedValue.DEFINED),
+ mapAttr(attrs, enclosingMethod(), a -> EnclosingMethodRecord.ofEnclosingMethodAttribute(a)),
+ mapAttr(attrs, exceptions(), a -> new HashSet<>(a.exceptions().stream().map(e -> e.asInternalName()).toList())),
+ mapAttr(attrs, innerClasses(), a -> a.classes().stream().collect(toMap(ic -> ic.innerClass().asInternalName(), ic -> InnerClassRecord.ofInnerClassInfo(ic)))),
+ mapAttr(attrs, methodParameters(), a -> a.parameters().stream().map(mp -> MethodParameterRecord.ofMethodParameter(mp)).toList()),
+ mapAttr(attrs, module(), a -> ModuleRecord.ofModuleAttribute(a)),
+ mapAttr(attrs, moduleHashes(), a -> ModuleHashesRecord.ofModuleHashesAttribute(a)),
+ mapAttr(attrs, moduleMainClass(), a -> a.mainClass().asInternalName()),
+ mapAttr(attrs, modulePackages(), a -> a.packages().stream().map(p -> p.name().stringValue()).collect(toSet())),
+ mapAttr(attrs, moduleResolution(), a -> a.resolutionFlags()),
+ mapAttr(attrs, moduleTarget(), a -> a.targetPlatform().stringValue()),
+ mapAttr(attrs, nestHost(), a -> a.nestHost().asInternalName()),
+ mapAttr(attrs, nestMembers(), a -> a.nestMembers().stream().map(m -> m.asInternalName()).collect(toSet())),
+ mapAttr(attrs, permittedSubclasses(), a -> new HashSet<>(a.permittedSubclasses().stream().map(e -> e.asInternalName()).toList())),
+ mapAttr(attrs, record(), a -> a.components().stream().map(rc -> RecordComponentRecord.ofRecordComponent(rc, cf)).toList()),
elements.get().filter(e -> e instanceof RuntimeVisibleAnnotationsAttribute).map(e -> (RuntimeVisibleAnnotationsAttribute) e).flatMap(a -> a.annotations().stream())
.map(AnnotationRecord::ofAnnotation).collect(toSetOrNull()),
elements.get().filter(e -> e instanceof RuntimeInvisibleAnnotationsAttribute).map(e -> (RuntimeInvisibleAnnotationsAttribute) e).flatMap(a -> a.annotations().stream())
.map(AnnotationRecord::ofAnnotation).collect(toSetOrNull()),
- mapAttr(attrs, RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, a -> a.parameterAnnotations().stream().map(list -> list.stream().map(AnnotationRecord::ofAnnotation).collect(toSet())).toList()),
- mapAttr(attrs, RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS, a -> a.parameterAnnotations().stream().map(list -> list.stream().map(AnnotationRecord::ofAnnotation).collect(toSet())).toList()),
- mapAttr(attrs, RUNTIME_VISIBLE_TYPE_ANNOTATIONS, a -> a.annotations().stream().map(TypeAnnotationRecord::ofTypeAnnotation).collect(toSet())),
- mapAttr(attrs, RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, a -> a.annotations().stream().map(TypeAnnotationRecord::ofTypeAnnotation).collect(toSet())),
- mapAttr(attrs, SIGNATURE, a -> a.signature().stringValue()),
- mapAttr(attrs, SOURCE_DEBUG_EXTENSION, a -> new String(a.contents(), StandardCharsets.UTF_8)),
- mapAttr(attrs, SOURCE_FILE, a -> a.sourceFile().stringValue()),
- mapAttr(attrs, SOURCE_ID, a -> a.sourceId().stringValue()),
- mapAttr(attrs, SYNTHETIC, a -> DefinedValue.DEFINED)
+ mapAttr(attrs, runtimeVisibleParameterAnnotations(), a -> a.parameterAnnotations().stream().map(list -> list.stream().map(AnnotationRecord::ofAnnotation).collect(toSet())).toList()),
+ mapAttr(attrs, runtimeInvisibleParameterAnnotations(), a -> a.parameterAnnotations().stream().map(list -> list.stream().map(AnnotationRecord::ofAnnotation).collect(toSet())).toList()),
+ mapAttr(attrs, runtimeVisibleTypeAnnotations(), a -> a.annotations().stream().map(TypeAnnotationRecord::ofTypeAnnotation).collect(toSet())),
+ mapAttr(attrs, runtimeInvisibleTypeAnnotations(), a -> a.annotations().stream().map(TypeAnnotationRecord::ofTypeAnnotation).collect(toSet())),
+ mapAttr(attrs, signature(), a -> a.signature().stringValue()),
+ mapAttr(attrs, sourceDebugExtension(), a -> new String(a.contents(), StandardCharsets.UTF_8)),
+ mapAttr(attrs, sourceFile(), a -> a.sourceFile().stringValue()),
+ mapAttr(attrs, sourceId(), a -> a.sourceId().stringValue()),
+ mapAttr(attrs, synthetic(), a -> DefinedValue.DEFINED)
);
}
public static AttributesRecord ofAttributes(AttributeFinder af, CompatibilityFilter... cf) {
return new AttributesRecord(
- af.findAndMap(Attributes.ANNOTATION_DEFAULT, a -> ElementValueRecord.ofElementValue(a.defaultValue())),
- af.findAndMap(Attributes.BOOTSTRAP_METHODS, a -> a.bootstrapMethods().stream().map(bm -> BootstrapMethodRecord.ofBootstrapMethodEntry(bm)).collect(toSet())),
- af.findAndMap(Attributes.CODE, a -> CodeRecord.ofCodeAttribute(a, cf)),
- af.findAndMap(Attributes.COMPILATION_ID, a -> a.compilationId().stringValue()),
- af.findAndMap(Attributes.CONSTANT_VALUE, a -> ConstantPoolEntryRecord.ofCPEntry(a.constant())),
- af.findAndMap(Attributes.DEPRECATED, a -> DefinedValue.DEFINED),
- af.findAndMap(Attributes.ENCLOSING_METHOD, a -> EnclosingMethodRecord.ofEnclosingMethodAttribute(a)),
- af.findAndMap(Attributes.EXCEPTIONS, a -> a.exceptions().stream().map(e -> e.asInternalName()).collect(toSet())),
- af.findAndMap(Attributes.INNER_CLASSES, a -> a.classes().stream().collect(toMap(ic -> ic.innerClass().asInternalName(), ic -> InnerClassRecord.ofInnerClassInfo(ic)))),
- af.findAndMap(Attributes.METHOD_PARAMETERS, a -> a.parameters().stream().map(mp -> MethodParameterRecord.ofMethodParameter(mp)).toList()),
- af.findAndMap(Attributes.MODULE, a -> ModuleRecord.ofModuleAttribute(a)),
- af.findAndMap(Attributes.MODULE_HASHES, a -> ModuleHashesRecord.ofModuleHashesAttribute(a)),
- af.findAndMap(Attributes.MODULE_MAIN_CLASS, a -> a.mainClass().asInternalName()),
- af.findAndMap(Attributes.MODULE_PACKAGES, a -> a.packages().stream().map(p -> p.name().stringValue()).collect(toSet())),
- af.findAndMap(Attributes.MODULE_RESOLUTION, a -> a.resolutionFlags()),
- af.findAndMap(Attributes.MODULE_TARGET, a -> a.targetPlatform().stringValue()),
- af.findAndMap(Attributes.NEST_HOST, a -> a.nestHost().asInternalName()),
- af.findAndMap(Attributes.NEST_MEMBERS, a -> a.nestMembers().stream().map(m -> m.asInternalName()).collect(toSet())),
- af.findAndMap(Attributes.PERMITTED_SUBCLASSES, a -> a.permittedSubclasses().stream().map(e -> e.asInternalName()).collect(toSet())),
- af.findAndMap(RECORD, a -> a.components().stream().map(rc -> RecordComponentRecord.ofRecordComponent(rc, cf)).toList()),
- af.findAll(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).flatMap(a -> a.annotations().stream()).map(AnnotationRecord::ofAnnotation).collect(toSetOrNull()),
- af.findAll(Attributes.RUNTIME_INVISIBLE_ANNOTATIONS).flatMap(a -> a.annotations().stream()).map(AnnotationRecord::ofAnnotation).collect(toSetOrNull()),
- af.findAndMap(Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, a -> a.parameterAnnotations().stream().map(list -> list.stream().map(AnnotationRecord::ofAnnotation).collect(toSet())).toList()),
- af.findAndMap(Attributes.RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS, a -> a.parameterAnnotations().stream().map(list -> list.stream().map(AnnotationRecord::ofAnnotation).collect(toSet())).toList()),
- af.findAndMap(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, a -> a.annotations().stream().map(TypeAnnotationRecord::ofTypeAnnotation).collect(toSet())),
- af.findAndMap(Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, a -> a.annotations().stream().map(TypeAnnotationRecord::ofTypeAnnotation).collect(toSet())),
- af.findAndMap(Attributes.SIGNATURE, a -> a.signature().stringValue()),
- af.findAndMap(Attributes.SOURCE_DEBUG_EXTENSION, a -> new String(a.contents(), StandardCharsets.UTF_8)),
- af.findAndMap(Attributes.SOURCE_FILE, a -> a.sourceFile().stringValue()),
- af.findAndMap(Attributes.SOURCE_ID, a -> a.sourceId().stringValue()),
- af.findAndMap(Attributes.SYNTHETIC, a -> DefinedValue.DEFINED));
+ af.findAndMap(annotationDefault(), a -> ElementValueRecord.ofElementValue(a.defaultValue())),
+ af.findAndMap(bootstrapMethods(), a -> a.bootstrapMethods().stream().map(bm -> BootstrapMethodRecord.ofBootstrapMethodEntry(bm)).collect(toSet())),
+ af.findAndMap(code(), a -> CodeRecord.ofCodeAttribute(a, cf)),
+ af.findAndMap(compilationId(), a -> a.compilationId().stringValue()),
+ af.findAndMap(constantValue(), a -> ConstantPoolEntryRecord.ofCPEntry(a.constant())),
+ af.findAndMap(Attributes.deprecated(), a -> DefinedValue.DEFINED),
+ af.findAndMap(enclosingMethod(), a -> EnclosingMethodRecord.ofEnclosingMethodAttribute(a)),
+ af.findAndMap(exceptions(), a -> a.exceptions().stream().map(e -> e.asInternalName()).collect(toSet())),
+ af.findAndMap(innerClasses(), a -> a.classes().stream().collect(toMap(ic -> ic.innerClass().asInternalName(), ic -> InnerClassRecord.ofInnerClassInfo(ic)))),
+ af.findAndMap(methodParameters(), a -> a.parameters().stream().map(mp -> MethodParameterRecord.ofMethodParameter(mp)).toList()),
+ af.findAndMap(module(), a -> ModuleRecord.ofModuleAttribute(a)),
+ af.findAndMap(moduleHashes(), a -> ModuleHashesRecord.ofModuleHashesAttribute(a)),
+ af.findAndMap(moduleMainClass(), a -> a.mainClass().asInternalName()),
+ af.findAndMap(modulePackages(), a -> a.packages().stream().map(p -> p.name().stringValue()).collect(toSet())),
+ af.findAndMap(moduleResolution(), a -> a.resolutionFlags()),
+ af.findAndMap(moduleTarget(), a -> a.targetPlatform().stringValue()),
+ af.findAndMap(nestHost(), a -> a.nestHost().asInternalName()),
+ af.findAndMap(nestMembers(), a -> a.nestMembers().stream().map(m -> m.asInternalName()).collect(toSet())),
+ af.findAndMap(permittedSubclasses(), a -> a.permittedSubclasses().stream().map(e -> e.asInternalName()).collect(toSet())),
+ af.findAndMap(record(), a -> a.components().stream().map(rc -> RecordComponentRecord.ofRecordComponent(rc, cf)).toList()),
+ af.findAll(runtimeVisibleAnnotations()).flatMap(a -> a.annotations().stream()).map(AnnotationRecord::ofAnnotation).collect(toSetOrNull()),
+ af.findAll(runtimeInvisibleAnnotations()).flatMap(a -> a.annotations().stream()).map(AnnotationRecord::ofAnnotation).collect(toSetOrNull()),
+ af.findAndMap(runtimeVisibleParameterAnnotations(), a -> a.parameterAnnotations().stream().map(list -> list.stream().map(AnnotationRecord::ofAnnotation).collect(toSet())).toList()),
+ af.findAndMap(runtimeInvisibleParameterAnnotations(), a -> a.parameterAnnotations().stream().map(list -> list.stream().map(AnnotationRecord::ofAnnotation).collect(toSet())).toList()),
+ af.findAndMap(runtimeVisibleTypeAnnotations(), a -> a.annotations().stream().map(TypeAnnotationRecord::ofTypeAnnotation).collect(toSet())),
+ af.findAndMap(runtimeInvisibleTypeAnnotations(), a -> a.annotations().stream().map(TypeAnnotationRecord::ofTypeAnnotation).collect(toSet())),
+ af.findAndMap(signature(), a -> a.signature().stringValue()),
+ af.findAndMap(sourceDebugExtension(), a -> new String(a.contents(), StandardCharsets.UTF_8)),
+ af.findAndMap(sourceFile(), a -> a.sourceFile().stringValue()),
+ af.findAndMap(sourceId(), a -> a.sourceId().stringValue()),
+ af.findAndMap(synthetic(), a -> DefinedValue.DEFINED));
}
}
@@ -353,12 +353,12 @@ static CodeAttributesRecord ofStreamingElements(Supplier a.characterRangeTable().stream()).map(cr -> CharacterRangeRecord.ofCharacterRange(cr, code)).collect(toSetOrNull()),
- af.findAll(Attributes.LINE_NUMBER_TABLE).flatMap(a -> a.lineNumbers().stream()).map(ln -> new LineNumberRecord(ln.lineNumber(), code.targetIndex(ln.startPc()))).collect(toSetOrNull()),
- af.findAll(Attributes.LOCAL_VARIABLE_TABLE).flatMap(a -> a.localVariables().stream()).map(lv -> LocalVariableRecord.ofLocalVariableInfo(lv, code)).collect(toSetOrNull()),
- af.findAll(Attributes.LOCAL_VARIABLE_TYPE_TABLE).flatMap(a -> a.localVariableTypes().stream()).map(lv -> LocalVariableTypeRecord.ofLocalVariableTypeInfo(lv, code)).collect(toSetOrNull()),
- af.findAndMap(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, a -> a.annotations().stream().map(ann -> TypeAnnotationRecord.ofTypeAnnotation(ann, lr, code)).collect(toSet())),
- af.findAndMap(Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, a -> a.annotations().stream().map(ann -> TypeAnnotationRecord.ofTypeAnnotation(ann, lr, code)).collect(toSet())));
+ af.findAll(Attributes.characterRangeTable()).flatMap(a -> a.characterRangeTable().stream()).map(cr -> CharacterRangeRecord.ofCharacterRange(cr, code)).collect(toSetOrNull()),
+ af.findAll(Attributes.lineNumberTable()).flatMap(a -> a.lineNumbers().stream()).map(ln -> new LineNumberRecord(ln.lineNumber(), code.targetIndex(ln.startPc()))).collect(toSetOrNull()),
+ af.findAll(Attributes.localVariableTable()).flatMap(a -> a.localVariables().stream()).map(lv -> LocalVariableRecord.ofLocalVariableInfo(lv, code)).collect(toSetOrNull()),
+ af.findAll(Attributes.localVariableTypeTable()).flatMap(a -> a.localVariableTypes().stream()).map(lv -> LocalVariableTypeRecord.ofLocalVariableTypeInfo(lv, code)).collect(toSetOrNull()),
+ af.findAndMap(Attributes.runtimeVisibleTypeAnnotations(), a -> a.annotations().stream().map(ann -> TypeAnnotationRecord.ofTypeAnnotation(ann, lr, code)).collect(toSet())),
+ af.findAndMap(Attributes.runtimeInvisibleTypeAnnotations(), a -> a.annotations().stream().map(ann -> TypeAnnotationRecord.ofTypeAnnotation(ann, lr, code)).collect(toSet())));
}
}
diff --git a/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java b/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java
index 85fac4940665a..0c9b771c3ef62 100644
--- a/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java
+++ b/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java
@@ -76,7 +76,7 @@ static byte[] transform(ClassModel clm) {
// first pass transforms bound to unbound instructions
cob3.transforming(new CodeRebuildingTransform(), cob4 -> {
com.forEachElement(cob4::with);
- com.findAttribute(Attributes.STACK_MAP_TABLE).ifPresent(cob4::with);
+ com.findAttribute(Attributes.stackMapTable()).ifPresent(cob4::with);
}))));
case AnnotationDefaultAttribute a -> mb.with(AnnotationDefaultAttribute.of(transformAnnotationValue(a.defaultValue())));
case DeprecatedAttribute a -> mb.with(DeprecatedAttribute.of());
diff --git a/test/jdk/jdk/internal/reflect/CallerSensitive/CallerSensitiveFinder.java b/test/jdk/jdk/internal/reflect/CallerSensitive/CallerSensitiveFinder.java
index a313aab255267..2d5175dcf3fd0 100644
--- a/test/jdk/jdk/internal/reflect/CallerSensitive/CallerSensitiveFinder.java
+++ b/test/jdk/jdk/internal/reflect/CallerSensitive/CallerSensitiveFinder.java
@@ -164,7 +164,7 @@ public List run(Stream classes)throws IOException, InterruptedExce
private static final String CALLER_SENSITIVE_ANNOTATION = "Ljdk/internal/reflect/CallerSensitive;";
private static boolean isCallerSensitive(MethodModel m) {
- var attr = m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElse(null);
+ var attr = m.findAttribute(Attributes.runtimeVisibleAnnotations()).orElse(null);
if (attr != null) {
for (var ann : attr.annotations()) {
if (ann.className().equalsString(CALLER_SENSITIVE_ANNOTATION)) {
diff --git a/test/jdk/jdk/internal/reflect/CallerSensitive/CheckCSMs.java b/test/jdk/jdk/internal/reflect/CallerSensitive/CheckCSMs.java
index 0a8a0ccfaea11..6dff95000f075 100644
--- a/test/jdk/jdk/internal/reflect/CallerSensitive/CheckCSMs.java
+++ b/test/jdk/jdk/internal/reflect/CallerSensitive/CheckCSMs.java
@@ -238,7 +238,7 @@ private static boolean csmWithCallerParameter(ClassModel cf, MethodModel csm, Me
private static boolean isCallerSensitive(MethodModel m)
throws IllegalArgumentException
{
- var attr = m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElse(null);
+ var attr = m.findAttribute(Attributes.runtimeVisibleAnnotations()).orElse(null);
if (attr != null) {
for (var ann : attr.annotations()) {
if (ann.className().equalsString(CALLER_SENSITIVE_ANNOTATION)) {
@@ -250,7 +250,7 @@ private static boolean isCallerSensitive(MethodModel m)
}
private static boolean isCallerSensitiveAdapter(MethodModel m) {
- var attr = m.findAttribute(Attributes.RUNTIME_INVISIBLE_ANNOTATIONS).orElse(null);
+ var attr = m.findAttribute(Attributes.runtimeInvisibleAnnotations()).orElse(null);
if (attr != null) {
for (var ann : attr.annotations()) {
diff --git a/test/jdk/tools/jlink/plugins/StripJavaDebugAttributesPluginTest.java b/test/jdk/tools/jlink/plugins/StripJavaDebugAttributesPluginTest.java
index 79a52f5728810..0bcb19e087caf 100644
--- a/test/jdk/tools/jlink/plugins/StripJavaDebugAttributesPluginTest.java
+++ b/test/jdk/tools/jlink/plugins/StripJavaDebugAttributesPluginTest.java
@@ -137,16 +137,16 @@ private > void checkDebugAttributes(byte[] strippedClassF
ClassModel classFile = ClassFile.of().parse(strippedClassFile);
for (MethodModel method : classFile.methods()) {
String methodName = method.methodName().stringValue();
- CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow();
- if (code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElse(null) != null) {
+ CodeAttribute code = method.findAttribute(Attributes.code()).orElseThrow();
+ if (code.findAttribute(Attributes.lineNumberTable()).orElse(null) != null) {
throw new AssertionError("Debug attribute was not removed: " + "LINE_NUMBER_TABLE" +
" from method " + classFile.thisClass().asInternalName() + "#" + methodName);
}
- if (code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE).orElse(null) != null) {
+ if (code.findAttribute(Attributes.localVariableTable()).orElse(null) != null) {
throw new AssertionError("Debug attribute was not removed: " + "LOCAL_VARIABLE_TABLE" +
" from method " + classFile.thisClass().asInternalName() + "#" + methodName);
}
- if (code.findAttribute(Attributes.LOCAL_VARIABLE_TYPE_TABLE).orElse(null) != null) {
+ if (code.findAttribute(Attributes.localVariableTypeTable()).orElse(null) != null) {
throw new AssertionError("Debug attribute was not removed: " + "LOCAL_VARIABLE_TYPE_TABLE" +
" from method " + classFile.thisClass().asInternalName() + "#" + methodName);
}
diff --git a/test/langtools/tools/javac/4241573/T4241573.java b/test/langtools/tools/javac/4241573/T4241573.java
index 93164bad57f2d..9989ff83454ab 100644
--- a/test/langtools/tools/javac/4241573/T4241573.java
+++ b/test/langtools/tools/javac/4241573/T4241573.java
@@ -109,7 +109,7 @@ void verifySourceFileAttribute(File f) {
System.err.println("verify: " + f);
try {
ClassModel cf = ClassFile.of().parse(f.toPath());
- SourceFileAttribute sfa = cf.findAttribute(Attributes.SOURCE_FILE).orElseThrow();
+ SourceFileAttribute sfa = cf.findAttribute(Attributes.sourceFile()).orElseThrow();
String found = sfa.sourceFile().stringValue();
String expect = f.getName().replaceAll("([$.].*)?\\.class", ".java");
if (!expect.equals(found)) {
diff --git a/test/langtools/tools/javac/7003595/T7003595.java b/test/langtools/tools/javac/7003595/T7003595.java
index 94fb0c4b09c6c..c5c12259c14ad 100644
--- a/test/langtools/tools/javac/7003595/T7003595.java
+++ b/test/langtools/tools/javac/7003595/T7003595.java
@@ -163,7 +163,7 @@ void verifyBytecode(JavaSource source) {
throw new Error("Classfile not found: " + filename);
}
- InnerClassesAttribute innerClasses = cf.findAttribute(Attributes.INNER_CLASSES).orElse(null);
+ InnerClassesAttribute innerClasses = cf.findAttribute(Attributes.innerClasses()).orElse(null);
ArrayList foundInnerSig = new ArrayList<>();
if (innerClasses != null) {
diff --git a/test/langtools/tools/javac/8009170/RedundantByteCodeInArrayTest.java b/test/langtools/tools/javac/8009170/RedundantByteCodeInArrayTest.java
index a9821e75ac0f2..8f2ed91039cfd 100644
--- a/test/langtools/tools/javac/8009170/RedundantByteCodeInArrayTest.java
+++ b/test/langtools/tools/javac/8009170/RedundantByteCodeInArrayTest.java
@@ -56,7 +56,7 @@ void checkClassFile(File file)
//lets get all the methods in the class file.
for (MethodModel method : classFile.methods()) {
if (method.methodName().equalsString("arrMethod")) {
- CodeAttribute code = method.findAttribute(Attributes.CODE).orElse(null);
+ CodeAttribute code = method.findAttribute(Attributes.code()).orElse(null);
assert code != null;
if (code.maxLocals() > 4)
throw new AssertionError("Too many locals for method arrMethod");
diff --git a/test/langtools/tools/javac/AnonymousClass/AnonymousClassFlags.java b/test/langtools/tools/javac/AnonymousClass/AnonymousClassFlags.java
index 7769b1caf3226..fb78132e4f104 100644
--- a/test/langtools/tools/javac/AnonymousClass/AnonymousClassFlags.java
+++ b/test/langtools/tools/javac/AnonymousClass/AnonymousClassFlags.java
@@ -125,7 +125,7 @@ static void assertInnerFlags(ClassModel classFile, String name, int expected) {
}
private static int lookupInnerFlags(ClassModel classFile, String innerName) {
- InnerClassesAttribute inners = classFile.findAttribute(Attributes.INNER_CLASSES).orElse(null);
+ InnerClassesAttribute inners = classFile.findAttribute(Attributes.innerClasses()).orElse(null);
if (inners == null) {
throw new AssertionError("InnerClasses attribute missing in class " + classFile.thisClass().asInternalName());
}
diff --git a/test/langtools/tools/javac/MethodParameters/ClassFileVisitor.java b/test/langtools/tools/javac/MethodParameters/ClassFileVisitor.java
index 610256064142a..3e2d151808f2f 100644
--- a/test/langtools/tools/javac/MethodParameters/ClassFileVisitor.java
+++ b/test/langtools/tools/javac/MethodParameters/ClassFileVisitor.java
@@ -95,7 +95,7 @@ void visitClass(final String cname, final File cfile, final StringBuilder sb) th
isStatic = false;
isAnon = false;
- classFile.findAttribute(Attributes.INNER_CLASSES).ifPresent(this::visitInnerClasses);
+ classFile.findAttribute(Attributes.innerClasses()).ifPresent(this::visitInnerClasses);
isAnon = isInner & isAnon;
sb.append(isStatic ? "static " : "")
diff --git a/test/langtools/tools/javac/MethodParameters/LegacyOutputTest/LegacyOutputTest.java b/test/langtools/tools/javac/MethodParameters/LegacyOutputTest/LegacyOutputTest.java
index 3f613be7e82fe..dad79da509e67 100644
--- a/test/langtools/tools/javac/MethodParameters/LegacyOutputTest/LegacyOutputTest.java
+++ b/test/langtools/tools/javac/MethodParameters/LegacyOutputTest/LegacyOutputTest.java
@@ -86,7 +86,7 @@ List getParameterNames(String release) throws Exception {
}
ClassModel classFile = ClassFile.of().parse(Paths.get("Test.class"));
MethodModel method = getMethod(classFile, "f");
- MethodParametersAttribute attribute = method.findAttribute(Attributes.METHOD_PARAMETERS).orElse(null);
+ MethodParametersAttribute attribute = method.findAttribute(Attributes.methodParameters()).orElse(null);
if (attribute == null) {
return null;
}
diff --git a/test/langtools/tools/javac/MethodParametersTest.java b/test/langtools/tools/javac/MethodParametersTest.java
index 5c7a891cdb07a..8ce73671d1fd6 100644
--- a/test/langtools/tools/javac/MethodParametersTest.java
+++ b/test/langtools/tools/javac/MethodParametersTest.java
@@ -175,8 +175,8 @@ void modifyBaz(boolean flip) throws Exception {
if (!baz.methods().get(0).methodName().equalsString(""))
throw new Exception("Classfile Baz badly formed: method has name " +
baz.methods().get(0).methodName().stringValue());
- MethodParametersAttribute mpattr = baz.methods().get(0).findAttribute(Attributes.METHOD_PARAMETERS).orElse(null);
- CodeAttribute cattr = baz.methods().get(0).findAttribute(Attributes.CODE).orElse(null);;
+ MethodParametersAttribute mpattr = baz.methods().get(0).findAttribute(Attributes.methodParameters()).orElse(null);
+ CodeAttribute cattr = baz.methods().get(0).findAttribute(Attributes.code()).orElse(null);;
if (null == mpattr)
throw new Exception("Classfile Baz badly formed: no method parameters info");
if (null == cattr)
diff --git a/test/langtools/tools/javac/RequiredParameterFlags/ImplicitParameters.java b/test/langtools/tools/javac/RequiredParameterFlags/ImplicitParameters.java
index 64db03abdaeb9..0eb4d1b8a42ae 100644
--- a/test/langtools/tools/javac/RequiredParameterFlags/ImplicitParameters.java
+++ b/test/langtools/tools/javac/RequiredParameterFlags/ImplicitParameters.java
@@ -195,7 +195,7 @@ public void testCompactConstructor(ClassModel classFile) {
}
private void checkParameters(MethodModel method, int... parametersFlags) {
- MethodParametersAttribute methodParameters = method.findAttribute(Attributes.METHOD_PARAMETERS).orElseThrow();
+ MethodParametersAttribute methodParameters = method.findAttribute(Attributes.methodParameters()).orElseThrow();
Assert.checkNonNull(methodParameters, "MethodParameters attribute must be present");
List table = methodParameters.parameters();
Assert.check(table.size() == parametersFlags.length, () -> "Expected " + parametersFlags.length
diff --git a/test/langtools/tools/javac/StringConcat/TestIndyStringConcat.java b/test/langtools/tools/javac/StringConcat/TestIndyStringConcat.java
index 72576a7fcb8be..8ec49a17c4d3a 100644
--- a/test/langtools/tools/javac/StringConcat/TestIndyStringConcat.java
+++ b/test/langtools/tools/javac/StringConcat/TestIndyStringConcat.java
@@ -24,13 +24,12 @@
import jdk.test.lib.compiler.CompilerUtils;
import toolbox.ToolBox;
-import java.lang.classfile.Attributes;
import java.lang.classfile.BootstrapMethodEntry;
import java.lang.classfile.ClassFile;
import java.lang.classfile.ClassModel;
import java.lang.classfile.CodeElement;
+import java.lang.classfile.CodeModel;
import java.lang.classfile.MethodModel;
-import java.lang.classfile.attribute.CodeAttribute;
import java.lang.classfile.constantpool.MethodHandleEntry;
import java.lang.classfile.instruction.InvokeDynamicInstruction;
import java.nio.file.Path;
@@ -87,7 +86,7 @@ public static boolean hasStringConcatFactoryCall(Path file, String methodName) t
for (MethodModel method : classFile.methods()) {
if (method.methodName().equalsString(methodName)) {
- CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow();
+ CodeModel code = method.code().orElseThrow();
for (CodeElement i : code.elementList()) {
if (i instanceof InvokeDynamicInstruction indy) {
BootstrapMethodEntry bsmSpec = indy.invokedynamic().bootstrap();
diff --git a/test/langtools/tools/javac/StringConcat/WellKnownTypeSignatures.java b/test/langtools/tools/javac/StringConcat/WellKnownTypeSignatures.java
index 60d54944168dc..174e9721f3fec 100644
--- a/test/langtools/tools/javac/StringConcat/WellKnownTypeSignatures.java
+++ b/test/langtools/tools/javac/StringConcat/WellKnownTypeSignatures.java
@@ -104,7 +104,7 @@ public static void readIndyTypes() throws Exception {
for (MethodModel method : classFile.methods()) {
if (method.methodName().equalsString("main")) {
- CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow();
+ CodeAttribute code = method.findAttribute(Attributes.code()).orElseThrow();
for (CodeElement i : code.elementList()) {
if (i instanceof InvokeDynamicInstruction) {
InvokeDynamicInstruction indy = (InvokeDynamicInstruction) i;
diff --git a/test/langtools/tools/javac/StringConcat/access/Test.java b/test/langtools/tools/javac/StringConcat/access/Test.java
index 93ee3ec7c3f1f..c4aa54618ea70 100644
--- a/test/langtools/tools/javac/StringConcat/access/Test.java
+++ b/test/langtools/tools/javac/StringConcat/access/Test.java
@@ -182,7 +182,7 @@ public static void readIndyTypes() throws Exception {
for (MethodModel method : classFile.methods()) {
if (method.methodName().equalsString("main")) {
- CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow();
+ CodeAttribute code = method.findAttribute(Attributes.code()).orElseThrow();
for (CodeElement i : code.elementList()) {
if (i instanceof InvokeDynamicInstruction) {
InvokeDynamicEntry indyInfo = ((InvokeDynamicInstruction) i).invokedynamic();
diff --git a/test/langtools/tools/javac/T6695379/AnnotationsAreNotCopiedToBridgeMethodsTest.java b/test/langtools/tools/javac/T6695379/AnnotationsAreNotCopiedToBridgeMethodsTest.java
index 53adfe17d18ad..bb486b3238263 100644
--- a/test/langtools/tools/javac/T6695379/AnnotationsAreNotCopiedToBridgeMethodsTest.java
+++ b/test/langtools/tools/javac/T6695379/AnnotationsAreNotCopiedToBridgeMethodsTest.java
@@ -63,9 +63,9 @@ > void checkClassFile(final Path cfilePath) throws Except
ClassModel classFile = ClassFile.of().parse(cfilePath);
for (MethodModel method : classFile.methods()) {
if ((method.flags().flagsMask() & ClassFile.ACC_BRIDGE) != 0) {
- Assert.checkNonNull(method.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS),
+ Assert.checkNonNull(method.findAttribute(Attributes.runtimeVisibleAnnotations()),
"Annotations hasn't been copied to bridge method");
- Assert.checkNonNull(method.findAttribute(Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS),
+ Assert.checkNonNull(method.findAttribute(Attributes.runtimeVisibleParameterAnnotations()),
"Annotations hasn't been copied to bridge method");
}
}
diff --git a/test/langtools/tools/javac/T6970173/DebugPointerAtBadPositionTest.java b/test/langtools/tools/javac/T6970173/DebugPointerAtBadPositionTest.java
index 350d03c8c3bb0..56813905ca563 100644
--- a/test/langtools/tools/javac/T6970173/DebugPointerAtBadPositionTest.java
+++ b/test/langtools/tools/javac/T6970173/DebugPointerAtBadPositionTest.java
@@ -94,8 +94,8 @@ void checkClassFile(final File cfile, String methodToFind) throws Exception {
for (MethodModel m : classFile.methods()) {
if (m.methodName().equalsString(methodToFind)) {
methodFound = true;
- CodeAttribute code = m.findAttribute(Attributes.CODE).orElseThrow();
- LineNumberTableAttribute lnt = code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElseThrow();
+ CodeAttribute code = m.findAttribute(Attributes.code()).orElseThrow();
+ LineNumberTableAttribute lnt = code.findAttribute(Attributes.lineNumberTable()).orElseThrow();
Assert.check(lnt.lineNumbers().size() == expectedLNT.length,
foundLNTLengthDifferentThanExpMsg);
int i = 0;
diff --git a/test/langtools/tools/javac/T7008643/InlinedFinallyConfuseDebuggersTest.java b/test/langtools/tools/javac/T7008643/InlinedFinallyConfuseDebuggersTest.java
index 5f76442471397..839c835c8007c 100644
--- a/test/langtools/tools/javac/T7008643/InlinedFinallyConfuseDebuggersTest.java
+++ b/test/langtools/tools/javac/T7008643/InlinedFinallyConfuseDebuggersTest.java
@@ -101,8 +101,8 @@ void checkClassFile(final File cfile, String methodToFind) throws Exception {
for (MethodModel m : classFile.methods()) {
if (m.methodName().equalsString(methodToFind)) {
methodFound = true;
- CodeAttribute code = m.findAttribute(Attributes.CODE).orElseThrow();
- LineNumberTableAttribute lnt = code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElseThrow();
+ CodeAttribute code = m.findAttribute(Attributes.code()).orElseThrow();
+ LineNumberTableAttribute lnt = code.findAttribute(Attributes.lineNumberTable()).orElseThrow();
Assert.check(lnt.lineNumbers().size() == expectedLNT.length,
"The LineNumberTable found has a length different to the expected one");
int i = 0;
diff --git a/test/langtools/tools/javac/T7053059/DoubleCastTest.java b/test/langtools/tools/javac/T7053059/DoubleCastTest.java
index 84c39a6cb1670..2aaf5d40f39af 100644
--- a/test/langtools/tools/javac/T7053059/DoubleCastTest.java
+++ b/test/langtools/tools/javac/T7053059/DoubleCastTest.java
@@ -68,7 +68,7 @@ public static void main(String... cmdline) throws Exception {
static void check(MethodModel m) throws Exception {
boolean last_is_cast = false;
ClassEntry last_ref = null;
- CodeAttribute ea = m.findAttribute(Attributes.CODE).orElseThrow();
+ CodeAttribute ea = m.findAttribute(Attributes.code()).orElseThrow();
for (int i = 0; i < ea.elementList().size(); ++i) {
CodeElement ce = ea.elementList().get(i);
if (ce instanceof TypeCheckInstruction ins && ins.opcode() == Opcode.CHECKCAST) {
diff --git a/test/langtools/tools/javac/T7093325.java b/test/langtools/tools/javac/T7093325.java
index 948d775c578e7..0a8fac0692b01 100644
--- a/test/langtools/tools/javac/T7093325.java
+++ b/test/langtools/tools/javac/T7093325.java
@@ -167,7 +167,7 @@ void verifyBytecode(Result> result) {
return;
}
- CodeAttribute code = test_method.findAttribute(Attributes.CODE).orElse(null);
+ CodeAttribute code = test_method.findAttribute(Attributes.code()).orElse(null);
if (code == null) {
fail("Code attribute not found in method test()");
diff --git a/test/langtools/tools/javac/T7165659/InnerClassAttrMustNotHaveStrictFPFlagTest.java b/test/langtools/tools/javac/T7165659/InnerClassAttrMustNotHaveStrictFPFlagTest.java
index fc4aae5a0ae46..d7b823d94ec2f 100644
--- a/test/langtools/tools/javac/T7165659/InnerClassAttrMustNotHaveStrictFPFlagTest.java
+++ b/test/langtools/tools/javac/T7165659/InnerClassAttrMustNotHaveStrictFPFlagTest.java
@@ -48,7 +48,7 @@ private void run() throws Exception {
void analyzeClassFile(File path) throws Exception {
ClassModel classFile = ClassFile.of().parse(path.toPath());
- InnerClassesAttribute innerClasses = classFile.findAttribute(Attributes.INNER_CLASSES).orElse(null);
+ InnerClassesAttribute innerClasses = classFile.findAttribute(Attributes.innerClasses()).orElse(null);
assert innerClasses != null;
for (InnerClassInfo classInfo : innerClasses.classes()) {
Assert.check(classInfo.flagsMask() != ClassFile.ACC_STRICT,
diff --git a/test/langtools/tools/javac/T8019486/WrongLNTForLambdaTest.java b/test/langtools/tools/javac/T8019486/WrongLNTForLambdaTest.java
index 7c334d35f7c92..24c9b81c96471 100644
--- a/test/langtools/tools/javac/T8019486/WrongLNTForLambdaTest.java
+++ b/test/langtools/tools/javac/T8019486/WrongLNTForLambdaTest.java
@@ -163,8 +163,8 @@ void checkClassFile(final File cfile, String methodToFind, int[][] expectedLNT)
for (MethodModel method : classFile.methods()) {
if (method.methodName().equalsString(methodToFind)) {
methodFound = true;
- CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow();
- LineNumberTableAttribute lnt = code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElseThrow();
+ CodeAttribute code = method.findAttribute(Attributes.code()).orElseThrow();
+ LineNumberTableAttribute lnt = code.findAttribute(Attributes.lineNumberTable()).orElseThrow();
Assert.check(lnt.lineNumbers().size() == expectedLNT.length,
"The LineNumberTable found has a length different to the expected one");
int i = 0;
diff --git a/test/langtools/tools/javac/T8022186/DeadCodeGeneratedForEmptyTryTest.java b/test/langtools/tools/javac/T8022186/DeadCodeGeneratedForEmptyTryTest.java
index d3b6851f87bac..8dd87820423ac 100644
--- a/test/langtools/tools/javac/T8022186/DeadCodeGeneratedForEmptyTryTest.java
+++ b/test/langtools/tools/javac/T8022186/DeadCodeGeneratedForEmptyTryTest.java
@@ -64,7 +64,7 @@ void checkClassFile(final Path path) throws Exception {
constantPool = classFile.constantPool();
for (MethodModel method: classFile.methods()) {
if (method.methodName().equalsString("methodToLookFor")) {
- CodeAttribute codeAtt = method.findAttribute(Attributes.CODE).orElseThrow();
+ CodeAttribute codeAtt = method.findAttribute(Attributes.code()).orElseThrow();
codeAtt.elementList().stream()
.filter(ce -> ce instanceof Instruction)
.forEach(ins -> checkIndirectRefToString((Instruction) ins));
diff --git a/test/langtools/tools/javac/T8024039/NoDeadCodeGenerationOnTrySmtTest.java b/test/langtools/tools/javac/T8024039/NoDeadCodeGenerationOnTrySmtTest.java
index 27d01bbf27b49..36afea59094fb 100644
--- a/test/langtools/tools/javac/T8024039/NoDeadCodeGenerationOnTrySmtTest.java
+++ b/test/langtools/tools/javac/T8024039/NoDeadCodeGenerationOnTrySmtTest.java
@@ -106,7 +106,7 @@ void checkClassFile(final File cfile, String[] methodsToFind) throws Exception {
for (MethodModel m : classFile.methods()) {
if (m.methodName().equalsString(methodToFind)) {
numberOfmethodsFound++;
- CodeAttribute code = m.findAttribute(Attributes.CODE).orElseThrow();
+ CodeAttribute code = m.findAttribute(Attributes.code()).orElseThrow();
Assert.check(code.exceptionHandlers().size() == expectedExceptionTable.length,
"The ExceptionTable found has a length different to the expected one");
int i = 0;
diff --git a/test/langtools/tools/javac/T8028504/DontGenerateLVTForGNoneOpTest.java b/test/langtools/tools/javac/T8028504/DontGenerateLVTForGNoneOpTest.java
index 90352ba6702b3..150b0fc8c7cbc 100644
--- a/test/langtools/tools/javac/T8028504/DontGenerateLVTForGNoneOpTest.java
+++ b/test/langtools/tools/javac/T8028504/DontGenerateLVTForGNoneOpTest.java
@@ -52,9 +52,9 @@ void run() throws Exception {
void checkClassFile(final File cfile) throws Exception {
ClassModel classFile = ClassFile.of().parse(cfile.toPath());
for (MethodModel method : classFile.methods()) {
- CodeAttribute code = method.findAttribute(Attributes.CODE).orElse(null);
+ CodeAttribute code = method.findAttribute(Attributes.code()).orElse(null);
if (code != null) {
- if (code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE).orElse(null) != null) {
+ if (code.findAttribute(Attributes.localVariableTable()).orElse(null) != null) {
throw new AssertionError("LVT shouldn't be generated for g:none");
}
}
diff --git a/test/langtools/tools/javac/T8180141/MissingLNTEntryForBreakContinueTest.java b/test/langtools/tools/javac/T8180141/MissingLNTEntryForBreakContinueTest.java
index 5ca65bf9ad871..1a095ab5301e6 100644
--- a/test/langtools/tools/javac/T8180141/MissingLNTEntryForBreakContinueTest.java
+++ b/test/langtools/tools/javac/T8180141/MissingLNTEntryForBreakContinueTest.java
@@ -92,8 +92,8 @@ void testFor(String id, String statement) throws Throwable {
ClassModel classFile = ClassFile.of().parse(file.toPath());
for (MethodModel m : classFile.methods()) {
if (m.methodName().equalsString("foo")) {
- CodeAttribute code = m.findAttribute(Attributes.CODE).orElseThrow();
- LineNumberTableAttribute lnt = code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElseThrow();
+ CodeAttribute code = m.findAttribute(Attributes.code()).orElseThrow();
+ LineNumberTableAttribute lnt = code.findAttribute(Attributes.lineNumberTable()).orElseThrow();
checkLNT(lnt, MyAttr.lineNumber);
}
}
diff --git a/test/langtools/tools/javac/T8180660/MissingLNTEntryForFinalizerTest.java b/test/langtools/tools/javac/T8180660/MissingLNTEntryForFinalizerTest.java
index 504057ed7be7a..1cd9ee211e0e1 100644
--- a/test/langtools/tools/javac/T8180660/MissingLNTEntryForFinalizerTest.java
+++ b/test/langtools/tools/javac/T8180660/MissingLNTEntryForFinalizerTest.java
@@ -88,8 +88,8 @@ void test() throws Throwable {
ClassModel classFile = ClassFile.of().parse(file.toPath());
for (MethodModel m : classFile.methods()) {
if (m.methodName().equalsString("foo")) {
- CodeAttribute code = m.findAttribute(Attributes.CODE).orElseThrow();
- LineNumberTableAttribute lnt = code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElseThrow();
+ CodeAttribute code = m.findAttribute(Attributes.code()).orElseThrow();
+ LineNumberTableAttribute lnt = code.findAttribute(Attributes.lineNumberTable()).orElseThrow();
checkLNT(lnt, MyAttr.lineNumber);
}
}
diff --git a/test/langtools/tools/javac/T8210435/NoLocalsMustBeReservedForDCEedVarsTest.java b/test/langtools/tools/javac/T8210435/NoLocalsMustBeReservedForDCEedVarsTest.java
index 69819dd845ef3..35ccb627b4402 100644
--- a/test/langtools/tools/javac/T8210435/NoLocalsMustBeReservedForDCEedVarsTest.java
+++ b/test/langtools/tools/javac/T8210435/NoLocalsMustBeReservedForDCEedVarsTest.java
@@ -68,7 +68,7 @@ void run() throws Exception {
ClassModel classFile = ClassFile.of().parse(cfile.toPath());
for (MethodModel method: classFile.methods()) {
if (method.methodName().stringValue().equals("foo")) {
- CodeAttribute codeAttr = method.findAttribute(Attributes.CODE).orElse(null);
+ CodeAttribute codeAttr = method.findAttribute(Attributes.code()).orElse(null);
assert codeAttr != null;
Assert.check(codeAttr.maxLocals() == 0, "max locals found " + codeAttr.maxLocals());
}
diff --git a/test/langtools/tools/javac/T8222949/TestConstantDynamic.java b/test/langtools/tools/javac/T8222949/TestConstantDynamic.java
index 79e1fbb047ff0..d6f728eda5a3b 100644
--- a/test/langtools/tools/javac/T8222949/TestConstantDynamic.java
+++ b/test/langtools/tools/javac/T8222949/TestConstantDynamic.java
@@ -186,7 +186,7 @@ void verifyBytecode(Result> res) {
fail("Test method not found");
return;
}
- CodeAttribute ea = testMethod.findAttribute(Attributes.CODE).orElse(null);
+ CodeAttribute ea = testMethod.findAttribute(Attributes.code()).orElse(null);
if (ea == null) {
fail("Code attribute for test() method not found");
return;
@@ -216,7 +216,7 @@ void verifyBytecode(Result> res) {
return;
}
- BootstrapMethodsAttribute bsm_attr = cf.findAttribute(Attributes.BOOTSTRAP_METHODS).orElseThrow();
+ BootstrapMethodsAttribute bsm_attr = cf.findAttribute(Attributes.bootstrapMethods()).orElseThrow();
if (bsm_attr.bootstrapMethods().size() != 1) {
fail("Bad number of method specifiers " +
"in BootstrapMethods attribute");
@@ -251,7 +251,7 @@ void verifyBytecode(Result> res) {
return;
}
- LineNumberTableAttribute lnt = ea.findAttribute(Attributes.LINE_NUMBER_TABLE).orElse(null);
+ LineNumberTableAttribute lnt = ea.findAttribute(Attributes.lineNumberTable()).orElse(null);
if (lnt == null) {
fail("No LineNumberTable attribute");
diff --git a/test/langtools/tools/javac/TryWithResources/TwrSimpleClose.java b/test/langtools/tools/javac/TryWithResources/TwrSimpleClose.java
index 45e30cd451678..4c1e3a4827518 100644
--- a/test/langtools/tools/javac/TryWithResources/TwrSimpleClose.java
+++ b/test/langtools/tools/javac/TryWithResources/TwrSimpleClose.java
@@ -101,7 +101,7 @@ void run(String trySpec, int expectedCloseCount) throws Exception {
ClassModel cf = ClassFile.of().parse(new ByteArrayInputStream(data).readAllBytes());
for (MethodModel m : cf.methods()) {
- CodeAttribute codeAttr = m.findAttribute(Attributes.CODE).orElseThrow();
+ CodeAttribute codeAttr = m.findAttribute(Attributes.code()).orElseThrow();
for (CodeElement ce : codeAttr.elementList()) {
if (ce instanceof InvokeInstruction ins && ins.opcode() == Opcode.INVOKEVIRTUAL) {
MemberRefEntry method = ins.method();
diff --git a/test/langtools/tools/javac/annotations/ApplicableAnnotationsOnRecords.java b/test/langtools/tools/javac/annotations/ApplicableAnnotationsOnRecords.java
index 30d8a579b40ce..0bc65af8aa165 100644
--- a/test/langtools/tools/javac/annotations/ApplicableAnnotationsOnRecords.java
+++ b/test/langtools/tools/javac/annotations/ApplicableAnnotationsOnRecords.java
@@ -63,21 +63,21 @@ public static void main(String... args) throws Exception {
if (methodName.equals("toString") || methodName.equals("hashCode") || methodName.equals("equals") || methodName.equals("main")) {
// ignore
} else if (methodName.equals("")) {
- var paAnnos = mm.findAttribute(Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS).orElseThrow().parameterAnnotations();
+ var paAnnos = mm.findAttribute(Attributes.runtimeVisibleParameterAnnotations()).orElseThrow().parameterAnnotations();
Assert.check(paAnnos.size() > 0);
for (var pa : paAnnos) {
Assert.check(pa.size() == 1);
Assert.check(Objects.equals(pa.get(0).classSymbol().descriptorString(), "LParameterAnnotation;"));
}
} else {
- var annos = mm.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElseThrow().annotations();
+ var annos = mm.findAttribute(Attributes.runtimeVisibleAnnotations()).orElseThrow().annotations();
Assert.check(annos.size() == 1);
Assert.check(Objects.equals(annos.get(0).classSymbol().descriptorString(), "LMethodAnnotation;"));
}
}
Assert.check(cm.fields().size() > 0);
for (FieldModel fm : cm.fields()) {
- var annos = fm.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElseThrow().annotations();
+ var annos = fm.findAttribute(Attributes.runtimeVisibleAnnotations()).orElseThrow().annotations();
Assert.check(annos.size() == 1);
Assert.check(Objects.equals(annos.getFirst().classSymbol().descriptorString(), "LFieldAnnotation;"));
}
diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/TypeAnnotationsPositionsOnRecords.java b/test/langtools/tools/javac/annotations/typeAnnotations/TypeAnnotationsPositionsOnRecords.java
index 2f6ac3a47172e..6d2aabaee80c6 100644
--- a/test/langtools/tools/javac/annotations/typeAnnotations/TypeAnnotationsPositionsOnRecords.java
+++ b/test/langtools/tools/javac/annotations/typeAnnotations/TypeAnnotationsPositionsOnRecords.java
@@ -197,15 +197,15 @@ void checkFields(ClassModel classFile, int... positions) {
// utility methods
void findAnnotations(ClassModel cm, AttributedElement m, List annos) {
- findAnnotations(cm, m, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, annos);
- findAnnotations(cm, m, Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, annos);
+ findAnnotations(cm, m, Attributes.runtimeVisibleTypeAnnotations(), annos);
+ findAnnotations(cm, m, Attributes.runtimeInvisibleTypeAnnotations(), annos);
}
> void findAnnotations(ClassModel cf, AttributedElement m, AttributeMapper attrName, List annos) {
Attribute attr = m.findAttribute(attrName).orElse(null);
addAnnos(annos, attr);
if (m instanceof MethodModel) {
- CodeAttribute cattr = m.findAttribute(Attributes.CODE).orElse(null);
+ CodeAttribute cattr = m.findAttribute(Attributes.code()).orElse(null);
if (cattr != null) {
attr = cattr.findAttribute(attrName).orElse(null);
addAnnos(annos, attr);
diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/VariablesDeclaredWithVarTest.java b/test/langtools/tools/javac/annotations/typeAnnotations/VariablesDeclaredWithVarTest.java
index ffd45ddfca41c..7384f4bd5d733 100644
--- a/test/langtools/tools/javac/annotations/typeAnnotations/VariablesDeclaredWithVarTest.java
+++ b/test/langtools/tools/javac/annotations/typeAnnotations/VariablesDeclaredWithVarTest.java
@@ -110,15 +110,15 @@ void checkClassFile(final File cfile, int... taPositions) throws Exception {
}
void findAnnotations(ClassModel cf, MethodModel m, List annos) {
- findAnnotations(cf, m, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, annos);
- findAnnotations(cf, m, Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, annos);
+ findAnnotations(cf, m, Attributes.runtimeVisibleTypeAnnotations(), annos);
+ findAnnotations(cf, m, Attributes.runtimeInvisibleTypeAnnotations(), annos);
}
> void findAnnotations(ClassModel cf, AttributedElement m, AttributeMapper attrName, List annos) {
Attribute attr = m.findAttribute(attrName).orElse(null);
addAnnos(annos, attr);
if (m instanceof MethodModel) {
- CodeAttribute cattr = m.findAttribute(Attributes.CODE).orElse(null);
+ CodeAttribute cattr = m.findAttribute(Attributes.code()).orElse(null);
if (cattr != null) {
attr = cattr.findAttribute(attrName).orElse(null);
addAnnos(annos, attr);
diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/AnonymousClassTest.java b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/AnonymousClassTest.java
index bf2bfd2a370f5..64c33ed9fd94c 100644
--- a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/AnonymousClassTest.java
+++ b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/AnonymousClassTest.java
@@ -100,7 +100,7 @@ public static void main(String args[]) throws Exception {
static void testAnonymousClassDeclaration() throws Exception {
ClassModel cm = ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest$1.class"));
RuntimeVisibleTypeAnnotationsAttribute rvta =
- cm.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).orElse(null);
+ cm.findAttribute(Attributes.runtimeVisibleTypeAnnotations()).orElse(null);
assert rvta != null;
assertEquals(
Set.of(
@@ -115,7 +115,7 @@ static void testTopLevelMethod() throws Exception {
ClassModel cm = ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest.class"));
MethodModel method = findMethod(cm, "f");
Set annotations = getRuntimeVisibleTypeAnnotations(method);
- CodeAttribute cAttr = method.findAttribute(Attributes.CODE).orElse(null);
+ CodeAttribute cAttr = method.findAttribute(Attributes.code()).orElse(null);
assertEquals(
Set.of("@LAnonymousClassTest$TA;(0) NEW, offset=0, location=[INNER_TYPE]"),
annotations.stream().map(a -> annotationDebugString(cm, cAttr, a)).collect(toSet()));
@@ -126,7 +126,7 @@ static void testInnerClassMethod() throws Exception {
ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest$Inner.class"));
MethodModel method = findMethod(cm, "g");
Set annotations = getRuntimeVisibleTypeAnnotations(method);
- CodeAttribute cAttr = method.findAttribute(Attributes.CODE).orElse(null);
+ CodeAttribute cAttr = method.findAttribute(Attributes.code()).orElse(null);
// The annotation needs two INNER_TYPE type path entries to apply to
// AnonymousClassTest$Inner$1.
assertEquals(
@@ -141,7 +141,7 @@ static void testQualifiedSuperType() throws Exception {
ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest.class"));
MethodModel method = findMethod(cm, "g");
Set annotations = getRuntimeVisibleTypeAnnotations(method);
- CodeAttribute cAttr = method.findAttribute(Attributes.CODE).orElse(null);
+ CodeAttribute cAttr = method.findAttribute(Attributes.code()).orElse(null);
// Only @TA(4) is propagated to the anonymous class declaration.
assertEquals(
Set.of("@LAnonymousClassTest$TA;(4) NEW, offset=0, location=[INNER_TYPE]"),
@@ -152,7 +152,7 @@ static void testQualifiedSuperType() throws Exception {
ClassModel cm =
ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest$2.class"));
RuntimeVisibleTypeAnnotationsAttribute rvta =
- cm.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).orElse(null);
+ cm.findAttribute(Attributes.runtimeVisibleTypeAnnotations()).orElse(null);
assert rvta != null;
assertEquals(
Set.of(
@@ -168,14 +168,14 @@ static void testInstanceAndClassInit() throws Exception {
ClassModel cm = ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest.class"));
MethodModel method = findMethod(cm, "");
Set annotations = getRuntimeVisibleTypeAnnotations(method);
- CodeAttribute cAttr1 = method.findAttribute(Attributes.CODE).orElse(null);
+ CodeAttribute cAttr1 = method.findAttribute(Attributes.code()).orElse(null);
assertEquals(
Set.of("@LAnonymousClassTest$TA;(5) NEW, offset=4, location=[INNER_TYPE]"),
annotations.stream().map(a -> annotationDebugString(cm, cAttr1, a)).collect(toSet()) );
method = findMethod(cm, "");
annotations = getRuntimeVisibleTypeAnnotations(method);
- CodeAttribute cAttr2 = method.findAttribute(Attributes.CODE).orElse(null);
+ CodeAttribute cAttr2 = method.findAttribute(Attributes.code()).orElse(null);
assertEquals(
Set.of("@LAnonymousClassTest$TA;(6) NEW, offset=16, location=[INNER_TYPE]"),
annotations.stream().map(a -> annotationDebugString(cm, cAttr2, a)).collect(toSet()) );
@@ -184,14 +184,14 @@ static void testInstanceAndClassInit() throws Exception {
// Returns the Method's RuntimeVisibleTypeAnnotations, and asserts that there are no RVTIs
// erroneously associated with the Method instead of its Code attribute.
private static Set getRuntimeVisibleTypeAnnotations(MethodModel method) {
- if (method.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).orElse(null) != null) {
+ if (method.findAttribute(Attributes.runtimeVisibleTypeAnnotations()).orElse(null) != null) {
throw new AssertionError(
"expected no RuntimeVisibleTypeAnnotations attribute on enclosing method");
}
- CodeAttribute code = method.findAttribute(Attributes.CODE).orElse(null);
+ CodeAttribute code = method.findAttribute(Attributes.code()).orElse(null);
assert code != null;
RuntimeVisibleTypeAnnotationsAttribute rvta =
- code.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).orElse(null);
+ code.findAttribute(Attributes.runtimeVisibleTypeAnnotations()).orElse(null);
assert rvta != null;
return new HashSet<>(rvta.annotations());
}
diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java
index 4926e15b25845..11abffa8c9186 100644
--- a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java
+++ b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java
@@ -88,10 +88,10 @@ void test(MethodModel mm ) {
// 'local' determines whether to look for annotations in code attribute or not.
void test(AttributedElement m, Boolean local) {
- test(m, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, local);
- test(m, Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, local);
- test(m, Attributes.RUNTIME_VISIBLE_ANNOTATIONS, local);
- test(m, Attributes.RUNTIME_INVISIBLE_ANNOTATIONS, local);
+ test(m, Attributes.runtimeVisibleTypeAnnotations(), local);
+ test(m, Attributes.runtimeInvisibleTypeAnnotations(), local);
+ test(m, Attributes.runtimeVisibleAnnotations(), local);
+ test(m, Attributes.runtimeInvisibleAnnotations(), local);
}
// Test the result of MethodModel.findAttribute according to expectations
@@ -164,7 +164,7 @@ > Attribute extractAnnotation(AttributedElement m, Att
CodeAttribute cAttr;
Attribute attr = null;
if (local) {
- cAttr = m.findAttribute(Attributes.CODE).orElse(null);
+ cAttr = m.findAttribute(Attributes.code()).orElse(null);
if (cAttr != null) {
attr = cAttr.findAttribute(annName).orElse(null);
}
diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/NoTargetAnnotations.java b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/NoTargetAnnotations.java
index 13082ba9dad9d..ffab642c1d59c 100644
--- a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/NoTargetAnnotations.java
+++ b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/NoTargetAnnotations.java
@@ -71,8 +71,8 @@ ClassModel getClassFile(String name) throws IOException {
void testDeclaration(AttributedElement m) {
- testDecl(m, Attributes.RUNTIME_VISIBLE_ANNOTATIONS);
- testDecl(m, Attributes.RUNTIME_INVISIBLE_ANNOTATIONS);
+ testDecl(m, Attributes.runtimeVisibleAnnotations());
+ testDecl(m, Attributes.runtimeInvisibleAnnotations());
}
// test the result of AttributedElement.findAttribute according to expectations
diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TestAnonInnerClasses.java b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TestAnonInnerClasses.java
index 59ed653927bd1..fc232d06b6457 100644
--- a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TestAnonInnerClasses.java
+++ b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TestAnonInnerClasses.java
@@ -63,10 +63,10 @@ public class TestAnonInnerClasses extends ClassfileTestHelper {
File testSrc = new File(System.getProperty("test.src"));
AttributeMapper> [] AnnoAttributes = new AttributeMapper>[]{
- Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS,
- Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS,
- Attributes.RUNTIME_VISIBLE_ANNOTATIONS,
- Attributes.RUNTIME_INVISIBLE_ANNOTATIONS
+ Attributes.runtimeVisibleTypeAnnotations(),
+ Attributes.runtimeInvisibleTypeAnnotations(),
+ Attributes.runtimeVisibleAnnotations(),
+ Attributes.runtimeInvisibleAnnotations()
};
// template for source files
@@ -175,7 +175,7 @@ > void test(AttributedElement m) {
((MethodModel) m).methodName().stringValue() : ((FieldModel) m).fieldName().stringValue();
attr = m.findAttribute(AnnoType).orElse(null);
//fetch index annotations from code attribute.
- CAttr = m.findAttribute(Attributes.CODE).orElse(null);
+ CAttr = m.findAttribute(Attributes.code()).orElse(null);
if (CAttr != null) {
cattr = CAttr.findAttribute(AnnoType).orElse(null);
}
diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TestNewCastArray.java b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TestNewCastArray.java
index 741747a9b4cd0..048c1836664ab 100644
--- a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TestNewCastArray.java
+++ b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TestNewCastArray.java
@@ -88,7 +88,7 @@ > void test(String clazz, AttributedElement m, AttributeM
memberName = mm.methodName().stringValue();
if(codeattr) {
//fetch index of and code attribute and annotations from code attribute.
- cAttr = mm.findAttribute(Attributes.CODE).orElse(null);
+ cAttr = mm.findAttribute(Attributes.code()).orElse(null);
if(cAttr != null) {
attr = cAttr.findAttribute(name).orElse(null);
}
@@ -99,7 +99,7 @@ > void test(String clazz, AttributedElement m, AttributeM
case FieldModel fm -> {
memberName = fm.fieldName().stringValue();
if(codeattr) {
- cAttr = fm.findAttribute(Attributes.CODE).orElse(null);
+ cAttr = fm.findAttribute(Attributes.code()).orElse(null);
if(cAttr != null) {
attr = cAttr.findAttribute(name).orElse(null);
}
@@ -207,14 +207,14 @@ public void run() {
assert cm != null;
if(clazz.startsWith("Test1")) {
for (FieldModel fm: cm.fields())
- test(clazz, fm, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, false);
+ test(clazz, fm, Attributes.runtimeVisibleTypeAnnotations(), false);
for (MethodModel mm: cm.methods())
- test(clazz, mm, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, false);
+ test(clazz, mm, Attributes.runtimeVisibleTypeAnnotations(), false);
} else {
for (FieldModel fm: cm.fields())
- test(clazz, fm, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, true);
+ test(clazz, fm, Attributes.runtimeVisibleTypeAnnotations(), true);
for (MethodModel mm: cm.methods())
- test(clazz, mm, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, true);
+ test(clazz, mm, Attributes.runtimeVisibleTypeAnnotations(), true);
}
}
report();
diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TypeAnnotationPropagationTest.java b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TypeAnnotationPropagationTest.java
index ae92d7aae0446..9f7873bb2c0b7 100644
--- a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TypeAnnotationPropagationTest.java
+++ b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TypeAnnotationPropagationTest.java
@@ -58,9 +58,9 @@ public void run() throws Exception {
}
assert f != null;
- CodeAttribute cattr = f.findAttribute(Attributes.CODE).orElse(null);
+ CodeAttribute cattr = f.findAttribute(Attributes.code()).orElse(null);
assert cattr != null;
- RuntimeVisibleTypeAnnotationsAttribute attr = cattr.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).orElse(null);
+ RuntimeVisibleTypeAnnotationsAttribute attr = cattr.findAttribute(Attributes.runtimeVisibleTypeAnnotations()).orElse(null);
assert attr != null;
List annosPosition = ((TypeAnnotation.LocalVarTarget) attr.annotations().get(0).targetInfo()).table();
diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java b/test/langtools/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java
index 7e35a081de71d..e2e69a01a491c 100644
--- a/test/langtools/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java
+++ b/test/langtools/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java
@@ -37,8 +37,8 @@ public static List extendedAnnotationsOf(ClassModel cm) {
/////////////////// Extract type annotations //////////////////
private static void findAnnotations(ClassModel cm, List annos) {
- findAnnotations(cm, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, annos);
- findAnnotations(cm, Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, annos);
+ findAnnotations(cm, Attributes.runtimeVisibleTypeAnnotations(), annos);
+ findAnnotations(cm, Attributes.runtimeInvisibleTypeAnnotations(), annos);
for (FieldModel f : cm.fields()) {
findAnnotations(f, annos);
@@ -49,8 +49,8 @@ private static void findAnnotations(ClassModel cm, List