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..4d0c3773ba148 100644 --- a/src/java.base/share/classes/java/lang/classfile/Attributes.java +++ b/src/java.base/share/classes/java/lang/classfile/Attributes.java @@ -207,778 +207,1208 @@ 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; + } + + private static final class AnnotationDefaultMapper extends AbstractAttributeMapper { + private static AnnotationDefaultMapper INSTANCE = new AnnotationDefaultMapper(); + + private AnnotationDefaultMapper() { + super(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; + } + }; + /** + * {@return Attribute mapper for the {@code BootstrapMethods} attribute} + * @since 23 + */ + public static AttributeMapper bootstrapMethods() { + return BootstrapMethodsMapper.INSTANCE; + } + + private static final class BootstrapMethodsMapper extends AbstractAttributeMapper { + private static BootstrapMethodsMapper INSTANCE = new BootstrapMethodsMapper(); + + private BootstrapMethodsMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code CharacterRangeTable} attribute} + * @since 23 + */ + public static AttributeMapper characterRangeTable() { + return CharacterRangeTableMapper.INSTANCE; + } + + private static final class CharacterRangeTableMapper extends AbstractAttributeMapper { + private static CharacterRangeTableMapper INSTANCE = new CharacterRangeTableMapper(); + + private CharacterRangeTableMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code Code} attribute} + * @since 23 + */ + public static AttributeMapper code() { + return CodeMapper.INSTANCE; + } + + private static final class CodeMapper extends AbstractAttributeMapper { + private static CodeMapper INSTANCE = new CodeMapper(); + + private CodeMapper() { + super(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; + } + } + + + /** + * {@return Attribute mapper for the {@code CompilationID} attribute} + * @since 23 + */ + public static AttributeMapper compilationId() { + return CompilationIDMapper.INSTANCE; + } + + private static final class CompilationIDMapper extends AbstractAttributeMapper { + private static CompilationIDMapper INSTANCE = new CompilationIDMapper(); + + private CompilationIDMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code ConstantValue} attribute} + * @since 23 + */ + public static AttributeMapper constantValue() { + return ConstantValueMapper.INSTANCE; + } + + private static final class ConstantValueMapper extends AbstractAttributeMapper { + private static ConstantValueMapper INSTANCE = new ConstantValueMapper(); + + private ConstantValueMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code Deprecated} attribute} + * @since 23 + */ + public static AttributeMapper deprecated() { + return DeprecatedMapper.INSTANCE; + } + + private static final class DeprecatedMapper extends AbstractAttributeMapper { + private static DeprecatedMapper INSTANCE = new DeprecatedMapper(); + + private DeprecatedMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code EnclosingMethod} attribute} + * @since 23 + */ + public static AttributeMapper enclosingMethod() { + return EnclosingMethodMapper.INSTANCE; + } + + private static final class EnclosingMethodMapper extends AbstractAttributeMapper { + private static EnclosingMethodMapper INSTANCE = new EnclosingMethodMapper(); + + private EnclosingMethodMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code Exceptions} attribute} + * @since 23 + */ + public static AttributeMapper exceptions() { + return ExceptionsMapper.INSTANCE; + } + + private static final class ExceptionsMapper extends AbstractAttributeMapper { + private static ExceptionsMapper INSTANCE = new ExceptionsMapper(); + + private ExceptionsMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code InnerClasses} attribute} + * @since 23 + */ + public static AttributeMapper innerClasses() { + return InnerClassesMapper.INSTANCE; + } + + private static final class InnerClassesMapper extends AbstractAttributeMapper { + private static InnerClassesMapper INSTANCE = new InnerClassesMapper(); + + private InnerClassesMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code LineNumberTable} attribute} + * @since 23 + */ + public static AttributeMapper lineNumberTable() { + return LineNumberTableMapper.INSTANCE; + } + + private static final class LineNumberTableMapper extends AbstractAttributeMapper { + private static LineNumberTableMapper INSTANCE = new LineNumberTableMapper(); + + private LineNumberTableMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code LocalVariableTable} attribute} + * @since 23 + */ + public static AttributeMapper localVariableTable() { + return LocalVariableTableMapper.INSTANCE; + } + + private static final class LocalVariableTableMapper extends AbstractAttributeMapper { + private static LocalVariableTableMapper INSTANCE = new LocalVariableTableMapper(); + + private LocalVariableTableMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code LocalVariableTypeTable} attribute} + * @since 23 + */ + public static AttributeMapper localVariableTypeTable() { + return LocalVariableTypeTableMapper.INSTANCE; + } + + private static final class LocalVariableTypeTableMapper extends AbstractAttributeMapper { + private static LocalVariableTypeTableMapper INSTANCE = new LocalVariableTypeTableMapper(); + + private LocalVariableTypeTableMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code MethodParameters} attribute} + * @since 23 + */ + public static AttributeMapper methodParameters() { + return MethodParametersMapper.INSTANCE; + } + + private static final class MethodParametersMapper extends AbstractAttributeMapper { + private static MethodParametersMapper INSTANCE = new MethodParametersMapper(); + + private MethodParametersMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code Module} attribute} + * @since 23 + */ + public static AttributeMapper module() { + return ModuleMapper.INSTANCE; + } + + private static final class ModuleMapper extends AbstractAttributeMapper { + private static ModuleMapper INSTANCE = new ModuleMapper(); + + private ModuleMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code ModuleHashes} attribute} + * @since 23 + */ + public static AttributeMapper moduleHashes() { + return ModuleHashesMapper.INSTANCE; + } + + private static final class ModuleHashesMapper extends AbstractAttributeMapper { + private static ModuleHashesMapper INSTANCE = new ModuleHashesMapper(); + + private ModuleHashesMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code ModuleMainClass} attribute} + * @since 23 + */ + public static AttributeMapper moduleMainClass() { + return ModuleMainClassMapper.INSTANCE; + } + + private static final class ModuleMainClassMapper extends AbstractAttributeMapper { + private static ModuleMainClassMapper INSTANCE = new ModuleMainClassMapper(); + + private ModuleMainClassMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code ModulePackages} attribute} + * @since 23 + */ + public static AttributeMapper modulePackages() { + return ModulePackagesMapper.INSTANCE; + } + + private static final class ModulePackagesMapper extends AbstractAttributeMapper { + private static ModulePackagesMapper INSTANCE = new ModulePackagesMapper(); + + private ModulePackagesMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code ModuleResolution} attribute} + * @since 23 + */ + public static AttributeMapper moduleResolution() { + return ModuleResolutionMapper.INSTANCE; + } + + private static final class ModuleResolutionMapper extends AbstractAttributeMapper { + private static ModuleResolutionMapper INSTANCE = new ModuleResolutionMapper(); + + private ModuleResolutionMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code ModuleTarget} attribute} + * @since 23 + */ + public static AttributeMapper moduleTarget() { + return ModuleTargetMapper.INSTANCE; + } + + private static final class ModuleTargetMapper extends AbstractAttributeMapper { + private static ModuleTargetMapper INSTANCE = new ModuleTargetMapper(); + + private ModuleTargetMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code NestHost} attribute} + * @since 23 + */ + public static AttributeMapper nestHost() { + return NestHostMapper.INSTANCE; + } + + private static final class NestHostMapper extends AbstractAttributeMapper { + private static NestHostMapper INSTANCE = new NestHostMapper(); + + private NestHostMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code NestMembers} attribute} + * @since 23 + */ + public static AttributeMapper nestMembers() { + return NestMembersMapper.INSTANCE; + } + + private static final class NestMembersMapper extends AbstractAttributeMapper { + private static NestMembersMapper INSTANCE = new NestMembersMapper(); + + private NestMembersMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code PermittedSubclasses} attribute} + * @since 23 + */ + public static AttributeMapper permittedSubclasses() { + return PermittedSubclassesMapper.INSTANCE; + } + + private static final class PermittedSubclassesMapper extends AbstractAttributeMapper { + private static PermittedSubclassesMapper INSTANCE = new PermittedSubclassesMapper(); + + private PermittedSubclassesMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code Record} attribute} + * @since 23 + */ + public static AttributeMapper record() { + return RecordMapper.INSTANCE; + } + + private static final class RecordMapper extends AbstractAttributeMapper { + private static RecordMapper INSTANCE = new RecordMapper(); + + private RecordMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code RuntimeInvisibleAnnotations} attribute} + * @since 23 + */ + public static AttributeMapper runtimeInvisibleAnnotations() { + return RuntimeInvisibleAnnotationsMapper.INSTANCE; + } + + private static final class RuntimeInvisibleAnnotationsMapper extends AbstractAttributeMapper { + private static RuntimeInvisibleAnnotationsMapper INSTANCE = new RuntimeInvisibleAnnotationsMapper(); + + private RuntimeInvisibleAnnotationsMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code RuntimeInvisibleParameterAnnotations} attribute} + * @since 23 + */ + public static AttributeMapper runtimeInvisibleParameterAnnotations() { + return RuntimeInvisibleParameterAnnotationsMapper.INSTANCE; + } + + private static final class RuntimeInvisibleParameterAnnotationsMapper extends AbstractAttributeMapper { + private static RuntimeInvisibleParameterAnnotationsMapper INSTANCE = new RuntimeInvisibleParameterAnnotationsMapper(); + + private RuntimeInvisibleParameterAnnotationsMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code RuntimeInvisibleTypeAnnotations} attribute} + * @since 23 + */ + public static AttributeMapper runtimeInvisibleTypeAnnotations() { + return RuntimeInvisibleTypeAnnotationsMapper.INSTANCE; + } + + private static final class RuntimeInvisibleTypeAnnotationsMapper extends AbstractAttributeMapper { + private static RuntimeInvisibleTypeAnnotationsMapper INSTANCE = new RuntimeInvisibleTypeAnnotationsMapper(); + + private RuntimeInvisibleTypeAnnotationsMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code RuntimeVisibleAnnotations} attribute} + * @since 23 + */ + public static AttributeMapper runtimeVisibleAnnotations() { + return RuntimeVisibleAnnotationsMapper.INSTANCE; + } + + private static final class RuntimeVisibleAnnotationsMapper extends AbstractAttributeMapper { + private static RuntimeVisibleAnnotationsMapper INSTANCE = new RuntimeVisibleAnnotationsMapper(); + + private RuntimeVisibleAnnotationsMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code RuntimeVisibleParameterAnnotations} attribute} + * @since 23 + */ + public static AttributeMapper runtimeVisibleParameterAnnotations() { + return RuntimeVisibleParameterAnnotationsMapper.INSTANCE; + } + + private static final class RuntimeVisibleParameterAnnotationsMapper extends AbstractAttributeMapper { + private static RuntimeVisibleParameterAnnotationsMapper INSTANCE = new RuntimeVisibleParameterAnnotationsMapper(); + + private RuntimeVisibleParameterAnnotationsMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code RuntimeVisibleTypeAnnotations} attribute} + * @since 23 + */ + public static AttributeMapper runtimeVisibleTypeAnnotations() { + return RuntimeVisibleTypeAnnotationsMapper.INSTANCE; + } + + private static final class RuntimeVisibleTypeAnnotationsMapper extends AbstractAttributeMapper { + private static RuntimeVisibleTypeAnnotationsMapper INSTANCE = new RuntimeVisibleTypeAnnotationsMapper(); + + private RuntimeVisibleTypeAnnotationsMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code Signature} attribute} + * @since 23 + */ + public static AttributeMapper signature() { + return SignatureMapper.INSTANCE; + } + + private static final class SignatureMapper extends AbstractAttributeMapper { + private static SignatureMapper INSTANCE = new SignatureMapper(); + + private SignatureMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code SourceDebugExtension} attribute} + * @since 23 + */ + public static AttributeMapper sourceDebugExtension() { + return SourceDebugExtensionMapper.INSTANCE; + } + + private static final class SourceDebugExtensionMapper extends AbstractAttributeMapper { + private static SourceDebugExtensionMapper INSTANCE = new SourceDebugExtensionMapper(); + + private SourceDebugExtensionMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code SourceFile} attribute} + * @since 23 + */ + public static AttributeMapper sourceFile() { + return SourceFileMapper.INSTANCE; + } + + private static final class SourceFileMapper extends AbstractAttributeMapper { + private static SourceFileMapper INSTANCE = new SourceFileMapper(); + + private SourceFileMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code SourceID} attribute} + * @since 23 + */ + public static AttributeMapper sourceId() { + return SourceIDMapper.INSTANCE; + } + + private static final class SourceIDMapper extends AbstractAttributeMapper { + private static SourceIDMapper INSTANCE = new SourceIDMapper(); + + private SourceIDMapper() { + super(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; + } + } + + /** + * {@return Attribute mapper for the {@code StackMapTable} attribute} + * @since 23 + */ + public static AttributeMapper stackMapTable() { + return StackMapTableMapper.INSTANCE; + } + + private static final class StackMapTableMapper extends AbstractAttributeMapper { + private static StackMapTableMapper INSTANCE = new StackMapTableMapper(); + + private StackMapTableMapper() { + super(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; + } + } + + + /** + * {@return Attribute mapper for the {@code Synthetic} attribute} + * @since 23 + */ + public static AttributeMapper synthetic() { + return SyntheticMapper.INSTANCE; + } + + private static final class SyntheticMapper extends AbstractAttributeMapper { + private static SyntheticMapper INSTANCE = new SyntheticMapper(); + + private SyntheticMapper() { + super(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 the attribute mapper for a standard attribute} @@ -986,57 +1416,63 @@ public AttributeMapper.AttributeStability stability() { * @param name the name of the attribute to find */ public static AttributeMapper standardAttribute(Utf8Entry name) { - return _ATTR_MAP.get(name); + return PredefinedAttributes._ATTR_MAP.get(name); } /** - * All standard attribute mappers. + * {@return All standard attribute mappers.} + * @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 Set> predefinedAttributes() { + return PredefinedAttributes._ATTRS; + } + + private static final class PredefinedAttributes { + private static final Set> _ATTRS = Set.of( + annotationDefault(), + bootstrapMethods(), + characterRangeTable(), + code(), + compilationId(), + constantValue(), + deprecated(), + enclosingMethod(), + exceptions(), + innerClasses(), + lineNumberTable(), + localVariableTable(), + localVariableTypeTable(), + methodParameters(), + module(), + moduleHashes(), + moduleMainClass(), + modulePackages(), + moduleResolution(), + moduleTarget(), + nestHost(), + nestMembers(), + permittedSubclasses(), + record(), + runtimeInvisibleAnnotations(), + runtimeInvisibleParameterAnnotations(), + runtimeInvisibleTypeAnnotations(), + runtimeVisibleAnnotations(), + runtimeVisibleParameterAnnotations(), + runtimeVisibleTypeAnnotations(), + signature(), + sourceDebugExtension(), + sourceFile(), + sourceId(), + stackMapTable(), + synthetic()); + + private static final Map> _ATTR_MAP; + static { + var map = new HashMap>(64); + for (var am : _ATTRS) { + map.put(AbstractPoolEntry.rawUtf8EntryFromStandardAttributeName(am.name()), am); + } + _ATTR_MAP = Collections.unmodifiableMap(map); + } } } 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..60784f4686c56 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 @@ -889,7 +889,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 +907,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 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..42a1a32680fdd 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 CustomAttribute + || a instanceof ModuleAttribute + || a instanceof ModuleHashesAttribute + || a instanceof ModuleMainClassAttribute + || a instanceof ModulePackagesAttribute + || a instanceof ModuleResolutionAttribute + || a instanceof ModuleTargetAttribute + || a instanceof InnerClassesAttribute + || a instanceof SourceFileAttribute + || a instanceof SourceDebugExtensionAttribute + || a instanceof RuntimeVisibleAnnotationsAttribute + || a instanceof RuntimeInvisibleAnnotationsAttribute); + } } 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 2022f8f01547d..1f6c18032a48d 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 394f7cc807aa4..959ba07e8880c 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 @@ -227,7 +227,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]; @@ -245,7 +245,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 @@ -318,8 +318,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) { @@ -338,7 +338,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; @@ -350,7 +350,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; @@ -362,7 +362,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; @@ -374,10 +374,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 81e6f341a13fb..2dd2e25b2c8f8 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 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 028fc480f58aa..50b8adf1f55f6 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 @@ -395,13 +395,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(); @@ -476,7 +476,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()); @@ -503,7 +503,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(); @@ -555,9 +555,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)); } } @@ -585,7 +585,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/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/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/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/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 1c35b071cc206..afc62b0cbcbe2 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 cfd3201c95a4a..5fe0c987bc2d0 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 innerSig = (ClassTypeSig) sig.superclassSignature() // ArrayList .typeArgs().getFirst() // Outer.Inner .boundType().orElseThrow(); // assert it's exact bound 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 889589393173a..c2d73d560ae6c 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/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/classfiles/attributes/annotations/RuntimeParameterAnnotationsForLambdaTest.java b/test/langtools/tools/javac/classfiles/attributes/annotations/RuntimeParameterAnnotationsForLambdaTest.java index baf3a599095d2..ef9bd07cd6942 100644 --- a/test/langtools/tools/javac/classfiles/attributes/annotations/RuntimeParameterAnnotationsForLambdaTest.java +++ b/test/langtools/tools/javac/classfiles/attributes/annotations/RuntimeParameterAnnotationsForLambdaTest.java @@ -104,10 +104,10 @@ public void test() throws TestFailedException { protected void testAttributes( TestCase.TestMethodInfo testMethod, MethodModel method) { - RuntimeInvisibleParameterAnnotationsAttribute invAttr = method.findAttribute(Attributes.RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS).orElse(null); - checkNull(invAttr, String.format("%s should be null", Attributes.RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS)); - RuntimeVisibleParameterAnnotationsAttribute vAttr = method.findAttribute(Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS).orElse(null); - checkNull(vAttr, String.format("%s should be null", Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS)); + RuntimeInvisibleParameterAnnotationsAttribute invAttr = method.findAttribute(Attributes.runtimeInvisibleParameterAnnotations()).orElse(null); + checkNull(invAttr, String.format("%s should be null", Attributes.runtimeInvisibleParameterAnnotations())); + RuntimeVisibleParameterAnnotationsAttribute vAttr = method.findAttribute(Attributes.runtimeVisibleParameterAnnotations()).orElse(null); + checkNull(vAttr, String.format("%s should be null", Attributes.runtimeVisibleParameterAnnotations())); } public String generateLambdaSource(TestCase.TestMethodInfo method) { diff --git a/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedPackageTest.java b/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedPackageTest.java index 8befbb143dad5..49629cdbe61aa 100644 --- a/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedPackageTest.java +++ b/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedPackageTest.java @@ -83,7 +83,7 @@ private void test(String package_info, String src) { new String[]{"package-info.java", package_info}, new String[]{"notDeprecated.java", src}) .getClasses().get(CLASS_NAME)); - DeprecatedAttribute attr = cm.findAttribute(Attributes.DEPRECATED).orElse(null); + DeprecatedAttribute attr = cm.findAttribute(Attributes.deprecated()).orElse(null); checkNull(attr, "Class can not have deprecated attribute : " + CLASS_NAME); } catch (Exception e) { addFailure(e); diff --git a/test/langtools/tools/javac/classfiles/attributes/innerclasses/NoInnerClassesTest.java b/test/langtools/tools/javac/classfiles/attributes/innerclasses/NoInnerClassesTest.java index 540bd09a18f49..35d65208bc5df 100644 --- a/test/langtools/tools/javac/classfiles/attributes/innerclasses/NoInnerClassesTest.java +++ b/test/langtools/tools/javac/classfiles/attributes/innerclasses/NoInnerClassesTest.java @@ -47,6 +47,6 @@ public static void main(String[] args) throws IOException { public void test() throws IOException { ClassModel classModel = readClassFile("NoInnerClassesTest"); - assertNull(classModel.findAttribute(Attributes.INNER_CLASSES).orElse(null), "Found inner class attribute"); + assertNull(classModel.findAttribute(Attributes.innerClasses()).orElse(null), "Found inner class attribute"); } } diff --git a/test/langtools/tools/javac/platform/ModuleVersionTest.java b/test/langtools/tools/javac/platform/ModuleVersionTest.java index 1b01fc397e84f..0e8f8b8c05f0b 100644 --- a/test/langtools/tools/javac/platform/ModuleVersionTest.java +++ b/test/langtools/tools/javac/platform/ModuleVersionTest.java @@ -103,7 +103,7 @@ public class Test { ClassModel clazz = ClassFile.of().parse(moduleInfo); assertTrue(clazz.isModuleInfo()); - ModuleAttribute module = clazz.findAttribute(Attributes.MODULE).get(); + ModuleAttribute module = clazz.findAttribute(Attributes.module()).get(); ModuleRequireInfo req = module.requires().get(0); assertEquals("java.base", req.requires().name().stringValue()); assertEquals(expectedVersion, req.requiresVersion().get().stringValue()); diff --git a/test/langtools/tools/javap/typeAnnotations/JSR175Annotations.java b/test/langtools/tools/javap/typeAnnotations/JSR175Annotations.java index 1aa3ddbebd8dc..1f5b2f43958d4 100644 --- a/test/langtools/tools/javap/typeAnnotations/JSR175Annotations.java +++ b/test/langtools/tools/javap/typeAnnotations/JSR175Annotations.java @@ -58,8 +58,8 @@ public void run() throws Exception { } void test(AttributedElement m) { - test(m, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS); - test(m, Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS); + test(m, Attributes.runtimeVisibleTypeAnnotations()); + test(m, Attributes.runtimeInvisibleTypeAnnotations()); } // test the result of AttributedElement.findAttribute according to expectations diff --git a/test/langtools/tools/javap/typeAnnotations/Visibility.java b/test/langtools/tools/javap/typeAnnotations/Visibility.java index d2f16b49d9b71..ebffbf9176dcc 100644 --- a/test/langtools/tools/javap/typeAnnotations/Visibility.java +++ b/test/langtools/tools/javap/typeAnnotations/Visibility.java @@ -55,8 +55,8 @@ public void run() throws Exception { } void test(MethodModel mm) { - test(mm, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS); - test(mm, Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS); + test(mm, Attributes.runtimeVisibleTypeAnnotations()); + test(mm, Attributes.runtimeInvisibleTypeAnnotations()); } // test the result of mm.findAttribute according to expectations