List of usage examples for org.objectweb.asm.util TraceMethodVisitor TraceMethodVisitor
public TraceMethodVisitor(final Printer printer)
From source file:com.android.build.gradle.internal.incremental.ByteCodeUtils.java
License:Apache License
/** * Converts the given method to a String. */// w ww. j ava2s .c om public static String textify(@NonNull MethodNode method) { Textifier textifier = new Textifier(); TraceMethodVisitor trace = new TraceMethodVisitor(textifier); method.accept(trace); String ret = ""; for (Object line : textifier.getText()) { ret += line; } return ret; }
From source file:com.github.fge.grappa.transform.AsmTestUtils.java
License:Apache License
public static String getMethodInstructionList(MethodNode methodNode) { Preconditions.checkNotNull(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);/*from w w w . j a va 2s . c om*/ printWriter.flush(); String[] lines = PATTERN.split(stringWriter.toString()); 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" + NEWLINE.join(lines) + '\n'; }
From source file:com.github.fge.grappa.transform.AsmTestUtils.java
License:Apache License
public static void assertTraceDumpEquality(MethodNode method, String traceDump) throws Exception { Preconditions.checkNotNull(method, "method"); Printer printer = new NonMaxTextifier(); TraceMethodVisitor traceMethodVisitor = new TraceMethodVisitor(printer); // MethodAdapter checkMethodAdapter = new MethodAdapter(traceMethodVisitor); MethodVisitor checkMethodAdapter = new CheckMethodAdapter(traceMethodVisitor); method.accept(checkMethodAdapter);/*www. ja v a 2 s . c o m*/ StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); printer.print(printWriter); printWriter.flush(); assertEquals(stringWriter.toString(), traceDump); }
From source file:com.google.template.soy.jbcsrc.BytecodeProducer.java
License:Apache License
/** * Returns a human readable string for the code that this {@link BytecodeProducer} generates. */// w w w.j a v a 2 s .c o m final String trace() { // TODO(lukes): textifier has support for custom label names by overriding appendLabel. // Consider trying to make use of (using the Label.info field? adding a custom NamedLabel // sub type?) Textifier textifier = new Textifier(Opcodes.ASM5) { { // reset tab sizes. Since we don't care about formatting class names or method signatures // (only code). We only need to set the tab2,tab3 and ltab settings (tab is for class // members). this.tab = null; // trigger an error if used. this.tab2 = " "; // tab setting for instructions this.tab3 = ""; // tab setting for switch cases this.ltab = ""; // tab setting for labels } }; gen(new CodeBuilder(new TraceMethodVisitor(textifier), 0, "trace", "()V")); StringWriter writer = new StringWriter(); textifier.print(new PrintWriter(writer)); return writer.toString(); // Note textifier always adds a trailing newline }
From source file:com.google.template.soy.jbcsrc.restricted.BytecodeProducer.java
License:Apache License
/** Returns a human readable string for the code that this {@link BytecodeProducer} generates. */ public final String trace() { // TODO(lukes): textifier has support for custom label names by overriding appendLabel. // Consider trying to make use of (using the Label.info field? adding a custom NamedLabel // sub type?) Textifier textifier = new Textifier(Opcodes.ASM6) { {//from w w w. j av a2 s . com // reset tab sizes. Since we don't care about formatting class names or method // signatures (only code). We only need to set the tab2,tab3 and ltab settings (tab is // for class members). this.tab = null; // trigger an error if used. this.tab2 = " "; // tab setting for instructions this.tab3 = ""; // tab setting for switch cases this.ltab = ""; // tab setting for labels } }; gen(new CodeBuilder(new TraceMethodVisitor(textifier), 0, "trace", "()V")); StringWriter writer = new StringWriter(); textifier.print(new PrintWriter(writer)); return writer.toString(); // Note textifier always adds a trailing newline }
From source file:com.googlecode.dex2jar.test.TestUtils.java
License:Apache License
static void printAnalyzerResult(MethodNode method, Analyzer a, final PrintWriter pw) throws IllegalArgumentException, IllegalAccessException { Frame[] frames = a.getFrames(); Textifier t = new Textifier(); TraceMethodVisitor mv = new TraceMethodVisitor(t); String format = "%05d %-" + (method.maxStack + method.maxLocals + 6) + "s|%s"; for (int j = 0; j < method.instructions.size(); ++j) { method.instructions.get(j).accept(mv); StringBuffer s = new StringBuffer(); Frame f = frames[j];//w w w . j a v a 2 s.co m if (f == null) { s.append('?'); } else { for (int k = 0; k < f.getLocals(); ++k) { s.append(getShortName(f.getLocal(k).toString())); } s.append(" : "); for (int k = 0; k < f.getStackSize(); ++k) { s.append(getShortName(f.getStack(k).toString())); } } pw.printf(format, j, s, buf.get(t)); // mv.text.get(j)); } for (int j = 0; j < method.tryCatchBlocks.size(); ++j) { ((TryCatchBlockNode) method.tryCatchBlocks.get(j)).accept(mv); pw.print(" " + buf.get(t)); } pw.println(); pw.flush(); }
From source file:com.googlecode.dex2jar.tools.AsmVerify.java
License:Apache License
static void printAnalyzerResult(MethodNode method, Analyzer a, final PrintWriter pw) throws IllegalArgumentException { Frame[] frames = a.getFrames(); Textifier t = new Textifier(); TraceMethodVisitor mv = new TraceMethodVisitor(t); String format = "%05d %-" + (method.maxStack + method.maxLocals + 6) + "s|%s"; for (int j = 0; j < method.instructions.size(); ++j) { method.instructions.get(j).accept(mv); StringBuffer s = new StringBuffer(); Frame f = frames[j];/*from ww w .j a va 2 s .c o m*/ if (f == null) { s.append('?'); } else { for (int k = 0; k < f.getLocals(); ++k) { s.append(getShortName(f.getLocal(k).toString())); } s.append(" : "); for (int k = 0; k < f.getStackSize(); ++k) { s.append(getShortName(f.getStack(k).toString())); } } try { pw.printf(format, j, s, buf.get(t)); // mv.text.get(j)); } catch (IllegalAccessException e) { e.printStackTrace(); } } for (TryCatchBlockNode tryCatchBlockNode : method.tryCatchBlocks) { tryCatchBlockNode.accept(mv); try { pw.print(" " + buf.get(t)); } catch (IllegalAccessException e) { e.printStackTrace(); } } pw.println(); pw.flush(); }
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);/*from w ww . j a v a 2s.co 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);/*from w ww . j a va2 s . c om*/ StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); printer.print(printWriter); printWriter.flush(); assertEquals(stringWriter.toString(), traceDump); }
From source file:com.sun.fortress.compiler.codegen.ManglingClassWriter.java
License:Open Source License
/** * Does not mangle name/desc/sig; takes them as provided. * /* www .j ava 2s . c om*/ * @param access * @param name * @param desc * @param signature * @param exceptions * @return */ public ManglingMethodVisitor visitNoMangleMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); return new ManglingMethodVisitor(TRACE_METHODS ? new TraceMethodVisitor(mv) : mv, access, name, desc); }