Require pre-super redirector handlers to be static, closes #174, v0.6.10

This commit is contained in:
Mumfrey committed 2017-05-25 12:47:22 +01:00
1 parent 3329a3d084
commit 8a169bb7c0
7 files changed
+178 -63

No files matched your search

@@ -165,6 +165,57 @@ public final class Bytecode {
return null;
}
/**
* Find the first insn node with a matching opcode in the specified method
*
* @param method method to search
* @param opcode opcode to search for
* @return found node or null if not found
*/
public static AbstractInsnNode findInsn(MethodNode method, int opcode) {
Iterator<AbstractInsnNode> findReturnIter = method.instructions.iterator();
while (findReturnIter.hasNext()) {
AbstractInsnNode insn = findReturnIter.next();
if (insn.getOpcode() == opcode) {
return insn;
}
}
return null;
}
/**
* Find the call to <tt>super()</tt> in a constructor. This attempts to
* locate the first call to <tt>&lt;init&gt;</tt> which isn't an inline call
* to another object ctor being passed into the super invocation.
*
* @param method ctor to scan
* @param superName name of superclass
* @return Call to <tt>super()</tt> or <tt>null</tt> if not found
*/
public static MethodInsnNode findSuperInit(MethodNode method, String superName) {
if (!Constants.CTOR.equals(method.name)) {
return null;
}
int news = 0;
for (Iterator<AbstractInsnNode> iter = method.instructions.iterator(); iter.hasNext();) {
AbstractInsnNode insn = iter.next();
if (insn instanceof TypeInsnNode && insn.getOpcode() == Opcodes.NEW) {
news++;
} else if (insn instanceof MethodInsnNode && insn.getOpcode() == Opcodes.INVOKESPECIAL) {
MethodInsnNode methodNode = (MethodInsnNode)insn;
if (Constants.CTOR.equals(methodNode.name)) {
if (news > 0) {
news--;
} else if (methodNode.owner.equals(superName)) {
return methodNode;
}
}
}
}
return null;
}
/**
* Runs textifier on the specified class node and dumps the output to the
* specified output stream