X-Git-Url: http://git.megacz.com/?p=org.ibex.classgen.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fclassgen%2FType.java;h=491cc1227a2194dee33741d1f7e929f441d684ae;hp=a8a68d8d651e0e1e1ac9ff2e06e48fbf610c7228;hb=69b2d27ebab56f1b0e4df2a3a301f4d852439e8e;hpb=4844910be8170dc35fb1b993bb2c9e7e6d7d15e6 diff --git a/src/org/ibex/classgen/Type.java b/src/org/ibex/classgen/Type.java index a8a68d8..491cc12 100644 --- a/src/org/ibex/classgen/Type.java +++ b/src/org/ibex/classgen/Type.java @@ -33,7 +33,7 @@ public class Type { public static Type instance(String d) { Type ret = (Type)instances.get(d); if (ret != null) return ret; - if (d.endsWith("[")) return new Type.Array(instance(d.substring(d.length()-1))); + if (d.startsWith("[")) return new Type.Array(instance(d.substring(1))); return new Type.Class(d); } @@ -42,7 +42,7 @@ public class Type { public int hashCode() { return descriptor.hashCode(); } public boolean equals(java.lang.Object o) { return this==o; } - public Type.Array makeArray() { return (Type.Array)instance(descriptor+"["); } + public Type.Array makeArray() { return (Type.Array)instance("["+descriptor); } public Type.Ref asRef() { throw new RuntimeException("attempted to use "+this+" as a Type.Ref, which it is not"); } public Type.Class asClass() { throw new RuntimeException("attempted to use "+this+" as a Type.Class, which it is not"); } @@ -89,13 +89,57 @@ public class Type { for(int i=0;st.hasMoreTokens();i++) a[i] = st.nextToken(); return a; } + + public Method method(String name, Type returnType, Type[] argTypes) { return new Method(name, returnType, argTypes); } + public Field field(String name, Type type) { return new Field(name, type); } + + public abstract class Member { + public final String name; + private Member(String name) { this.name = name; } + public Type.Class getDeclaringClass() { return Type.Class.this; } + public abstract String getDescriptor(); + public boolean equals(Object o_) { + if(!(o_ instanceof Member)) return false; + Member o = (Member) o_; + return o.getDeclaringClass().equals(getDeclaringClass()) && + o.name.equals(name) && + o.getDescriptor().equals(getDescriptor()); + } + public int hashCode() { return getDeclaringClass().hashCode() ^ name.hashCode() ^ getDescriptor().hashCode(); } + } + + public class Field extends Member { + /** Create a reference to field name of class c with the type t */ + public final Type type; + private Field(String name, Type t) { super(name); this.type = t; } + public String getDescriptor() { return name; } + } + + public class Method extends Member { + final Type[] argTypes; + final Type returnType; + private Method(String name, Type returnType, Type[] argTypes) { + super(name); + this.argTypes = argTypes; + this.returnType = returnType; + } + public String getDescriptor() { + StringBuffer sb = new StringBuffer(argTypes.length*4); + sb.append("("); + for(int i=0;i