mirror of
https://github.com/zaaarf/lillero.git
synced 2024-11-22 07:24:50 +01:00
feat: replaced put(), get() and call() with InsnNode extensions
This commit is contained in:
parent
65d732c079
commit
9a355f33af
3 changed files with 53 additions and 52 deletions
|
@ -86,56 +86,4 @@ public class StackTools implements Opcodes {
|
|||
method.localVariables.add(variable);
|
||||
return targetIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a node setting the given {@link FieldProxy} to the value currently
|
||||
* on top of the stack.
|
||||
* @implSpec if the field is not static, you are to load the containing
|
||||
* object onto the stack the value you want to assign.
|
||||
* @param f a {@link FieldProxy} representing the field to put.
|
||||
* @return a {@link FieldInsnNode} representing the built node.
|
||||
* @since 0.3.0
|
||||
*/
|
||||
public static FieldInsnNode put(FieldProxy f) {
|
||||
return new FieldInsnNode(
|
||||
Modifier.isStatic(f.getModifiers()) ? PUTSTATIC : PUTFIELD,
|
||||
f.getParent().replace('.', '/'),
|
||||
f.getSrgName(),
|
||||
f.getDescriptor()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a node loading the given {@link FieldProxy} onto the stack.
|
||||
* @implSpec if the field is not static, you are to load the containing
|
||||
* object onto the stack before calling this.
|
||||
* @param f a {@link FieldProxy} representing the field to load.
|
||||
* @return a {@link FieldInsnNode} representing the built node.
|
||||
* @since 0.3.0
|
||||
*/
|
||||
public static FieldInsnNode get(FieldProxy f) {
|
||||
return new FieldInsnNode(
|
||||
Modifier.isStatic(f.getModifiers()) ? GETSTATIC : GETFIELD,
|
||||
f.getParent().replace('.', '/'),
|
||||
f.getSrgName(),
|
||||
f.getDescriptor()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a node calling the given {@link MethodProxy} with the given opcode.
|
||||
* @param m a {@link MethodProxy} representing the method to call.
|
||||
* @param opcode the opcode to use to call, must be one of INVOKEDYNAMIC,
|
||||
* INVOKESPECIAL, INVOKEINTERFACE, INVOKESTATIC or INVOKEVIRTUAL.
|
||||
* @return a {@link MethodInsnNode} representing the built node.
|
||||
* @since 0.3.0
|
||||
*/
|
||||
public static MethodInsnNode call(MethodProxy m, int opcode) {
|
||||
return new MethodInsnNode(
|
||||
opcode,
|
||||
m.getParent().replace('.', '/'),
|
||||
m.getSrgName(),
|
||||
m.getDescriptor()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
26
src/main/java/ftbsc/lll/tools/nodes/FieldProxyInsnNode.java
Normal file
26
src/main/java/ftbsc/lll/tools/nodes/FieldProxyInsnNode.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
package ftbsc.lll.tools.nodes;
|
||||
|
||||
import ftbsc.lll.proxies.FieldProxy;
|
||||
import org.objectweb.asm.tree.FieldInsnNode;
|
||||
|
||||
/**
|
||||
* Overrides the {@link FieldInsnNode} to add a constructor
|
||||
* taking in a {@link FieldProxy}.
|
||||
* @since 0.3.0
|
||||
*/
|
||||
public class FieldProxyInsnNode extends FieldInsnNode {
|
||||
/**
|
||||
* Constructs a new {@link FieldInsnNode} starting
|
||||
* from a {@link FieldProxy}.
|
||||
* @param opcode the opcode, must be one of GETSTATIC, PUTSTATIC,
|
||||
* GETFIELD or PUTFIELD
|
||||
*/
|
||||
public FieldProxyInsnNode(int opcode, FieldProxy proxy) {
|
||||
super(
|
||||
opcode,
|
||||
proxy.getParent().replace('.', '/'),
|
||||
proxy.getSrgName(),
|
||||
proxy.getDescriptor()
|
||||
);
|
||||
}
|
||||
}
|
27
src/main/java/ftbsc/lll/tools/nodes/MethodProxyInsnNode.java
Normal file
27
src/main/java/ftbsc/lll/tools/nodes/MethodProxyInsnNode.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package ftbsc.lll.tools.nodes;
|
||||
|
||||
import ftbsc.lll.proxies.MethodProxy;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
|
||||
/**
|
||||
* Overrides the {@link MethodInsnNode} to add a constructor
|
||||
* taking in a {@link MethodProxy}.
|
||||
* @since 0.3.0
|
||||
*/
|
||||
public class MethodProxyInsnNode extends MethodInsnNode {
|
||||
|
||||
/**
|
||||
* Constructs a new {@link MethodInsnNode} starting
|
||||
* from a {@link MethodProxy}.
|
||||
* @param opcode the opcode, must be one of INVOKEVIRTUAL,
|
||||
* INVOKESPECIAL, INVOKESTATIC or INVOKEINTERFACE
|
||||
*/
|
||||
public MethodProxyInsnNode(MethodProxy m, int opcode) {
|
||||
super(
|
||||
opcode,
|
||||
m.getParent().replace('.', '/'),
|
||||
m.getSrgName(),
|
||||
m.getDescriptor()
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue