[jboss-cvs] javassist/src/main/javassist/convert ...

Shigeru Chiba chiba at is.titech.ac.jp
Thu Jul 19 06:21:26 EDT 2007


  User: chiba   
  Date: 07/07/19 06:21:26

  Modified:    src/main/javassist/convert  TransformCall.java
  Log:
  modified redirectMethodCall() in CodeConverter
  
  Revision  Changes    Path
  1.11      +36 -5     javassist/src/main/javassist/convert/TransformCall.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TransformCall.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/convert/TransformCall.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- TransformCall.java	4 Jun 2007 03:11:11 -0000	1.10
  +++ TransformCall.java	19 Jul 2007 10:21:26 -0000	1.11
  @@ -17,7 +17,9 @@
   
   import javassist.CtClass;
   import javassist.CtMethod;
  +import javassist.ClassPool;
   import javassist.Modifier;
  +import javassist.NotFoundException;
   import javassist.bytecode.*;
   
   public class TransformCall extends Transformer {
  @@ -55,7 +57,10 @@
   
       /**
        * Modify INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC and INVOKEVIRTUAL
  -     * so that a different method is invoked.
  +     * so that a different method is invoked.  The class name in the operand
  +     * of these instructions might be a subclass of the target class specified
  +     * by <code>classname</code>.   This method transforms the instruction
  +     * in that case unless the subclass overrides the target method.
        */
       public int transform(CtClass clazz, int pos, CodeIterator iterator,
                            ConstPool cp) throws BadBytecode
  @@ -64,15 +69,41 @@
           if (c == INVOKEINTERFACE || c == INVOKESPECIAL
                           || c == INVOKESTATIC || c == INVOKEVIRTUAL) {
               int index = iterator.u16bitAt(pos + 1);
  -            int typedesc = cp.isMember(classname, methodname, index);
  -            if (typedesc != 0)
  -                if (cp.getUtf8Info(typedesc).equals(methodDescriptor))
  -                    pos = match(c, pos, iterator, typedesc, cp);
  +            String cname = cp.eqMember(methodname, methodDescriptor, index);
  +            if (cname != null && matchClass(cname, clazz.getClassPool())) {
  +                int ntinfo = cp.getMemberNameAndType(index);
  +                pos = match(c, pos, iterator,
  +                            cp.getNameAndTypeDescriptor(ntinfo), cp);
  +            }
           }
   
           return pos;
       }
   
  +    private boolean matchClass(String name, ClassPool pool) {
  +        if (classname.equals(name))
  +            return true;
  +
  +        try {
  +            CtClass clazz = pool.get(name);
  +            CtClass declClazz = pool.get(classname);
  +            if (clazz.subtypeOf(declClazz))
  +                try {
  +                    CtMethod m = clazz.getMethod(methodname, methodDescriptor);
  +                    return m.getDeclaringClass().getName().equals(classname);
  +                }
  +                catch (NotFoundException e) {
  +                    // maybe the original method has been removed.
  +                    return true;
  +                }
  +        }
  +        catch (NotFoundException e) {
  +            return false;
  +        }
  +
  +        return false;
  +    }
  +
       protected int match(int c, int pos, CodeIterator iterator,
                           int typedesc, ConstPool cp) throws BadBytecode
       {
  
  
  



More information about the jboss-cvs-commits mailing list