< prev index next >

src/java.base/share/classes/java/lang/classfile/Attributes.java

Print this page

  27 import java.util.Collections;
  28 import java.util.HashMap;
  29 import java.util.List;
  30 import java.util.Map;
  31 import java.util.Set;
  32 
  33 import java.lang.classfile.attribute.AnnotationDefaultAttribute;
  34 import java.lang.classfile.attribute.BootstrapMethodsAttribute;
  35 import java.lang.classfile.attribute.CharacterRangeInfo;
  36 import java.lang.classfile.attribute.CharacterRangeTableAttribute;
  37 import java.lang.classfile.attribute.CodeAttribute;
  38 import java.lang.classfile.attribute.CompilationIDAttribute;
  39 import java.lang.classfile.attribute.ConstantValueAttribute;
  40 import java.lang.classfile.attribute.DeprecatedAttribute;
  41 import java.lang.classfile.attribute.EnclosingMethodAttribute;
  42 import java.lang.classfile.attribute.ExceptionsAttribute;
  43 import java.lang.classfile.attribute.InnerClassInfo;
  44 import java.lang.classfile.attribute.InnerClassesAttribute;
  45 import java.lang.classfile.attribute.LineNumberInfo;
  46 import java.lang.classfile.attribute.LineNumberTableAttribute;

  47 import java.lang.classfile.attribute.LocalVariableInfo;
  48 import java.lang.classfile.attribute.LocalVariableTableAttribute;
  49 import java.lang.classfile.attribute.LocalVariableTypeInfo;
  50 import java.lang.classfile.attribute.LocalVariableTypeTableAttribute;
  51 import java.lang.classfile.attribute.MethodParameterInfo;
  52 import java.lang.classfile.attribute.MethodParametersAttribute;
  53 import java.lang.classfile.attribute.ModuleAttribute;
  54 import java.lang.classfile.attribute.ModuleExportInfo;
  55 import java.lang.classfile.attribute.ModuleHashInfo;
  56 import java.lang.classfile.attribute.ModuleHashesAttribute;
  57 import java.lang.classfile.attribute.ModuleMainClassAttribute;
  58 import java.lang.classfile.attribute.ModuleOpenInfo;
  59 import java.lang.classfile.attribute.ModulePackagesAttribute;
  60 import java.lang.classfile.attribute.ModuleProvideInfo;
  61 import java.lang.classfile.attribute.ModuleRequireInfo;
  62 import java.lang.classfile.attribute.ModuleResolutionAttribute;
  63 import java.lang.classfile.attribute.ModuleTargetAttribute;
  64 import java.lang.classfile.attribute.NestHostAttribute;
  65 import java.lang.classfile.attribute.NestMembersAttribute;
  66 import java.lang.classfile.attribute.PermittedSubclassesAttribute;

 112     public static final String NAME_COMPILATION_ID = "CompilationID";
 113 
 114     /** ConstantValue */
 115     public static final String NAME_CONSTANT_VALUE = "ConstantValue";
 116 
 117     /** Deprecated */
 118     public static final String NAME_DEPRECATED = "Deprecated";
 119 
 120     /** EnclosingMethod */
 121     public static final String NAME_ENCLOSING_METHOD = "EnclosingMethod";
 122 
 123     /** Exceptions */
 124     public static final String NAME_EXCEPTIONS = "Exceptions";
 125 
 126     /** InnerClasses */
 127     public static final String NAME_INNER_CLASSES = "InnerClasses";
 128 
 129     /** LineNumberTable */
 130     public static final String NAME_LINE_NUMBER_TABLE = "LineNumberTable";
 131 



 132     /** LocalVariableTable */
 133     public static final String NAME_LOCAL_VARIABLE_TABLE = "LocalVariableTable";
 134 
 135     /** LocalVariableTypeTable */
 136     public static final String NAME_LOCAL_VARIABLE_TYPE_TABLE = "LocalVariableTypeTable";
 137 
 138     /** MethodParameters */
 139     public static final String NAME_METHOD_PARAMETERS = "MethodParameters";
 140 
 141     /** Module */
 142     public static final String NAME_MODULE = "Module";
 143 
 144     /** ModuleHashes */
 145     public static final String NAME_MODULE_HASHES = "ModuleHashes";
 146 
 147     /** ModuleMainClass */
 148     public static final String NAME_MODULE_MAIN_CLASS = "ModuleMainClass";
 149 
 150     /** ModulePackages */
 151     public static final String NAME_MODULE_PACKAGES = "ModulePackages";

 703 
 704     /** Attribute mapper for the {@code PermittedSubclasses} attribute */
 705     public static final AttributeMapper<PermittedSubclassesAttribute>
 706             PERMITTED_SUBCLASSES = new AbstractAttributeMapper<>(NAME_PERMITTED_SUBCLASSES) {
 707                 @Override
 708                 public PermittedSubclassesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
 709                     return new BoundAttribute.BoundPermittedSubclassesAttribute(cf, this, p);
 710                 }
 711 
 712                 @Override
 713                 protected void writeBody(BufWriter buf, PermittedSubclassesAttribute attr) {
 714                     buf.writeListIndices(attr.permittedSubclasses());
 715                 }
 716 
 717                 @Override
 718                 public AttributeMapper.AttributeStability stability() {
 719                     return AttributeStability.CP_REFS;
 720                 }
 721             };
 722 



















 723     /** Attribute mapper for the {@code Record} attribute */
 724     public static final AttributeMapper<RecordAttribute>
 725             RECORD = new AbstractAttributeMapper<>(NAME_RECORD) {
 726                 @Override
 727                 public RecordAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
 728                     return new BoundAttribute.BoundRecordAttribute(cf, this, p);
 729                 }
 730 
 731                 @Override
 732                 protected void writeBody(BufWriter buf, RecordAttribute attr) {
 733                     List<RecordComponentInfo> components = attr.components();
 734                     buf.writeU2(components.size());
 735                     for (RecordComponentInfo info : components) {
 736                         buf.writeIndex(info.name());
 737                         buf.writeIndex(info.descriptor());
 738                         buf.writeList(info.attributes());
 739                     }
 740                 }
 741 
 742                 @Override

 987      */
 988     public static AttributeMapper<?> standardAttribute(Utf8Entry name) {
 989         return _ATTR_MAP.get(name);
 990     }
 991 
 992     /**
 993      * All standard attribute mappers.
 994      */
 995     public static final Set<AttributeMapper<?>> PREDEFINED_ATTRIBUTES = Set.of(
 996             ANNOTATION_DEFAULT,
 997             BOOTSTRAP_METHODS,
 998             CHARACTER_RANGE_TABLE,
 999             CODE,
1000             COMPILATION_ID,
1001             CONSTANT_VALUE,
1002             DEPRECATED,
1003             ENCLOSING_METHOD,
1004             EXCEPTIONS,
1005             INNER_CLASSES,
1006             LINE_NUMBER_TABLE,

1007             LOCAL_VARIABLE_TABLE,
1008             LOCAL_VARIABLE_TYPE_TABLE,
1009             METHOD_PARAMETERS,
1010             MODULE,
1011             MODULE_HASHES,
1012             MODULE_MAIN_CLASS,
1013             MODULE_PACKAGES,
1014             MODULE_RESOLUTION,
1015             MODULE_TARGET,
1016             NEST_HOST,
1017             NEST_MEMBERS,
1018             PERMITTED_SUBCLASSES,
1019             RECORD,
1020             RUNTIME_INVISIBLE_ANNOTATIONS,
1021             RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS,
1022             RUNTIME_INVISIBLE_TYPE_ANNOTATIONS,
1023             RUNTIME_VISIBLE_ANNOTATIONS,
1024             RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS,
1025             RUNTIME_VISIBLE_TYPE_ANNOTATIONS,
1026             SIGNATURE,

  27 import java.util.Collections;
  28 import java.util.HashMap;
  29 import java.util.List;
  30 import java.util.Map;
  31 import java.util.Set;
  32 
  33 import java.lang.classfile.attribute.AnnotationDefaultAttribute;
  34 import java.lang.classfile.attribute.BootstrapMethodsAttribute;
  35 import java.lang.classfile.attribute.CharacterRangeInfo;
  36 import java.lang.classfile.attribute.CharacterRangeTableAttribute;
  37 import java.lang.classfile.attribute.CodeAttribute;
  38 import java.lang.classfile.attribute.CompilationIDAttribute;
  39 import java.lang.classfile.attribute.ConstantValueAttribute;
  40 import java.lang.classfile.attribute.DeprecatedAttribute;
  41 import java.lang.classfile.attribute.EnclosingMethodAttribute;
  42 import java.lang.classfile.attribute.ExceptionsAttribute;
  43 import java.lang.classfile.attribute.InnerClassInfo;
  44 import java.lang.classfile.attribute.InnerClassesAttribute;
  45 import java.lang.classfile.attribute.LineNumberInfo;
  46 import java.lang.classfile.attribute.LineNumberTableAttribute;
  47 import java.lang.classfile.attribute.LoadableDescriptorsAttribute;
  48 import java.lang.classfile.attribute.LocalVariableInfo;
  49 import java.lang.classfile.attribute.LocalVariableTableAttribute;
  50 import java.lang.classfile.attribute.LocalVariableTypeInfo;
  51 import java.lang.classfile.attribute.LocalVariableTypeTableAttribute;
  52 import java.lang.classfile.attribute.MethodParameterInfo;
  53 import java.lang.classfile.attribute.MethodParametersAttribute;
  54 import java.lang.classfile.attribute.ModuleAttribute;
  55 import java.lang.classfile.attribute.ModuleExportInfo;
  56 import java.lang.classfile.attribute.ModuleHashInfo;
  57 import java.lang.classfile.attribute.ModuleHashesAttribute;
  58 import java.lang.classfile.attribute.ModuleMainClassAttribute;
  59 import java.lang.classfile.attribute.ModuleOpenInfo;
  60 import java.lang.classfile.attribute.ModulePackagesAttribute;
  61 import java.lang.classfile.attribute.ModuleProvideInfo;
  62 import java.lang.classfile.attribute.ModuleRequireInfo;
  63 import java.lang.classfile.attribute.ModuleResolutionAttribute;
  64 import java.lang.classfile.attribute.ModuleTargetAttribute;
  65 import java.lang.classfile.attribute.NestHostAttribute;
  66 import java.lang.classfile.attribute.NestMembersAttribute;
  67 import java.lang.classfile.attribute.PermittedSubclassesAttribute;

 113     public static final String NAME_COMPILATION_ID = "CompilationID";
 114 
 115     /** ConstantValue */
 116     public static final String NAME_CONSTANT_VALUE = "ConstantValue";
 117 
 118     /** Deprecated */
 119     public static final String NAME_DEPRECATED = "Deprecated";
 120 
 121     /** EnclosingMethod */
 122     public static final String NAME_ENCLOSING_METHOD = "EnclosingMethod";
 123 
 124     /** Exceptions */
 125     public static final String NAME_EXCEPTIONS = "Exceptions";
 126 
 127     /** InnerClasses */
 128     public static final String NAME_INNER_CLASSES = "InnerClasses";
 129 
 130     /** LineNumberTable */
 131     public static final String NAME_LINE_NUMBER_TABLE = "LineNumberTable";
 132 
 133     /** LoadableDescriptors */
 134     public static final String NAME_LOADABLE_DESCRIPTORS = "LoadableDescriptors";
 135 
 136     /** LocalVariableTable */
 137     public static final String NAME_LOCAL_VARIABLE_TABLE = "LocalVariableTable";
 138 
 139     /** LocalVariableTypeTable */
 140     public static final String NAME_LOCAL_VARIABLE_TYPE_TABLE = "LocalVariableTypeTable";
 141 
 142     /** MethodParameters */
 143     public static final String NAME_METHOD_PARAMETERS = "MethodParameters";
 144 
 145     /** Module */
 146     public static final String NAME_MODULE = "Module";
 147 
 148     /** ModuleHashes */
 149     public static final String NAME_MODULE_HASHES = "ModuleHashes";
 150 
 151     /** ModuleMainClass */
 152     public static final String NAME_MODULE_MAIN_CLASS = "ModuleMainClass";
 153 
 154     /** ModulePackages */
 155     public static final String NAME_MODULE_PACKAGES = "ModulePackages";

 707 
 708     /** Attribute mapper for the {@code PermittedSubclasses} attribute */
 709     public static final AttributeMapper<PermittedSubclassesAttribute>
 710             PERMITTED_SUBCLASSES = new AbstractAttributeMapper<>(NAME_PERMITTED_SUBCLASSES) {
 711                 @Override
 712                 public PermittedSubclassesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
 713                     return new BoundAttribute.BoundPermittedSubclassesAttribute(cf, this, p);
 714                 }
 715 
 716                 @Override
 717                 protected void writeBody(BufWriter buf, PermittedSubclassesAttribute attr) {
 718                     buf.writeListIndices(attr.permittedSubclasses());
 719                 }
 720 
 721                 @Override
 722                 public AttributeMapper.AttributeStability stability() {
 723                     return AttributeStability.CP_REFS;
 724                 }
 725             };
 726 
 727     /** Attribute mapper for the {@code LoadableDescriptors} attribute */
 728     public static final AttributeMapper<LoadableDescriptorsAttribute>
 729             LOADABLE_DESCRIPTORS = new AbstractAttributeMapper<>(NAME_LOADABLE_DESCRIPTORS) {
 730                 @Override
 731                 public LoadableDescriptorsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
 732                     return new BoundAttribute.BoundLoadableDescriptorsAttribute(cf, this, p);
 733                 }
 734 
 735                 @Override
 736                 protected void writeBody(BufWriter buf, LoadableDescriptorsAttribute attr) {
 737                     buf.writeListIndices(attr.loadableDescriptors());
 738                 }
 739 
 740                 @Override
 741                 public AttributeMapper.AttributeStability stability() {
 742                     return AttributeStability.CP_REFS;
 743                 }
 744             };
 745 
 746     /** Attribute mapper for the {@code Record} attribute */
 747     public static final AttributeMapper<RecordAttribute>
 748             RECORD = new AbstractAttributeMapper<>(NAME_RECORD) {
 749                 @Override
 750                 public RecordAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
 751                     return new BoundAttribute.BoundRecordAttribute(cf, this, p);
 752                 }
 753 
 754                 @Override
 755                 protected void writeBody(BufWriter buf, RecordAttribute attr) {
 756                     List<RecordComponentInfo> components = attr.components();
 757                     buf.writeU2(components.size());
 758                     for (RecordComponentInfo info : components) {
 759                         buf.writeIndex(info.name());
 760                         buf.writeIndex(info.descriptor());
 761                         buf.writeList(info.attributes());
 762                     }
 763                 }
 764 
 765                 @Override

