From ced4ae1f0e2130b36cb51faf6345d5b8e036585e Mon Sep 17 00:00:00 2001 From: chiba Date: Tue, 14 Oct 2003 14:12:47 +0000 Subject: changed the behavior of CtClassType.setSuperclass(). See javadoc comments. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@54 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- src/main/javassist/CtClass.java | 22 +++++++++++++++++----- src/main/javassist/CtClassType.java | 5 ++++- src/main/javassist/bytecode/ClassFileWriter.java | 12 +++++++++++- 3 files changed, 32 insertions(+), 7 deletions(-) (limited to 'src/main/javassist') diff --git a/src/main/javassist/CtClass.java b/src/main/javassist/CtClass.java index 6304a7da..b51fcd87 100644 --- a/src/main/javassist/CtClass.java +++ b/src/main/javassist/CtClass.java @@ -35,7 +35,7 @@ public abstract class CtClass { /** * The version number of this release. */ - public static final String version = "2.7 beta 2"; + public static final String version = "2.7 beta 3"; /** * Prints the version number and the copyright notice. @@ -415,14 +415,24 @@ public abstract class CtClass { * It returns null if this object represents the * java.lang.Object class and thus it does not have * the super class. + * + *

If this object represents an interface, this method + * always returns the java.lang.Object class. + * To obtain the super interfaces + * extended by that interface, call getInterfaces(). */ public CtClass getSuperclass() throws NotFoundException { return null; } /** - * Changes a super class. The new super class must be compatible - * with the old one. + * Changes a super class unless this object represents an interface. + * The new super class must be compatible with the old one. + * + *

If this object represents an interface, this method is equivalent + * to addInterface(); it appends clazz to + * the list of the super interfaces extended by that interface. + * Note that an interface can extend multiple super interfaces. */ public void setSuperclass(CtClass clazz) throws CannotCompileException { checkModify(); @@ -430,14 +440,16 @@ public abstract class CtClass { /** * Obtains the class objects representing the interfaces implemented - * by the class. + * by the class or, if this object represents an interface, the interfaces + * extended by that interface. */ public CtClass[] getInterfaces() throws NotFoundException { return new CtClass[0]; } /** - * Sets interfaces. + * Sets implemented interfaces. If this object represents an interface, + * this method sets the interfaces extended by that interface. * * @param list a list of the CtClass objects * representing interfaces, or diff --git a/src/main/javassist/CtClassType.java b/src/main/javassist/CtClassType.java index 33d286c0..de1b2f19 100644 --- a/src/main/javassist/CtClassType.java +++ b/src/main/javassist/CtClassType.java @@ -260,7 +260,10 @@ class CtClassType extends CtClass { public void setSuperclass(CtClass clazz) throws CannotCompileException { checkModify(); - getClassFile2().setSuperclass(clazz.getName()); + if (isInterface()) + addInterface(clazz); + else + getClassFile2().setSuperclass(clazz.getName()); } public CtClass[] getInterfaces() throws NotFoundException { diff --git a/src/main/javassist/bytecode/ClassFileWriter.java b/src/main/javassist/bytecode/ClassFileWriter.java index 05d49ec8..83ced02a 100644 --- a/src/main/javassist/bytecode/ClassFileWriter.java +++ b/src/main/javassist/bytecode/ClassFileWriter.java @@ -47,8 +47,18 @@ public class ClassFileWriter { & ~AccessFlag.SYNCHRONIZED); out.println(Modifier.toString(mod) + " class " + cf.getName() + " extends " + cf.getSuperclass()); - out.println(); + String[] infs = cf.getInterfaces(); + if (infs != null && infs.length > 0) { + out.print(" implements "); + out.print(infs[0]); + for (int i = 1; i < infs.length; ++i) + out.print(", " + infs[i]); + + out.println(); + } + + out.println(); ConstPool cp = cf.getConstPool(); list = cf.getFields(); n = list.size(); -- cgit v1.2.3