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
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";
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}
|
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
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";
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}
|