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