class Utility {
/** Parse Java type such as "char", or "java.lang.String[]" and return the
* signature in byte code format, e.g. "C" or "[Ljava/lang/String;" respectively.
*
* @param type Java type
* @return byte code signature
*/
public static String getSignature( String type ) {
StringBuilder buf = new StringBuilder();
char[] chars = type.toCharArray();
boolean char_found = false;
boolean delim = false;
int index = -1;
loop: for (int i = 0; i < chars.length; i++) {
switch (chars[i]) {
case ' ':
case '\t':
case '\n':
case '\r':
case '\f':
if (char_found) {
delim = true;
}
break;
case '[':
if (!char_found) {
throw new RuntimeException("Illegal type: " + type);
}
index = i;
break loop;
default:
char_found = true;
if (!delim) {
buf.append(chars[i]);
}
}
}
int brackets = 0;
if (index > 0) {
brackets = countBrackets(type.substring(index));
}
type = buf.toString();
buf.setLength(0);
for (int i = 0; i < brackets; i++) {
buf.append('[');
}
boolean found = false;
for (int i = Const.T_BOOLEAN; (i <= Const.T_VOID) && !found; i++) {
if (Const.getTypeName(i).equals(type)) {
found = true;
buf.append(Const.getShortTypeName(i));
}
}
if (!found) {
buf.append('L').append(type.replace('.', '/')).append(';');
}
return buf.toString();
}
}