replace Type.instance()
authoradam <adam@megacz.com>
Sun, 3 Jul 2005 03:13:51 +0000 (03:13 +0000)
committeradam <adam@megacz.com>
Sun, 3 Jul 2005 03:13:51 +0000 (03:13 +0000)
darcs-hash:20050703031351-5007d-2b53afa41b7615d2b4853055cb96f6512721d807.gz

src/org/ibex/classgen/ConstantPool.java
src/org/ibex/classgen/FieldGen.java
src/org/ibex/classgen/Type.java

index cd75987..4d62df7 100644 (file)
@@ -123,7 +123,7 @@ class ConstantPool implements CGConst {
             if(member.name == null) throw new Error("should never happen");
             switch(tag) {
                 case CONSTANT_FIELDREF:
-                    return klass.getTypeClass().field(member.name.s, Type.instance(member.type.s));
+                    return klass.getTypeClass().field(member.name.s, Type.fromDescriptor(member.type.s));
                 case CONSTANT_METHODREF:
                 case CONSTANT_INTERFACEMETHODREF:
                     Type.Class.Method m = klass.getTypeClass().method(member.name.s,member.type.s);
index f29e1da..1e7373d 100644 (file)
@@ -26,7 +26,7 @@ public class FieldGen implements CGConst {
         if((flags & ~VALID_FIELD_FLAGS) != 0)
             throw new ClassFile.ClassReadExn("invalid flags");        
         name = cp.getUtf8KeyByIndex(in.readShort());
-        type = Type.instance(cp.getUtf8KeyByIndex(in.readShort()));
+        type = Type.fromDescriptor(cp.getUtf8KeyByIndex(in.readShort()));
         attrs = new ClassFile.AttrGen(in,cp);
     }
 
index 14747db..405bdbb 100644 (file)
@@ -29,11 +29,14 @@ public abstract class Type implements CGConst {
     /** A zero element Type[] array (can be passed as the "args" param when a method takes no arguments */
     public static final Type[] NO_ARGS = new Type[0];
     
-    /** guarantee: there will only be one instance of Type for a given descriptor ==> equals() and == are interchangeable */
-    public static Type instance(String d) {
+    /** 
+     *  A "descriptor" is the classfile-mangled text representation of a type (see JLS section 4.3)
+     *  guarantee: there will only be one instance of Type for a given descriptor ==> equals() and == are interchangeable
+     */
+    public static Type fromDescriptor(String d) {
         Type ret = (Type)instances.get(d);
         if (ret != null) return ret;
-        if (d.startsWith("[")) return new Type.Array(instance(d.substring(1)));
+        if (d.startsWith("[")) return new Type.Array(Type.fromDescriptor(d.substring(1)));
         return new Type.Class(d);
     }
 
@@ -42,7 +45,7 @@ public abstract class Type implements CGConst {
     
     public final String  getDescriptor() { return descriptor; }
 
-    public Type.Array  makeArray() { return (Type.Array)instance("["+descriptor); }
+    public Type.Array  makeArray() { return (Type.Array)Type.fromDescriptor("["+descriptor); }
     public Type.Array  makeArray(int i) { return i==0 ? (Type.Array)this : makeArray().makeArray(i-1); }
 
     public Type.Ref    asRef()       { throw new RuntimeException("attempted to use "+this+" as a Type.Ref, which it is not"); }
@@ -85,7 +88,7 @@ public abstract class Type implements CGConst {
         public Type.Array asArray() { return this; }
         public boolean isArray() { return true; }
         public String debugToString() { return base.debugToString() + "[]"; }
-        public Type getElementType() { return Type.instance(getDescriptor().substring(0, getDescriptor().length()-1)); }
+        public Type getElementType() { return Type.fromDescriptor(getDescriptor().substring(0, getDescriptor().length()-1)); }
     }
 
     public static class Class extends Type.Ref {
@@ -93,7 +96,7 @@ public abstract class Type implements CGConst {
         public Type.Class asClass() { return this; }
         public boolean isClass() { return true; }
         public static Type.Class instance(String className) {
-            return (Type.Class)Type.instance("L"+className.replace('.', '/')+";"); }
+            return (Type.Class)Type.fromDescriptor("L"+className.replace('.', '/')+";"); }
         //public boolean extendsOrImplements(Type.Class c, Context cx) { }
         String internalForm() { return descriptor.substring(1, descriptor.length()-1); }
         public String debugToString() { return internalForm().replace('/','.'); }
@@ -138,12 +141,12 @@ public abstract class Type implements CGConst {
                     p = argsDesc.indexOf(';');
                     if(p == -1) throw new IllegalArgumentException("invalid method type descriptor");
                 }
-                argsBuf[i] = Type.instance(argsDesc.substring(0,p+1));
+                argsBuf[i] = Type.fromDescriptor(argsDesc.substring(0,p+1));
                 argsDesc = argsDesc.substring(p+1);
             }
             Type args[] = new Type[i];
             System.arraycopy(argsBuf,0,args,0,i);
-            return method(name, Type.instance(retDesc), args);
+            return method(name, Type.fromDescriptor(retDesc), args);
         }
 
         public abstract class Member {