1 /*
  2  * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 package java.lang.classfile;
 26 
 27 import java.lang.classfile.AttributeMapper.AttributeStability;
 28 import java.lang.classfile.attribute.*;
 29 
 30 import jdk.internal.classfile.impl.AbstractAttributeMapper.*;
 31 
 32 /**
 33  * Attribute mappers for predefined (JVMS {@jvms 4.7}) and JDK-specific
 34  * nonstandard attributes.
 35  * <p>
 36  * Unless otherwise specified, each mapper returned by methods in this class:
 37  * <ul>
 38  * <li>is predefined in the JVMS instead of JDK-specific;
 39  * <li>does not permit {@linkplain AttributeMapper#allowMultiple() multiple
 40  * attribute instances} in the same structure;
 41  * <li>the attribute has a {@linkplain AttributeMapper#stability() data
 42  * dependency} on the {@linkplain AttributeStability#CP_REFS constant pool}.
 43  * </ul>
 44  *
 45  * @see AttributeMapper
 46  * @see java.lang.classfile.attribute
 47  * @since 24
 48  */
 49 public final class Attributes {
 50 
 51     /** AnnotationDefault */
 52     public static final String NAME_ANNOTATION_DEFAULT = "AnnotationDefault";
 53 
 54     /** BootstrapMethods */
 55     public static final String NAME_BOOTSTRAP_METHODS = "BootstrapMethods";
 56 
 57     /** CharacterRangeTable */
 58     public static final String NAME_CHARACTER_RANGE_TABLE = "CharacterRangeTable";
 59 
 60     /** Code */
 61     public static final String NAME_CODE = "Code";
 62 
 63     /** CompilationID */
 64     public static final String NAME_COMPILATION_ID = "CompilationID";
 65 
 66     /** ConstantValue */
 67     public static final String NAME_CONSTANT_VALUE = "ConstantValue";
 68 
 69     /** Deprecated */
 70     public static final String NAME_DEPRECATED = "Deprecated";
 71 
 72     /** EnclosingMethod */
 73     public static final String NAME_ENCLOSING_METHOD = "EnclosingMethod";
 74 
 75     /** Exceptions */
 76     public static final String NAME_EXCEPTIONS = "Exceptions";
 77 
 78     /** InnerClasses */
 79     public static final String NAME_INNER_CLASSES = "InnerClasses";
 80 
 81     /** LineNumberTable */
 82     public static final String NAME_LINE_NUMBER_TABLE = "LineNumberTable";
 83 
 84     /** LoadableDescriptors */
 85     public static final String NAME_LOADABLE_DESCRIPTORS = "LoadableDescriptors";
 86 
 87     /** LocalVariableTable */
 88     public static final String NAME_LOCAL_VARIABLE_TABLE = "LocalVariableTable";
 89 
 90     /** LocalVariableTypeTable */
 91     public static final String NAME_LOCAL_VARIABLE_TYPE_TABLE = "LocalVariableTypeTable";
 92 
 93     /** MethodParameters */
 94     public static final String NAME_METHOD_PARAMETERS = "MethodParameters";
 95 
 96     /** Module */
 97     public static final String NAME_MODULE = "Module";
 98 
 99     /** ModuleHashes */
100     public static final String NAME_MODULE_HASHES = "ModuleHashes";
101 
102     /** ModuleMainClass */
103     public static final String NAME_MODULE_MAIN_CLASS = "ModuleMainClass";
104 
105     /** ModulePackages */
106     public static final String NAME_MODULE_PACKAGES = "ModulePackages";
107 
108     /** ModuleResolution */
109     public static final String NAME_MODULE_RESOLUTION = "ModuleResolution";
110 
111     /** ModuleTarget */
112     public static final String NAME_MODULE_TARGET = "ModuleTarget";
113 
114     /** NestHost */
115     public static final String NAME_NEST_HOST = "NestHost";
116 
117     /** NestMembers */
118     public static final String NAME_NEST_MEMBERS = "NestMembers";
119 
120     /** PermittedSubclasses */
121     public static final String NAME_PERMITTED_SUBCLASSES = "PermittedSubclasses";
122 
123     /** Record */
124     public static final String NAME_RECORD = "Record";
125 
126     /** RuntimeInvisibleAnnotations */
127     public static final String NAME_RUNTIME_INVISIBLE_ANNOTATIONS = "RuntimeInvisibleAnnotations";
128 
129     /** RuntimeInvisibleParameterAnnotations */
130     public static final String NAME_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS = "RuntimeInvisibleParameterAnnotations";
131 
132     /** RuntimeInvisibleTypeAnnotations */
133     public static final String NAME_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS = "RuntimeInvisibleTypeAnnotations";
134 
135     /** RuntimeVisibleAnnotations */
136     public static final String NAME_RUNTIME_VISIBLE_ANNOTATIONS = "RuntimeVisibleAnnotations";
137 
138     /** RuntimeVisibleParameterAnnotations */
139     public static final String NAME_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS = "RuntimeVisibleParameterAnnotations";
140 
141     /** RuntimeVisibleTypeAnnotations */
142     public static final String NAME_RUNTIME_VISIBLE_TYPE_ANNOTATIONS = "RuntimeVisibleTypeAnnotations";
143 
144     /** Signature */
145     public static final String NAME_SIGNATURE = "Signature";
146 
147     /** SourceDebugExtension */
148     public static final String NAME_SOURCE_DEBUG_EXTENSION = "SourceDebugExtension";
149 
150     /** SourceFile */
151     public static final String NAME_SOURCE_FILE = "SourceFile";
152 
153     /** SourceID */
154     public static final String NAME_SOURCE_ID = "SourceID";
155 
156     /** StackMapTable */
157     public static final String NAME_STACK_MAP_TABLE = "StackMapTable";
158 
159     /** Synthetic */
160     public static final String NAME_SYNTHETIC = "Synthetic";
161 
162     private Attributes() {
163     }
164 
165     /**
166      * {@return the mapper for the {@code AnnotationDefault} attribute}
167      */
168     public static AttributeMapper<AnnotationDefaultAttribute> annotationDefault() {
169         return AnnotationDefaultMapper.INSTANCE;
170     }
171 
172     /**
173      * {@return the mapper for the {@code BootstrapMethods} attribute}
174      */
175     public static AttributeMapper<BootstrapMethodsAttribute> bootstrapMethods() {
176         return BootstrapMethodsMapper.INSTANCE;
177     }
178 
179     /**
180      * {@return the mapper for the {@code CharacterRangeTable} attribute}
181      * This is a JDK-specific attribute.
182      * The mapper permits multiple instances in a {@code Code} attribute, but this
183      * attribute should be only emitted once.
184      * This has a data dependency on {@linkplain AttributeStability#LABELS labels}.
185      */
186     public static AttributeMapper<CharacterRangeTableAttribute> characterRangeTable() {
187         return CharacterRangeTableMapper.INSTANCE;
188     }
189 
190     /**
191      * {@return the mapper for the {@code Code} attribute}
192      */
193     public static AttributeMapper<CodeAttribute> code() {
194         return CodeMapper.INSTANCE;
195     }
196 
197     /**
198      * {@return the mapper for the {@code CompilationID} attribute}
199      * This is a JDK-specific attribute.
200      */
201     public static AttributeMapper<CompilationIDAttribute> compilationId() {
202         return CompilationIDMapper.INSTANCE;
203     }
204 
205     /**
206      * {@return the mapper for the {@code ConstantValue} attribute}
207      */
208     public static AttributeMapper<ConstantValueAttribute> constantValue() {
209         return ConstantValueMapper.INSTANCE;
210     }
211 
212     /**
213      * {@return the mapper for the {@code Deprecated} attribute}
214      * The mapper permits multiple instances in a given location.
215      * This has {@linkplain AttributeStability#STATELESS no data dependency}.
216      */
217     public static AttributeMapper<DeprecatedAttribute> deprecated() {
218         return DeprecatedMapper.INSTANCE;
219     }
220 
221     /**
222      * {@return the mapper for the {@code EnclosingMethod} attribute}
223      */
224     public static AttributeMapper<EnclosingMethodAttribute> enclosingMethod() {
225         return EnclosingMethodMapper.INSTANCE;
226     }
227 
228     /**
229      * {@return the mapper for the {@code Exceptions} attribute}
230      */
231     public static AttributeMapper<ExceptionsAttribute> exceptions() {
232         return ExceptionsMapper.INSTANCE;
233     }
234 
235     /**
236      * {@return the mapper for the {@code InnerClasses} attribute}
237      */
238     public static AttributeMapper<InnerClassesAttribute> innerClasses() {
239         return InnerClassesMapper.INSTANCE;
240     }
241 
242     /**
243      * {@return the mapper for the {@code LineNumberTable} attribute}
244      * The mapper permits multiple instances in a {@code Code} attribute.
245      * This has a data dependency on {@linkplain AttributeStability#LABELS labels}.
246      */
247     public static AttributeMapper<LineNumberTableAttribute> lineNumberTable() {
248         return LineNumberTableMapper.INSTANCE;
249     }
250 
251     /**
252      * {@return Attribute mapper for the {@code LoadableDescriptors} attribute}
253      * @since 23
254      */
255     public static AttributeMapper<LoadableDescriptorsAttribute> loadableDescriptors() {
256         return LoadableDescriptorsMapper.INSTANCE;
257     }
258 
259     /**
260      * {@return the mapper for the {@code LocalVariableTable} attribute}
261      * The mapper permits multiple instances in a {@code Code} attribute.
262      * This has a data dependency on {@linkplain AttributeStability#LABELS labels}.
263      */
264     public static AttributeMapper<LocalVariableTableAttribute> localVariableTable() {
265         return LocalVariableTableMapper.INSTANCE;
266     }
267 
268     /**
269      * {@return the mapper for the {@code LocalVariableTypeTable} attribute}
270      * The mapper permits multiple instances in a given location.
271      * This has a data dependency on {@linkplain AttributeStability#LABELS labels}.
272      */
273     public static AttributeMapper<LocalVariableTypeTableAttribute> localVariableTypeTable() {
274         return LocalVariableTypeTableMapper.INSTANCE;
275     }
276 
277     /**
278      * {@return the mapper for the {@code MethodParameters} attribute}
279      */
280     public static AttributeMapper<MethodParametersAttribute> methodParameters() {
281         return MethodParametersMapper.INSTANCE;
282     }
283 
284     /**
285      * {@return the mapper for the {@code Module} attribute}
286      */
287     public static AttributeMapper<ModuleAttribute> module() {
288         return ModuleMapper.INSTANCE;
289     }
290 
291     /**
292      * {@return the mapper for the {@code ModuleHashes} attribute}
293      * This is a JDK-specific attribute.
294      */
295     public static AttributeMapper<ModuleHashesAttribute> moduleHashes() {
296         return ModuleHashesMapper.INSTANCE;
297     }
298 
299     /**
300      * {@return the mapper for the {@code ModuleMainClass} attribute}
301      */
302     public static AttributeMapper<ModuleMainClassAttribute> moduleMainClass() {
303         return ModuleMainClassMapper.INSTANCE;
304     }
305 
306     /**
307      * {@return the mapper for the {@code ModulePackages} attribute}
308      */
309     public static AttributeMapper<ModulePackagesAttribute> modulePackages() {
310         return ModulePackagesMapper.INSTANCE;
311     }
312 
313     /**
314      * {@return the mapper for the {@code ModuleResolution} attribute}
315      * This is a JDK-specific attribute.
316      * This has {@linkplain AttributeStability#STATELESS no data dependency}.
317      */
318     public static AttributeMapper<ModuleResolutionAttribute> moduleResolution() {
319         return ModuleResolutionMapper.INSTANCE;
320     }
321 
322     /**
323      * {@return the mapper for the {@code ModuleTarget} attribute}
324      * This is a JDK-specific attribute.
325      */
326     public static AttributeMapper<ModuleTargetAttribute> moduleTarget() {
327         return ModuleTargetMapper.INSTANCE;
328     }
329 
330     /**
331      * {@return the mapper for the {@code NestHost} attribute}
332      */
333     public static AttributeMapper<NestHostAttribute> nestHost() {
334         return NestHostMapper.INSTANCE;
335     }
336 
337     /**
338      * {@return the mapper for the {@code NestMembers} attribute}
339      */
340     public static AttributeMapper<NestMembersAttribute> nestMembers() {
341         return NestMembersMapper.INSTANCE;
342     }
343 
344     /**
345      * {@return the mapper for the {@code PermittedSubclasses} attribute}
346      */
347     public static AttributeMapper<PermittedSubclassesAttribute> permittedSubclasses() {
348         return PermittedSubclassesMapper.INSTANCE;
349     }
350 
351     /**
352      * {@return the mapper for the {@code Record} attribute}
353      */
354     public static AttributeMapper<RecordAttribute> record() {
355         return RecordMapper.INSTANCE;
356     }
357 
358     /**
359      * {@return the mapper for the {@code RuntimeInvisibleAnnotations} attribute}
360      */
361     public static AttributeMapper<RuntimeInvisibleAnnotationsAttribute> runtimeInvisibleAnnotations() {
362         return RuntimeInvisibleAnnotationsMapper.INSTANCE;
363     }
364 
365     /**
366      * {@return the mapper for the {@code RuntimeInvisibleParameterAnnotations} attribute}
367      */
368     public static AttributeMapper<RuntimeInvisibleParameterAnnotationsAttribute> runtimeInvisibleParameterAnnotations() {
369         return RuntimeInvisibleParameterAnnotationsMapper.INSTANCE;
370     }
371 
372     /**
373      * {@return the mapper for the {@code RuntimeInvisibleTypeAnnotations} attribute}
374      * This has a data dependency on {@linkplain AttributeStability#UNSTABLE
375      * arbitrary indices} in the {@code class} file format.
376      */
377     public static AttributeMapper<RuntimeInvisibleTypeAnnotationsAttribute> runtimeInvisibleTypeAnnotations() {
378         return RuntimeInvisibleTypeAnnotationsMapper.INSTANCE;
379     }
380 
381     /**
382      * {@return the mapper for the {@code RuntimeVisibleAnnotations} attribute}
383      */
384     public static AttributeMapper<RuntimeVisibleAnnotationsAttribute> runtimeVisibleAnnotations() {
385         return RuntimeVisibleAnnotationsMapper.INSTANCE;
386     }
387 
388     /**
389      * {@return the mapper for the {@code RuntimeVisibleParameterAnnotations} attribute}
390      */
391     public static AttributeMapper<RuntimeVisibleParameterAnnotationsAttribute> runtimeVisibleParameterAnnotations() {
392         return RuntimeVisibleParameterAnnotationsMapper.INSTANCE;
393     }
394 
395     /**
396      * {@return the mapper for the {@code RuntimeVisibleTypeAnnotations} attribute}
397      * This has a data dependency on {@linkplain AttributeStability#UNSTABLE
398      * arbitrary indices} in the {@code class} file format.
399      */
400     public static AttributeMapper<RuntimeVisibleTypeAnnotationsAttribute> runtimeVisibleTypeAnnotations() {
401         return RuntimeVisibleTypeAnnotationsMapper.INSTANCE;
402     }
403 
404     /**
405      * {@return the mapper for the {@code Signature} attribute}
406      */
407     public static AttributeMapper<SignatureAttribute> signature() {
408         return SignatureMapper.INSTANCE;
409     }
410 
411     /**
412      * {@return the mapper for the {@code SourceDebugExtension} attribute}
413      * This has {@linkplain AttributeStability#STATELESS no data dependency}.
414      */
415     public static AttributeMapper<SourceDebugExtensionAttribute> sourceDebugExtension() {
416         return SourceDebugExtensionMapper.INSTANCE;
417     }
418 
419     /**
420      * {@return the mapper for the {@code SourceFile} attribute}
421      */
422     public static AttributeMapper<SourceFileAttribute> sourceFile() {
423         return SourceFileMapper.INSTANCE;
424     }
425 
426     /**
427      * {@return the mapper for the {@code SourceID} attribute}
428      * This is a JDK-specific attribute.
429      */
430     public static AttributeMapper<SourceIDAttribute> sourceId() {
431         return SourceIDMapper.INSTANCE;
432     }
433 
434     /**
435      * {@return the mapper for the {@code StackMapTable} attribute}
436      * This has a data dependency on {@linkplain AttributeStability#LABELS labels}.
437      */
438     public static AttributeMapper<StackMapTableAttribute> stackMapTable() {
439         return StackMapTableMapper.INSTANCE;
440     }
441 
442     /**
443      * {@return the mapper for the {@code Synthetic} attribute}
444      * The mapper permits multiple instances in a given location.
445      * This has {@linkplain AttributeStability#STATELESS no data dependency}.
446      */
447     public static AttributeMapper<SyntheticAttribute> synthetic() {
448         return SyntheticMapper.INSTANCE;
449     }
450 }