From 5d8b492b2c284a96c9055a8d89bfac5bec7d09d5 Mon Sep 17 00:00:00 2001 From: adam Date: Sun, 3 Jul 2005 04:52:36 +0000 Subject: [PATCH] more accessor methods for ClassFile and Type.Class darcs-hash:20050703045236-5007d-8b01f78c5f32dfad00b6a4306b84eaefdbbb5d4a.gz --- src/org/ibex/classgen/ClassFile.java | 22 +++++++++++++++++----- src/org/ibex/classgen/Type.java | 19 ++++++++++++++++++- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/org/ibex/classgen/ClassFile.java b/src/org/ibex/classgen/ClassFile.java index 70c447b..036f923 100644 --- a/src/org/ibex/classgen/ClassFile.java +++ b/src/org/ibex/classgen/ClassFile.java @@ -6,13 +6,25 @@ import java.io.*; /** Class generation object representing the whole classfile */ public class ClassFile extends Type.Class.Body { private final Type.Class thisType; - private final Type.Class superType; - private final Type.Class[] interfaces; + final Type.Class superType; + final Type.Class[] interfaces; private final short minor; private final short major; private final Vector fields = new Vector(); - public final Vector methods = new Vector(); + private final Vector methods = new Vector(); + + public Type.Class.Method.Body[] methods() { + Type.Class.Method.Body[] ret = new Type.Class.Method.Body[methods.size()]; + methods.copyInto(ret); + return ret; + } + + public Type.Class.Field.Body[] fields() { + Type.Class.Field.Body[] ret = new Type.Class.Field.Body[fields.size()]; + fields.copyInto(ret); + return ret; + } static String flagsToString(int flags, boolean isClass) { StringBuffer sb = new StringBuffer(32); @@ -96,8 +108,8 @@ public class ClassFile extends Type.Class.Body { @see FieldGen @see CGConst */ - public final FieldGen addField(String name, Type type, int flags) { - FieldGen fg = new FieldGen(getType().field(name, type), flags); + public final Type.Class.Field.Body addField(Type.Class.Field field, int flags) { + FieldGen fg = new FieldGen(field, flags); fields.addElement(fg); return fg; } diff --git a/src/org/ibex/classgen/Type.java b/src/org/ibex/classgen/Type.java index 6e20f67..44e6476 100644 --- a/src/org/ibex/classgen/Type.java +++ b/src/org/ibex/classgen/Type.java @@ -97,9 +97,22 @@ public abstract class Type implements CGConst { public boolean isClass() { return true; } public static Type.Class instance(String className) { return (Type.Class)Type.fromDescriptor("L"+className.replace('.', '/')+";"); } - //public boolean extendsOrImplements(Type.Class c, Context cx) { } + public boolean extendsOrImplements(Type.Class c, Context cx) { + if (this==c) return true; + if (this==OBJECT) return false; + ClassFile cf = cx.resolve(getName()); + if (cf==null) { + System.err.println("warning: could not resolve class " + getName()); + return false; + } + if (cf.superType == c) return true; + for(int i=0; i