Browse Source

changed the behavior of CtClassType.setSuperclass().


git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@35 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
tags/rel_3_17_1_ga
chiba 21 years ago
parent
commit
fe122bdfe2
2 changed files with 16 additions and 34 deletions
  1. 2
    0
      Readme.html
  2. 14
    34
      src/main/javassist/bytecode/ClassFile.java

+ 2
- 0
Readme.html View File

@@ -239,6 +239,8 @@ see javassist.Dump.
<p>- version 2.6 in August, 2003.

<ul>
<li>The behavior of CtClass.setSuperclass() was changed.
To obtain the previous behavior, call CtClass.replaceClassName().
<li>CtConstructor.setBody() now works for class initializers.
<li>CtNewMethod.delegator() now works for static methods.
<li>javassist.expr.Expr.indexOfBytecode() has been added.

+ 14
- 34
src/main/javassist/bytecode/ClassFile.java View File

@@ -171,46 +171,26 @@ public final class ClassFile {
/**
* Sets the super class.
*
* <p>Unless the old super class is
* <code>java.lang.Object</code>, this method substitutes the new name
* for all occurrences of the old class name in the class file.
* If the old super class is <code>java.lang.Object</code>,
* only the calls to a super constructor are modified.
* <p>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);
}
}


Loading…
Cancel
Save