本文整理汇总了Java中org.objectweb.asm.tree.InsnList.toArray方法的典型用法代码示例。如果您正苦于以下问题:Java InsnList.toArray方法的具体用法?Java InsnList.toArray怎么用?Java InsnList.toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.objectweb.asm.tree.InsnList
的用法示例。
在下文中一共展示了InsnList.toArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNode
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
protected AbstractInsnNode getNode(InsnList nodes, Predicate<AbstractInsnNode> validator) {
for (AbstractInsnNode node : nodes.toArray()) {
if (validator.test(node)) {
return node;
}
}
return null;
}
示例2: getNodeLast
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
protected AbstractInsnNode getNodeLast(InsnList nodes, Predicate<AbstractInsnNode> validator) {
AbstractInsnNode last = null;
for (AbstractInsnNode node : nodes.toArray()) {
if (validator.test(node)) {
last = node;
}
}
return last;
}
示例3: ListContains
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
public static boolean ListContains(InsnList il, String s) {
for (AbstractInsnNode ain : il.toArray())
if (InstructionContains(ain, s))
return true;
return false;
}
示例4: fixMethodBody
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
/**
* Rewrites the method bytecode to remove the "Stub!" exception.
*/
private void fixMethodBody(MethodNode methodNode, ClassNode classNode) {
if ((methodNode.access & Opcodes.ACC_NATIVE) != 0
|| (methodNode.access & Opcodes.ACC_ABSTRACT) != 0) {
// Abstract and native method don't have bodies to rewrite.
return;
}
if ((classNode.access & Opcodes.ACC_ENUM) != 0 && ENUM_METHODS.contains(methodNode.name)) {
// Don't break enum classes.
return;
}
Type returnType = Type.getReturnType(methodNode.desc);
InsnList instructions = methodNode.instructions;
List localVariables = methodNode.localVariables;
List tryCatchBlocks = methodNode.tryCatchBlocks;
if (localVariables != null && !localVariables.isEmpty()) {
localVariables.clear();
}
if (tryCatchBlocks != null && !tryCatchBlocks.isEmpty()) {
tryCatchBlocks.clear();
}
if (methodNode.name.equals(CONSTRUCTOR)) {
// Keep the call to parent constructor, delete the exception after that.
boolean deadCode = false;
for (AbstractInsnNode instruction : instructions.toArray()) {
if (!deadCode) {
if (instruction.getOpcode() == Opcodes.INVOKESPECIAL) {
instructions.insert(instruction, new InsnNode(Opcodes.RETURN));
// Start removing all following instructions.
deadCode = true;
}
} else {
instructions.remove(instruction);
}
}
} else {
instructions.clear();
if (returnDefaultValues || methodNode.name.equals(CLASS_CONSTRUCTOR)) {
if (INTEGER_LIKE_TYPES.contains(returnType)) {
instructions.add(new InsnNode(Opcodes.ICONST_0));
} else if (returnType.equals(Type.LONG_TYPE)) {
instructions.add(new InsnNode(Opcodes.LCONST_0));
} else if (returnType.equals(Type.FLOAT_TYPE)) {
instructions.add(new InsnNode(Opcodes.FCONST_0));
} else if (returnType.equals(Type.DOUBLE_TYPE)) {
instructions.add(new InsnNode(Opcodes.DCONST_0));
} else {
instructions.add(new InsnNode(Opcodes.ACONST_NULL));
}
instructions.add(new InsnNode(returnType.getOpcode(Opcodes.IRETURN)));
} else {
instructions.insert(throwExceptionsList(methodNode, classNode));
}
}
}
示例5: fixMethodBody
import org.objectweb.asm.tree.InsnList; //导入方法依赖的package包/类
/**
* Rewrites the method bytecode to remove the "Stub!" exception.
*/
private void fixMethodBody(MethodNode methodNode, ClassNode classNode) {
if ((methodNode.access & Opcodes.ACC_NATIVE) != 0
|| (methodNode.access & Opcodes.ACC_ABSTRACT) != 0) {
// Abstract and native method don't have bodies to rewrite.
return;
}
if ((classNode.access & Opcodes.ACC_ENUM) != 0 && ENUM_METHODS.contains(methodNode.name)) {
// Don't break enum classes.
return;
}
Type returnType = Type.getReturnType(methodNode.desc);
InsnList instructions = methodNode.instructions;
if (methodNode.name.equals(CONSTRUCTOR)) {
// Keep the call to parent constructor, delete the exception after that.
boolean deadCode = false;
for (AbstractInsnNode instruction : instructions.toArray()) {
if (!deadCode) {
if (instruction.getOpcode() == Opcodes.INVOKESPECIAL) {
instructions.insert(instruction, new InsnNode(Opcodes.RETURN));
// Start removing all following instructions.
deadCode = true;
}
} else {
instructions.remove(instruction);
}
}
} else {
instructions.clear();
if (returnDefaultValues || methodNode.name.equals(CLASS_CONSTRUCTOR)) {
if (INTEGER_LIKE_TYPES.contains(returnType)) {
instructions.add(new InsnNode(Opcodes.ICONST_0));
} else if (returnType.equals(Type.LONG_TYPE)) {
instructions.add(new InsnNode(Opcodes.LCONST_0));
} else if (returnType.equals(Type.FLOAT_TYPE)) {
instructions.add(new InsnNode(Opcodes.FCONST_0));
} else if (returnType.equals(Type.DOUBLE_TYPE)) {
instructions.add(new InsnNode(Opcodes.DCONST_0));
} else {
instructions.add(new InsnNode(Opcodes.ACONST_NULL));
}
instructions.add(new InsnNode(returnType.getOpcode(Opcodes.IRETURN)));
} else {
instructions.insert(throwExceptionsList(methodNode, classNode));
}
}
}