Skip to content

Commit 612ae73

Browse files
committed
8342465: Improve API documentation for java.lang.classfile
Reviewed-by: asotona Backport-of: 1d8ccb8
1 parent a315b93 commit 612ae73

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2929
-1013
lines changed

src/java.base/share/classes/java/lang/classfile/AccessFlags.java

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,37 +30,70 @@
3030
import jdk.internal.classfile.impl.AccessFlagsImpl;
3131

3232
/**
33-
* Models the access flags for a class, method, or field. Delivered as a
34-
* {@link ClassElement}, {@link FieldElement}, or {@link MethodElement}
35-
* when traversing the corresponding model type.
33+
* Models the access flags for a class, method, or field. The access flags
34+
* appears exactly once in each class, method, or field; a {@link
35+
* ClassBuilder} and a {@link FieldBuilder} chooses an unspecified default value
36+
* if access flags are not provided, and a {@link MethodBuilder} is always
37+
* created with access flags.
38+
* <p>
39+
* {@code AccessFlags} cannot be created via a factory method directly; it can
40+
* be created with {@code withFlags} methods on the respective builders.
41+
* <p>
42+
* A {@link MethodBuilder} throws an {@link IllegalArgumentException} if it is
43+
* supplied an {@code AccessFlags} object that changes the preexisting
44+
* {@link ClassFile#ACC_STATIC ACC_STATIC} flag of the builder, because the
45+
* access flag change may invalidate previously supplied data to the builder.
3646
*
47+
* @apiNote
48+
* The access flags of classes, methods, and fields are modeled as a standalone
49+
* object to support streaming as elements for {@link ClassFileTransform}.
50+
* Other access flags are not elements of a {@link CompoundElement} and thus not
51+
* modeled by {@code AccessFlags}; they provide their own {@code flagsMask},
52+
* {@code flags}, and {@code has} methods.
53+
*
54+
* @see ClassModel#flags()
55+
* @see FieldModel#flags()
56+
* @see MethodModel#flags()
57+
* @see ClassBuilder#withFlags
58+
* @see FieldBuilder#withFlags
59+
* @see MethodBuilder#withFlags
3760
* @since 24
3861
*/
3962
public sealed interface AccessFlags
4063
extends ClassElement, MethodElement, FieldElement
4164
permits AccessFlagsImpl {
4265

4366
/**
44-
* {@return the access flags, as a bit mask}
67+
* {@return the access flags, as a bit mask} It is in the range of unsigned
68+
* short, {@code [0, 0xFFFF]}.
4569
*/
4670
int flagsMask();
4771

4872
/**
49-
* {@return the access flags}
73+
* {@return the access flags, as a set of flag enums}
74+
*
75+
* @throws IllegalArgumentException if the flags mask has any undefined bit set
76+
* @see #location()
5077
*/
5178
Set<AccessFlag> flags();
5279

5380
/**
54-
* {@return whether the specified flag is present} The specified flag
55-
* should be a valid flag for the classfile location associated with this
56-
* element otherwise false is returned.
81+
* {@return whether the specified flag is set} If the specified flag
82+
* is not available to this {@linkplain #location() location}, returns
83+
* {@code false}.
84+
*
5785
* @param flag the flag to test
86+
* @see #location()
5887
*/
5988
boolean has(AccessFlag flag);
6089

6190
/**
62-
* {@return the classfile location for this element, which is either class,
63-
* method, or field}
91+
* {@return the {@code class} file location for this element, which is
92+
* either class, method, or field}
93+
*
94+
* @see AccessFlag.Location#CLASS
95+
* @see AccessFlag.Location#FIELD
96+
* @see AccessFlag.Location#METHOD
6497
*/
6598
AccessFlag.Location location();
6699
}

