[jboss-cvs] javassist/src/main/javassist ...
Shigeru Chiba
chiba at is.titech.ac.jp
Thu Aug 31 23:04:43 EDT 2006
User: chiba
Date: 06/08/31 23:04:43
Modified: src/main/javassist CtConstructor.java
Log:
updated CtConstructor#isEmpty().
Revision Changes Path
1.17 +19 -8 javassist/src/main/javassist/CtConstructor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CtConstructor.java
===================================================================
RCS file: /cvsroot/jboss/javassist/src/main/javassist/CtConstructor.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- CtConstructor.java 30 Aug 2006 16:25:25 -0000 1.16
+++ CtConstructor.java 1 Sep 2006 03:04:43 -0000 1.17
@@ -129,7 +129,11 @@
}
/**
- * Returns true if the constructor is the default one.
+ * Returns true if the constructor (or static initializer)
+ * is the default one. This method returns true if the constructor
+ * takes some arguments but it does not perform anything except
+ * calling <code>super()</code> (the no-argument constructor of
+ * the super class).
*/
public boolean isEmpty() {
CodeAttribute ca = getMethodInfo2().getCodeAttribute();
@@ -141,18 +145,25 @@
CodeIterator it = ca.iterator();
try {
int pos, desc;
- return it.byteAt(it.next()) == Opcode.ALOAD_0
+ int op0 = it.byteAt(it.next());
+ return op0 == Opcode.RETURN // empty static initializer
+ || (op0 == Opcode.ALOAD_0
&& it.byteAt(pos = it.next()) == Opcode.INVOKESPECIAL
- && (desc = cp.isConstructor(CtClass.javaLangObject,
+ && (desc = cp.isConstructor(getSuperclassName(),
it.u16bitAt(pos + 1))) != 0
- && cp.getUtf8Info(desc).equals("()V")
+ && "()V".equals(cp.getUtf8Info(desc))
&& it.byteAt(it.next()) == Opcode.RETURN
- && !it.hasNext();
+ && !it.hasNext());
}
catch (BadBytecode e) {}
return false;
}
+ private String getSuperclassName() {
+ ClassFile cf = declaringClass.getClassFile2();
+ return cf.getSuperclass();
+ }
+
/**
* Returns true if this constructor calls a constructor
* of the super class. This method returns false if it
More information about the jboss-cvs-commits
mailing list