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