@@ -54,10 +54,6 @@ public class Util {
5454 private Util () {
5555 }
5656
57- public static String arrayOf (CharSequence s ) {
58- return "[" + s ;
59- }
60-
6157 public static int parameterSlots (MethodTypeDesc mDesc ) {
6258 int count = 0 ;
6359 for (int i = 0 ; i < mDesc .parameterCount (); i ++) {
@@ -85,70 +81,19 @@ public static int maxLocals(int flags, MethodTypeDesc mDesc) {
8581 }
8682
8783 /**
88- * Convert a descriptor of classes or interfaces or arrays, or an internal
89- * name of a class or interface, into a fully qualified binary name, that can
90- * be resolved by {@link Class#forName(String) Class::forName}. Primitive type
91- * descriptors should never be passed into this method.
92- *
93- * @param descOrInternalName a descriptor or internal name
94- * @return the fully qualified binary name
84+ * Converts a descriptor of classes or interfaces into
85+ * a binary name. Rejects primitive types or arrays.
86+ * This is an inverse of {@link ClassDesc#of(String)}.
9587 */
96- public static String toBinaryName (String descOrInternalName ) {
97- if (descOrInternalName .startsWith ("L" )) {
98- // descriptors of classes or interfaces
99- if (descOrInternalName .length () <= 2 || !descOrInternalName .endsWith (";" )) {
100- throw new IllegalArgumentException (descOrInternalName );
101- }
102- return descOrInternalName .substring (1 , descOrInternalName .length () - 1 ).replace ('/' , '.' );
103- } else {
104- // arrays, classes or interfaces' internal names
105- return descOrInternalName .replace ('/' , '.' );
106- }
107- }
108-
109- public static Iterator <String > parameterTypes (String s ) {
110- //TODO: gracefully non-method types
111- return new Iterator <>() {
112- int ch = 1 ;
113-
114- @ Override
115- public boolean hasNext () {
116- return s .charAt (ch ) != ')' ;
117- }
118-
119- @ Override
120- public String next () {
121- char curr = s .charAt (ch );
122- switch (curr ) {
123- case 'C' , 'B' , 'S' , 'I' , 'J' , 'F' , 'D' , 'Z' :
124- ch ++;
125- return String .valueOf (curr );
126- case '[' :
127- ch ++;
128- return "[" + next ();
129- case 'L' : {
130- int start = ch ;
131- while (s .charAt (++ch ) != ';' ) { }
132- ++ch ;
133- return s .substring (start , ch );
134- }
135- default :
136- throw new AssertionError ("cannot parse string: " + s );
137- }
138- }
139- };
140- }
141-
142- public static String returnDescriptor (String s ) {
143- return s .substring (s .indexOf (')' ) + 1 );
88+ public static String toBinaryName (ClassDesc cd ) {
89+ return toInternalName (cd ).replace ('/' , '.' );
14490 }
14591
14692 public static String toInternalName (ClassDesc cd ) {
14793 var desc = cd .descriptorString ();
148- return switch (desc .charAt (0 )) {
149- case 'L' -> desc .substring (1 , desc .length () - 1 );
150- default -> throw new IllegalArgumentException (desc );
151- };
94+ if (desc .charAt (0 ) == 'L' )
95+ return desc .substring (1 , desc .length () - 1 );
96+ throw new IllegalArgumentException (desc );
15297 }
15398
15499 public static ClassDesc toClassDesc (String classInternalNameOrArrayDesc ) {
0 commit comments