From fe122bdfe25febcb190a9e91a07eb3c3268d1e75 Mon Sep 17 00:00:00 2001 From: chiba Date: Fri, 22 Aug 2003 17:25:14 +0000 Subject: changed the behavior of CtClassType.setSuperclass(). git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@35 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- src/main/javassist/bytecode/ClassFile.java | 48 +++++++++--------------------- 1 file changed, 14 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/main/javassist/bytecode/ClassFile.java b/src/main/javassist/bytecode/ClassFile.java index 3fc6fdb6..c1b99257 100644 --- a/src/main/javassist/bytecode/ClassFile.java +++ b/src/main/javassist/bytecode/ClassFile.java @@ -171,46 +171,26 @@ public final class ClassFile { /** * Sets the super class. * - *

Unless the old super class is - * java.lang.Object, this method substitutes the new name - * for all occurrences of the old class name in the class file. - * If the old super class is java.lang.Object, - * only the calls to a super constructor are modified. + *

This method modifies constructors so that they call + * constructors declared in the new super class. */ public void setSuperclass(String superclass) throws CannotCompileException { - if (constPool.getClassInfo(superClass).equals("java.lang.Object")) { - if (superclass != null) - try { - superClass = constPool.addClassInfo(superclass); - setSuperclass2(superclass); - } - catch (BadBytecode e) { - throw new CannotCompileException(e); - } - } - else { - if (superclass == null) - superclass = "java.lang.Object"; + if (superclass == null) + superclass = "java.lang.Object"; - renameClass(constPool.getClassInfo(superClass), superclass); + try { + superClass = constPool.addClassInfo(superclass); + LinkedList list = methods; + int n = list.size(); + for (int i = 0; i < n; ++i) { + MethodInfo minfo = (MethodInfo)list.get(i); + minfo.setSuperclass(superclass); + } } - } - - /* If the original super class is java.lang.Object, a special - * treatment is needed. Some occurrences of java.lang.Object - * in the class file should not be changed into the new super - * class name. For example, the call of Vector.addElement(Object) - * should not be changed into the call of Vector.addElement(X), - * where X is the new super class. - */ - private void setSuperclass2(String superclass) throws BadBytecode { - LinkedList list = methods; - int n = list.size(); - for (int i = 0; i < n; ++i) { - MethodInfo minfo = (MethodInfo)list.get(i); - minfo.setSuperclass(superclass); + catch (BadBytecode e) { + throw new CannotCompileException(e); } } -- cgit v1.2.3