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.invoke;
26
27 import java.util.List;
28
29 /**
30 * An entity that has a field or method type descriptor
31 *
32 * @jvms 4.3.2 Field Descriptors
33 * @jvms 4.3.3 Method Descriptors
34 *
35 * @since 12
36 */
37 public interface TypeDescriptor {
38 /**
39 * Return the type descriptor string for this instance, which must be either
40 * a field type descriptor (JVMS 4.3.2) or method type descriptor (JVMS 4.3.3).
41 *
42 * @return the type descriptor
43 * @jvms 4.3.2 Field Descriptors
44 * @jvms 4.3.3 Method Descriptors
45 */
46 String descriptorString();
47
48
49 /**
50 * An entity that has a field type descriptor
51 *
52 * @param <F> the class implementing {@linkplain TypeDescriptor.OfField}
53 * @jvms 4.3.2 Field Descriptors
54 * @since 12
55 */
56 interface OfField<F extends TypeDescriptor.OfField<F>> extends TypeDescriptor {
57 /**
58 * Does this field descriptor describe an array type?
59 * @return whether this field descriptor describes an array type
60 */
61 boolean isArray();
62
63 /**
64 * Does this field descriptor describe a primitive type (including void.)
65 *
66 * @return whether this field descriptor describes a primitive type
67 */
68 boolean isPrimitive();
69
70 /**
71 * If this field descriptor describes an array type, return
72 * a descriptor for its component type, otherwise return {@code null}.
73 * @return the component type, or {@code null} if this field descriptor does
74 * not describe an array type
75 */
76 F componentType();
77
78 /**
79 * Return a descriptor for the array type whose component type is described by this
80 * descriptor
81 * @return the descriptor for the array type
82 */
83 F arrayType();
84 }
85
86
87 /**
88 * An entity that has a method type descriptor
89 *
90 * @param <F> the type representing field type descriptors
91 * @param <M> the class implementing {@linkplain TypeDescriptor.OfMethod}
92 * @jvms 4.3.2 Field Descriptors
93 * @jvms 4.3.3 Method Descriptors
94 * @since 12
95 */
96 interface OfMethod<F extends TypeDescriptor.OfField<F>, M extends TypeDescriptor.OfMethod<F, M>>
97 extends TypeDescriptor {
98
99 /**
100 * Return the number of parameters in the method type
101 * @return the number of parameters
102 */
103 int parameterCount();
104
105 /**
106 * Return a field descriptor describing the requested parameter of the method type
107 * described by this descriptor
108 * @param i the index of the parameter
|
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.invoke;
26
27 import java.util.List;
28
29 /**
30 * An entity that has a type descriptor.
31 *
32 * @since 12
33 */
34 public interface TypeDescriptor {
35 /**
36 * Returns the descriptor string for this {@code TypeDescriptor} object.
37 *
38 * If this {@code TypeDescriptor} object can be described in nominal form,
39 * then this method returns a type descriptor as specified in JVMS {@jvms 4.3}.
40 * The result descriptor string can be used to produce
41 * a {@linkplain java.lang.constant.ConstantDesc nominal descriptor}.
42 *
43 * Otherwise, the result string is not a type descriptor.
44 * No {@linkplain java.lang.constant.ConstantDesc nominal descriptor}
45 * can be produced from the result string.
46 *
47 * @return the descriptor string for this {@code TypeDescriptor} object
48 * @jvms 4.3.2 Field Descriptors
49 * @jvms 4.3.3 Method Descriptors
50 */
51 String descriptorString();
52
53
54 /**
55 * An entity that has a field type descriptor.
56 * Field descriptors conforming to JVMS {@jvms 4.3.2} can be described
57 * nominally via {@link Class#describeConstable Class::describeConstable};
58 * otherwise they cannot be described nominally.
59 *
60 * @param <F> the class implementing {@linkplain TypeDescriptor.OfField}
61 * @jvms 4.3.2 Field Descriptors
62 * @since 12
63 */
64 interface OfField<F extends TypeDescriptor.OfField<F>> extends TypeDescriptor {
65 /**
66 * Does this field descriptor describe an array type?
67 * @return whether this field descriptor describes an array type
68 */
69 boolean isArray();
70
71 /**
72 * Does this field descriptor describe a primitive type (including void.)
73 *
74 * @return whether this field descriptor describes a primitive type
75 */
76 boolean isPrimitive();
77
78 /**
79 * If this field descriptor describes an array type, return
80 * a descriptor for its component type, otherwise return {@code null}.
81 * @return the component type, or {@code null} if this field descriptor does
82 * not describe an array type
83 */
84 F componentType();
85
86 /**
87 * Return a descriptor for the array type whose component type is described by this
88 * descriptor
89 * @return the descriptor for the array type
90 */
91 F arrayType();
92 }
93
94
95 /**
96 * An entity that has a method type descriptor
97 * Method descriptors conforming to JVMS {@jvms 4.3.3} can be described
98 * nominally via {@link MethodType#describeConstable MethodType::describeConstable};
99 * otherwise they cannot be described nominally.
100 *
101 * @param <F> the type representing field type descriptors
102 * @param <M> the class implementing {@linkplain TypeDescriptor.OfMethod}
103 * @jvms 4.3.2 Field Descriptors
104 * @jvms 4.3.3 Method Descriptors
105 * @since 12
106 */
107 interface OfMethod<F extends TypeDescriptor.OfField<F>, M extends TypeDescriptor.OfMethod<F, M>>
108 extends TypeDescriptor {
109
110 /**
111 * Return the number of parameters in the method type
112 * @return the number of parameters
113 */
114 int parameterCount();
115
116 /**
117 * Return a field descriptor describing the requested parameter of the method type
118 * described by this descriptor
119 * @param i the index of the parameter
|