Skip to content

Commit

Permalink
Change: Add stack checking to old Target#findInitNodeFor overload a…
Browse files Browse the repository at this point in the history
…nd un-deprecate it.

The only reason MixinExtras uses this method is to match Redirect's behaviour, so I would like it to be kept in line with that.
Additionally, there is nothing wrong with not checking the desc as long as you've definitely found the right `NEW` insn, which the injection point handles itself.
  • Loading branch information
LlamaLad7 committed May 21, 2024
1 parent 1f34ee9 commit b57bd53
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -638,22 +638,19 @@ public Iterator<AbstractInsnNode> iterator() {
*
* @param newNode NEW insn
* @return INVOKESPECIAL opcode of ctor, or null if not found
*
* @deprecated Use {@link #findInitNodeFor(TypeInsnNode, String)} instead:
* this method only matches the first matching <tt>&lt;init&gt;</tt>
* after the specified <tt>NEW</tt>, it also does not filter based on
* the descriptor passed into <tt>BeforeNew</tt>.
*/
@Deprecated
public MethodInsnNode findInitNodeFor(TypeInsnNode newNode) {
int start = this.indexOf(newNode);
int depth = 0;
for (Iterator<AbstractInsnNode> iter = this.insns.iterator(start); iter.hasNext();) {
AbstractInsnNode insn = iter.next();
if (insn instanceof MethodInsnNode && insn.getOpcode() == Opcodes.INVOKESPECIAL) {
MethodInsnNode methodNode = (MethodInsnNode)insn;
if (Constants.CTOR.equals(methodNode.name) && methodNode.owner.equals(newNode.desc)) {
if (Constants.CTOR.equals(methodNode.name) && --depth == 0 && methodNode.owner.equals(newNode.desc)) {
return methodNode;
}
} else if (insn instanceof TypeInsnNode && insn.getOpcode() == Opcodes.NEW) {
depth++;
}
}
return null;
Expand Down

0 comments on commit b57bd53

Please sign in to comment.