src/java.base/share/classes/java/lang/classfile/AnnotationValue.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public sealed interface AnnotationValue {
5454

5555
/**
5656
* Models an annotation value of an element-value pair.
57-
* The {@linkplain #tag tag} of this value is {@value TAG_ANNOTATION}.
57+
* The {@linkplain #tag tag} of this value is {@value %c TAG_ANNOTATION}.
5858
*
5959
* @since 24
6060
*/
@@ -66,7 +66,7 @@ sealed interface OfAnnotation extends AnnotationValue
6666

6767
/**
6868
* Models an array value of an element-value pair.
69-
* The {@linkplain #tag tag} of this value is {@value TAG_ARRAY}.
69+
* The {@linkplain #tag tag} of this value is {@value %c TAG_ARRAY}.
7070
*
7171
* @since 24
7272
*/
@@ -122,7 +122,7 @@ sealed interface OfConstant extends AnnotationValue {
122122

123123
/**
124124
* Models a string value of an element-value pair.
125-
* The {@linkplain #tag tag} of this value is {@value TAG_STRING}.
125+
* The {@linkplain #tag tag} of this value is {@value %c TAG_STRING}.
126126
*
127127
* @since 24
128128
*/
@@ -149,7 +149,7 @@ default String resolvedValue() {
149149

150150
/**
151151
* Models a double value of an element-value pair.
152-
* The {@linkplain #tag tag} of this value is {@value TAG_DOUBLE}.
152+
* The {@linkplain #tag tag} of this value is {@value %c TAG_DOUBLE}.
153153
*
154154
* @since 24
155155
*/
@@ -176,7 +176,7 @@ default Double resolvedValue() {
176176

177177
/**
178178
* Models a float value of an element-value pair.
179-
* The {@linkplain #tag tag} of this value is {@value TAG_FLOAT}.
179+
* The {@linkplain #tag tag} of this value is {@value %c TAG_FLOAT}.
180180
*
181181
* @since 24
182182
*/
@@ -203,7 +203,7 @@ default Float resolvedValue() {
203203

204204
/**
205205
* Models a long value of an element-value pair.
206-
* The {@linkplain #tag tag} of this value is {@value TAG_LONG}.
206+
* The {@linkplain #tag tag} of this value is {@value %c TAG_LONG}.
207207
*
208208
* @since 24
209209
*/
@@ -230,7 +230,7 @@ default Long resolvedValue() {
230230

231231
/**
232232
* Models an int value of an element-value pair.
233-
* The {@linkplain #tag tag} of this value is {@value TAG_INT}.
233+
* The {@linkplain #tag tag} of this value is {@value %c TAG_INT}.
234234
*
235235
* @since 24
236236
*/
@@ -257,7 +257,7 @@ default Integer resolvedValue() {
257257

258258
/**
259259
* Models a short value of an element-value pair.
260-
* The {@linkplain #tag tag} of this value is {@value TAG_SHORT}.
260+
* The {@linkplain #tag tag} of this value is {@value %c TAG_SHORT}.
261261
*
262262
* @since 24
263263
*/
@@ -287,7 +287,7 @@ default Short resolvedValue() {
287287

288288
/**
289289
* Models a char value of an element-value pair.
290-
* The {@linkplain #tag tag} of this value is {@value TAG_CHAR}.
290+
* The {@linkplain #tag tag} of this value is {@value %c TAG_CHAR}.
291291
*
292292
* @since 24
293293
*/
@@ -317,7 +317,7 @@ default Character resolvedValue() {
317317

318318
/**
319319
* Models a byte value of an element-value pair.
320-
* The {@linkplain #tag tag} of this value is {@value TAG_BYTE}.
320+
* The {@linkplain #tag tag} of this value is {@value %c TAG_BYTE}.
321321
*
322322
* @since 24
323323
*/
@@ -347,7 +347,7 @@ default Byte resolvedValue() {
347347

348348
/**
349349
* Models a boolean value of an element-value pair.
350-
* The {@linkplain #tag tag} of this value is {@value TAG_BOOLEAN}.
350+
* The {@linkplain #tag tag} of this value is {@value %c TAG_BOOLEAN}.
351351
*
352352
* @since 24
353353
*/
@@ -377,7 +377,7 @@ default Boolean resolvedValue() {
377377

378378
/**
379379
* Models a class value of an element-value pair.
380-
* The {@linkplain #tag tag} of this value is {@value TAG_CLASS}.
380+
* The {@linkplain #tag tag} of this value is {@value %c TAG_CLASS}.
381381
*
382382
* @since 24
383383
*/
@@ -394,7 +394,7 @@ default ClassDesc classSymbol() {
394394

395395
/**
396396
* Models an enum value of an element-value pair.
397-
* The {@linkplain #tag tag} of this value is {@value TAG_ENUM}.
397+
* The {@linkplain #tag tag} of this value is {@value %c TAG_ENUM}.
398398
*
399399
* @since 24
400400
*/

src/java.base/share/classes/java/lang/classfile/AttributedElement.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@
3939
* A {@link ClassFileElement} describing a {@code class} file structure that has
4040
* attributes, such as a {@code class} file, a field, a method, a {@link
4141
* CodeAttribute Code} attribute, or a record component.
42+
* <p>
43+
* Unless otherwise specified, most attributes that can be discovered in a
44+
* {@link CompoundElement} implements the corresponding {@linkplain
45+
* ClassFileElement##membership membership subinterface} of {@code
46+
* ClassFileElement}, and can be sent to a {@link ClassFileBuilder} to be
47+
* integrated into the built structure.
4248
*
49+
* @see java.lang.classfile.attribute
4350
* @jvms 4.7 Attributes
4451
* @sealedGraph
4552
* @since 24

0 commit comments

Comments
 (0)