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