@Override public void convertCode(DexMethodNode methodNode, MethodVisitor mv) { MethodVisitor mw = AsmBridge.searchMethodWriter(mv); MethodNode mn = new MethodNode(Opcodes.ASM5, methodNode.access, methodNode.method.getName(), methodNode.method.getDesc(), null, null); try { super.convertCode(methodNode, mn); } catch (Exception ex) { if (exceptionHandler == null) { throw new DexException(ex, "fail convert code for %s", methodNode.method); } else { mn.instructions.clear(); mn.tryCatchBlocks.clear(); exceptionHandler.handleMethodTranslateException(methodNode.method, methodNode, mn, ex); } } // code convert ok, copy to MethodWriter and check for Size mn.accept(mv); if (mw != null) { try { AsmBridge.sizeOfMethodWriter(mw); } catch (Exception ex) { mn.instructions.clear(); mn.tryCatchBlocks.clear(); exceptionHandler.handleMethodTranslateException(methodNode.method, methodNode, mn, ex); AsmBridge.replaceMethodWriter(mw, mn); } } } }
method.instructions.clear();
public CodeBlock clear() { instructionList.clear(); tryCatchBlockList.clear(); localVariableList.clear(); annotations.clear(); arity = 0; returns = false; return this; } }
@Override public void apply(MethodPatcher.PatchData patch, MethodNode methodNode, AbstractInsnNode location, Method method) { methodNode.instructions.clear(); methodNode.instructions.add(method.insnList); } },
@Override void transform(Iterator<MethodNode> methods) { boolean done = false; while (methods.hasNext()) { MethodNode m = methods.next(); if (isEmptyMethod.equals(m.name)) { m.instructions.clear(); m.visitInsn(Opcodes.ICONST_0); m.visitInsn(Opcodes.IRETURN); done = true; break; } } if (!done) { mainLogger.info("Transforming failed."); } } });
@Override public void process(@Nonnull final ParserClassNode classNode, @Nonnull final RuleMethod method) throws Exception { Objects.requireNonNull(classNode, "classNode"); Objects.requireNonNull(method, "method"); // replace all method code with a simple call to the super method final String parentDesc = classNode.getParentType().getInternalName(); final InsnList argumentLoaders = createArgumentLoaders(method.desc); final CodeBlock block = CodeBlock.newCodeBlock() .aload(0) .addAll(argumentLoaders) // TODO: create .invokeSpecial with MethodNode argument? .invokespecial(parentDesc, method.name, method.desc) .areturn(); method.instructions.clear(); method.instructions.add(block.getInstructionList()); } }
m.instructions.clear(); m.localVariables.clear(); m.tryCatchBlocks.clear();
@Override void transform(Iterator<MethodNode> methods) { boolean done = false; while (methods.hasNext()) { MethodNode m = methods.next(); if (containerFurnaceMethod.equals(m.name)) { m.instructions.clear(); m.instructions.add(new VarInsnNode(ALOAD, 0)); m.instructions.add(new VarInsnNode(ALOAD, 1)); m.instructions.add(new VarInsnNode(ILOAD, 2)); m.instructions.add(new MethodInsnNode(INVOKESTATIC, "com/enderio/core/common/transform/EnderCoreMethods", "transferStackInSlot", containerFurnaceMethodSig, false)); m.instructions.add(new InsnNode(Opcodes.ARETURN)); done = true; break; } } if (!done) { mainLogger.info("Transforming failed."); } } });
public void process(ParserClassNode classNode, RuleMethod method) throws Exception { checkArgNotNull(classNode, "classNode"); checkArgNotNull(method, "method"); // replace all method code with a simple call to the super method method.instructions.clear(); method.instructions.add(new VarInsnNode(ALOAD, 0)); method.instructions.add(createArgumentLoaders(method.desc)); method.instructions.add(new MethodInsnNode(INVOKESPECIAL, classNode.getParentType().getInternalName(), method.name, method.desc, classNode.isInterface())); method.instructions.add(new InsnNode(ARETURN)); }
private void instrumentConstructor(MethodNode method) { makeMethodPrivate(method); if (containsStubs) { method.instructions.clear(); RobolectricGeneratorAdapter generator = new RobolectricGeneratorAdapter(method); generator.loadThis(); generator.visitMethodInsn(INVOKESPECIAL, classNode.superName, "<init>", "()V"); generator.returnValue(); generator.endMethod(); } InsnList removedInstructions = extractCallToSuperConstructor(method); method.name = new ShadowImpl().directMethodName(ShadowConstants.CONSTRUCTOR_METHOD_NAME); classNode.methods.add(redirectorMethod(method, ShadowConstants.CONSTRUCTOR_METHOD_NAME)); String[] exceptions = exceptionArray(method); MethodNode methodNode = new MethodNode(method.access, "<init>", method.desc, method.signature, exceptions); makeMethodPublic(methodNode); RobolectricGeneratorAdapter generator = new RobolectricGeneratorAdapter(methodNode); methodNode.instructions = removedInstructions; generator.loadThis(); generator.invokeVirtual(classType, new Method(ROBO_INIT_METHOD_NAME, "()V")); generateShadowCall(method, ShadowConstants.CONSTRUCTOR_METHOD_NAME, generator); generator.endMethod(); classNode.methods.add(methodNode); }
instructions.clear();
instructions.clear();