List of usage examples for org.objectweb.asm.tree MethodNode accept
public void accept(final MethodVisitor methodVisitor)
From source file:com.googlecode.d2j.dex.ExDex2Asm.java
License:Apache License
@Override public void convertCode(DexMethodNode methodNode, MethodVisitor mv) { if (!AsmBridge.isMethodWriter(mv)) { throw new RuntimeException("We use a MethodWriter tricky here!"); }//from w w w. j a va 2 s.c o m MethodNode mn = new MethodNode(Opcodes.ASM4, 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); try { AsmBridge.sizeOfMethodWriter(mv); } catch (Exception ex) { mn.instructions.clear(); mn.tryCatchBlocks.clear(); exceptionHandler.handleMethodTranslateException(methodNode.method, methodNode, mn, ex); AsmBridge.replaceMethodWriter(mv, mn); } }
From source file:com.googlecode.ddom.weaver.mixin.MergeAdapter.java
License:Apache License
private void mergeMixinMethod(MixinInfo mixin, MethodNode mn) { String[] exceptions = new String[mn.exceptions.size()]; mn.exceptions.toArray(exceptions);//ww w.ja v a 2 s. com MethodVisitor mv = cv.visitMethod(mn.access, mn.name, mn.desc, mn.signature, exceptions); if (mv != null) { mn.instructions.resetLabels(); mv = sourceMapper.getMethodAdapter(mixin.get(SourceInfo.class), mv); mv = new RemappingMethodAdapter(mn.access, mn.desc, mv, remapper); mn.accept(mv); } }
From source file:com.lodgon.parboiled.transform.AsmTestUtils.java
License:Apache License
public static String getMethodInstructionList(MethodNode methodNode) { checkArgNotNull(methodNode, "methodNode"); Printer printer = new NonMaxTextifier(); TraceMethodVisitor traceMethodVisitor = new TraceMethodVisitor(printer); methodNode.accept(traceMethodVisitor); StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); printer.print(printWriter);/* w w w . j av a 2 s . c o m*/ printWriter.flush(); String[] lines = stringWriter.toString().split("\n"); int lineNr = 0; for (int i = 0; i < lines.length; i++) { if (!lines[i].startsWith(" @")) { lines[i] = String.format("%2d %s", lineNr++, lines[i]); } } return "Method '" + methodNode.name + "':\n" + StringUtils.join(lines, "\n") + '\n'; }
From source file:com.lodgon.parboiled.transform.AsmTestUtils.java
License:Apache License
public static void assertTraceDumpEquality(MethodNode method, String traceDump) throws Exception { checkArgNotNull(method, "method"); Printer printer = new NonMaxTextifier(); TraceMethodVisitor traceMethodVisitor = new TraceMethodVisitor(printer); // MethodAdapter checkMethodAdapter = new MethodAdapter(traceMethodVisitor); MethodVisitor checkMethodAdapter = new CheckMethodAdapter(traceMethodVisitor); method.accept(checkMethodAdapter); StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); printer.print(printWriter);//ww w . j a v a 2 s. co m printWriter.flush(); assertEquals(stringWriter.toString(), traceDump); }
From source file:com.mogujie.instantrun.IncrementalSupportVisitor.java
License:Apache License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { AcesoProguardMap.instance().putMethod(visitedClassName, IncrementalTool.getMtdSig(name, desc)); access = IncrementalTool.transformAccessForInstantRun(access); MethodVisitor defaultVisitor = super.visitMethod(access, name, desc, signature, exceptions); MethodNode method = getMethodByNameInClass(name, desc, classNode); // does the method use blacklisted APIs. boolean hasIncompatibleChange = InstantRunMethodVerifier.verifyMethod(method); if (hasIncompatibleChange || disableRedirectionForClass || !isAccessCompatibleWithInstantRun(access) || name.equals(ByteCodeUtils.CLASS_INITIALIZER)) { return defaultVisitor; } else {//from ww w . j a va 2s . c o m ArrayList<Type> args = new ArrayList<Type>(Arrays.asList(Type.getArgumentTypes(desc))); boolean isStatic = (access & Opcodes.ACC_STATIC) != 0; if (!isStatic) { args.add(0, Type.getType(Object.class)); } ISMethodVisitor mv = new ISMethodVisitor(defaultVisitor, access, name, desc); if (name.equals(ByteCodeUtils.CONSTRUCTOR)) { } else { mv.addRedirection(new MethodRedirection(new LabelNode(mv.getStartLabel()), visitedClassName, name, desc, args, Type.getReturnType(desc), isStatic)); } method.accept(mv); return null; } }
From source file:com.mogujie.instantrun.InstantRunMethodVerifier.java
License:Apache License
/** * Verifies a method implementation against the blacklisted list of APIs. *///from w w w . ja va 2 s . co m public static boolean verifyMethod(MethodNode method) { VerifierMethodVisitor mv = new VerifierMethodVisitor(method); method.accept(mv); return (mv.incompatibleChange == InstantRunVerifierStatus.INCOMPATIBLE); }
From source file:com.sun.tdk.jcov.instrument.BlockCodeMethodAdapter.java
License:Open Source License
@Override public void visitEnd() { super.visitEnd(); SimpleBasicBlock[] basicBlocks = completeComputationOfCodeLabelNodes(); computeEndBCIsAndFoldInExits(basicBlocks); //debugDump(); insertInstrumentation();/* ww w. j a v a 2 s . c om*/ method().setBasicBlocks(basicBlocks); // push the result to the writer MethodNode methodNode = (MethodNode) mv; methodNode.accept(nextVisitor); }
From source file:com.sun.tdk.jcov.instrument.BranchCodeMethodAdapter.java
License:Open Source License
@Override public void visitEnd() { super.visitEnd(); BasicBlock[] basicBlocks = completeComputationOfCodeLabelNodes(); computeEndBCIsAndFoldInExits(basicBlocks); //debugDump(); insertInstrumentation();/* w w w .j a v a 2s .com*/ method().setBasicBlocks(basicBlocks); // push the result to the writer MethodNode methodNode = (MethodNode) mv; methodNode.accept(nextVisitor); }
From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java
License:MIT License
/** * Runs textifier on the specified method node and dumps the output to the * specified output stream// www.java 2 s . com * * @param methodNode method to textify * @param out output stream */ public static void textify(MethodNode methodNode, OutputStream out) { TraceClassVisitor trace = new TraceClassVisitor(new PrintWriter(out)); MethodVisitor mv = trace.visitMethod(methodNode.access, methodNode.name, methodNode.desc, methodNode.signature, (String[]) methodNode.exceptions.toArray(new String[0])); methodNode.accept(mv); trace.visitEnd(); }
From source file:de.loskutov.bco.asm.CommentedASMifierClassVisitor.java
License:Open Source License
@Override public ASMifier visitMethod(int access, String name1, String desc, String signature, String[] exceptions) { if (options.fieldFilter != null || options.methodFilter != null && !options.methodFilter.equals(name1 + desc)) { return getDummyVisitor(); }/* ww w .j av a 2s .c o m*/ MethodNode meth = null; List<String> exList = Arrays.asList(exceptions); for (MethodNode mn : classNode.methods) { if (mn.name.equals(name1) && mn.desc.equals(desc) && mn.exceptions.equals(exList)) { meth = mn; break; } } assert meth != null; currMethod = new DecompiledMethod(className, new HashMap<Label, Integer>(), meth, options, access); ASMifier textifier = super.visitMethod(access, name1, desc, signature, exceptions); TraceMethodVisitor tm = new TraceMethodVisitor(textifier); meth.accept(tm); Object methodEnd = text.remove(text.size() - 1); Object methodtext = text.remove(text.size() - 1); currMethod.setText((List) methodtext); text.add(currMethod); text.add(methodEnd); return textifier; }