diff options
author | shifujun <shifujun@foxmail.com> | 2019-02-01 17:26:07 +0800 |
---|---|---|
committer | shifujun <shifujun@foxmail.com> | 2019-02-01 17:33:00 +0800 |
commit | c85bc4f090044d657419f82b5fc33434ab911c62 (patch) | |
tree | 0ab0bd3ecc8d9370abb62f4ea13df00fb8e19bf9 /src/main/javassist/convert | |
parent | 6ea8021f1517ee2923bd5d50dc466594ac7f68bf (diff) | |
download | javassist-c85bc4f090044d657419f82b5fc33434ab911c62.tar.gz javassist-c85bc4f090044d657419f82b5fc33434ab911c62.zip |
add a new CodeConverter method:redirectMethodCallToStatic
Diffstat (limited to 'src/main/javassist/convert')
-rw-r--r-- | src/main/javassist/convert/TransformCallToStatic.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/main/javassist/convert/TransformCallToStatic.java b/src/main/javassist/convert/TransformCallToStatic.java new file mode 100644 index 00000000..87181edf --- /dev/null +++ b/src/main/javassist/convert/TransformCallToStatic.java @@ -0,0 +1,29 @@ +package javassist.convert; + +import javassist.CtMethod; +import javassist.bytecode.BadBytecode; +import javassist.bytecode.CodeIterator; +import javassist.bytecode.ConstPool; +import javassist.bytecode.Descriptor; +import javassist.bytecode.Opcode; + +public class TransformCallToStatic extends TransformCall { + public TransformCallToStatic(Transformer next, CtMethod origMethod, CtMethod substMethod) { + super(next, origMethod, substMethod); + methodDescriptor = origMethod.getMethodInfo2().getDescriptor(); + } + + @Override + protected int match(int c, int pos, CodeIterator iterator, int typedesc, ConstPool cp) { + if (newIndex == 0) { + String desc = Descriptor.insertParameter(classname, methodDescriptor); + int nt = cp.addNameAndTypeInfo(newMethodname, desc); + int ci = cp.addClassInfo(newClassname); + newIndex = cp.addMethodrefInfo(ci, nt); + constPool = cp; + } + iterator.writeByte(Opcode.INVOKESTATIC, pos); + iterator.write16bit(newIndex, pos + 1); + return pos; + } +} |