|
1 | 1 | /*
|
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
30 | 30 | import jdk.internal.classfile.impl.AbstractPoolEntry;
|
31 | 31 |
|
32 | 32 | /**
|
33 |
| - * Models a {@code CONSTANT_Class_info} constant in the constant pool of a |
34 |
| - * classfile. |
35 |
| - * @jvms 4.4.1 The CONSTANT_Class_info Structure |
| 33 | + * Models a {@code CONSTANT_Class_info} structure, representing a reference |
| 34 | + * type, in the constant pool of a {@code class} file. |
| 35 | + * <p> |
| 36 | + * The use of a {@code ClassEntry} is modeled by a {@link ClassDesc} that is not |
| 37 | + * primitive. Conversions are through {@link ConstantPoolBuilder#classEntry( |
| 38 | + * ClassDesc)} and {@link #asSymbol()}. |
| 39 | + * <p> |
| 40 | + * A {@code ClassEntry} is composite: |
| 41 | + * {@snippet lang=text : |
| 42 | + * // @link substring="ClassEntry" target="ConstantPoolBuilder#classEntry(Utf8Entry)" : |
| 43 | + * ClassEntry(Utf8Entry name) // @link substring="name" target="#name" |
| 44 | + * } |
| 45 | + * where {@code name} represents: |
| 46 | + * <ul> |
| 47 | + * <li>The internal form of a binary name (JVMS {@jvms 4.2.1}), if and only if |
| 48 | + * this {@code ClassEntry} represents a class or interface, such as {@code |
| 49 | + * java/lang/String} for the {@link String} class. |
| 50 | + * <li>A field descriptor string (JVMS {@jvms 4.3.2}) representing an array type, |
| 51 | + * if and only if this {@code ClassEntry} represents an array type, such as |
| 52 | + * {@code [I} for the {@code int[]} type, or {@code [Ljava/lang/String;} for the |
| 53 | + * {@code String[]} type. |
| 54 | + * </ul> |
| 55 | + * A field descriptor string for an array type can be distinguished by its |
| 56 | + * leading {@code '['} character. |
36 | 57 | *
|
| 58 | + * @apiNote |
| 59 | + * The internal form of a binary name, where all occurrences of {@code .} in the |
| 60 | + * name are replaced by {@code /}, is informally known as an <dfn>{@index |
| 61 | + * "internal name"}</dfn>. This concept also applies to package names in |
| 62 | + * addition to class and interface names. |
| 63 | + * |
| 64 | + * @see ConstantPoolBuilder#classEntry ConstantPoolBuilder::classEntry |
| 65 | + * @see ClassDesc |
| 66 | + * @jvms 4.4.1 The {@code CONSTANT_Class_info} Structure |
37 | 67 | * @since 24
|
38 | 68 | */
|
39 | 69 | public sealed interface ClassEntry
|
40 | 70 | extends LoadableConstantEntry
|
41 | 71 | permits AbstractPoolEntry.ClassEntryImpl {
|
42 | 72 |
|
| 73 | + /** |
| 74 | + * {@inheritDoc} |
| 75 | + * <p> |
| 76 | + * This is equivalent to {@link #asSymbol() asSymbol()}. |
| 77 | + */ |
43 | 78 | @Override
|
44 | 79 | default ConstantDesc constantValue() {
|
45 | 80 | return asSymbol();
|
46 | 81 | }
|
47 | 82 |
|
48 | 83 | /**
|
49 |
| - * {@return the UTF8 constant pool entry for the class name} |
| 84 | + * {@return the {@code Utf8Entry} referred by this structure} If the |
| 85 | + * value of the UTF8 starts with a {@code [}, this represents an array type |
| 86 | + * and the value is a descriptor string; otherwise, this represents a class |
| 87 | + * or interface and the value is the {@linkplain ##internalname internal |
| 88 | + * form} of a binary name. |
| 89 | + * |
| 90 | + * @see ConstantPoolBuilder#classEntry(Utf8Entry) |
| 91 | + * ConstantPoolBuilder::classEntry(Utf8Entry) |
50 | 92 | */
|
51 | 93 | Utf8Entry name();
|
52 | 94 |
|
53 | 95 | /**
|
54 |
| - * {@return the class name, as an internal binary name} |
| 96 | + * {@return the represented reference type, as the {@linkplain |
| 97 | + * ##internalname internal form} of a binary name or an array descriptor |
| 98 | + * string} This is a shortcut for {@link #name() name().stringValue()}. |
55 | 99 | */
|
56 | 100 | String asInternalName();
|
57 | 101 |
|
58 | 102 | /**
|
59 |
| - * {@return the class name, as a symbolic descriptor} |
| 103 | + * {@return the represented reference type, as a symbolic descriptor} The |
| 104 | + * returned descriptor is never {@linkplain ClassDesc#isPrimitive() |
| 105 | + * primitive}. |
| 106 | + * |
| 107 | + * @see ConstantPoolBuilder#classEntry(ClassDesc) |
| 108 | + * ConstantPoolBuilder::classEntry(ClassDesc) |
60 | 109 | */
|
61 | 110 | ClassDesc asSymbol();
|
62 | 111 | }
|
0 commit comments