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