|
1 /* |
|
2 * Copyright (c) 2017, 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. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 package jdk.experimental.bytecode; |
|
25 |
|
26 import java.util.Iterator; |
|
27 |
|
28 /** |
|
29 * Helper to create and manipulate type descriptors of T. |
|
30 * |
|
31 * @param <S> the type of symbols |
|
32 * @param <T> the type of type descriptors |
|
33 */ |
|
34 public interface TypeHelper<S, T> { |
|
35 /** |
|
36 * Return the type descriptor of an element given the type |
|
37 * descriptor of an array. |
|
38 * |
|
39 * @param t the type descriptor of the array |
|
40 * @return the element type |
|
41 */ |
|
42 T elemtype(T t); |
|
43 |
|
44 /** |
|
45 * Return the type descriptor of an array given the type descriptor |
|
46 * of an element. |
|
47 * |
|
48 * @param t the type descriptor of the element |
|
49 * @return the type descriptor of the array |
|
50 */ |
|
51 T arrayOf(T t); |
|
52 |
|
53 /** |
|
54 * Return an iterator over the type descriptors of the parameters of a |
|
55 * method. |
|
56 * |
|
57 * @param t the method type descriptor |
|
58 * @return an iterator over the type descriptors of the parameters |
|
59 */ |
|
60 Iterator<T> parameterTypes(T t); |
|
61 |
|
62 /** |
|
63 * Return the type descriptor of a {@code TypeTag}. |
|
64 * |
|
65 * @param tag the {@code TypeTag} of a primitive type |
|
66 * @return the type descriptor of the primitive type |
|
67 */ |
|
68 T fromTag(TypeTag tag); |
|
69 |
|
70 /** |
|
71 * Return the return type descriptor of a method. |
|
72 * |
|
73 * @param t the method type descriptor |
|
74 * @return the return type descriptor |
|
75 */ |
|
76 T returnType(T t); |
|
77 |
|
78 /** |
|
79 * Return the type descriptor for a symbol. |
|
80 * |
|
81 * @param s the symbol |
|
82 * @return the type descriptor |
|
83 */ |
|
84 T type(S s); |
|
85 |
|
86 /** |
|
87 * Return the symbol corresponding to a type descriptor. |
|
88 * |
|
89 * @param type the type descriptor |
|
90 * @return the symbol |
|
91 */ |
|
92 S symbol(T type); |
|
93 |
|
94 /** |
|
95 * Return the {@code TypeTag} corresponding to a type descriptor. Reference |
|
96 * types return {@code TypeTag.A}. |
|
97 * |
|
98 * @param t a type descriptor |
|
99 * @return the corresponding {@code TypeTag} |
|
100 */ |
|
101 TypeTag tag(T t); |
|
102 |
|
103 /** |
|
104 * Return the symbol corresponding to a JVM type descriptor string. |
|
105 * |
|
106 * @param s a JVM type descriptor string |
|
107 * @return the corresponding symbol |
|
108 */ |
|
109 S symbolFrom(String s); |
|
110 |
|
111 /** |
|
112 * Return the common supertype descriptor of two type descriptors. |
|
113 * |
|
114 * @param t1 a type descriptor |
|
115 * @param t2 a type descriptor |
|
116 * @return the common supertype descriptor |
|
117 */ |
|
118 T commonSupertype(T t1, T t2); |
|
119 |
|
120 /** |
|
121 * Return the type descriptor for the null type. |
|
122 * |
|
123 * @return the type descriptor for the null type |
|
124 */ |
|
125 T nullType(); |
|
126 } |