Skip to content

Commit 575712c

Browse files
committed
8342466: Improve API documentation for java.lang.classfile.attribute
1 parent f6492aa commit 575712c

File tree

68 files changed

+2446
-963
lines changed

Some content is hidden

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

68 files changed

+2446
-963
lines changed

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

Lines changed: 10 additions & 5 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
@@ -41,8 +41,9 @@
4141
* type_annotation} structure (JVMS {@jvms 4.7.20}). This model indicates the
4242
* interface of the annotation and a set of element-value pairs.
4343
* <p>
44-
* This model can reconstruct an annotation, given the location of the modeled structure
45-
* in the class file and the definition of the annotation interface.
44+
* This model can reconstruct an annotation, given the location of the modeled
45+
* structure in the {@code class} file and the definition of the annotation
46+
* interface.
4647
* <p>
4748
* Two {@code Annotation} objects should be compared using the {@link
4849
* Object#equals(Object) equals} method.
@@ -54,8 +55,8 @@
5455
* elements with default values (JLS {@jls 9.6.2}), and whether the reconstructed annotation
5556
* is a container annotation for multiple annotations (JLS {@jls 9.7.5}).
5657
*
57-
* @see AnnotationElement
58-
* @see AnnotationValue
58+
* @see java.lang.annotation.Annotation
59+
* @see java.lang.reflect.AnnotatedElement Annotations in core reflection
5960
* @see TypeAnnotation
6061
* @see RuntimeVisibleAnnotationsAttribute
6162
* @see RuntimeInvisibleAnnotationsAttribute
@@ -70,11 +71,15 @@ public sealed interface Annotation
7071
/**
7172
* {@return the constant pool entry holding the {@linkplain Class#descriptorString
7273
* descriptor string} of the annotation interface}
74+
*
75+
* @see java.lang.annotation.Annotation#annotationType()
7376
*/
7477
Utf8Entry className();
7578

7679
/**
7780
* {@return the annotation interface, as a symbolic descriptor}
81+
*
82+
* @see java.lang.annotation.Annotation#annotationType()
7883
*/
7984
default ClassDesc classSymbol() {
8085
return Util.fieldTypeSymbol(className());

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

Lines changed: 3 additions & 3 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
@@ -40,8 +40,8 @@
4040
* {@link Object#equals(Object) equals} method.
4141
*
4242
* @see Annotation
43-
* @see AnnotationValue
44-
*
43+
* @see java.lang.reflect.AnnotatedElement Annotations in core reflection
44+
* @jvms 4.7.16.1 The {@code element_value} structure
4545
* @since 24
4646
*/
4747
public sealed interface AnnotationElement

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

Lines changed: 2 additions & 1 deletion
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
@@ -45,6 +45,7 @@
4545
*
4646
* @see Annotation
4747
* @see AnnotationElement
48+
* @see java.lang.reflect.AnnotatedElement Annotations in core reflection
4849
*
4950
* @sealedGraph
5051
* @since 24

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

Lines changed: 41 additions & 10 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
@@ -31,15 +31,40 @@
3131
import jdk.internal.classfile.impl.UnboundAttribute;
3232

3333
/**
34-
* Models a classfile attribute (JVMS {@jvms 4.7}). Many, though not all, subtypes of
35-
* {@linkplain Attribute} will implement {@link ClassElement}, {@link
36-
* MethodElement}, {@link FieldElement}, or {@link CodeElement}; attributes that
37-
* are also elements will be delivered when traversing the elements of the
38-
* corresponding model type. Additionally, all attributes are accessible
39-
* directly from the corresponding model type through {@link
40-
* AttributedElement#findAttribute(AttributeMapper)}.
41-
* @param <A> the attribute type
34+
* Models an attribute (JVMS {@jvms 4.7}) in the {@code class} file format.
35+
* Attributes exist on certain {@code class} file structures modeled by {@link
36+
* AttributedElement}, which provides basic read access to the attributes.
37+
* <p>
38+
* Two special subtypes of {@code Attribute} are {@link CustomAttribute}, which
39+
* all user-defined attributes should extend from, and {@link UnknownAttribute},
40+
* representing attributes read from {@code class} file but are not recognized
41+
* by the {@link ClassFile.AttributeMapperOption}.
42+
* <p>
43+
* Many attributes implement {@link ClassElement}, {@link FieldElement}, {@link
44+
* MethodElement}, or {@link CodeElement} interfaces. They can be written to
45+
* the {@code class} file as part of those enclosing structures via {@link
46+
* ClassBuilder#with}, {@link FieldBuilder#with}, {@link MethodBuilder#with}, or
47+
* {@link CodeBuilder#with}. If an attribute does not {@linkplain
48+
* AttributeMapper#allowMultiple allow multiple instances} in one structure,
49+
* the last supplied instance appears on the built structure. These interfaces
50+
* also allow such attributes to be delivered in the traversal of corresponding
51+
* {@link CompoundElement}; the exact rules are specified in the modeling
52+
* subinterfaces.
53+
* <p>
54+
* Some attributes, like {@link BootstrapMethodsAttribute BootstrapMethods} and
55+
* {@link LocalVariableTableAttribute LocalVariableTable}, are present in
56+
* structures like {@link ClassModel} or {@link CodeModel}, but they do not
57+
* implement {@link ClassElement} or {@link CodeElement}. Such attributes are
58+
* usually modeled as an integral part to the declaring structure, specified
59+
* in the modeling subinterfaces.
4260
*
61+
* @param <A> the attribute type
62+
* @see java.lang.classfile.attribute
63+
* @see AttributeMapper
64+
* @see AttributedElement
65+
* @see CustomAttribute
66+
* @see UnknownAttribute
67+
* @jvms 4.7 Attributes
4368
* @sealedGraph
4469
* @since 24
4570
*/
@@ -62,7 +87,13 @@ public sealed interface Attribute<A extends Attribute<A>>
6287
StackMapTableAttribute, SyntheticAttribute,
6388
UnknownAttribute, BoundAttribute, UnboundAttribute, CustomAttribute {
6489
/**
65-
* {@return the name of the attribute}
90+
* {@return the name of the attribute} The {@linkplain
91+
* Utf8Entry#stringValue() string value} of the name is equivalent to the
92+
* value of {@link AttributeMapper#name() attributeMapper().name()}.
93+
* <p>
94+
* If this attribute is read from a {@code class} file, this method returns
95+
* the {@link Utf8Entry} indicating the attribute name in the {@code class}
96+
* file.
6697
*/
6798
Utf8Entry attributeName();
6899

0 commit comments

Comments
 (0)