1 package org.ibex.classgen;
3 import java.util.StringTokenizer;
6 public static final Type VOID = new Type("V");
7 public static final Type INT = new Type("I");
8 public static final Type STRING = new Type.Object("java.lang.String");
9 public static final Type[] NO_ARGS = new Type[0];
14 Type(String descriptor) { this.descriptor = descriptor; }
16 public final String getDescriptor() { return descriptor; }
17 public int hashCode() { return descriptor.hashCode(); }
18 public boolean equals(Object o) { return o instanceof Type && ((Type)o).descriptor.equals(descriptor); }
20 public static Type arrayType(Type base) { return arrayType(base,1); }
21 public static Type arrayType(Type base, int dim) {
22 StringBuffer sb = new StringBuffer(base.descriptor.length() + dim);
23 for(int i=0;i<dim;i++) sb.append("[");
24 sb.append(base.descriptor);
25 return new Type(sb.toString());
28 public static class Object extends Type {
29 public Object(String s) {
30 if(!s.startsWith("L") || !s.endsWith(";")) s = "L" + s.replace('.','/') + ";";
31 if(!validDescriptorString(s)) throw new IllegalArgumentException("invalid descriptor string");
35 public String[] components() {
36 StringTokenizer st = new StringTokenizer(descriptor.substring(1,descriptor.length()-1),"/");
37 String[] a = new String[st.countTokens()];
38 for(int i=0;st.hasMoreTokens();i++) a[i] = st.nextToken();
42 public String internalForm() { return descriptor.substring(1,descriptor.length()-1); }
44 // FEATURE: Do a proper check here (invalid chars, etc)
45 public boolean validDescriptorString(String s) {
46 return s.startsWith("L") && s.endsWith(";");