]> source.dussan.org Git - javassist.git/commitdiff
updated CtConstructor#isEmpty().
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Fri, 1 Sep 2006 03:04:43 +0000 (03:04 +0000)
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Fri, 1 Sep 2006 03:04:43 +0000 (03:04 +0000)
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@322 30ef5769-5b8d-40dd-aea6-55b5d6557bb3

src/main/javassist/CtConstructor.java
src/main/javassist/util/proxy/ProxyFactory.java

index c60c11245fe81a2fb1a18e83c28fb3b73b50bbd8..03f390ad0b4cb6e1c137e0c1d6fcadae20fd0c11 100644 (file)
@@ -129,7 +129,11 @@ public final class CtConstructor extends CtBehavior {
     }
 
     /**
-     * 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 @@ public final class CtConstructor extends CtBehavior {
         CodeIterator it = ca.iterator();
         try {
             int pos, desc;
-            return it.byteAt(it.next()) == Opcode.ALOAD_0
-                && it.byteAt(pos = it.next()) == Opcode.INVOKESPECIAL
-                && (desc = cp.isConstructor(CtClass.javaLangObject,
-                                            it.u16bitAt(pos + 1))) != 0
-                && cp.getUtf8Info(desc).equals("()V")
-                && it.byteAt(it.next()) == Opcode.RETURN
-                && !it.hasNext();
+            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(getSuperclassName(),
+                                                it.u16bitAt(pos + 1))) != 0
+                    && "()V".equals(cp.getUtf8Info(desc))
+                    && it.byteAt(it.next()) == Opcode.RETURN
+                    && !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
index 7fe72c7746842b5756c1ae0296c71fe0cfb4262a..e3d6b65e42d201d08f6a1c613eda61bfd54fdffb 100644 (file)
@@ -192,7 +192,10 @@ public class ProxyFactory {
     }
 
     /**
-     * A provider of class loaders.  
+     * A provider of class loaders.
+     *
+     * @see #classLoaderProvider
+     * @since 3.4
      */
     public static interface ClassLoaderProvider {
         /**
@@ -212,6 +215,15 @@ public class ProxyFactory {
      * <p>The value of this field can be updated for changing the default
      * implementation.
      *
+     * <p>Example:
+     * <ul><pre>
+     * ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider() {
+     *     public ClassLoader get(ProxyFactory pf) {
+     *         return Thread.currentThread().getContextClassLoader();
+     *     }
+     * };
+     * </pre></ul>
+     *
      * @since 3.4
      */
     public static ClassLoaderProvider classLoaderProvider