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