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