1010      */
1011     public static AttributeMapper<?> standardAttribute(Utf8Entry name) {
1012         return _ATTR_MAP.get(name);
1013     }
1014 
1015     /**
1016      * All standard attribute mappers.
1017      */
1018     public static final Set<AttributeMapper<?>> PREDEFINED_ATTRIBUTES = Set.of(
1019             ANNOTATION_DEFAULT,
1020             BOOTSTRAP_METHODS,
1021             CHARACTER_RANGE_TABLE,
1022             CODE,
1023             COMPILATION_ID,
1024             CONSTANT_VALUE,
1025             DEPRECATED,
1026             ENCLOSING_METHOD,
1027             EXCEPTIONS,
1028             INNER_CLASSES,
1029             LINE_NUMBER_TABLE,
1030             LOADABLE_DESCRIPTORS,
1031             LOCAL_VARIABLE_TABLE,
1032             LOCAL_VARIABLE_TYPE_TABLE,
1033             METHOD_PARAMETERS,
1034             MODULE,
1035             MODULE_HASHES,
1036             MODULE_MAIN_CLASS,
1037             MODULE_PACKAGES,
1038             MODULE_RESOLUTION,
1039             MODULE_TARGET,
1040             NEST_HOST,
1041             NEST_MEMBERS,
1042             PERMITTED_SUBCLASSES,
1043             RECORD,
1044             RUNTIME_INVISIBLE_ANNOTATIONS,
1045             RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS,
1046             RUNTIME_INVISIBLE_TYPE_ANNOTATIONS,
1047             RUNTIME_VISIBLE_ANNOTATIONS,
1048             RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS,
1049             RUNTIME_VISIBLE_TYPE_ANNOTATIONS,
1050             SIGNATURE,
< prev index next >