From cfdc64fcb43e3b261dddc6cc6947235a9e76154e Mon Sep 17 00:00:00 2001 From: Adam Sotona Date: Fri, 24 May 2024 15:58:34 +0000 Subject: [PATCH] 8331291: java.lang.classfile.Attributes class performs a lot of static initializations Reviewed-by: liach, redestad, vromero --- .../java/lang/classfile/Attributes.java | 1228 +++++------------ .../impl/AbstractAttributeMapper.java | 760 +++++++++- .../classfile/impl/BoundAttribute.java | 92 +- .../internal/classfile/impl/ClassImpl.java | 55 +- .../classfile/impl/ClassReaderImpl.java | 4 +- .../jdk/internal/classfile/impl/CodeImpl.java | 18 +- .../classfile/impl/DirectCodeBuilder.java | 12 +- .../internal/classfile/impl/MethodImpl.java | 2 +- .../classfile/impl/SplitConstantPool.java | 2 +- .../classfile/impl/StackMapGenerator.java | 2 +- .../classfile/impl/UnboundAttribute.java | 70 +- .../jdk/internal/classfile/impl/Util.java | 2 +- .../impl/verifier/VerificationWrapper.java | 4 +- .../classes/sun/tools/jar/FingerPrint.java | 2 +- .../com/sun/tools/javap/AttributeWriter.java | 2 +- .../com/sun/tools/javap/ClassWriter.java | 20 +- .../com/sun/tools/javap/JavapTask.java | 2 +- .../tools/javap/LocalVariableTableWriter.java | 2 +- .../javap/LocalVariableTypeTableWriter.java | 2 +- .../com/sun/tools/javap/SourceWriter.java | 4 +- .../com/sun/tools/javap/StackMapWriter.java | 2 +- .../sun/tools/javap/TypeAnnotationWriter.java | 4 +- .../com/sun/tools/jdeps/Dependencies.java | 8 +- .../runtime/test/TestResolvedJavaMethod.java | 2 +- test/jdk/java/lang/StackWalker/TestBCI.java | 2 +- .../java/lang/invoke/lambda/LambdaAsm.java | 2 +- .../AdvancedTransformationsTest.java | 6 +- .../jdk/classfile/AnnotationModelTest.java | 2 +- test/jdk/jdk/classfile/AttributesTest.java | 55 + .../jdk/jdk/classfile/BoundAttributeTest.java | 2 +- test/jdk/jdk/classfile/CorpusTest.java | 6 +- .../jdk/classfile/FilterDeadLabelsTest.java | 6 +- test/jdk/jdk/classfile/LimitsTest.java | 4 +- .../jdk/classfile/LowJCovAttributeTest.java | 6 +- test/jdk/jdk/classfile/LvtTest.java | 4 +- .../MassAdaptCopyPrimitiveMatchCodeTest.java | 2 +- test/jdk/jdk/classfile/ModuleBuilderTest.java | 8 +- test/jdk/jdk/classfile/SignaturesTest.java | 12 +- .../jdk/classfile/TestRecordComponent.java | 4 +- .../examples/AnnotationsExamples.java | 25 +- .../classfile/examples/ModuleExamples.java | 6 +- .../jdk/classfile/helpers/ClassRecord.java | 130 +- .../helpers/RebuildingTransformation.java | 2 +- .../CallerSensitiveFinder.java | 2 +- .../reflect/CallerSensitive/CheckCSMs.java | 4 +- .../StripJavaDebugAttributesPluginTest.java | 8 +- .../tools/javac/4241573/T4241573.java | 2 +- .../tools/javac/7003595/T7003595.java | 2 +- .../8009170/RedundantByteCodeInArrayTest.java | 2 +- .../AnonymousClass/AnonymousClassFlags.java | 2 +- .../MethodParameters/ClassFileVisitor.java | 2 +- .../LegacyOutputTest/LegacyOutputTest.java | 2 +- .../tools/javac/MethodParametersTest.java | 4 +- .../ImplicitParameters.java | 2 +- .../StringConcat/TestIndyStringConcat.java | 5 +- .../StringConcat/WellKnownTypeSignatures.java | 2 +- .../tools/javac/StringConcat/access/Test.java | 2 +- ...ationsAreNotCopiedToBridgeMethodsTest.java | 4 +- .../DebugPointerAtBadPositionTest.java | 4 +- .../InlinedFinallyConfuseDebuggersTest.java | 4 +- .../tools/javac/T7053059/DoubleCastTest.java | 2 +- test/langtools/tools/javac/T7093325.java | 2 +- ...rClassAttrMustNotHaveStrictFPFlagTest.java | 2 +- .../javac/T8019486/WrongLNTForLambdaTest.java | 4 +- .../DeadCodeGeneratedForEmptyTryTest.java | 2 +- .../NoDeadCodeGenerationOnTrySmtTest.java | 2 +- .../DontGenerateLVTForGNoneOpTest.java | 4 +- .../MissingLNTEntryForBreakContinueTest.java | 4 +- .../MissingLNTEntryForFinalizerTest.java | 4 +- ...oLocalsMustBeReservedForDCEedVarsTest.java | 2 +- .../javac/T8222949/TestConstantDynamic.java | 6 +- .../TryWithResources/TwrSimpleClose.java | 2 +- .../ApplicableAnnotationsOnRecords.java | 6 +- .../TypeAnnotationsPositionsOnRecords.java | 6 +- .../VariablesDeclaredWithVarTest.java | 6 +- .../classfile/AnonymousClassTest.java | 20 +- .../classfile/ClassfileTestHelper.java | 10 +- .../classfile/NoTargetAnnotations.java | 4 +- .../classfile/TestAnonInnerClasses.java | 10 +- .../classfile/TestNewCastArray.java | 12 +- .../TypeAnnotationPropagationTest.java | 4 +- .../referenceinfos/ReferenceInfoUtil.java | 10 +- .../intersection/DuplicatedCheckcastTest.java | 2 +- .../InnerClasses/SyntheticClasses.java | 4 +- .../AnnotationDefaultTest.java | 2 +- .../EnclosingMethod/EnclosingMethodTest.java | 2 +- .../LineNumberTable/LineNumberTestBase.java | 6 +- .../attributes/LineNumberTable/T8050993.java | 4 +- .../LocalVariableTestBase.java | 2 +- .../attributes/Module/ModuleTestBase.java | 2 +- .../attributes/Signature/Driver.java | 6 +- .../SourceFile/NoSourceFileAttribute.java | 2 +- .../SourceFile/SourceFileTestBase.java | 2 +- .../Synthetic/SyntheticTestDriver.java | 6 +- .../RuntimeAnnotationsTestBase.java | 4 +- ...timeParameterAnnotationsForLambdaTest.java | 8 +- .../RuntimeParameterAnnotationsTestBase.java | 4 +- .../deprecated/DeprecatedPackageTest.java | 2 +- .../attributes/deprecated/DeprecatedTest.java | 10 +- .../InnerClassesHierarchyTest.java | 2 +- .../innerclasses/InnerClassesIndexTest.java | 2 +- .../innerclasses/InnerClassesTestBase.java | 2 +- .../innerclasses/NoInnerClassesTest.java | 2 +- .../IndyCorrectInvocationName.java | 4 +- .../tools/javac/code/CharImmediateValue.java | 2 +- .../javac/defaultMethods/TestDefaultBody.java | 2 +- .../super/TestDirectSuperInterfaceInvoke.java | 2 +- .../_super/NonDirectSuper/NonDirectSuper.java | 2 +- .../tools/javac/file/SymLinkTest.java | 2 +- .../tools/javac/flow/LVTHarness.java | 4 +- .../tools/javac/lambda/ByteCodeTest.java | 2 +- .../javac/lambda/LocalVariableTable.java | 4 +- .../lambda/TestBootstrapMethodsCount.java | 2 +- .../tools/javac/lambda/TestInvokeDynamic.java | 6 +- .../lambda/bytecode/TestLambdaBytecode.java | 4 +- .../TestLambdaBytecodeTargetRelease14.java | 4 +- .../deduplication/DeduplicationTest.java | 2 +- .../javac/launcher/SourceLauncherTest.java | 4 +- .../ConditionalLineNumberTest.java | 2 +- .../linenumbers/FinallyLineNumberTest.java | 2 +- .../linenumbers/NestedLineNumberTest.java | 2 +- .../linenumbers/NullCheckLineNumberTest.java | 2 +- test/langtools/tools/javac/meth/TestCP.java | 2 +- .../javac/modules/AnnotationsOnModules.java | 14 +- .../tools/javac/modules/JavaBaseTest.java | 2 +- .../tools/javac/modules/ModuleVersion.java | 2 +- .../tools/javac/modules/OpenModulesTest.java | 2 +- .../javac/multicatch/7005371/T7005371.java | 4 +- .../tools/javac/multicatch/Pos05.java | 2 +- .../tools/javac/patterns/Annotations.java | 4 +- .../javac/patterns/LocalVariableTable.java | 4 +- .../NestedPatternVariablesBytecode.java | 2 +- .../javac/patterns/NoUnnecessaryCast.java | 2 +- .../javac/platform/ModuleVersionTest.java | 2 +- .../processing/model/element/TestOrigin.java | 2 +- .../javac/records/RecordCompilationTests.java | 2 +- .../RecordComponentTypeTest.java | 2 +- .../sealed/SealedDiffConfigurationsTest.java | 4 +- .../tools/javac/varargs/6199075/T6199075.java | 2 +- .../tools/javac/varargs/7042566/T7042566.java | 2 +- test/langtools/tools/javap/T6716452.java | 4 +- .../javap/classfile/6888367/T6888367.java | 6 +- .../typeAnnotations/JSR175Annotations.java | 4 +- .../tools/javap/typeAnnotations/NewArray.java | 6 +- .../tools/javap/typeAnnotations/Presence.java | 6 +- .../javap/typeAnnotations/PresenceInner.java | 4 +- .../javap/typeAnnotations/TypeCasts.java | 6 +- .../javap/typeAnnotations/Visibility.java | 4 +- .../javap/typeAnnotations/Wildcards.java | 4 +- 149 files changed, 1669 insertions(+), 1323 deletions(-) create mode 100644 test/jdk/jdk/classfile/AttributesTest.java 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 75e06e7c3f3..1e91090f8af 100644 --- a/src/java.base/share/classes/java/lang/classfile/Attributes.java +++ b/src/java.base/share/classes/java/lang/classfile/Attributes.java @@ -24,77 +24,74 @@ */ package java.lang.classfile; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import java.lang.classfile.attribute.AnnotationDefaultAttribute; -import java.lang.classfile.attribute.BootstrapMethodsAttribute; -import java.lang.classfile.attribute.CharacterRangeInfo; -import java.lang.classfile.attribute.CharacterRangeTableAttribute; -import java.lang.classfile.attribute.CodeAttribute; -import java.lang.classfile.attribute.CompilationIDAttribute; -import java.lang.classfile.attribute.ConstantValueAttribute; -import java.lang.classfile.attribute.DeprecatedAttribute; -import java.lang.classfile.attribute.EnclosingMethodAttribute; -import java.lang.classfile.attribute.ExceptionsAttribute; -import java.lang.classfile.attribute.InnerClassInfo; -import java.lang.classfile.attribute.InnerClassesAttribute; -import java.lang.classfile.attribute.LineNumberInfo; -import java.lang.classfile.attribute.LineNumberTableAttribute; -import java.lang.classfile.attribute.LocalVariableInfo; -import java.lang.classfile.attribute.LocalVariableTableAttribute; -import java.lang.classfile.attribute.LocalVariableTypeInfo; -import java.lang.classfile.attribute.LocalVariableTypeTableAttribute; -import java.lang.classfile.attribute.MethodParameterInfo; -import java.lang.classfile.attribute.MethodParametersAttribute; -import java.lang.classfile.attribute.ModuleAttribute; -import java.lang.classfile.attribute.ModuleExportInfo; -import java.lang.classfile.attribute.ModuleHashInfo; -import java.lang.classfile.attribute.ModuleHashesAttribute; -import java.lang.classfile.attribute.ModuleMainClassAttribute; -import java.lang.classfile.attribute.ModuleOpenInfo; -import java.lang.classfile.attribute.ModulePackagesAttribute; -import java.lang.classfile.attribute.ModuleProvideInfo; -import java.lang.classfile.attribute.ModuleRequireInfo; -import java.lang.classfile.attribute.ModuleResolutionAttribute; -import java.lang.classfile.attribute.ModuleTargetAttribute; -import java.lang.classfile.attribute.NestHostAttribute; -import java.lang.classfile.attribute.NestMembersAttribute; -import java.lang.classfile.attribute.PermittedSubclassesAttribute; -import java.lang.classfile.attribute.RecordAttribute; -import java.lang.classfile.attribute.RecordComponentInfo; -import java.lang.classfile.attribute.RuntimeInvisibleAnnotationsAttribute; -import java.lang.classfile.attribute.RuntimeInvisibleParameterAnnotationsAttribute; -import java.lang.classfile.attribute.RuntimeInvisibleTypeAnnotationsAttribute; -import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute; -import java.lang.classfile.attribute.RuntimeVisibleParameterAnnotationsAttribute; -import java.lang.classfile.attribute.RuntimeVisibleTypeAnnotationsAttribute; -import java.lang.classfile.attribute.SignatureAttribute; -import java.lang.classfile.attribute.SourceDebugExtensionAttribute; -import java.lang.classfile.attribute.SourceFileAttribute; -import java.lang.classfile.attribute.SourceIDAttribute; -import java.lang.classfile.attribute.StackMapTableAttribute; -import java.lang.classfile.attribute.SyntheticAttribute; -import java.lang.classfile.constantpool.Utf8Entry; -import jdk.internal.classfile.impl.AbstractAttributeMapper; -import jdk.internal.classfile.impl.BoundAttribute; -import jdk.internal.classfile.impl.CodeImpl; -import jdk.internal.classfile.impl.AbstractPoolEntry; -import jdk.internal.classfile.impl.StackMapDecoder; +import java.lang.classfile.AttributeMapper.AttributeStability; +import java.lang.classfile.attribute.*; +import jdk.internal.classfile.impl.AbstractAttributeMapper.*; import jdk.internal.javac.PreviewFeature; /** * Attribute mappers for standard classfile attributes. + *

+ * Unless otherwise specified, mappers returned by each method + * do not permit multiple attribute instances in a given location. + *

+ * The most stable {@link AttributeStability#STATELESS STATELESS} mappers are: + *

+ * + * The mappers with {@link AttributeStability#CP_REFS CP_REFS} stability are: + * + * + * The mappers with {@link AttributeStability#LABELS LABELS} stability are: + * + * + * The {@link AttributeStability#UNSTABLE UNSTABLE} mappers are: + * * * @see AttributeMapper * * @since 22 */ @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) -public class Attributes { +public final class Attributes { /** AnnotationDefault */ public static final String NAME_ANNOTATION_DEFAULT = "AnnotationDefault"; @@ -207,836 +204,297 @@ public class Attributes { private Attributes() { } - /** Attribute mapper for the {@code AnnotationDefault} attribute */ - public static final AttributeMapper - ANNOTATION_DEFAULT = new AbstractAttributeMapper<>(NAME_ANNOTATION_DEFAULT) { - @Override - public AnnotationDefaultAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundAnnotationDefaultAttr(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, AnnotationDefaultAttribute attr) { - attr.defaultValue().writeTo(buf); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code BootstrapMethods} attribute */ - public static final AttributeMapper - BOOTSTRAP_METHODS = new AbstractAttributeMapper<>(NAME_BOOTSTRAP_METHODS) { - @Override - public BootstrapMethodsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundBootstrapMethodsAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, BootstrapMethodsAttribute attr) { - buf.writeList(attr.bootstrapMethods()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code CharacterRangeTable} attribute */ - public static final AttributeMapper - CHARACTER_RANGE_TABLE = new AbstractAttributeMapper<>(NAME_CHARACTER_RANGE_TABLE, true) { - @Override - public CharacterRangeTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundCharacterRangeTableAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, CharacterRangeTableAttribute attr) { - List ranges = attr.characterRangeTable(); - buf.writeU2(ranges.size()); - for (CharacterRangeInfo info : ranges) { - buf.writeU2(info.startPc()); - buf.writeU2(info.endPc()); - buf.writeInt(info.characterRangeStart()); - buf.writeInt(info.characterRangeEnd()); - buf.writeU2(info.flags()); - } - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.LABELS; - } - }; - - /** Attribute mapper for the {@code Code} attribute */ - public static final AttributeMapper - CODE = new AbstractAttributeMapper<>(NAME_CODE) { - @Override - public CodeAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new CodeImpl(e, cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, CodeAttribute attr) { - throw new UnsupportedOperationException("Code attribute does not support direct write"); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - - /** Attribute mapper for the {@code CompilationID} attribute */ - public static final AttributeMapper - COMPILATION_ID = new AbstractAttributeMapper<>(NAME_COMPILATION_ID, true) { - @Override - public CompilationIDAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundCompilationIDAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, CompilationIDAttribute attr) { - buf.writeIndex(attr.compilationId()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code ConstantValue} attribute */ - public static final AttributeMapper - CONSTANT_VALUE = new AbstractAttributeMapper<>(NAME_CONSTANT_VALUE) { - @Override - public ConstantValueAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundConstantValueAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, ConstantValueAttribute attr) { - buf.writeIndex(attr.constant()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code Deprecated} attribute */ - public static final AttributeMapper - DEPRECATED = new AbstractAttributeMapper<>(NAME_DEPRECATED, true) { - @Override - public DeprecatedAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundDeprecatedAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, DeprecatedAttribute attr) { - // empty - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.STATELESS; - } - }; - - /** Attribute mapper for the {@code EnclosingMethod} attribute */ - public static final AttributeMapper - ENCLOSING_METHOD = new AbstractAttributeMapper<>(NAME_ENCLOSING_METHOD) { - @Override - public EnclosingMethodAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundEnclosingMethodAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, EnclosingMethodAttribute attr) { - buf.writeIndex(attr.enclosingClass()); - buf.writeIndexOrZero(attr.enclosingMethod().orElse(null)); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code Exceptions} attribute */ - public static final AttributeMapper - EXCEPTIONS = new AbstractAttributeMapper<>(NAME_EXCEPTIONS) { - @Override - public ExceptionsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundExceptionsAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, ExceptionsAttribute attr) { - buf.writeListIndices(attr.exceptions()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code InnerClasses} attribute */ - public static final AttributeMapper - INNER_CLASSES = new AbstractAttributeMapper<>(NAME_INNER_CLASSES) { - @Override - public InnerClassesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundInnerClassesAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, InnerClassesAttribute attr) { - List classes = attr.classes(); - buf.writeU2(classes.size()); - for (InnerClassInfo ic : classes) { - buf.writeIndex(ic.innerClass()); - buf.writeIndexOrZero(ic.outerClass().orElse(null)); - buf.writeIndexOrZero(ic.innerName().orElse(null)); - buf.writeU2(ic.flagsMask()); - } - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code LineNumberTable} attribute */ - public static final AttributeMapper - LINE_NUMBER_TABLE = new AbstractAttributeMapper<>(NAME_LINE_NUMBER_TABLE, true) { - @Override - public LineNumberTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundLineNumberTableAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, LineNumberTableAttribute attr) { - List lines = attr.lineNumbers(); - buf.writeU2(lines.size()); - for (LineNumberInfo line : lines) { - buf.writeU2(line.startPc()); - buf.writeU2(line.lineNumber()); - } - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.LABELS; - } - }; - - /** Attribute mapper for the {@code LocalVariableTable} attribute */ - public static final AttributeMapper - LOCAL_VARIABLE_TABLE = new AbstractAttributeMapper<>(NAME_LOCAL_VARIABLE_TABLE, true) { - @Override - public LocalVariableTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundLocalVariableTableAttribute(e, cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, LocalVariableTableAttribute attr) { - List infos = attr.localVariables(); - buf.writeU2(infos.size()); - for (LocalVariableInfo info : infos) { - buf.writeU2(info.startPc()); - buf.writeU2(info.length()); - buf.writeIndex(info.name()); - buf.writeIndex(info.type()); - buf.writeU2(info.slot()); - } - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.LABELS; - } - }; - - /** Attribute mapper for the {@code LocalVariableTypeTable} attribute */ - public static final AttributeMapper - LOCAL_VARIABLE_TYPE_TABLE = new AbstractAttributeMapper<>(NAME_LOCAL_VARIABLE_TYPE_TABLE, true) { - @Override - public LocalVariableTypeTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundLocalVariableTypeTableAttribute(e, cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, LocalVariableTypeTableAttribute attr) { - List infos = attr.localVariableTypes(); - buf.writeU2(infos.size()); - for (LocalVariableTypeInfo info : infos) { - buf.writeU2(info.startPc()); - buf.writeU2(info.length()); - buf.writeIndex(info.name()); - buf.writeIndex(info.signature()); - buf.writeU2(info.slot()); - } - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.LABELS; - } - }; - - /** Attribute mapper for the {@code MethodParameters} attribute */ - public static final AttributeMapper - METHOD_PARAMETERS = new AbstractAttributeMapper<>(NAME_METHOD_PARAMETERS) { - @Override - public MethodParametersAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundMethodParametersAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, MethodParametersAttribute attr) { - List parameters = attr.parameters(); - buf.writeU1(parameters.size()); - for (MethodParameterInfo info : parameters) { - buf.writeIndexOrZero(info.name().orElse(null)); - buf.writeU2(info.flagsMask()); - } - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code Module} attribute */ - public static final AttributeMapper - MODULE = new AbstractAttributeMapper<>(NAME_MODULE) { - @Override - public ModuleAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundModuleAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, ModuleAttribute attr) { - buf.writeIndex(attr.moduleName()); - buf.writeU2(attr.moduleFlagsMask()); - buf.writeIndexOrZero(attr.moduleVersion().orElse(null)); - buf.writeU2(attr.requires().size()); - for (ModuleRequireInfo require : attr.requires()) { - buf.writeIndex(require.requires()); - buf.writeU2(require.requiresFlagsMask()); - buf.writeIndexOrZero(require.requiresVersion().orElse(null)); - } - buf.writeU2(attr.exports().size()); - for (ModuleExportInfo export : attr.exports()) { - buf.writeIndex(export.exportedPackage()); - buf.writeU2(export.exportsFlagsMask()); - buf.writeListIndices(export.exportsTo()); - } - buf.writeU2(attr.opens().size()); - for (ModuleOpenInfo open : attr.opens()) { - buf.writeIndex(open.openedPackage()); - buf.writeU2(open.opensFlagsMask()); - buf.writeListIndices(open.opensTo()); - } - buf.writeListIndices(attr.uses()); - buf.writeU2(attr.provides().size()); - for (ModuleProvideInfo provide : attr.provides()) { - buf.writeIndex(provide.provides()); - buf.writeListIndices(provide.providesWith()); - } - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code ModuleHashes} attribute */ - public static final AttributeMapper - MODULE_HASHES = new AbstractAttributeMapper<>(NAME_MODULE_HASHES) { - @Override - public ModuleHashesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundModuleHashesAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, ModuleHashesAttribute attr) { - buf.writeIndex(attr.algorithm()); - List hashes = attr.hashes(); - buf.writeU2(hashes.size()); - for (ModuleHashInfo hash : hashes) { - buf.writeIndex(hash.moduleName()); - buf.writeU2(hash.hash().length); - buf.writeBytes(hash.hash()); - } - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code ModuleMainClass} attribute */ - public static final AttributeMapper - MODULE_MAIN_CLASS = new AbstractAttributeMapper<>(NAME_MODULE_MAIN_CLASS) { - @Override - public ModuleMainClassAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundModuleMainClassAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, ModuleMainClassAttribute attr) { - buf.writeIndex(attr.mainClass()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code ModulePackages} attribute */ - public static final AttributeMapper - MODULE_PACKAGES = new AbstractAttributeMapper<>(NAME_MODULE_PACKAGES) { - @Override - public ModulePackagesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundModulePackagesAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, ModulePackagesAttribute attr) { - buf.writeListIndices(attr.packages()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code ModuleResolution} attribute */ - public static final AttributeMapper - MODULE_RESOLUTION = new AbstractAttributeMapper<>(NAME_MODULE_RESOLUTION) { - @Override - public ModuleResolutionAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundModuleResolutionAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, ModuleResolutionAttribute attr) { - buf.writeU2(attr.resolutionFlags()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.STATELESS; - } - }; - - /** Attribute mapper for the {@code ModuleTarget} attribute */ - public static final AttributeMapper - MODULE_TARGET = new AbstractAttributeMapper<>(NAME_MODULE_TARGET) { - @Override - public ModuleTargetAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundModuleTargetAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, ModuleTargetAttribute attr) { - buf.writeIndex(attr.targetPlatform()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code NestHost} attribute */ - public static final AttributeMapper - NEST_HOST = new AbstractAttributeMapper<>(NAME_NEST_HOST) { - @Override - public NestHostAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundNestHostAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, NestHostAttribute attr) { - buf.writeIndex(attr.nestHost()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code NestMembers} attribute */ - public static final AttributeMapper - NEST_MEMBERS = new AbstractAttributeMapper<>(NAME_NEST_MEMBERS) { - @Override - public NestMembersAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundNestMembersAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, NestMembersAttribute attr) { - buf.writeListIndices(attr.nestMembers()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code PermittedSubclasses} attribute */ - public static final AttributeMapper - PERMITTED_SUBCLASSES = new AbstractAttributeMapper<>(NAME_PERMITTED_SUBCLASSES) { - @Override - public PermittedSubclassesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundPermittedSubclassesAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, PermittedSubclassesAttribute attr) { - buf.writeListIndices(attr.permittedSubclasses()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code Record} attribute */ - public static final AttributeMapper - RECORD = new AbstractAttributeMapper<>(NAME_RECORD) { - @Override - public RecordAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundRecordAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, RecordAttribute attr) { - List components = attr.components(); - buf.writeU2(components.size()); - for (RecordComponentInfo info : components) { - buf.writeIndex(info.name()); - buf.writeIndex(info.descriptor()); - buf.writeList(info.attributes()); - } - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code RuntimeInvisibleAnnotations} attribute */ - public static final AttributeMapper - RUNTIME_INVISIBLE_ANNOTATIONS = new AbstractAttributeMapper<>(NAME_RUNTIME_INVISIBLE_ANNOTATIONS) { - @Override - public RuntimeInvisibleAnnotationsAttribute readAttribute(AttributedElement enclosing, ClassReader cf, int pos) { - return new BoundAttribute.BoundRuntimeInvisibleAnnotationsAttribute(cf, pos); - } - - @Override - protected void writeBody(BufWriter buf, RuntimeInvisibleAnnotationsAttribute attr) { - buf.writeList(attr.annotations()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code RuntimeInvisibleParameterAnnotations} attribute */ - public static final AttributeMapper - RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS = new AbstractAttributeMapper<>(NAME_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS) { - @Override - public RuntimeInvisibleParameterAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundRuntimeInvisibleParameterAnnotationsAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, RuntimeInvisibleParameterAnnotationsAttribute attr) { - List> lists = attr.parameterAnnotations(); - buf.writeU1(lists.size()); - for (List list : lists) - buf.writeList(list); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code RuntimeInvisibleTypeAnnotations} attribute */ - public static final AttributeMapper - RUNTIME_INVISIBLE_TYPE_ANNOTATIONS = new AbstractAttributeMapper<>(NAME_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS) { - @Override - public RuntimeInvisibleTypeAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundRuntimeInvisibleTypeAnnotationsAttribute(e, cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, RuntimeInvisibleTypeAnnotationsAttribute attr) { - buf.writeList(attr.annotations()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.UNSTABLE; - } - }; - - /** Attribute mapper for the {@code RuntimeVisibleAnnotations} attribute */ - public static final AttributeMapper - RUNTIME_VISIBLE_ANNOTATIONS = new AbstractAttributeMapper<>(NAME_RUNTIME_VISIBLE_ANNOTATIONS) { - @Override - public RuntimeVisibleAnnotationsAttribute readAttribute(AttributedElement enclosing, ClassReader cf, int pos) { - return new BoundAttribute.BoundRuntimeVisibleAnnotationsAttribute(cf, pos); - } - - @Override - protected void writeBody(BufWriter buf, RuntimeVisibleAnnotationsAttribute attr) { - buf.writeList(attr.annotations()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code RuntimeVisibleParameterAnnotations} attribute */ - public static final AttributeMapper - RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS = new AbstractAttributeMapper<>(NAME_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS) { - @Override - public RuntimeVisibleParameterAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundRuntimeVisibleParameterAnnotationsAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, RuntimeVisibleParameterAnnotationsAttribute attr) { - List> lists = attr.parameterAnnotations(); - buf.writeU1(lists.size()); - for (List list : lists) - buf.writeList(list); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code RuntimeVisibleTypeAnnotations} attribute */ - public static final AttributeMapper - RUNTIME_VISIBLE_TYPE_ANNOTATIONS = new AbstractAttributeMapper<>(NAME_RUNTIME_VISIBLE_TYPE_ANNOTATIONS) { - @Override - public RuntimeVisibleTypeAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundRuntimeVisibleTypeAnnotationsAttribute(e, cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, RuntimeVisibleTypeAnnotationsAttribute attr) { - buf.writeList(attr.annotations()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.UNSTABLE; - } - }; - - /** Attribute mapper for the {@code Signature} attribute */ - public static final AttributeMapper - SIGNATURE = new AbstractAttributeMapper<>(NAME_SIGNATURE) { - @Override - public SignatureAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundSignatureAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, SignatureAttribute attr) { - buf.writeIndex(attr.signature()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code SourceDebugExtension} attribute */ - public static final AttributeMapper - SOURCE_DEBUG_EXTENSION = new AbstractAttributeMapper<>(NAME_SOURCE_DEBUG_EXTENSION) { - @Override - public SourceDebugExtensionAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundSourceDebugExtensionAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, SourceDebugExtensionAttribute attr) { - buf.writeBytes(attr.contents()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.STATELESS; - } - }; - - /** Attribute mapper for the {@code SourceFile} attribute */ - public static final AttributeMapper - SOURCE_FILE = new AbstractAttributeMapper<>(NAME_SOURCE_FILE) { - @Override - public SourceFileAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundSourceFileAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, SourceFileAttribute attr) { - buf.writeIndex(attr.sourceFile()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code SourceID} attribute */ - public static final AttributeMapper - SOURCE_ID = new AbstractAttributeMapper<>(NAME_SOURCE_ID) { - @Override - public SourceIDAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundSourceIDAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, SourceIDAttribute attr) { - buf.writeIndex(attr.sourceId()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.CP_REFS; - } - }; - - /** Attribute mapper for the {@code StackMapTable} attribute */ - public static final AttributeMapper - STACK_MAP_TABLE = new AbstractAttributeMapper<>(NAME_STACK_MAP_TABLE) { - @Override - public StackMapTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundStackMapTableAttribute((CodeImpl)e, cf, this, p); - } - - @Override - protected void writeBody(BufWriter b, StackMapTableAttribute attr) { - StackMapDecoder.writeFrames(b, attr.entries()); - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.LABELS; - } - }; - - - /** Attribute mapper for the {@code Synthetic} attribute */ - public static final AttributeMapper - SYNTHETIC = new AbstractAttributeMapper<>(NAME_SYNTHETIC, true) { - @Override - public SyntheticAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { - return new BoundAttribute.BoundSyntheticAttribute(cf, this, p); - } - - @Override - protected void writeBody(BufWriter buf, SyntheticAttribute attr) { - // empty - } - - @Override - public AttributeMapper.AttributeStability stability() { - return AttributeStability.STATELESS; - } - }; - /** - * {@return the attribute mapper for a standard attribute} - * - * @param name the name of the attribute to find + * {@return Attribute mapper for the {@code AnnotationDefault} attribute} + * @since 23 */ - public static AttributeMapper standardAttribute(Utf8Entry name) { - return _ATTR_MAP.get(name); + public static AttributeMapper annotationDefault() { + return AnnotationDefaultMapper.INSTANCE; } /** - * All standard attribute mappers. + * {@return Attribute mapper for the {@code BootstrapMethods} attribute} + * @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); + public static AttributeMapper bootstrapMethods() { + return BootstrapMethodsMapper.INSTANCE; + } - 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); + /** + * {@return Attribute mapper for the {@code CharacterRangeTable} attribute} + * The mapper permits multiple instances in a given location. + * @since 23 + */ + public static AttributeMapper characterRangeTable() { + return CharacterRangeTableMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code Code} attribute} + * @since 23 + */ + public static AttributeMapper code() { + return CodeMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code CompilationID} attribute} + * @since 23 + */ + public static AttributeMapper compilationId() { + return CompilationIDMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code ConstantValue} attribute} + * @since 23 + */ + public static AttributeMapper constantValue() { + return ConstantValueMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code Deprecated} attribute} + * The mapper permits multiple instances in a given location. + * @since 23 + */ + public static AttributeMapper deprecated() { + return DeprecatedMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code EnclosingMethod} attribute} + * @since 23 + */ + public static AttributeMapper enclosingMethod() { + return EnclosingMethodMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code Exceptions} attribute} + * @since 23 + */ + public static AttributeMapper exceptions() { + return ExceptionsMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code InnerClasses} attribute} + * @since 23 + */ + public static AttributeMapper innerClasses() { + return InnerClassesMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code LineNumberTable} attribute} + * The mapper permits multiple instances in a given location. + * @since 23 + */ + public static AttributeMapper lineNumberTable() { + return LineNumberTableMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code LocalVariableTable} attribute} + * The mapper permits multiple instances in a given location. + * @since 23 + */ + public static AttributeMapper localVariableTable() { + return LocalVariableTableMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code LocalVariableTypeTable} attribute} + * The mapper permits multiple instances in a given location. + * @since 23 + */ + public static AttributeMapper localVariableTypeTable() { + return LocalVariableTypeTableMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code MethodParameters} attribute} + * @since 23 + */ + public static AttributeMapper methodParameters() { + return MethodParametersMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code Module} attribute} + * @since 23 + */ + public static AttributeMapper module() { + return ModuleMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code ModuleHashes} attribute} + * @since 23 + */ + public static AttributeMapper moduleHashes() { + return ModuleHashesMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code ModuleMainClass} attribute} + * @since 23 + */ + public static AttributeMapper moduleMainClass() { + return ModuleMainClassMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code ModulePackages} attribute} + * @since 23 + */ + public static AttributeMapper modulePackages() { + return ModulePackagesMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code ModuleResolution} attribute} + * @since 23 + */ + public static AttributeMapper moduleResolution() { + return ModuleResolutionMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code ModuleTarget} attribute} + * @since 23 + */ + public static AttributeMapper moduleTarget() { + return ModuleTargetMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code NestHost} attribute} + * @since 23 + */ + public static AttributeMapper nestHost() { + return NestHostMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code NestMembers} attribute} + * @since 23 + */ + public static AttributeMapper nestMembers() { + return NestMembersMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code PermittedSubclasses} attribute} + * @since 23 + */ + public static AttributeMapper permittedSubclasses() { + return PermittedSubclassesMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code Record} attribute} + * @since 23 + */ + public static AttributeMapper record() { + return RecordMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code RuntimeInvisibleAnnotations} attribute} + * @since 23 + */ + public static AttributeMapper runtimeInvisibleAnnotations() { + return RuntimeInvisibleAnnotationsMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code RuntimeInvisibleParameterAnnotations} attribute} + * @since 23 + */ + public static AttributeMapper runtimeInvisibleParameterAnnotations() { + return RuntimeInvisibleParameterAnnotationsMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code RuntimeInvisibleTypeAnnotations} attribute} + * @since 23 + */ + public static AttributeMapper runtimeInvisibleTypeAnnotations() { + return RuntimeInvisibleTypeAnnotationsMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code RuntimeVisibleAnnotations} attribute} + * @since 23 + */ + public static AttributeMapper runtimeVisibleAnnotations() { + return RuntimeVisibleAnnotationsMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code RuntimeVisibleParameterAnnotations} attribute} + * @since 23 + */ + public static AttributeMapper runtimeVisibleParameterAnnotations() { + return RuntimeVisibleParameterAnnotationsMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code RuntimeVisibleTypeAnnotations} attribute} + * @since 23 + */ + public static AttributeMapper runtimeVisibleTypeAnnotations() { + return RuntimeVisibleTypeAnnotationsMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code Signature} attribute} + * @since 23 + */ + public static AttributeMapper signature() { + return SignatureMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code SourceDebugExtension} attribute} + * @since 23 + */ + public static AttributeMapper sourceDebugExtension() { + return SourceDebugExtensionMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code SourceFile} attribute} + * @since 23 + */ + public static AttributeMapper sourceFile() { + return SourceFileMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code SourceID} attribute} + * @since 23 + */ + public static AttributeMapper sourceId() { + return SourceIDMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code StackMapTable} attribute} + * @since 23 + */ + public static AttributeMapper stackMapTable() { + return StackMapTableMapper.INSTANCE; + } + + /** + * {@return Attribute mapper for the {@code Synthetic} attribute} + * The mapper permits multiple instances in a given location. + * @since 23 + */ + public static AttributeMapper synthetic() { + return SyntheticMapper.INSTANCE; } } diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractAttributeMapper.java b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractAttributeMapper.java index 861bcd3b601..9bb3f275ba1 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractAttributeMapper.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractAttributeMapper.java @@ -24,35 +24,45 @@ */ package jdk.internal.classfile.impl; +import java.lang.classfile.Annotation; import java.lang.classfile.Attribute; import java.lang.classfile.AttributeMapper; +import java.lang.classfile.AttributedElement; import java.lang.classfile.BufWriter; +import java.lang.classfile.ClassReader; +import java.lang.classfile.attribute.*; +import java.util.List; -public abstract class AbstractAttributeMapper> +import static java.lang.classfile.Attributes.*; + +public sealed abstract class AbstractAttributeMapper> implements AttributeMapper { private final String name; + private final AttributeMapper.AttributeStability stability; private final boolean allowMultiple; protected abstract void writeBody(BufWriter buf, T attr); - public AbstractAttributeMapper(String name) { - this(name, false); + public AbstractAttributeMapper(String name, AttributeMapper.AttributeStability stability) { + this(name, stability, false); } public AbstractAttributeMapper(String name, + AttributeMapper.AttributeStability stability, boolean allowMultiple) { this.name = name; + this.stability = stability; this.allowMultiple = allowMultiple; } @Override - public String name() { + public final String name() { return name; } @Override - public void writeAttribute(BufWriter buf, T attr) { + public final void writeAttribute(BufWriter buf, T attr) { buf.writeIndex(buf.constantPool().utf8Entry(name)); buf.writeInt(0); int start = buf.size(); @@ -61,6 +71,11 @@ public abstract class AbstractAttributeMapper> buf.patchInt(start - 4, 4, written); } + @Override + public AttributeMapper.AttributeStability stability() { + return stability; + } + @Override public boolean allowMultiple() { return allowMultiple; @@ -71,4 +86,739 @@ public abstract class AbstractAttributeMapper> return String.format("AttributeMapper[name=%s, allowMultiple=%b, stability=%s]", name, allowMultiple, stability()); } + + public static final class AnnotationDefaultMapper extends AbstractAttributeMapper { + public static final AnnotationDefaultMapper INSTANCE = new AnnotationDefaultMapper(); + + private AnnotationDefaultMapper() { + super(NAME_ANNOTATION_DEFAULT, AttributeStability.CP_REFS); + } + + @Override + public AnnotationDefaultAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundAnnotationDefaultAttr(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, AnnotationDefaultAttribute attr) { + attr.defaultValue().writeTo(buf); + } + } + + public static final class BootstrapMethodsMapper extends AbstractAttributeMapper { + public static final BootstrapMethodsMapper INSTANCE = new BootstrapMethodsMapper(); + + private BootstrapMethodsMapper() { + super(NAME_BOOTSTRAP_METHODS, AttributeStability.CP_REFS); + } + + @Override + public BootstrapMethodsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundBootstrapMethodsAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, BootstrapMethodsAttribute attr) { + buf.writeList(attr.bootstrapMethods()); + } + } + + public static final class CharacterRangeTableMapper extends AbstractAttributeMapper { + public static final CharacterRangeTableMapper INSTANCE = new CharacterRangeTableMapper(); + + private CharacterRangeTableMapper() { + super(NAME_CHARACTER_RANGE_TABLE, AttributeStability.LABELS, true); + } + + @Override + public CharacterRangeTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundCharacterRangeTableAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, CharacterRangeTableAttribute attr) { + List ranges = attr.characterRangeTable(); + buf.writeU2(ranges.size()); + for (CharacterRangeInfo info : ranges) { + buf.writeU2(info.startPc()); + buf.writeU2(info.endPc()); + buf.writeInt(info.characterRangeStart()); + buf.writeInt(info.characterRangeEnd()); + buf.writeU2(info.flags()); + } + } + } + + public static final class CodeMapper extends AbstractAttributeMapper { + public static final CodeMapper INSTANCE = new CodeMapper(); + + private CodeMapper() { + super(NAME_CODE, AttributeStability.CP_REFS); + } + + @Override + public CodeAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new CodeImpl(e, cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, CodeAttribute attr) { + throw new UnsupportedOperationException("Code attribute does not support direct write"); + } + } + + public static final class CompilationIDMapper extends AbstractAttributeMapper { + public static final CompilationIDMapper INSTANCE = new CompilationIDMapper(); + + private CompilationIDMapper() { + super(NAME_COMPILATION_ID, AttributeStability.CP_REFS); + } + + @Override + public CompilationIDAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundCompilationIDAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, CompilationIDAttribute attr) { + buf.writeIndex(attr.compilationId()); + } + } + + public static final class ConstantValueMapper extends AbstractAttributeMapper { + public static final ConstantValueMapper INSTANCE = new ConstantValueMapper(); + + private ConstantValueMapper() { + super(NAME_CONSTANT_VALUE, AttributeStability.CP_REFS); + } + + @Override + public ConstantValueAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundConstantValueAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, ConstantValueAttribute attr) { + buf.writeIndex(attr.constant()); + } + } + + public static final class DeprecatedMapper extends AbstractAttributeMapper { + public static final DeprecatedMapper INSTANCE = new DeprecatedMapper(); + + private DeprecatedMapper() { + super(NAME_DEPRECATED, AttributeStability.STATELESS, true); + } + + @Override + public DeprecatedAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundDeprecatedAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, DeprecatedAttribute attr) { + // empty + } + } + + public static final class EnclosingMethodMapper extends AbstractAttributeMapper { + public static final EnclosingMethodMapper INSTANCE = new EnclosingMethodMapper(); + + private EnclosingMethodMapper() { + super(NAME_ENCLOSING_METHOD, AttributeStability.CP_REFS); + } + + @Override + public EnclosingMethodAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundEnclosingMethodAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, EnclosingMethodAttribute attr) { + buf.writeIndex(attr.enclosingClass()); + buf.writeIndexOrZero(attr.enclosingMethod().orElse(null)); + } + } + + public static final class ExceptionsMapper extends AbstractAttributeMapper { + public static final ExceptionsMapper INSTANCE = new ExceptionsMapper(); + + private ExceptionsMapper() { + super(NAME_EXCEPTIONS, AttributeStability.CP_REFS); + } + + @Override + public ExceptionsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundExceptionsAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, ExceptionsAttribute attr) { + buf.writeListIndices(attr.exceptions()); + } + } + + public static final class InnerClassesMapper extends AbstractAttributeMapper { + public static final InnerClassesMapper INSTANCE = new InnerClassesMapper(); + + private InnerClassesMapper() { + super(NAME_INNER_CLASSES, AttributeStability.CP_REFS); + } + + @Override + public InnerClassesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundInnerClassesAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, InnerClassesAttribute attr) { + List classes = attr.classes(); + buf.writeU2(classes.size()); + for (InnerClassInfo ic : classes) { + buf.writeIndex(ic.innerClass()); + buf.writeIndexOrZero(ic.outerClass().orElse(null)); + buf.writeIndexOrZero(ic.innerName().orElse(null)); + buf.writeU2(ic.flagsMask()); + } + } + } + + public static final class LineNumberTableMapper extends AbstractAttributeMapper { + public static final LineNumberTableMapper INSTANCE = new LineNumberTableMapper(); + + private LineNumberTableMapper() { + super(NAME_LINE_NUMBER_TABLE, AttributeStability.LABELS, true); + } + + @Override + public LineNumberTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundLineNumberTableAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, LineNumberTableAttribute attr) { + List lines = attr.lineNumbers(); + buf.writeU2(lines.size()); + for (LineNumberInfo line : lines) { + buf.writeU2(line.startPc()); + buf.writeU2(line.lineNumber()); + } + } + } + + public static final class LocalVariableTableMapper extends AbstractAttributeMapper { + public static final LocalVariableTableMapper INSTANCE = new LocalVariableTableMapper(); + + private LocalVariableTableMapper() { + super(NAME_LOCAL_VARIABLE_TABLE, AttributeStability.LABELS, true); + } + + @Override + public LocalVariableTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundLocalVariableTableAttribute(e, cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, LocalVariableTableAttribute attr) { + List infos = attr.localVariables(); + buf.writeU2(infos.size()); + for (LocalVariableInfo info : infos) { + buf.writeU2(info.startPc()); + buf.writeU2(info.length()); + buf.writeIndex(info.name()); + buf.writeIndex(info.type()); + buf.writeU2(info.slot()); + } + } + } + + public static final class LocalVariableTypeTableMapper extends AbstractAttributeMapper { + public static final LocalVariableTypeTableMapper INSTANCE = new LocalVariableTypeTableMapper(); + + private LocalVariableTypeTableMapper() { + super(NAME_LOCAL_VARIABLE_TYPE_TABLE, AttributeStability.LABELS, true); + } + + @Override + public LocalVariableTypeTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundLocalVariableTypeTableAttribute(e, cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, LocalVariableTypeTableAttribute attr) { + List infos = attr.localVariableTypes(); + buf.writeU2(infos.size()); + for (LocalVariableTypeInfo info : infos) { + buf.writeU2(info.startPc()); + buf.writeU2(info.length()); + buf.writeIndex(info.name()); + buf.writeIndex(info.signature()); + buf.writeU2(info.slot()); + } + } + } + + public static final class MethodParametersMapper extends AbstractAttributeMapper { + public static final MethodParametersMapper INSTANCE = new MethodParametersMapper(); + + private MethodParametersMapper() { + super(NAME_METHOD_PARAMETERS, AttributeStability.CP_REFS); + } + + @Override + public MethodParametersAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundMethodParametersAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, MethodParametersAttribute attr) { + List parameters = attr.parameters(); + buf.writeU1(parameters.size()); + for (MethodParameterInfo info : parameters) { + buf.writeIndexOrZero(info.name().orElse(null)); + buf.writeU2(info.flagsMask()); + } + } + } + + public static final class ModuleMapper extends AbstractAttributeMapper { + public static final ModuleMapper INSTANCE = new ModuleMapper(); + + private ModuleMapper() { + super(NAME_MODULE, AttributeStability.CP_REFS); + } + + @Override + public ModuleAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundModuleAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, ModuleAttribute attr) { + buf.writeIndex(attr.moduleName()); + buf.writeU2(attr.moduleFlagsMask()); + buf.writeIndexOrZero(attr.moduleVersion().orElse(null)); + buf.writeU2(attr.requires().size()); + for (ModuleRequireInfo require : attr.requires()) { + buf.writeIndex(require.requires()); + buf.writeU2(require.requiresFlagsMask()); + buf.writeIndexOrZero(require.requiresVersion().orElse(null)); + } + buf.writeU2(attr.exports().size()); + for (ModuleExportInfo export : attr.exports()) { + buf.writeIndex(export.exportedPackage()); + buf.writeU2(export.exportsFlagsMask()); + buf.writeListIndices(export.exportsTo()); + } + buf.writeU2(attr.opens().size()); + for (ModuleOpenInfo open : attr.opens()) { + buf.writeIndex(open.openedPackage()); + buf.writeU2(open.opensFlagsMask()); + buf.writeListIndices(open.opensTo()); + } + buf.writeListIndices(attr.uses()); + buf.writeU2(attr.provides().size()); + for (ModuleProvideInfo provide : attr.provides()) { + buf.writeIndex(provide.provides()); + buf.writeListIndices(provide.providesWith()); + } + } + } + + public static final class ModuleHashesMapper extends AbstractAttributeMapper { + public static final ModuleHashesMapper INSTANCE = new ModuleHashesMapper(); + + private ModuleHashesMapper() { + super(NAME_MODULE_HASHES, AttributeStability.CP_REFS); + } + + @Override + public ModuleHashesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundModuleHashesAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, ModuleHashesAttribute attr) { + buf.writeIndex(attr.algorithm()); + List hashes = attr.hashes(); + buf.writeU2(hashes.size()); + for (ModuleHashInfo hash : hashes) { + buf.writeIndex(hash.moduleName()); + buf.writeU2(hash.hash().length); + buf.writeBytes(hash.hash()); + } + } + } + + public static final class ModuleMainClassMapper extends AbstractAttributeMapper { + public static final ModuleMainClassMapper INSTANCE = new ModuleMainClassMapper(); + + private ModuleMainClassMapper() { + super(NAME_MODULE_MAIN_CLASS, AttributeStability.CP_REFS); + } + + @Override + public ModuleMainClassAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundModuleMainClassAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, ModuleMainClassAttribute attr) { + buf.writeIndex(attr.mainClass()); + } + } + + public static final class ModulePackagesMapper extends AbstractAttributeMapper { + public static final ModulePackagesMapper INSTANCE = new ModulePackagesMapper(); + + private ModulePackagesMapper() { + super(NAME_MODULE_PACKAGES, AttributeStability.CP_REFS); + } + + @Override + public ModulePackagesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundModulePackagesAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, ModulePackagesAttribute attr) { + buf.writeListIndices(attr.packages()); + } + } + + public static final class ModuleResolutionMapper extends AbstractAttributeMapper { + public static final ModuleResolutionMapper INSTANCE = new ModuleResolutionMapper(); + + private ModuleResolutionMapper() { + super(NAME_MODULE_RESOLUTION, AttributeStability.STATELESS); + } + + @Override + public ModuleResolutionAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundModuleResolutionAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, ModuleResolutionAttribute attr) { + buf.writeU2(attr.resolutionFlags()); + } + } + + public static final class ModuleTargetMapper extends AbstractAttributeMapper { + public static final ModuleTargetMapper INSTANCE = new ModuleTargetMapper(); + + private ModuleTargetMapper() { + super(NAME_MODULE_TARGET, AttributeStability.CP_REFS); + } + + @Override + public ModuleTargetAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundModuleTargetAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, ModuleTargetAttribute attr) { + buf.writeIndex(attr.targetPlatform()); + } + } + + public static final class NestHostMapper extends AbstractAttributeMapper { + public static final NestHostMapper INSTANCE = new NestHostMapper(); + + private NestHostMapper() { + super(NAME_NEST_HOST, AttributeStability.CP_REFS); + } + + @Override + public NestHostAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundNestHostAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, NestHostAttribute attr) { + buf.writeIndex(attr.nestHost()); + } + } + + public static final class NestMembersMapper extends AbstractAttributeMapper { + public static final NestMembersMapper INSTANCE = new NestMembersMapper(); + + private NestMembersMapper() { + super(NAME_NEST_MEMBERS, AttributeStability.CP_REFS); + } + + @Override + public NestMembersAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundNestMembersAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, NestMembersAttribute attr) { + buf.writeListIndices(attr.nestMembers()); + } + } + + public static final class PermittedSubclassesMapper extends AbstractAttributeMapper { + public static final PermittedSubclassesMapper INSTANCE = new PermittedSubclassesMapper(); + + private PermittedSubclassesMapper() { + super(NAME_PERMITTED_SUBCLASSES, AttributeStability.CP_REFS); + } + + @Override + public PermittedSubclassesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundPermittedSubclassesAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, PermittedSubclassesAttribute attr) { + buf.writeListIndices(attr.permittedSubclasses()); + } + } + + public static final class RecordMapper extends AbstractAttributeMapper { + public static final RecordMapper INSTANCE = new RecordMapper(); + + private RecordMapper() { + super(NAME_RECORD, AttributeStability.CP_REFS); + } + + @Override + public RecordAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundRecordAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, RecordAttribute attr) { + List components = attr.components(); + buf.writeU2(components.size()); + for (RecordComponentInfo info : components) { + buf.writeIndex(info.name()); + buf.writeIndex(info.descriptor()); + buf.writeList(info.attributes()); + } + } + } + + public static final class RuntimeInvisibleAnnotationsMapper extends AbstractAttributeMapper { + public static final RuntimeInvisibleAnnotationsMapper INSTANCE = new RuntimeInvisibleAnnotationsMapper(); + + private RuntimeInvisibleAnnotationsMapper() { + super(NAME_RUNTIME_INVISIBLE_ANNOTATIONS, AttributeStability.CP_REFS); + } + + @Override + public RuntimeInvisibleAnnotationsAttribute readAttribute(AttributedElement enclosing, ClassReader cf, int pos) { + return new BoundAttribute.BoundRuntimeInvisibleAnnotationsAttribute(cf, pos); + } + + @Override + protected void writeBody(BufWriter buf, RuntimeInvisibleAnnotationsAttribute attr) { + buf.writeList(attr.annotations()); + } + } + + public static final class RuntimeInvisibleParameterAnnotationsMapper extends AbstractAttributeMapper { + public static final RuntimeInvisibleParameterAnnotationsMapper INSTANCE = new RuntimeInvisibleParameterAnnotationsMapper(); + + private RuntimeInvisibleParameterAnnotationsMapper() { + super(NAME_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS, AttributeStability.CP_REFS); + } + + @Override + public RuntimeInvisibleParameterAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundRuntimeInvisibleParameterAnnotationsAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, RuntimeInvisibleParameterAnnotationsAttribute attr) { + List> lists = attr.parameterAnnotations(); + buf.writeU1(lists.size()); + for (List list : lists) + buf.writeList(list); + } + } + + public static final class RuntimeInvisibleTypeAnnotationsMapper extends AbstractAttributeMapper { + public static final RuntimeInvisibleTypeAnnotationsMapper INSTANCE = new RuntimeInvisibleTypeAnnotationsMapper(); + + private RuntimeInvisibleTypeAnnotationsMapper() { + super(NAME_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, AttributeStability.UNSTABLE); + } + + @Override + public RuntimeInvisibleTypeAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundRuntimeInvisibleTypeAnnotationsAttribute(e, cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, RuntimeInvisibleTypeAnnotationsAttribute attr) { + buf.writeList(attr.annotations()); + } + } + + public static final class RuntimeVisibleAnnotationsMapper extends AbstractAttributeMapper { + public static final RuntimeVisibleAnnotationsMapper INSTANCE = new RuntimeVisibleAnnotationsMapper(); + + private RuntimeVisibleAnnotationsMapper() { + super(NAME_RUNTIME_VISIBLE_ANNOTATIONS, AttributeStability.CP_REFS); + } + + @Override + public RuntimeVisibleAnnotationsAttribute readAttribute(AttributedElement enclosing, ClassReader cf, int pos) { + return new BoundAttribute.BoundRuntimeVisibleAnnotationsAttribute(cf, pos); + } + + @Override + protected void writeBody(BufWriter buf, RuntimeVisibleAnnotationsAttribute attr) { + buf.writeList(attr.annotations()); + } + } + + public static final class RuntimeVisibleParameterAnnotationsMapper extends AbstractAttributeMapper { + public static final RuntimeVisibleParameterAnnotationsMapper INSTANCE = new RuntimeVisibleParameterAnnotationsMapper(); + + private RuntimeVisibleParameterAnnotationsMapper() { + super(NAME_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, AttributeStability.CP_REFS); + } + + @Override + public RuntimeVisibleParameterAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundRuntimeVisibleParameterAnnotationsAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, RuntimeVisibleParameterAnnotationsAttribute attr) { + List> lists = attr.parameterAnnotations(); + buf.writeU1(lists.size()); + for (List list : lists) + buf.writeList(list); + } + } + + public static final class RuntimeVisibleTypeAnnotationsMapper extends AbstractAttributeMapper { + public static final RuntimeVisibleTypeAnnotationsMapper INSTANCE = new RuntimeVisibleTypeAnnotationsMapper(); + + private RuntimeVisibleTypeAnnotationsMapper() { + super(NAME_RUNTIME_VISIBLE_TYPE_ANNOTATIONS, AttributeStability.UNSTABLE); + } + + @Override + public RuntimeVisibleTypeAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundRuntimeVisibleTypeAnnotationsAttribute(e, cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, RuntimeVisibleTypeAnnotationsAttribute attr) { + buf.writeList(attr.annotations()); + } + } + + public static final class SignatureMapper extends AbstractAttributeMapper { + public static final SignatureMapper INSTANCE = new SignatureMapper(); + + private SignatureMapper() { + super(NAME_SIGNATURE, AttributeStability.CP_REFS); + } + + @Override + public SignatureAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundSignatureAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, SignatureAttribute attr) { + buf.writeIndex(attr.signature()); + } + } + + public static final class SourceDebugExtensionMapper extends AbstractAttributeMapper { + public static final SourceDebugExtensionMapper INSTANCE = new SourceDebugExtensionMapper(); + + private SourceDebugExtensionMapper() { + super(NAME_SOURCE_DEBUG_EXTENSION, AttributeStability.STATELESS); + } + + @Override + public SourceDebugExtensionAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundSourceDebugExtensionAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, SourceDebugExtensionAttribute attr) { + buf.writeBytes(attr.contents()); + } + } + + public static final class SourceFileMapper extends AbstractAttributeMapper { + public static final SourceFileMapper INSTANCE = new SourceFileMapper(); + + private SourceFileMapper() { + super(NAME_SOURCE_FILE, AttributeStability.CP_REFS); + } + + @Override + public SourceFileAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundSourceFileAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, SourceFileAttribute attr) { + buf.writeIndex(attr.sourceFile()); + } + } + + public static final class SourceIDMapper extends AbstractAttributeMapper { + public static final SourceIDMapper INSTANCE = new SourceIDMapper(); + + private SourceIDMapper() { + super(NAME_SOURCE_ID, AttributeStability.CP_REFS); + } + + @Override + public SourceIDAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundSourceIDAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, SourceIDAttribute attr) { + buf.writeIndex(attr.sourceId()); + } + } + + public static final class StackMapTableMapper extends AbstractAttributeMapper { + public static final StackMapTableMapper INSTANCE = new StackMapTableMapper(); + + private StackMapTableMapper() { + super(NAME_STACK_MAP_TABLE, AttributeStability.LABELS); + } + + @Override + public StackMapTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundStackMapTableAttribute((CodeImpl)e, cf, this, p); + } + + @Override + protected void writeBody(BufWriter b, StackMapTableAttribute attr) { + StackMapDecoder.writeFrames(b, attr.entries()); + } + } + + public static final class SyntheticMapper extends AbstractAttributeMapper { + public static final SyntheticMapper INSTANCE = new SyntheticMapper(); + + private SyntheticMapper() { + super(NAME_SYNTHETIC, AttributeStability.STATELESS, true); + } + + @Override + public SyntheticAttribute readAttribute(AttributedElement e, ClassReader cf, int p) { + return new BoundAttribute.BoundSyntheticAttribute(cf, this, p); + } + + @Override + protected void writeBody(BufWriter buf, SyntheticAttribute attr) { + // empty + } + } } diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java b/src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java index d572e09040e..69e7f34731f 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java @@ -43,6 +43,8 @@ import java.lang.classfile.constantpool.PackageEntry; import java.lang.classfile.constantpool.Utf8Entry; import jdk.internal.access.SharedSecrets; +import static java.lang.classfile.Attributes.*; + public abstract sealed class BoundAttribute> extends AbstractElement implements Attribute { @@ -140,7 +142,7 @@ public abstract sealed class BoundAttribute> throw new IllegalArgumentException("attribute " + name.stringValue() + " too big to handle"); } - var mapper = Attributes.standardAttribute(name); + var mapper = standardAttribute(name); if (mapper == null) { mapper = customAttributes.apply(name); } @@ -889,7 +891,7 @@ public abstract sealed class BoundAttribute> public BoundRuntimeInvisibleAnnotationsAttribute(ClassReader cf, int payloadStart) { - super(cf, Attributes.RUNTIME_INVISIBLE_ANNOTATIONS, payloadStart); + super(cf, Attributes.runtimeInvisibleAnnotations(), payloadStart); } @Override @@ -907,7 +909,7 @@ public abstract sealed class BoundAttribute> public BoundRuntimeVisibleAnnotationsAttribute(ClassReader cf, int payloadStart) { - super(cf, Attributes.RUNTIME_VISIBLE_ANNOTATIONS, payloadStart); + super(cf, Attributes.runtimeVisibleAnnotations(), payloadStart); } @Override @@ -983,4 +985,88 @@ public abstract sealed class BoundAttribute> return classReader.readBytes(payloadStart + 8, codeLength()); } } + + /** + * {@return the attribute mapper for a standard attribute} + * + * @param name the name of the attribute to find + */ + public static AttributeMapper standardAttribute(Utf8Entry name) { + // critical bootstrap path, so no lambdas nor method handles here + return switch (name.hashCode()) { + case 0x78147009 -> + name.equalsString(NAME_ANNOTATION_DEFAULT) ? annotationDefault() : null; + case 0x665e3a3a -> + name.equalsString(NAME_BOOTSTRAP_METHODS) ? bootstrapMethods() : null; + case 0xcb7e162 -> + name.equalsString(NAME_CHARACTER_RANGE_TABLE) ? characterRangeTable() : null; + case 0x21e41e7e -> + name.equalsString(NAME_CODE) ? code() : null; + case 0x5a306b41 -> + name.equalsString(NAME_COMPILATION_ID) ? compilationId() : null; + case 0x3e191c7c -> + name.equalsString(NAME_CONSTANT_VALUE) ? constantValue() : null; + case 0x5e88ed0c -> + name.equalsString(NAME_DEPRECATED) ? deprecated() : null; + case 0x7284695e -> + name.equalsString(NAME_ENCLOSING_METHOD) ? enclosingMethod() : null; + case 0x21df25db -> + name.equalsString(NAME_EXCEPTIONS) ? exceptions() : null; + case 0x11392da9 -> + name.equalsString(NAME_INNER_CLASSES) ? innerClasses() : null; + case 0x167536fc -> + name.equalsString(NAME_LINE_NUMBER_TABLE) ? lineNumberTable() : null; + case 0x46939abc -> + name.equalsString(NAME_LOCAL_VARIABLE_TABLE) ? localVariableTable() : null; + case 0x63ee67f4 -> + name.equalsString(NAME_LOCAL_VARIABLE_TYPE_TABLE) ? localVariableTypeTable() : null; + case 0x2b597e15 -> + name.equalsString(NAME_METHOD_PARAMETERS) ? methodParameters() : null; + case 0x19f20ade -> + name.equalsString(NAME_MODULE) ? module() : null; + case 0x47f6395e -> + name.equalsString(NAME_MODULE_HASHES) ? moduleHashes() : null; + case 0x54db809 -> + name.equalsString(NAME_MODULE_MAIN_CLASS) ? moduleMainClass() : null; + case 0x1abd1c2c -> + name.equalsString(NAME_MODULE_PACKAGES) ? modulePackages() : null; + case 0x6ba46dd -> + name.equalsString(NAME_MODULE_RESOLUTION) ? moduleResolution() : null; + case 0x46f7d91d -> + name.equalsString(NAME_MODULE_TARGET) ? moduleTarget() : null; + case 0x5137f53 -> + name.equalsString(NAME_NEST_HOST) ? nestHost() : null; + case 0x4a8fa3b6 -> + name.equalsString(NAME_NEST_MEMBERS) ? nestMembers() : null; + case 0x55c73cb6 -> + name.equalsString(NAME_PERMITTED_SUBCLASSES) ? permittedSubclasses() : null; + case 0x3fe76d4e -> + name.equalsString(NAME_RECORD) ? record() : null; + case 0x180d6925 -> + name.equalsString(NAME_RUNTIME_INVISIBLE_ANNOTATIONS) ? runtimeInvisibleAnnotations() : null; + case 0x7be22752 -> + name.equalsString(NAME_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS) ? runtimeInvisibleParameterAnnotations() : null; + case 0x5299824 -> + name.equalsString(NAME_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS) ? runtimeInvisibleTypeAnnotations() : null; + case 0x3534786e -> + name.equalsString(NAME_RUNTIME_VISIBLE_ANNOTATIONS) ? runtimeVisibleAnnotations() : null; + case 0xb4b4ac6 -> + name.equalsString(NAME_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS) ? runtimeVisibleParameterAnnotations() : null; + case 0x6926482 -> + name.equalsString(NAME_RUNTIME_VISIBLE_TYPE_ANNOTATIONS) ? runtimeVisibleTypeAnnotations() : null; + case 0x16a42b7c -> + name.equalsString(NAME_SIGNATURE) ? signature() : null; + case 0x400ab245 -> + name.equalsString(NAME_SOURCE_DEBUG_EXTENSION) ? sourceDebugExtension() : null; + case 0x2af490d4 -> + name.equalsString(NAME_SOURCE_FILE) ? sourceFile() : null; + case 0x303e0c58 -> + name.equalsString(NAME_SOURCE_ID) ? sourceId() : null; + case 0x19c7d0cd -> + name.equalsString(NAME_STACK_MAP_TABLE) ? stackMapTable() : null; + case 0x3dc79b7a -> + name.equalsString(NAME_SYNTHETIC) ? synthetic() : null; + default -> null; + }; + } } diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/ClassImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/ClassImpl.java index 8604ec5e597..65e9a269265 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 final class ClassImpl } 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(); + return attributes().stream().allMatch(a -> + a instanceof ModuleAttribute + || a instanceof ModulePackagesAttribute + || a instanceof ModuleHashesAttribute + || a instanceof ModuleMainClassAttribute + || a instanceof ModuleResolutionAttribute + || a instanceof ModuleTargetAttribute + || a instanceof InnerClassesAttribute + || a instanceof SourceFileAttribute + || a instanceof SourceDebugExtensionAttribute + || a instanceof RuntimeVisibleAnnotationsAttribute + || a instanceof RuntimeInvisibleAnnotationsAttribute + || a instanceof CustomAttribute); } - - 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); } 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 4878ad56ae8..d7c1f7b28fd 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 @@ public final class ClassReaderImpl if (bootstrapMethodsAttribute == null) { bootstrapMethodsAttribute - = containedClass.findAttribute(Attributes.BOOTSTRAP_METHODS) + = containedClass.findAttribute(Attributes.bootstrapMethods()) .orElse(new UnboundAttribute.EmptyBootstrapAttribute()); } @@ -324,7 +324,7 @@ public final class ClassReaderImpl 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 4eba39989f6..ec6ba32801a 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/CodeImpl.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/CodeImpl.java @@ -230,7 +230,7 @@ public final class CodeImpl private void inflateLineNumbers() { for (Attribute a : attributes()) { - if (a.attributeMapper() == Attributes.LINE_NUMBER_TABLE) { + if (a.attributeMapper() == Attributes.lineNumberTable()) { BoundLineNumberTableAttribute attr = (BoundLineNumberTableAttribute) a; if (lineNumbers == null) lineNumbers = new int[codeLength + 1]; @@ -252,7 +252,7 @@ public final class CodeImpl } private void inflateJumpTargets() { - Optional a = findAttribute(Attributes.STACK_MAP_TABLE); + Optional a = findAttribute(Attributes.stackMapTable()); if (a.isEmpty()) { if (classReader.readU2(6) <= ClassFile.JAVA_6_VERSION) { //fallback to jump targets inflation without StackMapTableAttribute @@ -325,8 +325,8 @@ public final class CodeImpl } private void inflateTypeAnnotations() { - findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).ifPresent(RuntimeVisibleTypeAnnotationsAttribute::annotations); - findAttribute(Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS).ifPresent(RuntimeInvisibleTypeAnnotationsAttribute::annotations); + findAttribute(Attributes.runtimeVisibleTypeAnnotations()).ifPresent(RuntimeVisibleTypeAnnotationsAttribute::annotations); + findAttribute(Attributes.runtimeInvisibleTypeAnnotations()).ifPresent(RuntimeInvisibleTypeAnnotationsAttribute::annotations); } private void generateCatchTargets(Consumer consumer) { @@ -345,7 +345,7 @@ public final class CodeImpl private void generateDebugElements(Consumer consumer) { for (Attribute a : attributes()) { - if (a.attributeMapper() == Attributes.CHARACTER_RANGE_TABLE) { + if (a.attributeMapper() == Attributes.characterRangeTable()) { var attr = (BoundCharacterRangeTableAttribute) a; int cnt = classReader.readU2(attr.payloadStart); int p = attr.payloadStart + 2; @@ -357,7 +357,7 @@ public final class CodeImpl consumer.accept(instruction); } } - else if (a.attributeMapper() == Attributes.LOCAL_VARIABLE_TABLE) { + else if (a.attributeMapper() == Attributes.localVariableTable()) { var attr = (BoundLocalVariableTableAttribute) a; int cnt = classReader.readU2(attr.payloadStart); int p = attr.payloadStart + 2; @@ -369,7 +369,7 @@ public final class CodeImpl consumer.accept(instruction); } } - else if (a.attributeMapper() == Attributes.LOCAL_VARIABLE_TYPE_TABLE) { + else if (a.attributeMapper() == Attributes.localVariableTypeTable()) { var attr = (BoundLocalVariableTypeTableAttribute) a; int cnt = classReader.readU2(attr.payloadStart); int p = attr.payloadStart + 2; @@ -381,10 +381,10 @@ public final class CodeImpl 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 9f68177351f..b961a12031f 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 @@ public final class DirectCodeBuilder 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 final class DirectCodeBuilder } 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 final class DirectCodeBuilder } 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 final class DirectCodeBuilder 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 final class DirectCodeBuilder 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 @@ public final class DirectCodeBuilder 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 0baaa5865ae..9a96e586c55 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 final class MethodImpl @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 db2b4f030a3..8deac9e3f95 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 final class SplitConstantPool implements ConstantPoolBuilder { } 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 17fcc5046a1..4a8677e876f 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 @@ public final class StackMapGenerator { * @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 bdb293493bf..70b58e423f6 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 abstract sealed class UnboundAttribute> private final ConstantValueEntry entry; public UnboundConstantValueAttribute(ConstantValueEntry entry) { - super(Attributes.CONSTANT_VALUE); + super(Attributes.constantValue()); this.entry = entry; } @@ -164,7 +164,7 @@ public abstract sealed class UnboundAttribute> extends UnboundAttribute implements DeprecatedAttribute { public UnboundDeprecatedAttribute() { - super(Attributes.DEPRECATED); + super(Attributes.deprecated()); } } @@ -172,7 +172,7 @@ public abstract sealed class UnboundAttribute> extends UnboundAttribute implements SyntheticAttribute { public UnboundSyntheticAttribute() { - super(Attributes.SYNTHETIC); + super(Attributes.synthetic()); } } @@ -182,7 +182,7 @@ public abstract sealed class UnboundAttribute> private final Utf8Entry signature; public UnboundSignatureAttribute(Utf8Entry signature) { - super(Attributes.SIGNATURE); + super(Attributes.signature()); this.signature = signature; } @@ -198,7 +198,7 @@ public abstract sealed class UnboundAttribute> private final List exceptions; public UnboundExceptionsAttribute(List exceptions) { - super(Attributes.EXCEPTIONS); + super(Attributes.exceptions()); this.exceptions = List.copyOf(exceptions); } @@ -214,7 +214,7 @@ public abstract sealed class UnboundAttribute> private final AnnotationValue annotationDefault; public UnboundAnnotationDefaultAttribute(AnnotationValue annotationDefault) { - super(Attributes.ANNOTATION_DEFAULT); + super(Attributes.annotationDefault()); this.annotationDefault = annotationDefault; } @@ -229,7 +229,7 @@ public abstract sealed class UnboundAttribute> private final Utf8Entry sourceFile; public UnboundSourceFileAttribute(Utf8Entry sourceFile) { - super(Attributes.SOURCE_FILE); + super(Attributes.sourceFile()); this.sourceFile = sourceFile; } @@ -245,7 +245,7 @@ public abstract sealed class UnboundAttribute> private final List entries; public UnboundStackMapTableAttribute(List entries) { - super(Attributes.STACK_MAP_TABLE); + super(Attributes.stackMapTable()); this.entries = List.copyOf(entries); } @@ -261,7 +261,7 @@ public abstract sealed class UnboundAttribute> 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 abstract sealed class UnboundAttribute> private final List components; public UnboundRecordAttribute(List components) { - super(Attributes.RECORD); + super(Attributes.record()); this.components = List.copyOf(components); } @@ -294,7 +294,7 @@ public abstract sealed class UnboundAttribute> 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 abstract sealed class UnboundAttribute> 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 abstract sealed class UnboundAttribute> final Utf8Entry moduleTarget; public UnboundModuleTargetAttribute(Utf8Entry moduleTarget) { - super(Attributes.MODULE_TARGET); + super(Attributes.moduleTarget()); this.moduleTarget = moduleTarget; } @@ -348,7 +348,7 @@ public abstract sealed class UnboundAttribute> final ClassEntry mainClass; public UnboundModuleMainClassAttribute(ClassEntry mainClass) { - super(Attributes.MODULE_MAIN_CLASS); + super(Attributes.moduleMainClass()); this.mainClass = mainClass; } @@ -365,7 +365,7 @@ public abstract sealed class UnboundAttribute> 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 abstract sealed class UnboundAttribute> 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 abstract sealed class UnboundAttribute> private final int resolutionFlags; public UnboundModuleResolutionAttribute(int flags) { - super(Attributes.MODULE_RESOLUTION); + super(Attributes.moduleResolution()); resolutionFlags = flags; } @@ -419,7 +419,7 @@ public abstract sealed class UnboundAttribute> 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 abstract sealed class UnboundAttribute> 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 abstract sealed class UnboundAttribute> private final ClassEntry hostEntry; public UnboundNestHostAttribute(ClassEntry hostEntry) { - super(Attributes.NEST_HOST); + super(Attributes.nestHost()); this.hostEntry = hostEntry; } @@ -467,7 +467,7 @@ public abstract sealed class UnboundAttribute> private final Utf8Entry idEntry; public UnboundCompilationIDAttribute(Utf8Entry idEntry) { - super(Attributes.COMPILATION_ID); + super(Attributes.compilationId()); this.idEntry = idEntry; } @@ -483,7 +483,7 @@ public abstract sealed class UnboundAttribute> private final Utf8Entry idEntry; public UnboundSourceIDAttribute(Utf8Entry idEntry) { - super(Attributes.SOURCE_ID); + super(Attributes.sourceId()); this.idEntry = idEntry; } @@ -499,7 +499,7 @@ public abstract sealed class UnboundAttribute> private final byte[] contents; public UnboundSourceDebugExtensionAttribute(byte[] contents) { - super(Attributes.SOURCE_DEBUG_EXTENSION); + super(Attributes.sourceDebugExtension()); this.contents = contents; } @@ -515,7 +515,7 @@ public abstract sealed class UnboundAttribute> 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 abstract sealed class UnboundAttribute> 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 abstract sealed class UnboundAttribute> 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 abstract sealed class UnboundAttribute> 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 abstract sealed class UnboundAttribute> 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 abstract sealed class UnboundAttribute> 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 abstract sealed class UnboundAttribute> 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 abstract sealed class UnboundAttribute> 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 abstract sealed class UnboundAttribute> 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 abstract sealed class UnboundAttribute> 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 abstract sealed class UnboundAttribute> Collection uses, Collection provides) { - super(Attributes.MODULE); + super(Attributes.module()); this.moduleName = moduleName; this.moduleFlags = moduleFlags; this.moduleVersion = moduleVersion; @@ -921,7 +921,7 @@ public abstract sealed class UnboundAttribute> 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 7bff7e6f06d..0e969272c40 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 class Util { 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 6be4a611e97..fefc6b20cb2 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 @@ public final class VerificationWrapper { } 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 a4cfc59eb20..b28078916c5 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 @@ final class FingerPrint { 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 23bec4e7298..839ac2fd041 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 class AttributeWriter extends BasicWriter { 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 c5ac15ee7da..798d2f2d3a8 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 class ClassWriter extends BasicWriter { } } - 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 class ClassWriter extends BasicWriter { 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 class ClassWriter extends BasicWriter { } try { - var sigAttr = classModel.findAttribute(Attributes.SIGNATURE).orElse(null); + var sigAttr = classModel.findAttribute(Attributes.signature()).orElse(null); if (sigAttr == null) { // use info from class file header if ((classModel.flags().flagsMask() & ACC_INTERFACE) == 0 @@ -399,13 +399,13 @@ public class ClassWriter extends BasicWriter { writeModifiers(flags.flags().stream().filter(fl -> fl.sourceModifier()) .map(fl -> Modifier.toString(fl.mask())).toList()); print(() -> sigPrinter.print( - f.findAttribute(Attributes.SIGNATURE) + f.findAttribute(Attributes.signature()) .map(SignatureAttribute::asTypeSignature) .orElseGet(() -> Signature.of(f.fieldTypeSymbol())))); print(" "); print(() -> f.fieldName().stringValue()); if (options.showConstants) { - var a = f.findAttribute(Attributes.CONSTANT_VALUE); + var a = f.findAttribute(Attributes.constantValue()); if (a.isPresent()) { print(" = "); var cv = a.get(); @@ -480,7 +480,7 @@ public class ClassWriter extends BasicWriter { writeModifiers(modifiers); try { - var sigAttr = m.findAttribute(Attributes.SIGNATURE); + var sigAttr = m.findAttribute(Attributes.signature()); MethodSignature d; if (sigAttr.isEmpty()) { d = MethodSignature.parseFrom(m.methodType().stringValue()); @@ -507,7 +507,7 @@ public class ClassWriter extends BasicWriter { break; } - var e_attr = m.findAttribute(Attributes.EXCEPTIONS); + var e_attr = m.findAttribute(Attributes.exceptions()); // if there are generic exceptions, there must be erased exceptions if (e_attr.isPresent()) { var exceptions = e_attr.get(); @@ -559,9 +559,9 @@ public class ClassWriter extends BasicWriter { } if (options.showLineAndLocalVariableTables) { - code.findAttribute(Attributes.LINE_NUMBER_TABLE) + code.findAttribute(Attributes.lineNumberTable()) .ifPresent(a -> attrWriter.write(a, code)); - code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE) + code.findAttribute(Attributes.localVariableTable()) .ifPresent(a -> attrWriter.write(a, code)); } } @@ -589,7 +589,7 @@ public class ClassWriter extends BasicWriter { 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 1c32fff24e0..ac8ab164e62 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 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask, Messages { 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 d6b57ca4c48..f19d8fce4bb 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 @@ public class LocalVariableTableWriter extends InstructionDetailWriter { 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 f9ac8c70e0f..04e7b3fd0e0 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 @@ public class LocalVariableTypeTableWriter extends InstructionDetailWriter { 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 1d06727ff63..884c0fa9f80 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 class SourceWriter extends InstructionDetailWriter { 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 @@ public class SourceWriter extends InstructionDetailWriter { // 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 9a83fddbb87..a1d939bcc4f 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 class StackMapWriter extends InstructionDetailWriter { } 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 a0236955cfc..d5e19bc4241 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 class TypeAnnotationWriter extends InstructionDetailWriter { pcMap = new HashMap<>(); codeAttribute = attr; check(NoteKind.VISIBLE, - m.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS) + m.findAttribute(Attributes.runtimeVisibleTypeAnnotations()) .map(a -> a.annotations())); check(NoteKind.INVISIBLE, - m.findAttribute(Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS) + m.findAttribute(Attributes.runtimeInvisibleTypeAnnotations()) .map(a -> a.annotations())); } diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Dependencies.java b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Dependencies.java index 422845150f0..c0ac835f4b6 100644 --- a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Dependencies.java +++ b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Dependencies.java @@ -597,7 +597,7 @@ public class Dependencies { void scanAttributes(AttributedElement attrs) { try { - var sa = attrs.findAttribute(Attributes.SIGNATURE).orElse(null); + var sa = attrs.findAttribute(Attributes.signature()).orElse(null); if (sa != null) { switch (attrs) { case ClassModel _ -> scan(sa.asClassSignature()); @@ -606,14 +606,14 @@ public class Dependencies { } } - var rvaa = attrs.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElse(null); + var rvaa = attrs.findAttribute(Attributes.runtimeVisibleAnnotations()).orElse(null); if (rvaa != null) { for (var anno : rvaa.annotations()) { scan(anno.classSymbol()); } } - var rvpaa = attrs.findAttribute(Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS).orElse(null); + var rvpaa = attrs.findAttribute(Attributes.runtimeVisibleParameterAnnotations()).orElse(null); if (rvpaa != null) { for (var parameter : rvpaa.parameterAnnotations()) { for (var anno : parameter) { @@ -622,7 +622,7 @@ public class Dependencies { } } - var exceptions = attrs.findAttribute(Attributes.EXCEPTIONS).orElse(null); + var exceptions = attrs.findAttribute(Attributes.exceptions()).orElse(null); if (exceptions != null) { for (var e : exceptions.exceptions()) { addClass(e); diff --git a/test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaMethod.java b/test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaMethod.java index ae077b3b3f4..00973fd78c2 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 class TestResolvedJavaMethod extends MethodUniverse { Map methodMap = buildMethodMap(type); ClassModel cf = readClassfile(c); for (MethodModel cm : cf.methods()) { - cm.findAttribute(Attributes.CODE).ifPresent(codeAttr -> { + cm.findAttribute(Attributes.code()).ifPresent(codeAttr -> { String key = cm.methodName().stringValue() + ":" + cm.methodType().stringValue(); HotSpotResolvedJavaMethod m = (HotSpotResolvedJavaMethod) Objects.requireNonNull(methodMap.get(key)); boolean isMethodWithManyArgs = c == getClass() && m.getName().equals("methodWithManyArgs"); diff --git a/test/jdk/java/lang/StackWalker/TestBCI.java b/test/jdk/java/lang/StackWalker/TestBCI.java index 3cba0505e9c..4d5e6a6eaf4 100644 --- a/test/jdk/java/lang/StackWalker/TestBCI.java +++ b/test/jdk/java/lang/StackWalker/TestBCI.java @@ -134,7 +134,7 @@ public class TestBCI { this.name = m.methodName().stringValue(); this.desc = m.methodTypeSymbol(); m.code().orElseThrow(() -> new IllegalArgumentException("Missing Code in " + m)) - .findAttribute(Attributes.LINE_NUMBER_TABLE) + .findAttribute(Attributes.lineNumberTable()) .orElseThrow(() -> new IllegalArgumentException("Missing LineNumberTable in " + m)) .lineNumbers().forEach(entry -> bciToLineNumbers.computeIfAbsent(entry.startPc(), _ -> new TreeSet<>()) diff --git a/test/jdk/java/lang/invoke/lambda/LambdaAsm.java b/test/jdk/java/lang/invoke/lambda/LambdaAsm.java index ebca93d639a..8369ea2bcd3 100644 --- a/test/jdk/java/lang/invoke/lambda/LambdaAsm.java +++ b/test/jdk/java/lang/invoke/lambda/LambdaAsm.java @@ -125,7 +125,7 @@ public class LambdaAsm { 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 9b4609fe8bc..2ef7dca11ae 100644 --- a/test/jdk/jdk/classfile/AdvancedTransformationsTest.java +++ b/test/jdk/jdk/classfile/AdvancedTransformationsTest.java @@ -120,9 +120,9 @@ class AdvancedTransformationsTest { 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 @@ class AdvancedTransformationsTest { 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 ed647784219..25d02b8172f 100644 --- a/test/jdk/jdk/classfile/AnnotationModelTest.java +++ b/test/jdk/jdk/classfile/AnnotationModelTest.java @@ -54,7 +54,7 @@ class AnnotationModelTest { @Test void readAnnos() { var model = ClassFile.of().parse(fileBytes); - var annotations = model.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).get().annotations(); + var annotations = model.findAttribute(Attributes.runtimeVisibleAnnotations()).get().annotations(); assertEquals(annotations.size(), 3); } diff --git a/test/jdk/jdk/classfile/AttributesTest.java b/test/jdk/jdk/classfile/AttributesTest.java new file mode 100644 index 00000000000..0d156dd5860 --- /dev/null +++ b/test/jdk/jdk/classfile/AttributesTest.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8331291 + * @summary Testing Attributes API. + * @run junit AttributesTest + */ +import java.lang.classfile.AttributeMapper; +import java.lang.classfile.Attributes; +import java.lang.classfile.constantpool.Utf8Entry; +import java.lang.reflect.Field; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +import jdk.internal.classfile.impl.BoundAttribute; +import jdk.internal.classfile.impl.TemporaryConstantPool; + +class AttributesTest { + + @Test + void testAttributesMapping() throws Exception { + var cp = TemporaryConstantPool.INSTANCE; + for (Field f : Attributes.class.getDeclaredFields()) { + if (f.getName().startsWith("NAME_") && f.getType() == String.class) { + Utf8Entry attrName = cp.utf8Entry((String)f.get(null)); + AttributeMapper mapper = BoundAttribute.standardAttribute(attrName); + assertNotNull(mapper, attrName.stringValue() + " 0x" + Integer.toHexString(attrName.hashCode())); + assertEquals(attrName.stringValue(), mapper.name()); + } + } + } +} diff --git a/test/jdk/jdk/classfile/BoundAttributeTest.java b/test/jdk/jdk/classfile/BoundAttributeTest.java index 8a25146bab9..103bcffa898 100644 --- a/test/jdk/jdk/classfile/BoundAttributeTest.java +++ b/test/jdk/jdk/classfile/BoundAttributeTest.java @@ -61,7 +61,7 @@ class BoundAttributeTest { }); 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 b13657e2072..21e275a837d 100644 --- a/test/jdk/jdk/classfile/CorpusTest.java +++ b/test/jdk/jdk/classfile/CorpusTest.java @@ -83,7 +83,7 @@ class CorpusTest { 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 @@ class CorpusTest { 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 be527d7bc11..810f02d5f19 100644 --- a/test/jdk/jdk/classfile/FilterDeadLabelsTest.java +++ b/test/jdk/jdk/classfile/FilterDeadLabelsTest.java @@ -66,9 +66,9 @@ class FilterDeadLabelsTest { }))).methods().get(0).code().get(); assertTrue(code.exceptionHandlers().isEmpty()); - code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE).ifPresent(a -> assertTrue(a.localVariables().isEmpty())); - code.findAttribute(Attributes.LOCAL_VARIABLE_TYPE_TABLE).ifPresent(a -> assertTrue(a.localVariableTypes().isEmpty())); - code.findAttribute(Attributes.CHARACTER_RANGE_TABLE).ifPresent(a -> assertTrue(a.characterRangeTable().isEmpty())); + code.findAttribute(Attributes.localVariableTable()).ifPresent(a -> assertTrue(a.localVariables().isEmpty())); + code.findAttribute(Attributes.localVariableTypeTable()).ifPresent(a -> assertTrue(a.localVariableTypes().isEmpty())); + code.findAttribute(Attributes.characterRangeTable()).ifPresent(a -> assertTrue(a.characterRangeTable().isEmpty())); } @ParameterizedTest diff --git a/test/jdk/jdk/classfile/LimitsTest.java b/test/jdk/jdk/classfile/LimitsTest.java index a94a56ce33f..40ae8a5fb1f 100644 --- a/test/jdk/jdk/classfile/LimitsTest.java +++ b/test/jdk/jdk/classfile/LimitsTest.java @@ -127,7 +127,7 @@ class LimitsTest { assertThrows(IllegalArgumentException.class, () -> ClassFile.of().parse(ClassFile.of().build(ClassDesc.of("LookupSwitchClass"), cb -> cb.withMethod( "lookupSwitchMethod", MethodTypeDesc.of(ConstantDescs.CD_void), 0, mb -> - ((DirectMethodBuilder)mb).writeAttribute(new UnboundAttribute.AdHocAttribute(Attributes.CODE) { + ((DirectMethodBuilder)mb).writeAttribute(new UnboundAttribute.AdHocAttribute(Attributes.code()) { @Override public void writeBody(BufWriter b) { b.writeU2(-1);//max stack @@ -152,7 +152,7 @@ class LimitsTest { assertThrows(IllegalArgumentException.class, () -> ClassFile.of().parse(ClassFile.of().build(ClassDesc.of("TableSwitchClass"), cb -> cb.withMethod( "tableSwitchMethod", MethodTypeDesc.of(ConstantDescs.CD_void), 0, mb -> - ((DirectMethodBuilder)mb).writeAttribute(new UnboundAttribute.AdHocAttribute(Attributes.CODE) { + ((DirectMethodBuilder)mb).writeAttribute(new UnboundAttribute.AdHocAttribute(Attributes.code()) { @Override public void writeBody(BufWriter b) { b.writeU2(-1);//max stack diff --git a/test/jdk/jdk/classfile/LowJCovAttributeTest.java b/test/jdk/jdk/classfile/LowJCovAttributeTest.java index 9bc1e29155e..858b9c90416 100644 --- a/test/jdk/jdk/classfile/LowJCovAttributeTest.java +++ b/test/jdk/jdk/classfile/LowJCovAttributeTest.java @@ -94,8 +94,8 @@ class LowJCovAttributeTest { } } 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 @@ class LowJCovAttributeTest { // } // 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 35ec8dfcfa3..7c60d75823a 100644 --- a/test/jdk/jdk/classfile/LvtTest.java +++ b/test/jdk/jdk/classfile/LvtTest.java @@ -174,7 +174,7 @@ class LvtTest { 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 @@ class LvtTest { }); 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 825394bff0a..0ac9de70472 100644 --- a/test/jdk/jdk/classfile/MassAdaptCopyPrimitiveMatchCodeTest.java +++ b/test/jdk/jdk/classfile/MassAdaptCopyPrimitiveMatchCodeTest.java @@ -120,7 +120,7 @@ class MassAdaptCopyPrimitiveMatchCodeTest { 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 68dd16ab03a..38e2dfef35a 100644 --- a/test/jdk/jdk/classfile/ModuleBuilderTest.java +++ b/test/jdk/jdk/classfile/ModuleBuilderTest.java @@ -89,7 +89,7 @@ class 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 @@ class ModuleBuilderTest { // 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 @@ class ModuleBuilderTest { @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 f4da2405dcd..4bba69735da 100644 --- a/test/jdk/jdk/classfile/SignaturesTest.java +++ b/test/jdk/jdk/classfile/SignaturesTest.java @@ -133,7 +133,7 @@ class SignaturesTest { .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 @@ class SignaturesTest { 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 @@ class SignaturesTest { }); } 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 @@ class SignaturesTest { 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 @@ class SignaturesTest { @Test void testClassSignatureClassDesc() throws IOException { var observerCf = ClassFile.of().parse(Path.of(System.getProperty("test.classes"), "SignaturesTest$Observer.class")); - var sig = observerCf.findAttribute(Attributes.SIGNATURE).orElseThrow().asClassSignature(); + var sig = observerCf.findAttribute(Attributes.signature()).orElseThrow().asClassSignature(); var arrayListSig = sig.superclassSignature(); // ArrayList var arrayListTypeArg = (TypeArg.Bounded) arrayListSig.typeArgs().getFirst(); // Outer.Inner assertEquals(TypeArg.Bounded.WildcardIndicator.NONE, arrayListTypeArg.wildcardIndicator()); diff --git a/test/jdk/jdk/classfile/TestRecordComponent.java b/test/jdk/jdk/classfile/TestRecordComponent.java index a4d173e2c67..95d56ffae8d 100644 --- a/test/jdk/jdk/classfile/TestRecordComponent.java +++ b/test/jdk/jdk/classfile/TestRecordComponent.java @@ -93,7 +93,7 @@ class TestRecordComponent { 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 @@ class TestRecordComponent { 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 d9c39748965..846645d93a9 100644 --- a/test/jdk/jdk/classfile/examples/AnnotationsExamples.java +++ b/test/jdk/jdk/classfile/examples/AnnotationsExamples.java @@ -54,8 +54,9 @@ public class AnnotationsExamples { * 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 class AnnotationsExamples { */ 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 class AnnotationsExamples { } } } - - 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 class AnnotationsExamples { */ 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 class AnnotationsExamples { } } - 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 69e71aaeb5c..d4f4ff9a695 100644 --- a/test/jdk/jdk/classfile/examples/ModuleExamples.java +++ b/test/jdk/jdk/classfile/examples/ModuleExamples.java @@ -54,14 +54,14 @@ public class ModuleExamples { 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 b348a51f23e..a62ef172367 100644 --- a/test/jdk/jdk/classfile/helpers/ClassRecord.java +++ b/test/jdk/jdk/classfile/helpers/ClassRecord.java @@ -243,75 +243,75 @@ public record ClassRecord( .map(e -> (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 @@ public record ClassRecord( static CodeAttributesRecord ofAttributes(AttributeFinder af, CodeNormalizerHelper code, CodeAttribute lr, CompatibilityFilter... cf) { return new CodeAttributesRecord( - af.findAll(Attributes.CHARACTER_RANGE_TABLE).flatMap(a -> 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 85fac494066..0c9b771c3ef 100644 --- a/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java +++ b/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java @@ -76,7 +76,7 @@ class RebuildingTransformation { // first pass transforms bound to unbound instructions cob3.transforming(new CodeRebuildingTransform(), cob4 -> { com.forEachElement(cob4::with); - com.findAttribute(Attributes.STACK_MAP_TABLE).ifPresent(cob4::with); + com.findAttribute(Attributes.stackMapTable()).ifPresent(cob4::with); })))); case AnnotationDefaultAttribute a -> mb.with(AnnotationDefaultAttribute.of(transformAnnotationValue(a.defaultValue()))); case DeprecatedAttribute a -> mb.with(DeprecatedAttribute.of()); diff --git a/test/jdk/jdk/internal/reflect/CallerSensitive/CallerSensitiveFinder.java b/test/jdk/jdk/internal/reflect/CallerSensitive/CallerSensitiveFinder.java index a313aab2552..2d5175dcf3f 100644 --- a/test/jdk/jdk/internal/reflect/CallerSensitive/CallerSensitiveFinder.java +++ b/test/jdk/jdk/internal/reflect/CallerSensitive/CallerSensitiveFinder.java @@ -164,7 +164,7 @@ public class CallerSensitiveFinder { private static final String CALLER_SENSITIVE_ANNOTATION = "Ljdk/internal/reflect/CallerSensitive;"; private static boolean isCallerSensitive(MethodModel m) { - var attr = m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElse(null); + var attr = m.findAttribute(Attributes.runtimeVisibleAnnotations()).orElse(null); if (attr != null) { for (var ann : attr.annotations()) { if (ann.className().equalsString(CALLER_SENSITIVE_ANNOTATION)) { diff --git a/test/jdk/jdk/internal/reflect/CallerSensitive/CheckCSMs.java b/test/jdk/jdk/internal/reflect/CallerSensitive/CheckCSMs.java index 0a8a0ccfaea..6dff95000f0 100644 --- a/test/jdk/jdk/internal/reflect/CallerSensitive/CheckCSMs.java +++ b/test/jdk/jdk/internal/reflect/CallerSensitive/CheckCSMs.java @@ -238,7 +238,7 @@ public class CheckCSMs { private static boolean isCallerSensitive(MethodModel m) throws IllegalArgumentException { - var attr = m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElse(null); + var attr = m.findAttribute(Attributes.runtimeVisibleAnnotations()).orElse(null); if (attr != null) { for (var ann : attr.annotations()) { if (ann.className().equalsString(CALLER_SENSITIVE_ANNOTATION)) { @@ -250,7 +250,7 @@ public class CheckCSMs { } private static boolean isCallerSensitiveAdapter(MethodModel m) { - var attr = m.findAttribute(Attributes.RUNTIME_INVISIBLE_ANNOTATIONS).orElse(null); + var attr = m.findAttribute(Attributes.runtimeInvisibleAnnotations()).orElse(null); if (attr != null) { for (var ann : attr.annotations()) { diff --git a/test/jdk/tools/jlink/plugins/StripJavaDebugAttributesPluginTest.java b/test/jdk/tools/jlink/plugins/StripJavaDebugAttributesPluginTest.java index 79a52f57288..0bcb19e087c 100644 --- a/test/jdk/tools/jlink/plugins/StripJavaDebugAttributesPluginTest.java +++ b/test/jdk/tools/jlink/plugins/StripJavaDebugAttributesPluginTest.java @@ -137,16 +137,16 @@ public class StripJavaDebugAttributesPluginTest { ClassModel classFile = ClassFile.of().parse(strippedClassFile); for (MethodModel method : classFile.methods()) { String methodName = method.methodName().stringValue(); - CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow(); - if (code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElse(null) != null) { + CodeAttribute code = method.findAttribute(Attributes.code()).orElseThrow(); + if (code.findAttribute(Attributes.lineNumberTable()).orElse(null) != null) { throw new AssertionError("Debug attribute was not removed: " + "LINE_NUMBER_TABLE" + " from method " + classFile.thisClass().asInternalName() + "#" + methodName); } - if (code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE).orElse(null) != null) { + if (code.findAttribute(Attributes.localVariableTable()).orElse(null) != null) { throw new AssertionError("Debug attribute was not removed: " + "LOCAL_VARIABLE_TABLE" + " from method " + classFile.thisClass().asInternalName() + "#" + methodName); } - if (code.findAttribute(Attributes.LOCAL_VARIABLE_TYPE_TABLE).orElse(null) != null) { + if (code.findAttribute(Attributes.localVariableTypeTable()).orElse(null) != null) { throw new AssertionError("Debug attribute was not removed: " + "LOCAL_VARIABLE_TYPE_TABLE" + " from method " + classFile.thisClass().asInternalName() + "#" + methodName); } diff --git a/test/langtools/tools/javac/4241573/T4241573.java b/test/langtools/tools/javac/4241573/T4241573.java index 93164bad57f..9989ff83454 100644 --- a/test/langtools/tools/javac/4241573/T4241573.java +++ b/test/langtools/tools/javac/4241573/T4241573.java @@ -109,7 +109,7 @@ public class T4241573 { System.err.println("verify: " + f); try { ClassModel cf = ClassFile.of().parse(f.toPath()); - SourceFileAttribute sfa = cf.findAttribute(Attributes.SOURCE_FILE).orElseThrow(); + SourceFileAttribute sfa = cf.findAttribute(Attributes.sourceFile()).orElseThrow(); String found = sfa.sourceFile().stringValue(); String expect = f.getName().replaceAll("([$.].*)?\\.class", ".java"); if (!expect.equals(found)) { diff --git a/test/langtools/tools/javac/7003595/T7003595.java b/test/langtools/tools/javac/7003595/T7003595.java index 94fb0c4b09c..c5c12259c14 100644 --- a/test/langtools/tools/javac/7003595/T7003595.java +++ b/test/langtools/tools/javac/7003595/T7003595.java @@ -163,7 +163,7 @@ public class T7003595 { throw new Error("Classfile not found: " + filename); } - InnerClassesAttribute innerClasses = cf.findAttribute(Attributes.INNER_CLASSES).orElse(null); + InnerClassesAttribute innerClasses = cf.findAttribute(Attributes.innerClasses()).orElse(null); ArrayList foundInnerSig = new ArrayList<>(); if (innerClasses != null) { diff --git a/test/langtools/tools/javac/8009170/RedundantByteCodeInArrayTest.java b/test/langtools/tools/javac/8009170/RedundantByteCodeInArrayTest.java index a9821e75ac0..8f2ed91039c 100644 --- a/test/langtools/tools/javac/8009170/RedundantByteCodeInArrayTest.java +++ b/test/langtools/tools/javac/8009170/RedundantByteCodeInArrayTest.java @@ -56,7 +56,7 @@ public class RedundantByteCodeInArrayTest { //lets get all the methods in the class file. for (MethodModel method : classFile.methods()) { if (method.methodName().equalsString("arrMethod")) { - CodeAttribute code = method.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute code = method.findAttribute(Attributes.code()).orElse(null); assert code != null; if (code.maxLocals() > 4) throw new AssertionError("Too many locals for method arrMethod"); diff --git a/test/langtools/tools/javac/AnonymousClass/AnonymousClassFlags.java b/test/langtools/tools/javac/AnonymousClass/AnonymousClassFlags.java index 7769b1caf32..fb78132e4f1 100644 --- a/test/langtools/tools/javac/AnonymousClass/AnonymousClassFlags.java +++ b/test/langtools/tools/javac/AnonymousClass/AnonymousClassFlags.java @@ -125,7 +125,7 @@ public class AnonymousClassFlags { } private static int lookupInnerFlags(ClassModel classFile, String innerName) { - InnerClassesAttribute inners = classFile.findAttribute(Attributes.INNER_CLASSES).orElse(null); + InnerClassesAttribute inners = classFile.findAttribute(Attributes.innerClasses()).orElse(null); if (inners == null) { throw new AssertionError("InnerClasses attribute missing in class " + classFile.thisClass().asInternalName()); } diff --git a/test/langtools/tools/javac/MethodParameters/ClassFileVisitor.java b/test/langtools/tools/javac/MethodParameters/ClassFileVisitor.java index 61025606414..3e2d151808f 100644 --- a/test/langtools/tools/javac/MethodParameters/ClassFileVisitor.java +++ b/test/langtools/tools/javac/MethodParameters/ClassFileVisitor.java @@ -95,7 +95,7 @@ class ClassFileVisitor extends MethodParametersTester.Visitor { isStatic = false; isAnon = false; - classFile.findAttribute(Attributes.INNER_CLASSES).ifPresent(this::visitInnerClasses); + classFile.findAttribute(Attributes.innerClasses()).ifPresent(this::visitInnerClasses); isAnon = isInner & isAnon; sb.append(isStatic ? "static " : "") diff --git a/test/langtools/tools/javac/MethodParameters/LegacyOutputTest/LegacyOutputTest.java b/test/langtools/tools/javac/MethodParameters/LegacyOutputTest/LegacyOutputTest.java index 3f613be7e82..dad79da509e 100644 --- a/test/langtools/tools/javac/MethodParameters/LegacyOutputTest/LegacyOutputTest.java +++ b/test/langtools/tools/javac/MethodParameters/LegacyOutputTest/LegacyOutputTest.java @@ -86,7 +86,7 @@ public class LegacyOutputTest { } ClassModel classFile = ClassFile.of().parse(Paths.get("Test.class")); MethodModel method = getMethod(classFile, "f"); - MethodParametersAttribute attribute = method.findAttribute(Attributes.METHOD_PARAMETERS).orElse(null); + MethodParametersAttribute attribute = method.findAttribute(Attributes.methodParameters()).orElse(null); if (attribute == null) { return null; } diff --git a/test/langtools/tools/javac/MethodParametersTest.java b/test/langtools/tools/javac/MethodParametersTest.java index 5c7a891cdb0..8ce73671d1f 100644 --- a/test/langtools/tools/javac/MethodParametersTest.java +++ b/test/langtools/tools/javac/MethodParametersTest.java @@ -175,8 +175,8 @@ public class MethodParametersTest { if (!baz.methods().get(0).methodName().equalsString("")) throw new Exception("Classfile Baz badly formed: method has name " + baz.methods().get(0).methodName().stringValue()); - MethodParametersAttribute mpattr = baz.methods().get(0).findAttribute(Attributes.METHOD_PARAMETERS).orElse(null); - CodeAttribute cattr = baz.methods().get(0).findAttribute(Attributes.CODE).orElse(null);; + MethodParametersAttribute mpattr = baz.methods().get(0).findAttribute(Attributes.methodParameters()).orElse(null); + CodeAttribute cattr = baz.methods().get(0).findAttribute(Attributes.code()).orElse(null);; if (null == mpattr) throw new Exception("Classfile Baz badly formed: no method parameters info"); if (null == cattr) diff --git a/test/langtools/tools/javac/RequiredParameterFlags/ImplicitParameters.java b/test/langtools/tools/javac/RequiredParameterFlags/ImplicitParameters.java index 64db03abdae..0eb4d1b8a42 100644 --- a/test/langtools/tools/javac/RequiredParameterFlags/ImplicitParameters.java +++ b/test/langtools/tools/javac/RequiredParameterFlags/ImplicitParameters.java @@ -195,7 +195,7 @@ public class ImplicitParameters extends TestRunner { } private void checkParameters(MethodModel method, int... parametersFlags) { - MethodParametersAttribute methodParameters = method.findAttribute(Attributes.METHOD_PARAMETERS).orElseThrow(); + MethodParametersAttribute methodParameters = method.findAttribute(Attributes.methodParameters()).orElseThrow(); Assert.checkNonNull(methodParameters, "MethodParameters attribute must be present"); List table = methodParameters.parameters(); Assert.check(table.size() == parametersFlags.length, () -> "Expected " + parametersFlags.length diff --git a/test/langtools/tools/javac/StringConcat/TestIndyStringConcat.java b/test/langtools/tools/javac/StringConcat/TestIndyStringConcat.java index 72576a7fcb8..8ec49a17c4d 100644 --- a/test/langtools/tools/javac/StringConcat/TestIndyStringConcat.java +++ b/test/langtools/tools/javac/StringConcat/TestIndyStringConcat.java @@ -24,13 +24,12 @@ import jdk.test.lib.compiler.CompilerUtils; import toolbox.ToolBox; -import java.lang.classfile.Attributes; import java.lang.classfile.BootstrapMethodEntry; import java.lang.classfile.ClassFile; import java.lang.classfile.ClassModel; import java.lang.classfile.CodeElement; +import java.lang.classfile.CodeModel; import java.lang.classfile.MethodModel; -import java.lang.classfile.attribute.CodeAttribute; import java.lang.classfile.constantpool.MethodHandleEntry; import java.lang.classfile.instruction.InvokeDynamicInstruction; import java.nio.file.Path; @@ -87,7 +86,7 @@ public class TestIndyStringConcat { for (MethodModel method : classFile.methods()) { if (method.methodName().equalsString(methodName)) { - CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow(); + CodeModel code = method.code().orElseThrow(); for (CodeElement i : code.elementList()) { if (i instanceof InvokeDynamicInstruction indy) { BootstrapMethodEntry bsmSpec = indy.invokedynamic().bootstrap(); diff --git a/test/langtools/tools/javac/StringConcat/WellKnownTypeSignatures.java b/test/langtools/tools/javac/StringConcat/WellKnownTypeSignatures.java index 60d54944168..174e9721f3f 100644 --- a/test/langtools/tools/javac/StringConcat/WellKnownTypeSignatures.java +++ b/test/langtools/tools/javac/StringConcat/WellKnownTypeSignatures.java @@ -104,7 +104,7 @@ public class WellKnownTypeSignatures { for (MethodModel method : classFile.methods()) { if (method.methodName().equalsString("main")) { - CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow(); + CodeAttribute code = method.findAttribute(Attributes.code()).orElseThrow(); for (CodeElement i : code.elementList()) { if (i instanceof InvokeDynamicInstruction) { InvokeDynamicInstruction indy = (InvokeDynamicInstruction) i; diff --git a/test/langtools/tools/javac/StringConcat/access/Test.java b/test/langtools/tools/javac/StringConcat/access/Test.java index 93ee3ec7c3f..c4aa54618ea 100644 --- a/test/langtools/tools/javac/StringConcat/access/Test.java +++ b/test/langtools/tools/javac/StringConcat/access/Test.java @@ -182,7 +182,7 @@ public class Test { for (MethodModel method : classFile.methods()) { if (method.methodName().equalsString("main")) { - CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow(); + CodeAttribute code = method.findAttribute(Attributes.code()).orElseThrow(); for (CodeElement i : code.elementList()) { if (i instanceof InvokeDynamicInstruction) { InvokeDynamicEntry indyInfo = ((InvokeDynamicInstruction) i).invokedynamic(); diff --git a/test/langtools/tools/javac/T6695379/AnnotationsAreNotCopiedToBridgeMethodsTest.java b/test/langtools/tools/javac/T6695379/AnnotationsAreNotCopiedToBridgeMethodsTest.java index 53adfe17d18..bb486b32382 100644 --- a/test/langtools/tools/javac/T6695379/AnnotationsAreNotCopiedToBridgeMethodsTest.java +++ b/test/langtools/tools/javac/T6695379/AnnotationsAreNotCopiedToBridgeMethodsTest.java @@ -63,9 +63,9 @@ public class AnnotationsAreNotCopiedToBridgeMethodsTest { ClassModel classFile = ClassFile.of().parse(cfilePath); for (MethodModel method : classFile.methods()) { if ((method.flags().flagsMask() & ClassFile.ACC_BRIDGE) != 0) { - Assert.checkNonNull(method.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS), + Assert.checkNonNull(method.findAttribute(Attributes.runtimeVisibleAnnotations()), "Annotations hasn't been copied to bridge method"); - Assert.checkNonNull(method.findAttribute(Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS), + Assert.checkNonNull(method.findAttribute(Attributes.runtimeVisibleParameterAnnotations()), "Annotations hasn't been copied to bridge method"); } } diff --git a/test/langtools/tools/javac/T6970173/DebugPointerAtBadPositionTest.java b/test/langtools/tools/javac/T6970173/DebugPointerAtBadPositionTest.java index 350d03c8c3b..56813905ca5 100644 --- a/test/langtools/tools/javac/T6970173/DebugPointerAtBadPositionTest.java +++ b/test/langtools/tools/javac/T6970173/DebugPointerAtBadPositionTest.java @@ -94,8 +94,8 @@ public class DebugPointerAtBadPositionTest { for (MethodModel m : classFile.methods()) { if (m.methodName().equalsString(methodToFind)) { methodFound = true; - CodeAttribute code = m.findAttribute(Attributes.CODE).orElseThrow(); - LineNumberTableAttribute lnt = code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElseThrow(); + CodeAttribute code = m.findAttribute(Attributes.code()).orElseThrow(); + LineNumberTableAttribute lnt = code.findAttribute(Attributes.lineNumberTable()).orElseThrow(); Assert.check(lnt.lineNumbers().size() == expectedLNT.length, foundLNTLengthDifferentThanExpMsg); int i = 0; diff --git a/test/langtools/tools/javac/T7008643/InlinedFinallyConfuseDebuggersTest.java b/test/langtools/tools/javac/T7008643/InlinedFinallyConfuseDebuggersTest.java index 5f764424713..839c835c800 100644 --- a/test/langtools/tools/javac/T7008643/InlinedFinallyConfuseDebuggersTest.java +++ b/test/langtools/tools/javac/T7008643/InlinedFinallyConfuseDebuggersTest.java @@ -101,8 +101,8 @@ public class InlinedFinallyConfuseDebuggersTest { for (MethodModel m : classFile.methods()) { if (m.methodName().equalsString(methodToFind)) { methodFound = true; - CodeAttribute code = m.findAttribute(Attributes.CODE).orElseThrow(); - LineNumberTableAttribute lnt = code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElseThrow(); + CodeAttribute code = m.findAttribute(Attributes.code()).orElseThrow(); + LineNumberTableAttribute lnt = code.findAttribute(Attributes.lineNumberTable()).orElseThrow(); Assert.check(lnt.lineNumbers().size() == expectedLNT.length, "The LineNumberTable found has a length different to the expected one"); int i = 0; diff --git a/test/langtools/tools/javac/T7053059/DoubleCastTest.java b/test/langtools/tools/javac/T7053059/DoubleCastTest.java index 84c39a6cb16..2aaf5d40f39 100644 --- a/test/langtools/tools/javac/T7053059/DoubleCastTest.java +++ b/test/langtools/tools/javac/T7053059/DoubleCastTest.java @@ -68,7 +68,7 @@ public class DoubleCastTest { static void check(MethodModel m) throws Exception { boolean last_is_cast = false; ClassEntry last_ref = null; - CodeAttribute ea = m.findAttribute(Attributes.CODE).orElseThrow(); + CodeAttribute ea = m.findAttribute(Attributes.code()).orElseThrow(); for (int i = 0; i < ea.elementList().size(); ++i) { CodeElement ce = ea.elementList().get(i); if (ce instanceof TypeCheckInstruction ins && ins.opcode() == Opcode.CHECKCAST) { diff --git a/test/langtools/tools/javac/T7093325.java b/test/langtools/tools/javac/T7093325.java index 948d775c578..0a8fac0692b 100644 --- a/test/langtools/tools/javac/T7093325.java +++ b/test/langtools/tools/javac/T7093325.java @@ -167,7 +167,7 @@ public class T7093325 extends ComboInstance { return; } - CodeAttribute code = test_method.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute code = test_method.findAttribute(Attributes.code()).orElse(null); if (code == null) { fail("Code attribute not found in method test()"); diff --git a/test/langtools/tools/javac/T7165659/InnerClassAttrMustNotHaveStrictFPFlagTest.java b/test/langtools/tools/javac/T7165659/InnerClassAttrMustNotHaveStrictFPFlagTest.java index fc4aae5a0ae..d7b823d94ec 100644 --- a/test/langtools/tools/javac/T7165659/InnerClassAttrMustNotHaveStrictFPFlagTest.java +++ b/test/langtools/tools/javac/T7165659/InnerClassAttrMustNotHaveStrictFPFlagTest.java @@ -48,7 +48,7 @@ public class InnerClassAttrMustNotHaveStrictFPFlagTest { void analyzeClassFile(File path) throws Exception { ClassModel classFile = ClassFile.of().parse(path.toPath()); - InnerClassesAttribute innerClasses = classFile.findAttribute(Attributes.INNER_CLASSES).orElse(null); + InnerClassesAttribute innerClasses = classFile.findAttribute(Attributes.innerClasses()).orElse(null); assert innerClasses != null; for (InnerClassInfo classInfo : innerClasses.classes()) { Assert.check(classInfo.flagsMask() != ClassFile.ACC_STRICT, diff --git a/test/langtools/tools/javac/T8019486/WrongLNTForLambdaTest.java b/test/langtools/tools/javac/T8019486/WrongLNTForLambdaTest.java index 7c334d35f7c..24c9b81c964 100644 --- a/test/langtools/tools/javac/T8019486/WrongLNTForLambdaTest.java +++ b/test/langtools/tools/javac/T8019486/WrongLNTForLambdaTest.java @@ -163,8 +163,8 @@ public class WrongLNTForLambdaTest { for (MethodModel method : classFile.methods()) { if (method.methodName().equalsString(methodToFind)) { methodFound = true; - CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow(); - LineNumberTableAttribute lnt = code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElseThrow(); + CodeAttribute code = method.findAttribute(Attributes.code()).orElseThrow(); + LineNumberTableAttribute lnt = code.findAttribute(Attributes.lineNumberTable()).orElseThrow(); Assert.check(lnt.lineNumbers().size() == expectedLNT.length, "The LineNumberTable found has a length different to the expected one"); int i = 0; diff --git a/test/langtools/tools/javac/T8022186/DeadCodeGeneratedForEmptyTryTest.java b/test/langtools/tools/javac/T8022186/DeadCodeGeneratedForEmptyTryTest.java index d3b6851f87b..8dd87820423 100644 --- a/test/langtools/tools/javac/T8022186/DeadCodeGeneratedForEmptyTryTest.java +++ b/test/langtools/tools/javac/T8022186/DeadCodeGeneratedForEmptyTryTest.java @@ -64,7 +64,7 @@ public class DeadCodeGeneratedForEmptyTryTest { constantPool = classFile.constantPool(); for (MethodModel method: classFile.methods()) { if (method.methodName().equalsString("methodToLookFor")) { - CodeAttribute codeAtt = method.findAttribute(Attributes.CODE).orElseThrow(); + CodeAttribute codeAtt = method.findAttribute(Attributes.code()).orElseThrow(); codeAtt.elementList().stream() .filter(ce -> ce instanceof Instruction) .forEach(ins -> checkIndirectRefToString((Instruction) ins)); diff --git a/test/langtools/tools/javac/T8024039/NoDeadCodeGenerationOnTrySmtTest.java b/test/langtools/tools/javac/T8024039/NoDeadCodeGenerationOnTrySmtTest.java index 27d01bbf27b..36afea59094 100644 --- a/test/langtools/tools/javac/T8024039/NoDeadCodeGenerationOnTrySmtTest.java +++ b/test/langtools/tools/javac/T8024039/NoDeadCodeGenerationOnTrySmtTest.java @@ -106,7 +106,7 @@ public class NoDeadCodeGenerationOnTrySmtTest { for (MethodModel m : classFile.methods()) { if (m.methodName().equalsString(methodToFind)) { numberOfmethodsFound++; - CodeAttribute code = m.findAttribute(Attributes.CODE).orElseThrow(); + CodeAttribute code = m.findAttribute(Attributes.code()).orElseThrow(); Assert.check(code.exceptionHandlers().size() == expectedExceptionTable.length, "The ExceptionTable found has a length different to the expected one"); int i = 0; diff --git a/test/langtools/tools/javac/T8028504/DontGenerateLVTForGNoneOpTest.java b/test/langtools/tools/javac/T8028504/DontGenerateLVTForGNoneOpTest.java index 90352ba6702..150b0fc8c7c 100644 --- a/test/langtools/tools/javac/T8028504/DontGenerateLVTForGNoneOpTest.java +++ b/test/langtools/tools/javac/T8028504/DontGenerateLVTForGNoneOpTest.java @@ -52,9 +52,9 @@ public class DontGenerateLVTForGNoneOpTest { void checkClassFile(final File cfile) throws Exception { ClassModel classFile = ClassFile.of().parse(cfile.toPath()); for (MethodModel method : classFile.methods()) { - CodeAttribute code = method.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute code = method.findAttribute(Attributes.code()).orElse(null); if (code != null) { - if (code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE).orElse(null) != null) { + if (code.findAttribute(Attributes.localVariableTable()).orElse(null) != null) { throw new AssertionError("LVT shouldn't be generated for g:none"); } } diff --git a/test/langtools/tools/javac/T8180141/MissingLNTEntryForBreakContinueTest.java b/test/langtools/tools/javac/T8180141/MissingLNTEntryForBreakContinueTest.java index 5ca65bf9ad8..1a095ab5301 100644 --- a/test/langtools/tools/javac/T8180141/MissingLNTEntryForBreakContinueTest.java +++ b/test/langtools/tools/javac/T8180141/MissingLNTEntryForBreakContinueTest.java @@ -92,8 +92,8 @@ public class MissingLNTEntryForBreakContinueTest { ClassModel classFile = ClassFile.of().parse(file.toPath()); for (MethodModel m : classFile.methods()) { if (m.methodName().equalsString("foo")) { - CodeAttribute code = m.findAttribute(Attributes.CODE).orElseThrow(); - LineNumberTableAttribute lnt = code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElseThrow(); + CodeAttribute code = m.findAttribute(Attributes.code()).orElseThrow(); + LineNumberTableAttribute lnt = code.findAttribute(Attributes.lineNumberTable()).orElseThrow(); checkLNT(lnt, MyAttr.lineNumber); } } diff --git a/test/langtools/tools/javac/T8180660/MissingLNTEntryForFinalizerTest.java b/test/langtools/tools/javac/T8180660/MissingLNTEntryForFinalizerTest.java index 504057ed7be..1cd9ee211e0 100644 --- a/test/langtools/tools/javac/T8180660/MissingLNTEntryForFinalizerTest.java +++ b/test/langtools/tools/javac/T8180660/MissingLNTEntryForFinalizerTest.java @@ -88,8 +88,8 @@ public class MissingLNTEntryForFinalizerTest { ClassModel classFile = ClassFile.of().parse(file.toPath()); for (MethodModel m : classFile.methods()) { if (m.methodName().equalsString("foo")) { - CodeAttribute code = m.findAttribute(Attributes.CODE).orElseThrow(); - LineNumberTableAttribute lnt = code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElseThrow(); + CodeAttribute code = m.findAttribute(Attributes.code()).orElseThrow(); + LineNumberTableAttribute lnt = code.findAttribute(Attributes.lineNumberTable()).orElseThrow(); checkLNT(lnt, MyAttr.lineNumber); } } diff --git a/test/langtools/tools/javac/T8210435/NoLocalsMustBeReservedForDCEedVarsTest.java b/test/langtools/tools/javac/T8210435/NoLocalsMustBeReservedForDCEedVarsTest.java index 69819dd845e..35ccb627b44 100644 --- a/test/langtools/tools/javac/T8210435/NoLocalsMustBeReservedForDCEedVarsTest.java +++ b/test/langtools/tools/javac/T8210435/NoLocalsMustBeReservedForDCEedVarsTest.java @@ -68,7 +68,7 @@ public class NoLocalsMustBeReservedForDCEedVarsTest { ClassModel classFile = ClassFile.of().parse(cfile.toPath()); for (MethodModel method: classFile.methods()) { if (method.methodName().stringValue().equals("foo")) { - CodeAttribute codeAttr = method.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute codeAttr = method.findAttribute(Attributes.code()).orElse(null); assert codeAttr != null; Assert.check(codeAttr.maxLocals() == 0, "max locals found " + codeAttr.maxLocals()); } diff --git a/test/langtools/tools/javac/T8222949/TestConstantDynamic.java b/test/langtools/tools/javac/T8222949/TestConstantDynamic.java index 79e1fbb047f..d6f728eda5a 100644 --- a/test/langtools/tools/javac/T8222949/TestConstantDynamic.java +++ b/test/langtools/tools/javac/T8222949/TestConstantDynamic.java @@ -186,7 +186,7 @@ public class TestConstantDynamic extends ComboInstance { fail("Test method not found"); return; } - CodeAttribute ea = testMethod.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute ea = testMethod.findAttribute(Attributes.code()).orElse(null); if (ea == null) { fail("Code attribute for test() method not found"); return; @@ -216,7 +216,7 @@ public class TestConstantDynamic extends ComboInstance { return; } - BootstrapMethodsAttribute bsm_attr = cf.findAttribute(Attributes.BOOTSTRAP_METHODS).orElseThrow(); + BootstrapMethodsAttribute bsm_attr = cf.findAttribute(Attributes.bootstrapMethods()).orElseThrow(); if (bsm_attr.bootstrapMethods().size() != 1) { fail("Bad number of method specifiers " + "in BootstrapMethods attribute"); @@ -251,7 +251,7 @@ public class TestConstantDynamic extends ComboInstance { return; } - LineNumberTableAttribute lnt = ea.findAttribute(Attributes.LINE_NUMBER_TABLE).orElse(null); + LineNumberTableAttribute lnt = ea.findAttribute(Attributes.lineNumberTable()).orElse(null); if (lnt == null) { fail("No LineNumberTable attribute"); diff --git a/test/langtools/tools/javac/TryWithResources/TwrSimpleClose.java b/test/langtools/tools/javac/TryWithResources/TwrSimpleClose.java index 45e30cd4516..4c1e3a48275 100644 --- a/test/langtools/tools/javac/TryWithResources/TwrSimpleClose.java +++ b/test/langtools/tools/javac/TryWithResources/TwrSimpleClose.java @@ -101,7 +101,7 @@ public class TwrSimpleClose { ClassModel cf = ClassFile.of().parse(new ByteArrayInputStream(data).readAllBytes()); for (MethodModel m : cf.methods()) { - CodeAttribute codeAttr = m.findAttribute(Attributes.CODE).orElseThrow(); + CodeAttribute codeAttr = m.findAttribute(Attributes.code()).orElseThrow(); for (CodeElement ce : codeAttr.elementList()) { if (ce instanceof InvokeInstruction ins && ins.opcode() == Opcode.INVOKEVIRTUAL) { MemberRefEntry method = ins.method(); diff --git a/test/langtools/tools/javac/annotations/ApplicableAnnotationsOnRecords.java b/test/langtools/tools/javac/annotations/ApplicableAnnotationsOnRecords.java index 30d8a579b40..0bc65af8aa1 100644 --- a/test/langtools/tools/javac/annotations/ApplicableAnnotationsOnRecords.java +++ b/test/langtools/tools/javac/annotations/ApplicableAnnotationsOnRecords.java @@ -63,21 +63,21 @@ public record ApplicableAnnotationsOnRecords(@FieldAnnotation @MethodAnnotation if (methodName.equals("toString") || methodName.equals("hashCode") || methodName.equals("equals") || methodName.equals("main")) { // ignore } else if (methodName.equals("")) { - var paAnnos = mm.findAttribute(Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS).orElseThrow().parameterAnnotations(); + var paAnnos = mm.findAttribute(Attributes.runtimeVisibleParameterAnnotations()).orElseThrow().parameterAnnotations(); Assert.check(paAnnos.size() > 0); for (var pa : paAnnos) { Assert.check(pa.size() == 1); Assert.check(Objects.equals(pa.get(0).classSymbol().descriptorString(), "LParameterAnnotation;")); } } else { - var annos = mm.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElseThrow().annotations(); + var annos = mm.findAttribute(Attributes.runtimeVisibleAnnotations()).orElseThrow().annotations(); Assert.check(annos.size() == 1); Assert.check(Objects.equals(annos.get(0).classSymbol().descriptorString(), "LMethodAnnotation;")); } } Assert.check(cm.fields().size() > 0); for (FieldModel fm : cm.fields()) { - var annos = fm.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElseThrow().annotations(); + var annos = fm.findAttribute(Attributes.runtimeVisibleAnnotations()).orElseThrow().annotations(); Assert.check(annos.size() == 1); Assert.check(Objects.equals(annos.getFirst().classSymbol().descriptorString(), "LFieldAnnotation;")); } diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/TypeAnnotationsPositionsOnRecords.java b/test/langtools/tools/javac/annotations/typeAnnotations/TypeAnnotationsPositionsOnRecords.java index 2f6ac3a4717..6d2aabaee80 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/TypeAnnotationsPositionsOnRecords.java +++ b/test/langtools/tools/javac/annotations/typeAnnotations/TypeAnnotationsPositionsOnRecords.java @@ -197,15 +197,15 @@ public class TypeAnnotationsPositionsOnRecords { // utility methods void findAnnotations(ClassModel cm, AttributedElement m, List annos) { - findAnnotations(cm, m, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, annos); - findAnnotations(cm, m, Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, annos); + findAnnotations(cm, m, Attributes.runtimeVisibleTypeAnnotations(), annos); + findAnnotations(cm, m, Attributes.runtimeInvisibleTypeAnnotations(), annos); } > void findAnnotations(ClassModel cf, AttributedElement m, AttributeMapper attrName, List annos) { Attribute attr = m.findAttribute(attrName).orElse(null); addAnnos(annos, attr); if (m instanceof MethodModel) { - CodeAttribute cattr = m.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute cattr = m.findAttribute(Attributes.code()).orElse(null); if (cattr != null) { attr = cattr.findAttribute(attrName).orElse(null); addAnnos(annos, attr); diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/VariablesDeclaredWithVarTest.java b/test/langtools/tools/javac/annotations/typeAnnotations/VariablesDeclaredWithVarTest.java index ffd45ddfca4..7384f4bd5d7 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/VariablesDeclaredWithVarTest.java +++ b/test/langtools/tools/javac/annotations/typeAnnotations/VariablesDeclaredWithVarTest.java @@ -110,15 +110,15 @@ public class VariablesDeclaredWithVarTest { } void findAnnotations(ClassModel cf, MethodModel m, List annos) { - findAnnotations(cf, m, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, annos); - findAnnotations(cf, m, Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, annos); + findAnnotations(cf, m, Attributes.runtimeVisibleTypeAnnotations(), annos); + findAnnotations(cf, m, Attributes.runtimeInvisibleTypeAnnotations(), annos); } > void findAnnotations(ClassModel cf, AttributedElement m, AttributeMapper attrName, List annos) { Attribute attr = m.findAttribute(attrName).orElse(null); addAnnos(annos, attr); if (m instanceof MethodModel) { - CodeAttribute cattr = m.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute cattr = m.findAttribute(Attributes.code()).orElse(null); if (cattr != null) { attr = cattr.findAttribute(attrName).orElse(null); addAnnos(annos, attr); diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/AnonymousClassTest.java b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/AnonymousClassTest.java index bf2bfd2a370..64c33ed9fd9 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/AnonymousClassTest.java +++ b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/AnonymousClassTest.java @@ -100,7 +100,7 @@ public class AnonymousClassTest { static void testAnonymousClassDeclaration() throws Exception { ClassModel cm = ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest$1.class")); RuntimeVisibleTypeAnnotationsAttribute rvta = - cm.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).orElse(null); + cm.findAttribute(Attributes.runtimeVisibleTypeAnnotations()).orElse(null); assert rvta != null; assertEquals( Set.of( @@ -115,7 +115,7 @@ public class AnonymousClassTest { ClassModel cm = ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest.class")); MethodModel method = findMethod(cm, "f"); Set annotations = getRuntimeVisibleTypeAnnotations(method); - CodeAttribute cAttr = method.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute cAttr = method.findAttribute(Attributes.code()).orElse(null); assertEquals( Set.of("@LAnonymousClassTest$TA;(0) NEW, offset=0, location=[INNER_TYPE]"), annotations.stream().map(a -> annotationDebugString(cm, cAttr, a)).collect(toSet())); @@ -126,7 +126,7 @@ public class AnonymousClassTest { ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest$Inner.class")); MethodModel method = findMethod(cm, "g"); Set annotations = getRuntimeVisibleTypeAnnotations(method); - CodeAttribute cAttr = method.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute cAttr = method.findAttribute(Attributes.code()).orElse(null); // The annotation needs two INNER_TYPE type path entries to apply to // AnonymousClassTest$Inner$1. assertEquals( @@ -141,7 +141,7 @@ public class AnonymousClassTest { ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest.class")); MethodModel method = findMethod(cm, "g"); Set annotations = getRuntimeVisibleTypeAnnotations(method); - CodeAttribute cAttr = method.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute cAttr = method.findAttribute(Attributes.code()).orElse(null); // Only @TA(4) is propagated to the anonymous class declaration. assertEquals( Set.of("@LAnonymousClassTest$TA;(4) NEW, offset=0, location=[INNER_TYPE]"), @@ -152,7 +152,7 @@ public class AnonymousClassTest { ClassModel cm = ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest$2.class")); RuntimeVisibleTypeAnnotationsAttribute rvta = - cm.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).orElse(null); + cm.findAttribute(Attributes.runtimeVisibleTypeAnnotations()).orElse(null); assert rvta != null; assertEquals( Set.of( @@ -168,14 +168,14 @@ public class AnonymousClassTest { ClassModel cm = ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest.class")); MethodModel method = findMethod(cm, ""); Set annotations = getRuntimeVisibleTypeAnnotations(method); - CodeAttribute cAttr1 = method.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute cAttr1 = method.findAttribute(Attributes.code()).orElse(null); assertEquals( Set.of("@LAnonymousClassTest$TA;(5) NEW, offset=4, location=[INNER_TYPE]"), annotations.stream().map(a -> annotationDebugString(cm, cAttr1, a)).collect(toSet()) ); method = findMethod(cm, ""); annotations = getRuntimeVisibleTypeAnnotations(method); - CodeAttribute cAttr2 = method.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute cAttr2 = method.findAttribute(Attributes.code()).orElse(null); assertEquals( Set.of("@LAnonymousClassTest$TA;(6) NEW, offset=16, location=[INNER_TYPE]"), annotations.stream().map(a -> annotationDebugString(cm, cAttr2, a)).collect(toSet()) ); @@ -184,14 +184,14 @@ public class AnonymousClassTest { // Returns the Method's RuntimeVisibleTypeAnnotations, and asserts that there are no RVTIs // erroneously associated with the Method instead of its Code attribute. private static Set getRuntimeVisibleTypeAnnotations(MethodModel method) { - if (method.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).orElse(null) != null) { + if (method.findAttribute(Attributes.runtimeVisibleTypeAnnotations()).orElse(null) != null) { throw new AssertionError( "expected no RuntimeVisibleTypeAnnotations attribute on enclosing method"); } - CodeAttribute code = method.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute code = method.findAttribute(Attributes.code()).orElse(null); assert code != null; RuntimeVisibleTypeAnnotationsAttribute rvta = - code.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).orElse(null); + code.findAttribute(Attributes.runtimeVisibleTypeAnnotations()).orElse(null); assert rvta != null; return new HashSet<>(rvta.annotations()); } diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java index 4926e15b258..11abffa8c91 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java +++ b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java @@ -88,10 +88,10 @@ public class ClassfileTestHelper { // 'local' determines whether to look for annotations in code attribute or not. void test(AttributedElement m, Boolean local) { - test(m, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, local); - test(m, Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, local); - test(m, Attributes.RUNTIME_VISIBLE_ANNOTATIONS, local); - test(m, Attributes.RUNTIME_INVISIBLE_ANNOTATIONS, local); + test(m, Attributes.runtimeVisibleTypeAnnotations(), local); + test(m, Attributes.runtimeInvisibleTypeAnnotations(), local); + test(m, Attributes.runtimeVisibleAnnotations(), local); + test(m, Attributes.runtimeInvisibleAnnotations(), local); } // Test the result of MethodModel.findAttribute according to expectations @@ -164,7 +164,7 @@ public class ClassfileTestHelper { CodeAttribute cAttr; Attribute attr = null; if (local) { - cAttr = m.findAttribute(Attributes.CODE).orElse(null); + cAttr = m.findAttribute(Attributes.code()).orElse(null); if (cAttr != null) { attr = cAttr.findAttribute(annName).orElse(null); } diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/NoTargetAnnotations.java b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/NoTargetAnnotations.java index 13082ba9dad..ffab642c1d5 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/NoTargetAnnotations.java +++ b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/NoTargetAnnotations.java @@ -71,8 +71,8 @@ public class NoTargetAnnotations extends ClassfileTestHelper { void testDeclaration(AttributedElement m) { - testDecl(m, Attributes.RUNTIME_VISIBLE_ANNOTATIONS); - testDecl(m, Attributes.RUNTIME_INVISIBLE_ANNOTATIONS); + testDecl(m, Attributes.runtimeVisibleAnnotations()); + testDecl(m, Attributes.runtimeInvisibleAnnotations()); } // test the result of AttributedElement.findAttribute according to expectations diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TestAnonInnerClasses.java b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TestAnonInnerClasses.java index 59ed653927b..fc232d06b64 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TestAnonInnerClasses.java +++ b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TestAnonInnerClasses.java @@ -63,10 +63,10 @@ public class TestAnonInnerClasses extends ClassfileTestHelper { File testSrc = new File(System.getProperty("test.src")); AttributeMapper [] AnnoAttributes = new AttributeMapper[]{ - Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, - Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, - Attributes.RUNTIME_VISIBLE_ANNOTATIONS, - Attributes.RUNTIME_INVISIBLE_ANNOTATIONS + Attributes.runtimeVisibleTypeAnnotations(), + Attributes.runtimeInvisibleTypeAnnotations(), + Attributes.runtimeVisibleAnnotations(), + Attributes.runtimeInvisibleAnnotations() }; // template for source files @@ -175,7 +175,7 @@ public class TestAnonInnerClasses extends ClassfileTestHelper { ((MethodModel) m).methodName().stringValue() : ((FieldModel) m).fieldName().stringValue(); attr = m.findAttribute(AnnoType).orElse(null); //fetch index annotations from code attribute. - CAttr = m.findAttribute(Attributes.CODE).orElse(null); + CAttr = m.findAttribute(Attributes.code()).orElse(null); if (CAttr != null) { cattr = CAttr.findAttribute(AnnoType).orElse(null); } diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TestNewCastArray.java b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TestNewCastArray.java index 741747a9b4c..048c1836664 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TestNewCastArray.java +++ b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TestNewCastArray.java @@ -88,7 +88,7 @@ public class TestNewCastArray { memberName = mm.methodName().stringValue(); if(codeattr) { //fetch index of and code attribute and annotations from code attribute. - cAttr = mm.findAttribute(Attributes.CODE).orElse(null); + cAttr = mm.findAttribute(Attributes.code()).orElse(null); if(cAttr != null) { attr = cAttr.findAttribute(name).orElse(null); } @@ -99,7 +99,7 @@ public class TestNewCastArray { case FieldModel fm -> { memberName = fm.fieldName().stringValue(); if(codeattr) { - cAttr = fm.findAttribute(Attributes.CODE).orElse(null); + cAttr = fm.findAttribute(Attributes.code()).orElse(null); if(cAttr != null) { attr = cAttr.findAttribute(name).orElse(null); } @@ -207,14 +207,14 @@ public class TestNewCastArray { assert cm != null; if(clazz.startsWith("Test1")) { for (FieldModel fm: cm.fields()) - test(clazz, fm, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, false); + test(clazz, fm, Attributes.runtimeVisibleTypeAnnotations(), false); for (MethodModel mm: cm.methods()) - test(clazz, mm, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, false); + test(clazz, mm, Attributes.runtimeVisibleTypeAnnotations(), false); } else { for (FieldModel fm: cm.fields()) - test(clazz, fm, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, true); + test(clazz, fm, Attributes.runtimeVisibleTypeAnnotations(), true); for (MethodModel mm: cm.methods()) - test(clazz, mm, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, true); + test(clazz, mm, Attributes.runtimeVisibleTypeAnnotations(), true); } } report(); diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TypeAnnotationPropagationTest.java b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TypeAnnotationPropagationTest.java index ae92d7aae04..9f7873bb2c0 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TypeAnnotationPropagationTest.java +++ b/test/langtools/tools/javac/annotations/typeAnnotations/classfile/TypeAnnotationPropagationTest.java @@ -58,9 +58,9 @@ public class TypeAnnotationPropagationTest extends ClassfileTestHelper { } assert f != null; - CodeAttribute cattr = f.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute cattr = f.findAttribute(Attributes.code()).orElse(null); assert cattr != null; - RuntimeVisibleTypeAnnotationsAttribute attr = cattr.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).orElse(null); + RuntimeVisibleTypeAnnotationsAttribute attr = cattr.findAttribute(Attributes.runtimeVisibleTypeAnnotations()).orElse(null); assert attr != null; List annosPosition = ((TypeAnnotation.LocalVarTarget) attr.annotations().get(0).targetInfo()).table(); diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java b/test/langtools/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java index 7e35a081de7..e2e69a01a49 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java +++ b/test/langtools/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java @@ -37,8 +37,8 @@ public class ReferenceInfoUtil { /////////////////// Extract type annotations ////////////////// private static void findAnnotations(ClassModel cm, List annos) { - findAnnotations(cm, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, annos); - findAnnotations(cm, Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, annos); + findAnnotations(cm, Attributes.runtimeVisibleTypeAnnotations(), annos); + findAnnotations(cm, Attributes.runtimeInvisibleTypeAnnotations(), annos); for (FieldModel f : cm.fields()) { findAnnotations(f, annos); @@ -49,8 +49,8 @@ public class ReferenceInfoUtil { } private static void findAnnotations(AttributedElement ae, List annos) { - findAnnotations(ae, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, annos); - findAnnotations(ae, Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, annos); + findAnnotations(ae, Attributes.runtimeVisibleTypeAnnotations(), annos); + findAnnotations(ae, Attributes.runtimeInvisibleTypeAnnotations(), annos); } // test the result of Attributes.getIndex according to expectations @@ -78,7 +78,7 @@ public class ReferenceInfoUtil { } else throw new AssertionError(); } if (m instanceof MethodModel mm) { - CodeAttribute cAttr = mm.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute cAttr = mm.findAttribute(Attributes.code()).orElse(null); if (cAttr != null) { Attribute attr2 = cAttr.findAttribute(attrName).orElse(null);; if (attr2 != null) { diff --git a/test/langtools/tools/javac/cast/intersection/DuplicatedCheckcastTest.java b/test/langtools/tools/javac/cast/intersection/DuplicatedCheckcastTest.java index e8e947d408c..544314832e8 100644 --- a/test/langtools/tools/javac/cast/intersection/DuplicatedCheckcastTest.java +++ b/test/langtools/tools/javac/cast/intersection/DuplicatedCheckcastTest.java @@ -100,7 +100,7 @@ public class DuplicatedCheckcastTest extends TestRunner { ArrayList checkCastList = new ArrayList<>(); for (MethodModel method : cf.methods()) { if (method.methodName().equalsString("test")) { - CodeAttribute code_attribute = method.findAttribute(Attributes.CODE).orElseThrow(); + CodeAttribute code_attribute = method.findAttribute(Attributes.code()).orElseThrow(); for (CodeElement ce : code_attribute.elementList()) { if (ce instanceof Instruction instruction && Opcode.CHECKCAST == instruction.opcode()) { checkCastList.add(instruction); diff --git a/test/langtools/tools/javac/classfiles/InnerClasses/SyntheticClasses.java b/test/langtools/tools/javac/classfiles/InnerClasses/SyntheticClasses.java index bab02ade067..eca1b840b3a 100644 --- a/test/langtools/tools/javac/classfiles/InnerClasses/SyntheticClasses.java +++ b/test/langtools/tools/javac/classfiles/InnerClasses/SyntheticClasses.java @@ -47,14 +47,14 @@ public class SyntheticClasses { for (File classFile : Objects.requireNonNull(testClasses.listFiles(f -> f.getName().endsWith(".class")))) { ClassModel cf = ClassFile.of().parse(classFile.toPath()); if (cf.thisClass().asInternalName().matches(".*\\$[0-9]+")) { - EnclosingMethodAttribute encl = cf.findAttribute(Attributes.ENCLOSING_METHOD).orElse(null); + EnclosingMethodAttribute encl = cf.findAttribute(Attributes.enclosingMethod()).orElse(null); if (encl != null) { if (encl.enclosingMethodName().isPresent()) throw new IllegalStateException("Invalid EnclosingMethod.method: " + encl.enclosingMethodName().get().stringValue() + "."); } } - InnerClassesAttribute attr = cf.findAttribute(Attributes.INNER_CLASSES).orElse(null); + InnerClassesAttribute attr = cf.findAttribute(Attributes.innerClasses()).orElse(null); if (attr != null) { for (InnerClassInfo info : attr.classes()) { if (cf.majorVersion() < 51) diff --git a/test/langtools/tools/javac/classfiles/attributes/AnnotationDefault/AnnotationDefaultTest.java b/test/langtools/tools/javac/classfiles/attributes/AnnotationDefault/AnnotationDefaultTest.java index d099c4940f9..d9a3320ecc2 100644 --- a/test/langtools/tools/javac/classfiles/attributes/AnnotationDefault/AnnotationDefaultTest.java +++ b/test/langtools/tools/javac/classfiles/attributes/AnnotationDefault/AnnotationDefaultTest.java @@ -77,7 +77,7 @@ public class AnnotationDefaultTest extends TestResult { String methodName = method.methodName().stringValue(); printf("Testing method : %s\n", methodName); AnnotationDefaultAttribute attr = - method.findAttribute(Attributes.ANNOTATION_DEFAULT).orElse(null); + method.findAttribute(Attributes.annotationDefault()).orElse(null); if (hasDefault && !checkNotNull(attr, "Attribute is not null") || !hasDefault && checkNull(attr, "Attribute is null")) { diff --git a/test/langtools/tools/javac/classfiles/attributes/EnclosingMethod/EnclosingMethodTest.java b/test/langtools/tools/javac/classfiles/attributes/EnclosingMethod/EnclosingMethodTest.java index d34d3a7db05..b555014bebe 100644 --- a/test/langtools/tools/javac/classfiles/attributes/EnclosingMethod/EnclosingMethodTest.java +++ b/test/langtools/tools/javac/classfiles/attributes/EnclosingMethod/EnclosingMethodTest.java @@ -163,7 +163,7 @@ public class EnclosingMethodTest extends TestResult { checkEquals(countEnclosingMethodAttributes(classFile), 1l, "number of the EnclosingMethod attribute in the class is one : " + clazz); - EnclosingMethodAttribute attr = classFile.findAttribute(Attributes.ENCLOSING_METHOD).orElse(null); + EnclosingMethodAttribute attr = classFile.findAttribute(Attributes.enclosingMethod()).orElse(null); if (!checkNotNull(attr, "the EnclosingMethod attribute is not null : " + className)) { // stop checking, attr is null. test case failed diff --git a/test/langtools/tools/javac/classfiles/attributes/LineNumberTable/LineNumberTestBase.java b/test/langtools/tools/javac/classfiles/attributes/LineNumberTable/LineNumberTestBase.java index f9227dde4df..be4a5aaea91 100644 --- a/test/langtools/tools/javac/classfiles/attributes/LineNumberTable/LineNumberTestBase.java +++ b/test/langtools/tools/javac/classfiles/attributes/LineNumberTable/LineNumberTestBase.java @@ -72,15 +72,15 @@ public class LineNumberTestBase extends TestBase { classFile = ClassFile.of().parse(input.readAllBytes()); } for (MethodModel m : classFile.methods()) { - CodeAttribute code_attribute = m.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute code_attribute = m.findAttribute(Attributes.code()).orElse(null); assert code_attribute != null; assertEquals( - countAttributes(Attributes.LINE_NUMBER_TABLE, code_attribute), + countAttributes(Attributes.lineNumberTable(), code_attribute), 1, "Can be more than one LNT attribute, but javac should generate only one."); - LineNumberTableAttribute tableAttribute = code_attribute.findAttribute(Attributes.LINE_NUMBER_TABLE).orElse(null); + LineNumberTableAttribute tableAttribute = code_attribute.findAttribute(Attributes.lineNumberTable()).orElse(null); assert tableAttribute != null; checkAttribute(testCase, tableAttribute, code_attribute.codeLength()); Set methodCoveredLines = diff --git a/test/langtools/tools/javac/classfiles/attributes/LineNumberTable/T8050993.java b/test/langtools/tools/javac/classfiles/attributes/LineNumberTable/T8050993.java index dade8e98430..934a0ef09e7 100644 --- a/test/langtools/tools/javac/classfiles/attributes/LineNumberTable/T8050993.java +++ b/test/langtools/tools/javac/classfiles/attributes/LineNumberTable/T8050993.java @@ -24,10 +24,10 @@ public class T8050993 { Set expectedLineNumbers = new HashSet<>(Arrays.asList(49, 50, 47, 48)); for (MethodModel m : someTestIn.methods()) { if (m.methodName().equalsString("method")) { - CodeAttribute code_attribute = m.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute code_attribute = m.findAttribute(Attributes.code()).orElse(null); assert code_attribute != null; for (Attribute at : code_attribute.attributes()) { - if (Attributes.LINE_NUMBER_TABLE.equals(at)) { + if (Attributes.lineNumberTable().equals(at)) { assert at instanceof LineNumberTableAttribute; LineNumberTableAttribute att = (LineNumberTableAttribute) at; Set actualLinesNumbers = Arrays.stream(att.lineNumbers().toArray(new LineNumberInfo[0])) diff --git a/test/langtools/tools/javac/classfiles/attributes/LocalVariableTable/LocalVariableTestBase.java b/test/langtools/tools/javac/classfiles/attributes/LocalVariableTable/LocalVariableTestBase.java index 9d2e19c86ba..7bda1500b3e 100644 --- a/test/langtools/tools/javac/classfiles/attributes/LocalVariableTable/LocalVariableTestBase.java +++ b/test/langtools/tools/javac/classfiles/attributes/LocalVariableTable/LocalVariableTestBase.java @@ -104,7 +104,7 @@ public abstract class LocalVariableTestBase extends TestBase { String mName = m.methodName().stringValue(); if (methodName.equals(mName)) { System.out.println("Testing local variable table in method " + mName); - CodeAttribute code_attribute = m.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute code_attribute = m.findAttribute(Attributes.code()).orElse(null); assert code_attribute != null; List variableTables = getVariableTables(code_attribute); generalLocalVariableTableCheck(variableTables); diff --git a/test/langtools/tools/javac/classfiles/attributes/Module/ModuleTestBase.java b/test/langtools/tools/javac/classfiles/attributes/Module/ModuleTestBase.java index 8f7e5c04250..490e585e06a 100644 --- a/test/langtools/tools/javac/classfiles/attributes/Module/ModuleTestBase.java +++ b/test/langtools/tools/javac/classfiles/attributes/Module/ModuleTestBase.java @@ -70,7 +70,7 @@ public class ModuleTestBase { protected void testModuleAttribute(Path modulePath, ModuleDescriptor moduleDescriptor) throws Exception { ClassModel classFile = ClassFile.of().parse(modulePath.resolve("module-info.class")); - ModuleAttribute moduleAttribute = classFile.findAttribute(Attributes.MODULE).orElse(null); + ModuleAttribute moduleAttribute = classFile.findAttribute(Attributes.module()).orElse(null); assert moduleAttribute != null; testModuleName(moduleDescriptor, moduleAttribute); testModuleFlags(moduleDescriptor, moduleAttribute); diff --git a/test/langtools/tools/javac/classfiles/attributes/Signature/Driver.java b/test/langtools/tools/javac/classfiles/attributes/Signature/Driver.java index 4e565cde423..72f7d2a6b9b 100644 --- a/test/langtools/tools/javac/classfiles/attributes/Signature/Driver.java +++ b/test/langtools/tools/javac/classfiles/attributes/Signature/Driver.java @@ -134,7 +134,7 @@ public class Driver extends TestResult { // test class signature testAttribute( className, - () -> classFile.findAttribute(Attributes.SIGNATURE).orElse(null), + () -> classFile.findAttribute(Attributes.signature()).orElse(null), getClassExpectedSignature(className, clazz).get(className)); testFields(getExpectedFieldSignatures(clazz), classFile); @@ -173,7 +173,7 @@ public class Driver extends TestResult { } testAttribute( methodName, - () -> method.findAttribute(Attributes.SIGNATURE).orElse(null), + () -> method.findAttribute(Attributes.signature()).orElse(null), expectedSignatures.get(methodName)); foundMethods.add(methodName); } @@ -204,7 +204,7 @@ public class Driver extends TestResult { printf("Testing field %s\n", fieldName); testAttribute( fieldName, - () -> field.findAttribute(Attributes.SIGNATURE).orElse(null), + () -> field.findAttribute(Attributes.signature()).orElse(null), expectedSignatures.get(fieldName)); foundFields.add(fieldName); } diff --git a/test/langtools/tools/javac/classfiles/attributes/SourceFile/NoSourceFileAttribute.java b/test/langtools/tools/javac/classfiles/attributes/SourceFile/NoSourceFileAttribute.java index af9e603c964..d4a4972f135 100644 --- a/test/langtools/tools/javac/classfiles/attributes/SourceFile/NoSourceFileAttribute.java +++ b/test/langtools/tools/javac/classfiles/attributes/SourceFile/NoSourceFileAttribute.java @@ -48,7 +48,7 @@ public class NoSourceFileAttribute extends TestBase { public void test() throws IOException { assertNull( - ClassFile.of().parse(getClassFile(NoSourceFileAttribute.class).toPath()).findAttribute(Attributes.SOURCE_FILE).orElse(null), + ClassFile.of().parse(getClassFile(NoSourceFileAttribute.class).toPath()).findAttribute(Attributes.sourceFile()).orElse(null), "Classfile should have no SourceFile attribute when compiled without debug information."); } } diff --git a/test/langtools/tools/javac/classfiles/attributes/SourceFile/SourceFileTestBase.java b/test/langtools/tools/javac/classfiles/attributes/SourceFile/SourceFileTestBase.java index f827873588e..52d53f9dce4 100644 --- a/test/langtools/tools/javac/classfiles/attributes/SourceFile/SourceFileTestBase.java +++ b/test/langtools/tools/javac/classfiles/attributes/SourceFile/SourceFileTestBase.java @@ -108,7 +108,7 @@ public class SourceFileTestBase extends TestBase { SourceFileAttribute attribute = sourceFileAttributes.get(0); - assertEquals(attribute.attributeName(), Attributes.SOURCE_FILE.name(), "Incorrect attribute name"); + assertEquals(attribute.attributeName(), Attributes.sourceFile().name(), "Incorrect attribute name"); assertEquals(attribute.sourceFile().stringValue(), fileName, "Incorrect source file name"); assertEquals(((BoundAttribute)attribute).payloadLen(), 2, "Incorrect attribute length"); diff --git a/test/langtools/tools/javac/classfiles/attributes/Synthetic/SyntheticTestDriver.java b/test/langtools/tools/javac/classfiles/attributes/Synthetic/SyntheticTestDriver.java index 406df68a7fe..4db2585355e 100644 --- a/test/langtools/tools/javac/classfiles/attributes/Synthetic/SyntheticTestDriver.java +++ b/test/langtools/tools/javac/classfiles/attributes/Synthetic/SyntheticTestDriver.java @@ -118,7 +118,7 @@ public class SyntheticTestDriver extends TestResult { foundClasses.add(className); if (testAttribute( classFile, - () -> classFile.findAttribute(Attributes.SYNTHETIC).orElse(null), + () -> classFile.findAttribute(Attributes.synthetic()).orElse(null), classFile.flags()::flags, expectedClasses.keySet(), className, @@ -136,7 +136,7 @@ public class SyntheticTestDriver extends TestResult { foundMethods.add(methodName); if (testAttribute( classFile, - () -> method.findAttribute(Attributes.SYNTHETIC).orElse(null), + () -> method.findAttribute(Attributes.synthetic()).orElse(null), method.flags()::flags, expectedMethods, methodName, @@ -162,7 +162,7 @@ public class SyntheticTestDriver extends TestResult { foundFields.add(fieldName); if (testAttribute( classFile, - () -> field.findAttribute(Attributes.SYNTHETIC).orElse(null), + () -> field.findAttribute(Attributes.synthetic()).orElse(null), field.flags()::flags, expectedFields, fieldName, diff --git a/test/langtools/tools/javac/classfiles/attributes/annotations/RuntimeAnnotationsTestBase.java b/test/langtools/tools/javac/classfiles/attributes/annotations/RuntimeAnnotationsTestBase.java index a36a84e5e8f..970628be575 100644 --- a/test/langtools/tools/javac/classfiles/attributes/annotations/RuntimeAnnotationsTestBase.java +++ b/test/langtools/tools/javac/classfiles/attributes/annotations/RuntimeAnnotationsTestBase.java @@ -96,11 +96,11 @@ public abstract class RuntimeAnnotationsTestBase extends AnnotationsTestBase { Map actualInvisible = collectAnnotations( member, attributedElement, - Attributes.RUNTIME_INVISIBLE_ANNOTATIONS); + Attributes.runtimeInvisibleAnnotations()); Map actualVisible = collectAnnotations( member, attributedElement, - Attributes.RUNTIME_VISIBLE_ANNOTATIONS); + Attributes.runtimeVisibleAnnotations()); checkEquals(actualInvisible.keySet(), member.getRuntimeInvisibleAnnotations(), "RuntimeInvisibleAnnotations"); diff --git a/test/langtools/tools/javac/classfiles/attributes/annotations/RuntimeParameterAnnotationsForLambdaTest.java b/test/langtools/tools/javac/classfiles/attributes/annotations/RuntimeParameterAnnotationsForLambdaTest.java index baf3a599095..ef9bd07cd69 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 class RuntimeParameterAnnotationsForLambdaTest extends RuntimeParameterAn 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/annotations/RuntimeParameterAnnotationsTestBase.java b/test/langtools/tools/javac/classfiles/attributes/annotations/RuntimeParameterAnnotationsTestBase.java index 04b1ba2dd54..b8c90faf52b 100644 --- a/test/langtools/tools/javac/classfiles/attributes/annotations/RuntimeParameterAnnotationsTestBase.java +++ b/test/langtools/tools/javac/classfiles/attributes/annotations/RuntimeParameterAnnotationsTestBase.java @@ -67,12 +67,12 @@ public abstract class RuntimeParameterAnnotationsTestBase extends AnnotationsTes classFile, testMethod, method, - Attributes.RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS); + Attributes.runtimeInvisibleParameterAnnotations()); List> actualVisible = collectAnnotations( classFile, testMethod, method, - Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS); + Attributes.runtimeVisibleParameterAnnotations()); List parameters = testMethod.parameters; for (int i = 0; i < parameters.size(); ++i) { diff --git a/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedPackageTest.java b/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedPackageTest.java index 3f3a5f2a984..b3e7339b240 100644 --- a/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedPackageTest.java +++ b/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedPackageTest.java @@ -84,7 +84,7 @@ public class DeprecatedPackageTest extends TestResult { 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/deprecated/DeprecatedTest.java b/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedTest.java index ebe77e69056..425760ea137 100644 --- a/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedTest.java +++ b/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedTest.java @@ -243,7 +243,7 @@ public class DeprecatedTest extends TestResult { .findFirst().orElse(null); echo("Testing outer class : " + outerClassName); ClassModel cf = readClassFile(classes.get(outerClassName)); - DeprecatedAttribute attr = cf.findAttribute(Attributes.DEPRECATED).orElse(null); + DeprecatedAttribute attr = cf.findAttribute(Attributes.deprecated()).orElse(null); testAttribute(outerClassName, attr, cf); testInnerClasses(cf, classes); testMethods(cf); @@ -255,13 +255,13 @@ public class DeprecatedTest extends TestResult { private void testInnerClasses(ClassModel cf, Map classes) throws IOException { - InnerClassesAttribute innerAttr = cf.findAttribute(Attributes.INNER_CLASSES).orElse(null); + InnerClassesAttribute innerAttr = cf.findAttribute(Attributes.innerClasses()).orElse(null); assert innerAttr != null; for (InnerClassInfo innerClass : innerAttr.classes()) { String innerClassName = innerClass.innerClass().name().stringValue(); echo("Testing inner class : " + innerClassName); ClassModel innerCf = readClassFile(classes.get(innerClassName)); - DeprecatedAttribute attr = innerCf.findAttribute(Attributes.DEPRECATED).orElse(null); + DeprecatedAttribute attr = innerCf.findAttribute(Attributes.deprecated()).orElse(null); assert innerClass.innerName().isPresent(); String innerClassSimpleName = innerClass.innerName().get().stringValue(); testAttribute(innerClassSimpleName, attr, innerCf); @@ -276,7 +276,7 @@ public class DeprecatedTest extends TestResult { for (MethodModel m : cf.methods()) { String methodName = m.methodName().stringValue(); echo("Testing method : " + methodName); - DeprecatedAttribute attr = m.findAttribute(Attributes.DEPRECATED).orElse(null); + DeprecatedAttribute attr = m.findAttribute(Attributes.deprecated()).orElse(null); testAttribute(methodName, attr, cf); } } @@ -285,7 +285,7 @@ public class DeprecatedTest extends TestResult { for (FieldModel f : cm.fields()) { String fieldName = f.fieldName().stringValue(); echo("Testing field : " + fieldName); - DeprecatedAttribute attr = f.findAttribute(Attributes.DEPRECATED).orElse(null); + DeprecatedAttribute attr = f.findAttribute(Attributes.deprecated()).orElse(null); testAttribute(fieldName, attr, cm); } } diff --git a/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesHierarchyTest.java b/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesHierarchyTest.java index eb7e6f2e2df..124f46acded 100644 --- a/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesHierarchyTest.java +++ b/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesHierarchyTest.java @@ -98,7 +98,7 @@ public class InnerClassesHierarchyTest extends TestResult { continue; } ClassModel cf = readClassFile(currentClassName); - InnerClassesAttribute attr = cf.findAttribute(Attributes.INNER_CLASSES).orElse(null); + InnerClassesAttribute attr = cf.findAttribute(Attributes.innerClasses()).orElse(null); checkNotNull(attr, "Class should not contain " + "inner classes attribute : " + currentClassName); checkTrue(innerClasses.containsKey(currentClassName), diff --git a/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesIndexTest.java b/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesIndexTest.java index 826365a8011..96f2efc6ea6 100644 --- a/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesIndexTest.java +++ b/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesIndexTest.java @@ -69,7 +69,7 @@ public class InnerClassesIndexTest extends TestResult { try { addTestCase("Source is InnerClassesIndexTest.java"); ClassModel classFile = readClassFile(InnerClassesIndexTest.class); - InnerClassesAttribute attr = classFile.findAttribute(Attributes.INNER_CLASSES).orElse(null); + InnerClassesAttribute attr = classFile.findAttribute(Attributes.innerClasses()).orElse(null); Set foundClasses = new HashSet<>(); assert attr != null; diff --git a/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTestBase.java b/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTestBase.java index ca818817b6d..26972de3544 100644 --- a/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTestBase.java +++ b/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTestBase.java @@ -195,7 +195,7 @@ public abstract class InnerClassesTestBase extends TestResult { Map> class2Flags = test.getFlags(); ClassModel cm = readClassFile(compile(getCompileOptions(), test.getSource()) .getClasses().get(classToTest)); - InnerClassesAttribute innerClasses = cm.findAttribute(Attributes.INNER_CLASSES).orElse(null); + InnerClassesAttribute innerClasses = cm.findAttribute(Attributes.innerClasses()).orElse(null); int count = 0; for (Attribute a : cm.attributes()) { if (a instanceof InnerClassesAttribute) { diff --git a/test/langtools/tools/javac/classfiles/attributes/innerclasses/NoInnerClassesTest.java b/test/langtools/tools/javac/classfiles/attributes/innerclasses/NoInnerClassesTest.java index 540bd09a18f..35d65208bc5 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 class NoInnerClassesTest extends TestBase { 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/classwriter/IndyCorrectInvocationName.java b/test/langtools/tools/javac/classwriter/IndyCorrectInvocationName.java index 8711118b8fd..8b5e4e7b695 100644 --- a/test/langtools/tools/javac/classwriter/IndyCorrectInvocationName.java +++ b/test/langtools/tools/javac/classwriter/IndyCorrectInvocationName.java @@ -165,12 +165,12 @@ public class IndyCorrectInvocationName implements Plugin { Path testClass = classes.resolve("Test.class"); ClassModel cf = ClassFile.of().parse(testClass); - BootstrapMethodsAttribute bootAttr = cf.findAttribute(Attributes.BOOTSTRAP_METHODS).orElseThrow(); + BootstrapMethodsAttribute bootAttr = cf.findAttribute(Attributes.bootstrapMethods()).orElseThrow(); if (bootAttr.bootstrapMethodsSize() != 1) { throw new AssertionError("Incorrect number of bootstrap methods: " + bootAttr.bootstrapMethodsSize()); } - CodeAttribute codeAttr = cf.methods().get(1).findAttribute(Attributes.CODE).orElseThrow(); + CodeAttribute codeAttr = cf.methods().get(1).findAttribute(Attributes.code()).orElseThrow(); Set seenBootstraps = new HashSet<>(); Set seenNameAndTypes = new HashSet<>(); Set seenNames = new HashSet<>(); diff --git a/test/langtools/tools/javac/code/CharImmediateValue.java b/test/langtools/tools/javac/code/CharImmediateValue.java index 24f60c5d539..44e2744b74e 100644 --- a/test/langtools/tools/javac/code/CharImmediateValue.java +++ b/test/langtools/tools/javac/code/CharImmediateValue.java @@ -133,7 +133,7 @@ public class CharImmediateValue implements Plugin { Path testClass = classes.resolve("Test.class"); ClassModel cf = ClassFile.of().parse(testClass); - CodeAttribute codeAttr = cf.methods().get(1).findAttribute(Attributes.CODE).orElseThrow(); + CodeAttribute codeAttr = cf.methods().get(1).findAttribute(Attributes.code()).orElseThrow(); boolean seenCast = false; for (CodeElement i : codeAttr.elementList()) { if (i instanceof Instruction ins && ins.opcode() == Opcode.I2C) { diff --git a/test/langtools/tools/javac/defaultMethods/TestDefaultBody.java b/test/langtools/tools/javac/defaultMethods/TestDefaultBody.java index 5cad9ed6293..ec4e8b7b558 100644 --- a/test/langtools/tools/javac/defaultMethods/TestDefaultBody.java +++ b/test/langtools/tools/javac/defaultMethods/TestDefaultBody.java @@ -67,7 +67,7 @@ public class TestDefaultBody { MethodModel testMethod = null; CodeAttribute codeAttr = null; for (MethodModel m : cf.methods()) { - codeAttr = m.findAttribute(Attributes.CODE).orElse(null); + codeAttr = m.findAttribute(Attributes.code()).orElse(null); String mname = m.methodName().stringValue(); if (mname.equals(TEST_METHOD_NAME)) { testMethod = m; diff --git a/test/langtools/tools/javac/defaultMethods/super/TestDirectSuperInterfaceInvoke.java b/test/langtools/tools/javac/defaultMethods/super/TestDirectSuperInterfaceInvoke.java index 5e171b3cdf0..8be378eaf7b 100644 --- a/test/langtools/tools/javac/defaultMethods/super/TestDirectSuperInterfaceInvoke.java +++ b/test/langtools/tools/javac/defaultMethods/super/TestDirectSuperInterfaceInvoke.java @@ -86,7 +86,7 @@ public class TestDirectSuperInterfaceInvoke { try { final ClassModel cf = ClassFile.of().parse(file.toPath()); for (MethodModel m : cf.methods()) { - CodeAttribute codeAttr = m.findAttribute(Attributes.CODE).orElseThrow(); + CodeAttribute codeAttr = m.findAttribute(Attributes.code()).orElseThrow(); for (CodeElement ce : codeAttr.elementList()) { if (ce instanceof InvokeInstruction instr && instr.opcode() == Opcode.INVOKESPECIAL) { MemberRefEntry ref = instr.method(); diff --git a/test/langtools/tools/javac/expression/_super/NonDirectSuper/NonDirectSuper.java b/test/langtools/tools/javac/expression/_super/NonDirectSuper/NonDirectSuper.java index 05942c56722..e4879302058 100644 --- a/test/langtools/tools/javac/expression/_super/NonDirectSuper/NonDirectSuper.java +++ b/test/langtools/tools/javac/expression/_super/NonDirectSuper/NonDirectSuper.java @@ -61,7 +61,7 @@ public class NonDirectSuper { try { final ClassModel cf = ClassFile.of().parse(clazz.toPath()); for (MethodModel m : cf.methods()) { - CodeAttribute codeAttr = m.findAttribute(Attributes.CODE).orElseThrow(); + CodeAttribute codeAttr = m.findAttribute(Attributes.code()).orElseThrow(); for (CodeElement ce : codeAttr.elementList()) { if (ce instanceof InvokeInstruction instr && (instr.opcode() == Opcode.INVOKESPECIAL || instr.opcode() == Opcode.INVOKEVIRTUAL)) { diff --git a/test/langtools/tools/javac/file/SymLinkTest.java b/test/langtools/tools/javac/file/SymLinkTest.java index f9dea1d8bc3..45405aac2ee 100644 --- a/test/langtools/tools/javac/file/SymLinkTest.java +++ b/test/langtools/tools/javac/file/SymLinkTest.java @@ -95,7 +95,7 @@ public class SymLinkTest extends TestRunner { .writeAll(); ClassModel cf = ClassFile.of().parse(classes.resolve("HelloWorld.class")); - SourceFileAttribute sf = cf.findAttribute(Attributes.SOURCE_FILE).orElseThrow(); + SourceFileAttribute sf = cf.findAttribute(Attributes.sourceFile()).orElseThrow(); String sourceFile = sf.sourceFile().stringValue(); if (!"HelloWorld.java".equals(sourceFile)) { diff --git a/test/langtools/tools/javac/flow/LVTHarness.java b/test/langtools/tools/javac/flow/LVTHarness.java index 6e8afef9903..cd4374d93e2 100644 --- a/test/langtools/tools/javac/flow/LVTHarness.java +++ b/test/langtools/tools/javac/flow/LVTHarness.java @@ -138,8 +138,8 @@ public class LVTHarness { } void checkMethod(MethodModel method, AliveRanges ranges) { - CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow(); - LocalVariableTableAttribute lvt = code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE).orElseThrow(); + CodeAttribute code = method.findAttribute(Attributes.code()).orElseThrow(); + LocalVariableTableAttribute lvt = code.findAttribute(Attributes.localVariableTable()).orElseThrow(); List infoFromRanges = convertToStringList(ranges); List infoFromLVT = convertToStringList(lvt); diff --git a/test/langtools/tools/javac/lambda/ByteCodeTest.java b/test/langtools/tools/javac/lambda/ByteCodeTest.java index 7a5943935be..df5c8df1ff9 100644 --- a/test/langtools/tools/javac/lambda/ByteCodeTest.java +++ b/test/langtools/tools/javac/lambda/ByteCodeTest.java @@ -423,7 +423,7 @@ public class ByteCodeTest { } private Map readBSM() { - BootstrapMethodsAttribute bsmAttr = cf.findAttribute(Attributes.BOOTSTRAP_METHODS).orElse(null); + BootstrapMethodsAttribute bsmAttr = cf.findAttribute(Attributes.bootstrapMethods()).orElse(null); if (bsmAttr != null) { Map out = new HashMap<>(bsmAttr.bootstrapMethodsSize()); diff --git a/test/langtools/tools/javac/lambda/LocalVariableTable.java b/test/langtools/tools/javac/lambda/LocalVariableTable.java index 3a636751199..e78fed1288a 100644 --- a/test/langtools/tools/javac/lambda/LocalVariableTable.java +++ b/test/langtools/tools/javac/lambda/LocalVariableTable.java @@ -90,13 +90,13 @@ public class LocalVariableTable { return; } - CodeAttribute code = m.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute code = m.findAttribute(Attributes.code()).orElse(null); if (code == null) { error("Code attribute not found"); return; } - LocalVariableTableAttribute lvt = code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE).orElse(null); + LocalVariableTableAttribute lvt = code.findAttribute(Attributes.localVariableTable()).orElse(null); if (lvt == null) { error("LocalVariableTable attribute not found"); return; diff --git a/test/langtools/tools/javac/lambda/TestBootstrapMethodsCount.java b/test/langtools/tools/javac/lambda/TestBootstrapMethodsCount.java index c8b405b706a..1220bf4dfa4 100644 --- a/test/langtools/tools/javac/lambda/TestBootstrapMethodsCount.java +++ b/test/langtools/tools/javac/lambda/TestBootstrapMethodsCount.java @@ -112,7 +112,7 @@ public class TestBootstrapMethodsCount { File compiledTest = new File("Test.class"); try { ClassModel cf = ClassFile.of().parse(compiledTest.toPath()); - BootstrapMethodsAttribute bsm_attr = cf.findAttribute(Attributes.BOOTSTRAP_METHODS).orElseThrow(); + BootstrapMethodsAttribute bsm_attr = cf.findAttribute(Attributes.bootstrapMethods()).orElseThrow(); int length = bsm_attr.bootstrapMethodsSize(); if (length != 1) { throw new Error("Bad number of method specifiers " + diff --git a/test/langtools/tools/javac/lambda/TestInvokeDynamic.java b/test/langtools/tools/javac/lambda/TestInvokeDynamic.java index 56bb63fc2c9..05c304cdd31 100644 --- a/test/langtools/tools/javac/lambda/TestInvokeDynamic.java +++ b/test/langtools/tools/javac/lambda/TestInvokeDynamic.java @@ -265,7 +265,7 @@ public class TestInvokeDynamic extends ComboInstance { fail("Test method not found"); return; } - CodeAttribute ea = testMethod.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute ea = testMethod.findAttribute(Attributes.code()).orElse(null); if (ea == null) { fail("Code attribute for test() method not found"); return; @@ -289,7 +289,7 @@ public class TestInvokeDynamic extends ComboInstance { } BootstrapMethodsAttribute bsm_attr = cm - .findAttribute(Attributes.BOOTSTRAP_METHODS).orElseThrow(); + .findAttribute(Attributes.bootstrapMethods()).orElseThrow(); if (bsm_attr.bootstrapMethodsSize() != 1) { fail("Bad number of method specifiers " + "in BootstrapMethods attribute"); @@ -337,7 +337,7 @@ public class TestInvokeDynamic extends ComboInstance { return; } - LineNumberTableAttribute lnt = ea.findAttribute(Attributes.LINE_NUMBER_TABLE).orElse(null); + LineNumberTableAttribute lnt = ea.findAttribute(Attributes.lineNumberTable()).orElse(null); if (lnt == null) { fail("No LineNumberTable attribute"); diff --git a/test/langtools/tools/javac/lambda/bytecode/TestLambdaBytecode.java b/test/langtools/tools/javac/lambda/bytecode/TestLambdaBytecode.java index dd637489361..c19c848ee68 100644 --- a/test/langtools/tools/javac/lambda/bytecode/TestLambdaBytecode.java +++ b/test/langtools/tools/javac/lambda/bytecode/TestLambdaBytecode.java @@ -218,7 +218,7 @@ public class TestLambdaBytecode extends ComboInstance { fail("Test method not found"); return; } - CodeAttribute ea = testMethod.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute ea = testMethod.findAttribute(Attributes.code()).orElse(null); if (ea == null) { fail("Code attribute for test() method not found"); return; @@ -243,7 +243,7 @@ public class TestLambdaBytecode extends ComboInstance { return; } - BootstrapMethodsAttribute bsm_attr = cf.findAttribute(Attributes.BOOTSTRAP_METHODS).orElseThrow(); + BootstrapMethodsAttribute bsm_attr = cf.findAttribute(Attributes.bootstrapMethods()).orElseThrow(); if (bsm_attr.bootstrapMethodsSize() != 1) { fail("Bad number of method specifiers " + "in BootstrapMethods attribute"); diff --git a/test/langtools/tools/javac/lambda/bytecode/TestLambdaBytecodeTargetRelease14.java b/test/langtools/tools/javac/lambda/bytecode/TestLambdaBytecodeTargetRelease14.java index 2ac3e322970..326de3168b3 100644 --- a/test/langtools/tools/javac/lambda/bytecode/TestLambdaBytecodeTargetRelease14.java +++ b/test/langtools/tools/javac/lambda/bytecode/TestLambdaBytecodeTargetRelease14.java @@ -220,7 +220,7 @@ public class TestLambdaBytecodeTargetRelease14 extends ComboInstance ce instanceof Attributes) - .andThen(ClassTransform.endHandler(classBuilder -> classBuilder.with(newAttr)))); + byte[] newBytes = ClassFile.of().transform(cf, + ClassTransform.endHandler(classBuilder -> classBuilder.with(newAttr))); try (OutputStream out = Files.newOutputStream(moduleInfoFile)) { out.write(newBytes); } diff --git a/test/langtools/tools/javac/linenumbers/ConditionalLineNumberTest.java b/test/langtools/tools/javac/linenumbers/ConditionalLineNumberTest.java index 2727c9bdbd8..c44def84987 100644 --- a/test/langtools/tools/javac/linenumbers/ConditionalLineNumberTest.java +++ b/test/langtools/tools/javac/linenumbers/ConditionalLineNumberTest.java @@ -54,7 +54,7 @@ public class ConditionalLineNumberTest { ClassModel self = ClassFile.of().parse(ConditionalLineNumberTest.class.getResourceAsStream("ConditionalLineNumberTest.class").readAllBytes()); for (MethodModel m : self.methods()) { if (m.methodName().equalsString("method")) { - CodeAttribute code_attribute = m.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute code_attribute = m.findAttribute(Attributes.code()).orElse(null); assert code_attribute != null; for (Attribute at : code_attribute.attributes()) { if (at instanceof LineNumberTableAttribute) { diff --git a/test/langtools/tools/javac/linenumbers/FinallyLineNumberTest.java b/test/langtools/tools/javac/linenumbers/FinallyLineNumberTest.java index 0a6f23593c1..d150c6bb4b7 100644 --- a/test/langtools/tools/javac/linenumbers/FinallyLineNumberTest.java +++ b/test/langtools/tools/javac/linenumbers/FinallyLineNumberTest.java @@ -83,7 +83,7 @@ public class FinallyLineNumberTest { ClassModel self = ClassFile.of().parse(FinallyLineNumberTest.class.getResourceAsStream("FinallyLineNumberTest.class").readAllBytes()); for (MethodModel m : self.methods()) { if (m.methodName().equalsString("method")) { - CodeAttribute code_attribute = m.findAttribute(Attributes.CODE).orElseThrow(); + CodeAttribute code_attribute = m.findAttribute(Attributes.code()).orElseThrow(); for (Attribute at : code_attribute.attributes()) { if (at instanceof LineNumberTableAttribute lineAt) { return lineAt.lineNumbers(); diff --git a/test/langtools/tools/javac/linenumbers/NestedLineNumberTest.java b/test/langtools/tools/javac/linenumbers/NestedLineNumberTest.java index 481534ec2a0..108a31c23db 100644 --- a/test/langtools/tools/javac/linenumbers/NestedLineNumberTest.java +++ b/test/langtools/tools/javac/linenumbers/NestedLineNumberTest.java @@ -30,7 +30,7 @@ public class NestedLineNumberTest { ClassModel self = ClassFile.of().parse(NestedLineNumberTest.Test.class.getResourceAsStream("NestedLineNumberTest$Test.class").readAllBytes()); for (MethodModel m : self.methods()) { if ("".equals(m.methodName().stringValue())) { - CodeAttribute code_attribute = m.findAttribute(Attributes.CODE).orElseThrow(); + CodeAttribute code_attribute = m.findAttribute(Attributes.code()).orElseThrow(); for (Attribute at : code_attribute.attributes()) { if (at instanceof LineNumberTableAttribute lineAt) { return lineAt.lineNumbers(); diff --git a/test/langtools/tools/javac/linenumbers/NullCheckLineNumberTest.java b/test/langtools/tools/javac/linenumbers/NullCheckLineNumberTest.java index 91c562b2360..d74a0e5667b 100644 --- a/test/langtools/tools/javac/linenumbers/NullCheckLineNumberTest.java +++ b/test/langtools/tools/javac/linenumbers/NullCheckLineNumberTest.java @@ -63,7 +63,7 @@ public class NullCheckLineNumberTest { ClassModel self = ClassFile.of().parse(Objects.requireNonNull(Test.class.getResourceAsStream("NullCheckLineNumberTest$Test.class")).readAllBytes()); for (MethodModel m : self.methods()) { if ("".equals(m.methodName().stringValue())) { - CodeAttribute code_attribute = m.findAttribute(Attributes.CODE).orElseThrow(); + CodeAttribute code_attribute = m.findAttribute(Attributes.code()).orElseThrow(); for (Attribute at : code_attribute.attributes()) { if (at instanceof LineNumberTableAttribute lineAt) { return lineAt.lineNumbers().stream() diff --git a/test/langtools/tools/javac/meth/TestCP.java b/test/langtools/tools/javac/meth/TestCP.java index 31a5bd1762f..bc574134b89 100644 --- a/test/langtools/tools/javac/meth/TestCP.java +++ b/test/langtools/tools/javac/meth/TestCP.java @@ -135,7 +135,7 @@ public class TestCP { if (testMethod == null) { throw new Error("Test method not found"); } - CodeAttribute ea = testMethod.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute ea = testMethod.findAttribute(Attributes.code()).orElse(null); if (ea == null) { throw new Error("Code attribute for test() method not found"); } diff --git a/test/langtools/tools/javac/modules/AnnotationsOnModules.java b/test/langtools/tools/javac/modules/AnnotationsOnModules.java index 59b48fd4954..bfae27d4d21 100644 --- a/test/langtools/tools/javac/modules/AnnotationsOnModules.java +++ b/test/langtools/tools/javac/modules/AnnotationsOnModules.java @@ -86,7 +86,7 @@ public class AnnotationsOnModules extends ModuleTestBase { .writeAll(); ClassModel cf = ClassFile.of().parse(modulePath.resolve("m1x").resolve("module-info.class")); - RuntimeVisibleAnnotationsAttribute annotations = cf.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElse(null); + RuntimeVisibleAnnotationsAttribute annotations = cf.findAttribute(Attributes.runtimeVisibleAnnotations()).orElse(null); if (annotations == null || annotations.annotations().size() != 1) { throw new AssertionError("Annotations not correct!"); @@ -140,13 +140,13 @@ public class AnnotationsOnModules extends ModuleTestBase { } ClassModel cf = ClassFile.of().parse(modulePath.resolve("A").resolve("module-info.class")); - RuntimeVisibleAnnotationsAttribute annotations = cf.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElse(null); + RuntimeVisibleAnnotationsAttribute annotations = cf.findAttribute(Attributes.runtimeVisibleAnnotations()).orElse(null); if (annotations != null && annotations.annotations().size() > 0) { throw new AssertionError("Found annotation attributes. Expected no annotations for javadoc @deprecated tag."); } - if (cf.findAttribute(Attributes.DEPRECATED).isPresent()) { + if (cf.findAttribute(Attributes.deprecated()).isPresent()) { throw new AssertionError("Found Deprecated attribute. Expected no Deprecated attribute for javadoc @deprecated tag."); } } @@ -191,7 +191,7 @@ public class AnnotationsOnModules extends ModuleTestBase { } ClassModel cf = ClassFile.of().parse(modulePath.resolve("A").resolve("module-info.class")); - RuntimeVisibleAnnotationsAttribute annotations = cf.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElse(null); + RuntimeVisibleAnnotationsAttribute annotations = cf.findAttribute(Attributes.runtimeVisibleAnnotations()).orElse(null); if (annotations == null ) { throw new AssertionError("Annotations not found!"); @@ -314,7 +314,7 @@ public class AnnotationsOnModules extends ModuleTestBase { .writeAll(); ClassModel cf = ClassFile.of().parse(modulePath.resolve("m1x").resolve("module-info.class")); - RuntimeInvisibleAnnotationsAttribute annotations = cf.findAttribute(Attributes.RUNTIME_INVISIBLE_ANNOTATIONS).orElse(null); + RuntimeInvisibleAnnotationsAttribute annotations = cf.findAttribute(Attributes.runtimeInvisibleAnnotations()).orElse(null); if (annotations == null || annotations.annotations().size() != 1) { throw new AssertionError("Annotations not correct!"); @@ -356,7 +356,7 @@ public class AnnotationsOnModules extends ModuleTestBase { .writeAll(); ClassModel cf = ClassFile.of().parse(modulePath.resolve("B").resolve("module-info.class")); - RuntimeInvisibleAnnotationsAttribute annotations = cf.findAttribute(Attributes.RUNTIME_INVISIBLE_ANNOTATIONS).orElse(null); + RuntimeInvisibleAnnotationsAttribute annotations = cf.findAttribute(Attributes.runtimeInvisibleAnnotations()).orElse(null); if (annotations == null ) { throw new AssertionError("Annotations not found!"); @@ -431,7 +431,7 @@ public class AnnotationsOnModules extends ModuleTestBase { .writeAll(); ClassModel cf = ClassFile.of().parse(classes.resolve("m1x").resolve("module-info.class")); - RuntimeInvisibleAnnotationsAttribute invisibleAnnotations = cf.findAttribute(Attributes.RUNTIME_INVISIBLE_ANNOTATIONS).orElse(null); + RuntimeInvisibleAnnotationsAttribute invisibleAnnotations = cf.findAttribute(Attributes.runtimeInvisibleAnnotations()).orElse(null); if (invisibleAnnotations == null) { throw new AssertionError("Annotations not found!"); diff --git a/test/langtools/tools/javac/modules/JavaBaseTest.java b/test/langtools/tools/javac/modules/JavaBaseTest.java index 64f914e5d2f..188bc4801e5 100644 --- a/test/langtools/tools/javac/modules/JavaBaseTest.java +++ b/test/langtools/tools/javac/modules/JavaBaseTest.java @@ -206,7 +206,7 @@ public class JavaBaseTest { ClassModel cm1 = ClassFile.of().parse(modules1.resolve("module-info.class")); - ModuleAttribute modAttr1 = cm1.findAttribute(Attributes.MODULE).orElseThrow(); + ModuleAttribute modAttr1 = cm1.findAttribute(Attributes.module()).orElseThrow(); List requires = Arrays.asList(new ModuleRequireInfo[modAttr1.requires().size()]); for (int i = 0; i < modAttr1.requires().size(); ++i) { ModuleRequireInfo e1 = modAttr1.requires().get(i); diff --git a/test/langtools/tools/javac/modules/ModuleVersion.java b/test/langtools/tools/javac/modules/ModuleVersion.java index d6b514eee31..cbf9b82c54c 100644 --- a/test/langtools/tools/javac/modules/ModuleVersion.java +++ b/test/langtools/tools/javac/modules/ModuleVersion.java @@ -114,7 +114,7 @@ public class ModuleVersion extends ModuleTestBase { private void checkModuleVersion(Path classfile, String version) throws IOException { ClassModel cm = ClassFile.of().parse(classfile); - ModuleAttribute moduleAttribute = cm.findAttribute(Attributes.MODULE).orElse(null); + ModuleAttribute moduleAttribute = cm.findAttribute(Attributes.module()).orElse(null); if (moduleAttribute == null) { throw new AssertionError("Version attribute missing!"); diff --git a/test/langtools/tools/javac/modules/OpenModulesTest.java b/test/langtools/tools/javac/modules/OpenModulesTest.java index 4523b726548..e21601031e7 100644 --- a/test/langtools/tools/javac/modules/OpenModulesTest.java +++ b/test/langtools/tools/javac/modules/OpenModulesTest.java @@ -233,7 +233,7 @@ public class OpenModulesTest extends ModuleTestBase { Path miClass = m1Classes.resolve("module-info.class"); ClassModel cm = ClassFile.of().parse(miClass); - ModuleAttribute module = cm.findAttribute(Attributes.MODULE).orElseThrow(); + ModuleAttribute module = cm.findAttribute(Attributes.module()).orElseThrow(); ModuleAttribute newModule = ModuleAttribute.of(module.moduleName(), module.moduleFlagsMask() | ClassFile.ACC_OPEN, module.moduleVersion().orElse(null), diff --git a/test/langtools/tools/javac/multicatch/7005371/T7005371.java b/test/langtools/tools/javac/multicatch/7005371/T7005371.java index bf83cd26089..c99371642a6 100644 --- a/test/langtools/tools/javac/multicatch/7005371/T7005371.java +++ b/test/langtools/tools/javac/multicatch/7005371/T7005371.java @@ -70,11 +70,11 @@ public class T7005371 { if (testMethod == null) { throw new Error("Missing method: " + TEST_METHOD_NAME); } - CodeAttribute code = testMethod.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute code = testMethod.findAttribute(Attributes.code()).orElse(null); if (code == null) { throw new Error("Missing Code attribute for method: " + TEST_METHOD_NAME); } - LocalVariableTypeTableAttribute lvt_table = code.findAttribute(Attributes.LOCAL_VARIABLE_TYPE_TABLE).orElse(null); + LocalVariableTypeTableAttribute lvt_table = code.findAttribute(Attributes.localVariableTypeTable()).orElse(null); if (lvt_table == null) { throw new Error("Missing LocalVariableTypeTable attribute for method: " + TEST_METHOD_NAME); } diff --git a/test/langtools/tools/javac/multicatch/Pos05.java b/test/langtools/tools/javac/multicatch/Pos05.java index 1dade792178..16ee54f2ccd 100644 --- a/test/langtools/tools/javac/multicatch/Pos05.java +++ b/test/langtools/tools/javac/multicatch/Pos05.java @@ -90,7 +90,7 @@ public class Pos05 { if (testMethod == null) { throw new Error("Test method not found"); } - CodeAttribute ea = testMethod.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute ea = testMethod.findAttribute(Attributes.code()).orElse(null); if (ea == null) { throw new Error("Code attribute for test() method not found"); } diff --git a/test/langtools/tools/javac/patterns/Annotations.java b/test/langtools/tools/javac/patterns/Annotations.java index f14ab3fb970..a471cc57b63 100644 --- a/test/langtools/tools/javac/patterns/Annotations.java +++ b/test/langtools/tools/javac/patterns/Annotations.java @@ -67,8 +67,8 @@ public class Annotations extends JavacTestingAbstractProcessor { ClassModel cf = ClassFile.of().parse(annotationsClass.readAllBytes()); for (MethodModel m : cf.methods()) { if (m.methodName().equalsString("test")) { - CodeAttribute codeAttr = m.findAttribute(Attributes.CODE).orElseThrow(); - RuntimeInvisibleTypeAnnotationsAttribute annotations = codeAttr.findAttribute(Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS).orElseThrow(); + CodeAttribute codeAttr = m.findAttribute(Attributes.code()).orElseThrow(); + RuntimeInvisibleTypeAnnotationsAttribute annotations = codeAttr.findAttribute(Attributes.runtimeInvisibleTypeAnnotations()).orElseThrow(); String expected = "LAnnotations$DTA; pos: [LOCAL_VARIABLE, {start_pc=31, end_pc=38, index=1}], " + "LAnnotations$TA; pos: [LOCAL_VARIABLE, {start_pc=50, end_pc=57, index=1}], "; StringBuilder actual = new StringBuilder(); diff --git a/test/langtools/tools/javac/patterns/LocalVariableTable.java b/test/langtools/tools/javac/patterns/LocalVariableTable.java index 9fa29b09065..37051daf142 100644 --- a/test/langtools/tools/javac/patterns/LocalVariableTable.java +++ b/test/langtools/tools/javac/patterns/LocalVariableTable.java @@ -87,13 +87,13 @@ public class LocalVariableTable { return; } - CodeAttribute code = m.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute code = m.findAttribute(Attributes.code()).orElse(null); if (code == null) { error("Code attribute not found"); return; } - LocalVariableTableAttribute lvt = code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE).orElse(null); + LocalVariableTableAttribute lvt = code.findAttribute(Attributes.localVariableTable()).orElse(null); if (lvt == null) { error("LocalVariableTable attribute not found"); return; diff --git a/test/langtools/tools/javac/patterns/NestedPatternVariablesBytecode.java b/test/langtools/tools/javac/patterns/NestedPatternVariablesBytecode.java index 3759676e2c3..36068729146 100644 --- a/test/langtools/tools/javac/patterns/NestedPatternVariablesBytecode.java +++ b/test/langtools/tools/javac/patterns/NestedPatternVariablesBytecode.java @@ -85,7 +85,7 @@ public class NestedPatternVariablesBytecode extends TestRunner { .filter(this::isTestMethod) .findAny() .orElseThrow(); - CodeAttribute code_attribute = testMethod.findAttribute(Attributes.CODE).orElseThrow(); + CodeAttribute code_attribute = testMethod.findAttribute(Attributes.code()).orElseThrow(); List actualCode = getCodeInstructions(code_attribute); List expectedCode = Arrays.asList( diff --git a/test/langtools/tools/javac/patterns/NoUnnecessaryCast.java b/test/langtools/tools/javac/patterns/NoUnnecessaryCast.java index b7e7df089a5..55444e1d748 100644 --- a/test/langtools/tools/javac/patterns/NoUnnecessaryCast.java +++ b/test/langtools/tools/javac/patterns/NoUnnecessaryCast.java @@ -71,7 +71,7 @@ public class NoUnnecessaryCast { ICONST_0 IRETURN """; - CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow(); + CodeAttribute code = method.findAttribute(Attributes.code()).orElseThrow(); String actualInstructions = printCode(code); if (!expectedInstructions.equals(actualInstructions)) { throw new AssertionError("Unexpected instructions found:\n" + diff --git a/test/langtools/tools/javac/platform/ModuleVersionTest.java b/test/langtools/tools/javac/platform/ModuleVersionTest.java index 1b01fc397e8..0e8f8b8c05f 100644 --- a/test/langtools/tools/javac/platform/ModuleVersionTest.java +++ b/test/langtools/tools/javac/platform/ModuleVersionTest.java @@ -103,7 +103,7 @@ public class ModuleVersionTest { 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/javac/processing/model/element/TestOrigin.java b/test/langtools/tools/javac/processing/model/element/TestOrigin.java index ba4d7ec7ef9..1fae5374bea 100644 --- a/test/langtools/tools/javac/processing/model/element/TestOrigin.java +++ b/test/langtools/tools/javac/processing/model/element/TestOrigin.java @@ -276,7 +276,7 @@ public class TestOrigin extends TestRunner { Path moduleInfo = classes.resolve("module-info.class"); ClassModel cf = ClassFile.of().parse(moduleInfo); - ModuleAttribute module = cf.findAttribute(Attributes.MODULE).orElseThrow(); + ModuleAttribute module = cf.findAttribute(Attributes.module()).orElseThrow(); List newRequires = new ArrayList<>(3); newRequires.add(ModuleRequireInfo.of(module.requires().get(0).requires(), ClassFile.ACC_MANDATED, module.requires().get(0).requiresVersion().orElse(null))); diff --git a/test/langtools/tools/javac/records/RecordCompilationTests.java b/test/langtools/tools/javac/records/RecordCompilationTests.java index 0436169556f..9f5e73cc5d0 100644 --- a/test/langtools/tools/javac/records/RecordCompilationTests.java +++ b/test/langtools/tools/javac/records/RecordCompilationTests.java @@ -1320,7 +1320,7 @@ class RecordCompilationTests extends CompilationTestCase { ClassModel classFile = ClassFile.of().parse(fileEntry.toPath()); for (MethodModel method : classFile.methods()) { if (method.methodName().equalsString("")) { - CodeAttribute code_attribute = method.findAttribute(Attributes.CODE).orElseThrow(); + CodeAttribute code_attribute = method.findAttribute(Attributes.code()).orElseThrow(); for (CodeElement ce : code_attribute.elementList()) { if (ce instanceof Instruction instruction && instruction.opcode() == Opcode.PUTFIELD) { if (putField1 != null && putField2 != null) { diff --git a/test/langtools/tools/javac/records/recordComponent/RecordComponentTypeTest.java b/test/langtools/tools/javac/records/recordComponent/RecordComponentTypeTest.java index f11c464231f..015dc805eea 100644 --- a/test/langtools/tools/javac/records/recordComponent/RecordComponentTypeTest.java +++ b/test/langtools/tools/javac/records/recordComponent/RecordComponentTypeTest.java @@ -155,7 +155,7 @@ public class RecordComponentTypeTest extends TestRunner { } private void checkRuntimeVisibleAnnotation(AttributedElement attributedElement) throws Exception { - RuntimeVisibleAnnotationsAttribute annotations = attributedElement.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElseThrow(); + RuntimeVisibleAnnotationsAttribute annotations = attributedElement.findAttribute(Attributes.runtimeVisibleAnnotations()).orElseThrow(); boolean hasAnnotation = false; for (Annotation annotation : annotations.annotations()) { if (annotation.classSymbol().descriptorString().equals("LTestAnnotation;")) { diff --git a/test/langtools/tools/javac/sealed/SealedDiffConfigurationsTest.java b/test/langtools/tools/javac/sealed/SealedDiffConfigurationsTest.java index 16860d65cc2..6cec46ef2d1 100644 --- a/test/langtools/tools/javac/sealed/SealedDiffConfigurationsTest.java +++ b/test/langtools/tools/javac/sealed/SealedDiffConfigurationsTest.java @@ -133,7 +133,7 @@ public class SealedDiffConfigurationsTest extends TestRunner { private void checkSealedClassFile(Path out, String cfName, List expectedSubTypeNames) throws ConstantPoolException, Exception { ClassModel sealedCF = ClassFile.of().parse(out.resolve(cfName)); Assert.check((sealedCF.flags().flagsMask() & ClassFile.ACC_FINAL) == 0, String.format("class at file %s must not be final", cfName)); - PermittedSubclassesAttribute permittedSubclasses = sealedCF.findAttribute(Attributes.PERMITTED_SUBCLASSES).orElseThrow(); + PermittedSubclassesAttribute permittedSubclasses = sealedCF.findAttribute(Attributes.permittedSubclasses()).orElseThrow(); Assert.check(permittedSubclasses.permittedSubclasses().size() == expectedSubTypeNames.size()); List subtypeNames = new ArrayList<>(); permittedSubclasses.permittedSubclasses().forEach(i -> { @@ -152,7 +152,7 @@ public class SealedDiffConfigurationsTest extends TestRunner { if (shouldBeFinal) { Assert.check((subCF1.flags().flagsMask() & ClassFile.ACC_FINAL) != 0, String.format("class at file %s must be final", cfName)); } - Assert.checkNull(subCF1.findAttribute(Attributes.PERMITTED_SUBCLASSES).orElse(null)); + Assert.checkNull(subCF1.findAttribute(Attributes.permittedSubclasses()).orElse(null)); Assert.check(subCF1.superclass().orElseThrow().name().equalsString(superClassName)); } diff --git a/test/langtools/tools/javac/varargs/6199075/T6199075.java b/test/langtools/tools/javac/varargs/6199075/T6199075.java index d2eaab364f5..6e77280eea5 100644 --- a/test/langtools/tools/javac/varargs/6199075/T6199075.java +++ b/test/langtools/tools/javac/varargs/6199075/T6199075.java @@ -226,7 +226,7 @@ public class T6199075 { if (testMethod == null) { throw new Error("Test method not found"); } - CodeAttribute ea = testMethod.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute ea = testMethod.findAttribute(Attributes.code()).orElse(null); if (ea == null) { throw new Error("Code attribute for test() method not found"); } diff --git a/test/langtools/tools/javac/varargs/7042566/T7042566.java b/test/langtools/tools/javac/varargs/7042566/T7042566.java index 845cab3bdf8..41c8e9609ca 100644 --- a/test/langtools/tools/javac/varargs/7042566/T7042566.java +++ b/test/langtools/tools/javac/varargs/7042566/T7042566.java @@ -282,7 +282,7 @@ public class T7042566 extends ComboInstance { fail("Test method not found"); return; } - CodeAttribute ea = testMethod.findAttribute(Attributes.CODE).orElse(null); + CodeAttribute ea = testMethod.findAttribute(Attributes.code()).orElse(null); if (ea == null) { fail("Code attribute for test() method not found"); return; diff --git a/test/langtools/tools/javap/T6716452.java b/test/langtools/tools/javap/T6716452.java index 4cc8f4ec41d..63ccead52e7 100644 --- a/test/langtools/tools/javap/T6716452.java +++ b/test/langtools/tools/javap/T6716452.java @@ -51,8 +51,8 @@ public class T6716452 { } void test(MethodModel mm) { - test(mm, Attributes.CODE, CodeAttribute.class); - test(mm, Attributes.EXCEPTIONS, ExceptionsAttribute.class); + test(mm, Attributes.code(), CodeAttribute.class); + test(mm, Attributes.exceptions(), ExceptionsAttribute.class); } // test the result of MethodModel.findAttribute, MethodModel.attributes().indexOf() according to expectations diff --git a/test/langtools/tools/javap/classfile/6888367/T6888367.java b/test/langtools/tools/javap/classfile/6888367/T6888367.java index 16bc06321ca..3e3e3adcd7a 100644 --- a/test/langtools/tools/javap/classfile/6888367/T6888367.java +++ b/test/langtools/tools/javap/classfile/6888367/T6888367.java @@ -85,7 +85,7 @@ public class T6888367 { void testInnerClasses(ClassModel cm) throws Exception { InnerClassesAttribute ic = - cm.findAttribute(Attributes.INNER_CLASSES).orElse(null); + cm.findAttribute(Attributes.innerClasses()).orElse(null); assert ic != null; for (InnerClassInfo info: ic.classes()) { ClassEntry outerClass = info.outerClass().orElse(null); @@ -106,7 +106,7 @@ public class T6888367 { return; System.err.println(name); - SignatureAttribute sa = m.findAttribute(Attributes.SIGNATURE).orElse(null); + SignatureAttribute sa = m.findAttribute(Attributes.signature()).orElse(null); if (sa != null) System.err.println(" signature: " + sa.signature()); @@ -173,7 +173,7 @@ public class T6888367 { } AnnotValues getAnnotValues(String annotName, AttributedElement m) { - RuntimeInvisibleAnnotationsAttribute annots = m.findAttribute(Attributes.RUNTIME_INVISIBLE_ANNOTATIONS).orElse(null); + RuntimeInvisibleAnnotationsAttribute annots = m.findAttribute(Attributes.runtimeInvisibleAnnotations()).orElse(null); if (annots != null) { for (Annotation a: annots.annotations()) { if (a.classSymbol().descriptorString().equals("L" + annotName + ";")) { diff --git a/test/langtools/tools/javap/typeAnnotations/JSR175Annotations.java b/test/langtools/tools/javap/typeAnnotations/JSR175Annotations.java index 1aa3ddbebd8..1f5b2f43958 100644 --- a/test/langtools/tools/javap/typeAnnotations/JSR175Annotations.java +++ b/test/langtools/tools/javap/typeAnnotations/JSR175Annotations.java @@ -58,8 +58,8 @@ public class JSR175Annotations { } 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/NewArray.java b/test/langtools/tools/javap/typeAnnotations/NewArray.java index 7a5ca4675ce..cf08baf2955 100644 --- a/test/langtools/tools/javap/typeAnnotations/NewArray.java +++ b/test/langtools/tools/javap/typeAnnotations/NewArray.java @@ -52,8 +52,8 @@ public class NewArray { } 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 Attributes.getIndex according to expectations @@ -62,7 +62,7 @@ public class NewArray { Attribute attr_instance; CodeAttribute cAttr; - cAttr = mm.findAttribute(Attributes.CODE).orElse(null); + cAttr = mm.findAttribute(Attributes.code()).orElse(null); if (cAttr != null) { attr_instance = cAttr.findAttribute(attr_name).orElse(null); if (attr_instance != null) { diff --git a/test/langtools/tools/javap/typeAnnotations/Presence.java b/test/langtools/tools/javap/typeAnnotations/Presence.java index 7b144457070..2fb488e705e 100644 --- a/test/langtools/tools/javap/typeAnnotations/Presence.java +++ b/test/langtools/tools/javap/typeAnnotations/Presence.java @@ -59,8 +59,8 @@ public class Presence { } 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 @@ -80,7 +80,7 @@ public class Presence { } } if (m instanceof MethodModel) { - attr_instance = m.findAttribute(Attributes.CODE).orElse(null); + attr_instance = m.findAttribute(Attributes.code()).orElse(null); if(attr_instance!= null) { CodeAttribute cAttr = (CodeAttribute)attr_instance; attr_instance = cAttr.findAttribute(attr_name).orElse(null); diff --git a/test/langtools/tools/javap/typeAnnotations/PresenceInner.java b/test/langtools/tools/javap/typeAnnotations/PresenceInner.java index a47a5ea9f53..ccb79534616 100644 --- a/test/langtools/tools/javap/typeAnnotations/PresenceInner.java +++ b/test/langtools/tools/javap/typeAnnotations/PresenceInner.java @@ -71,8 +71,8 @@ public class PresenceInner { } 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/TypeCasts.java b/test/langtools/tools/javap/typeAnnotations/TypeCasts.java index 6d318107c92..c8ee0fde965 100644 --- a/test/langtools/tools/javap/typeAnnotations/TypeCasts.java +++ b/test/langtools/tools/javap/typeAnnotations/TypeCasts.java @@ -55,8 +55,8 @@ public class TypeCasts { } 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()); } @@ -66,7 +66,7 @@ public class TypeCasts { Attribute attr; CodeAttribute cAttr; - cAttr = mm.findAttribute(Attributes.CODE).orElse(null); + cAttr = mm.findAttribute(Attributes.code()).orElse(null); if (cAttr != null) { attr = cAttr.findAttribute(attr_name).orElse(null); if (attr != null) { diff --git a/test/langtools/tools/javap/typeAnnotations/Visibility.java b/test/langtools/tools/javap/typeAnnotations/Visibility.java index d2f16b49d9b..ebffbf9176d 100644 --- a/test/langtools/tools/javap/typeAnnotations/Visibility.java +++ b/test/langtools/tools/javap/typeAnnotations/Visibility.java @@ -55,8 +55,8 @@ public class Visibility { } 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 diff --git a/test/langtools/tools/javap/typeAnnotations/Wildcards.java b/test/langtools/tools/javap/typeAnnotations/Wildcards.java index 8ef0bb61e07..6bbabebdd37 100644 --- a/test/langtools/tools/javap/typeAnnotations/Wildcards.java +++ b/test/langtools/tools/javap/typeAnnotations/Wildcards.java @@ -56,8 +56,8 @@ public class Wildcards { System.out.println("PASSED"); } 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()); } > void test(AttributedElement m, AttributeMapper attr_name) { Attribute attr_instance = m.findAttribute(attr_name).orElse(null);