X-Git-Url: http://git.megacz.com/?p=org.ibex.classgen.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fclassgen%2FType.java;h=492986dab2da4f6fd4ba70ff17098f6e27b3db30;hp=af3da6bf3c353af64dce129060b634ee7da2eb38;hb=76a1336320be6b7dbae29acd341659ed648f9487;hpb=7f720b1730277f379d055ac5bcdeb5c86ca05551 diff --git a/src/org/ibex/classgen/Type.java b/src/org/ibex/classgen/Type.java index af3da6b..492986d 100644 --- a/src/org/ibex/classgen/Type.java +++ b/src/org/ibex/classgen/Type.java @@ -3,7 +3,7 @@ package org.ibex.classgen; import java.util.StringTokenizer; import java.util.Hashtable; -public class Type { +public class Type implements CGConst { private static Hashtable instances = new Hashtable(); // this has to appear at the top of the file @@ -44,6 +44,7 @@ public class Type { public boolean equals(java.lang.Object o) { return this==o; } public Type.Array makeArray() { return (Type.Array)instance("["+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"); } public Type.Class asClass() { throw new RuntimeException("attempted to use "+this+" as a Type.Class, which it is not"); } @@ -75,6 +76,7 @@ public class Type { public Type.Array asArray() { return this; } public boolean isArray() { return true; } public int dimension() { return getDescriptor().lastIndexOf('['); } + public Type getElementType() { return Type.instance(getDescriptor().substring(0, getDescriptor().length()-1)); } } public static class Class extends Type.Ref { @@ -139,12 +141,16 @@ public class Type { o.getDescriptor().equals(getDescriptor()); } public int hashCode() { return getDeclaringClass().hashCode() ^ name.hashCode() ^ getDescriptor().hashCode(); } + public String toString() { return debugToString(); } + public abstract String debugToString(); } public class Field extends Member { public final Type type; private Field(String name, Type t) { super(name); this.type = t; } public String getDescriptor() { return name; } + public Type getType() { return type; } + public String debugToString() { return getDeclaringClass()+"."+name+"["+type+"]"; } } public class Method extends Member { @@ -152,6 +158,22 @@ public class Type { public final Type returnType; public Type getArgType(int i) { return argTypes[i]; } public int getNumArgs() { return argTypes.length; } + public Type getReturnType() { return returnType; } + public String debugToString() { + StringBuffer sb = new StringBuffer(); + if (name.equals("")) sb.append("static "); + else { + if (name.equals("")) + sb.append(Class.this.getShortName()); + else + sb.append(returnType).append(" ").append(name); + sb.append("("); + for(int i=0; i 0) { + sb.append("throws"); + for(java.util.Enumeration e = thrownExceptions.keys();e.hasMoreElements();) + sb.append(" ").append(((Type.Class)e.nextElement()).debugToString()).append(","); + sb.setLength(sb.length()-1); + sb.append(" "); + } + if ((flags & (NATIVE|ABSTRACT))==0) { + sb.append("{\n"); + debugBodyToString(sb); + sb.append(" }\n"); + } else { + sb.append(";"); + } + } + } } }