当前位置: 首页>>代码示例>>Java>>正文


Java TraceMethodVisitor类代码示例

本文整理汇总了Java中org.objectweb.asm.util.TraceMethodVisitor的典型用法代码示例。如果您正苦于以下问题:Java TraceMethodVisitor类的具体用法?Java TraceMethodVisitor怎么用?Java TraceMethodVisitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TraceMethodVisitor类属于org.objectweb.asm.util包,在下文中一共展示了TraceMethodVisitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dump

import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
private static void dump(MethodNode method) {
	Textifier textifier = new Textifier();
	method.accept(new TraceMethodVisitor(textifier));

	StringWriter writer = new StringWriter();

	try (PrintWriter pw = new PrintWriter(writer)) {
		textifier.print(pw);
	}

	System.out.println(writer.toString());
}
 
开发者ID:sfPlayer1,项目名称:Matcher,代码行数:13,代码来源:Analysis.java

示例2: visitEnd

import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
@Override
public void visitEnd() {
  try {
    accept(inner);
    super.visitEnd();
  } catch(Exception e){
    Textifier t = new Textifier();
    accept(new TraceMethodVisitor(t));
    StringBuilderWriter sw = new StringBuilderWriter();
    PrintWriter pw = new PrintWriter(sw);
    t.print(pw);
    pw.flush();
    String bytecode = sw.getBuilder().toString();
    logger.error(String.format("Failure while rendering method %s, %s, %s.  ByteCode:\n %s", name, desc, signature, bytecode), e);
    throw new RuntimeException(String.format("Failure while rendering method %s, %s, %s.  ByteCode:\n %s", name, desc, signature, bytecode), e);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:18,代码来源:ValueHolderReplacementVisitor.java

示例3: viewByteCode

import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
/**
 * 格式化输出字节码
 * @param bytecode
 */
public static void viewByteCode(byte[] bytecode) {
    ClassReader cr = new ClassReader(bytecode);
    ClassNode cn = new ClassNode();
    cr.accept(cn, 0);
    final List<MethodNode> mns = cn.methods;
    Printer printer = new Textifier();
    TraceMethodVisitor mp = new TraceMethodVisitor(printer);
    for (MethodNode mn : mns) {
        InsnList inList = mn.instructions;
        System.out.println(mn.name);
        for (int i = 0; i < inList.size(); i++) {
            inList.get(i).accept(mp);
            StringWriter sw = new StringWriter();
            printer.print(new PrintWriter(sw));
            printer.getText().clear();
            System.out.print(sw.toString());
        }
    }
}
 
开发者ID:yutian-tianpl,项目名称:byte-cobweb,代码行数:24,代码来源:Helper.java

示例4: visitEnd

import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
@Override
public void visitEnd() {
	super.visitEnd();

	if (!found && errorNoMatch) {
		StringWriter output = new StringWriter();
		PrintWriter writer = new PrintWriter(output);
		writer.append("Cannot find nodes");
		if (methods.size() > 0) {
			writer.append(" for methods ").append(methods.toString());
		}
		writer.println();

		Printer printer = new Textifier();
		TraceMethodVisitor visitor = new TraceMethodVisitor(printer);
		for (AbstractInsnNode node : nodes) {
			node.accept(visitor);
		}

		printer.print(writer);

		throw new IllegalStateException(output.toString());
	}
}
 
开发者ID:SquidDev,项目名称:Patcher,代码行数:25,代码来源:FindingVisitor.java

示例5: viewByteCode

import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
public static void viewByteCode(byte[] bytecode) {
    ClassReader cr = new ClassReader(bytecode);
    ClassNode cn = new ClassNode();
    cr.accept(cn, 0);
    final List<MethodNode> mns = cn.methods;
    Printer printer = new Textifier();
    TraceMethodVisitor mp = new TraceMethodVisitor(printer);
    for (MethodNode mn : mns) {
        InsnList inList = mn.instructions;
        System.out.println(mn.name);
        for (int i = 0; i < inList.size(); i++) {
            inList.get(i).accept(mp);
            StringWriter sw = new StringWriter();
            printer.print(new PrintWriter(sw));
            printer.getText().clear();
            System.out.print(sw.toString());
        }
    }
}
 
开发者ID:brutusin,项目名称:instrumentation,代码行数:20,代码来源:Helper.java

示例6: trace

import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
/** 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) {
        {
          // 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
}
 
开发者ID:google,项目名称:closure-templates,代码行数:23,代码来源:BytecodeProducer.java

示例7: getMethodInstructionList

import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
public static String getMethodInstructionList(final MethodNode methodNode) {
    Preconditions.checkNotNull(methodNode, "methodNode");
    final Printer printer = new NonMaxTextifier();
    final TraceMethodVisitor traceMethodVisitor = new TraceMethodVisitor(printer);
    methodNode.accept(traceMethodVisitor);
    final StringWriter stringWriter = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(stringWriter);
    printer.print(printWriter);
    printWriter.flush();
    final 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';
}
 
开发者ID:fge,项目名称:grappa,代码行数:20,代码来源:AsmTestUtils.java

示例8: setUp

import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();
    jsr = new JSRInlinerAdapter(Opcodes.ASM5, null, 0, "m", "()V", null,
            null) {
        @Override
        public void visitEnd() {
            System.err.println("started w/ method:" + name);
            Textifier t = new Textifier();
            TraceMethodVisitor mv = new TraceMethodVisitor(t);
            for (int i = 0; i < instructions.size(); ++i) {
                instructions.get(i).accept(mv);
                System.err.print(Integer.toString(i + 100000).substring(1));
                System.err.print(" : " + t.text.get(i));
            }
            super.visitEnd();
            System.err.println("finished w/ method:" + name);
        }
    };
    exp = new MethodNode(0, "m", "()V", null, null);
}
 
开发者ID:lrytz,项目名称:asm-legacy-svn-clone,代码行数:22,代码来源:JSRInlinerAdapterUnitTest.java

示例9: printMethod

import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
public static void printMethod(PrintStream out, MethodNode method) {
    final Textifier textifier = new Textifier();
    final TraceMethodVisitor mv = new TraceMethodVisitor(textifier);

    out.println(method.name + method.desc);
    for (int j = 0; j < method.instructions.size(); ++j) {
        method.instructions.get(j).accept(mv);

        final StringBuffer s = new StringBuffer();
        while (s.length() < method.maxStack + method.maxLocals + 1) {
            s.append(' ');
        }
        out.print(Integer.toString(j + 100000).substring(1));
        out.print(" " + s + " : " + textifier.text.get(j));
    }
    for (int j = 0; j < method.tryCatchBlocks.size(); ++j) {
        ((TryCatchBlockNode) method.tryCatchBlocks.get(j)).accept(mv);
        out.print(" " + textifier.text.get(method.instructions.size()+j));
    }
    out.println(" MAXSTACK " + method.maxStack);
    out.println(" MAXLOCALS " + method.maxLocals);
    out.println();
}
 
开发者ID:hammacher,项目名称:javaslicer,代码行数:24,代码来源:Transformer.java

示例10: setUp

import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();
    jsr = new JSRInlinerAdapter(null, 0, "m", "()V", null, null) {
        @Override
        public void visitEnd() {
            System.err.println("started w/ method:" + name);
            Textifier t = new Textifier();
            TraceMethodVisitor mv = new TraceMethodVisitor(t);
            for (int i = 0; i < instructions.size(); ++i) {
                instructions.get(i).accept(mv);
                System.err.print(Integer.toString(i + 100000).substring(1));
                System.err.print(" : " + t.text.get(i));
            }
            super.visitEnd();
            System.err.println("finished w/ method:" + name);
        }
    };
    exp = new MethodNode(0, "m", "()V", null, null);
}
 
开发者ID:llbit,项目名称:ow2-asm,代码行数:21,代码来源:JSRInlinerAdapterUnitTest.java

示例11: toString

import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
@Override
public String toString() {
  triggerDelayedParsingIfNeccessary();
  TraceMethodVisitor visitor = new TraceMethodVisitor(new Textifier());
  node.accept(visitor);
  StringWriter writer = new StringWriter();
  visitor.p.print(new PrintWriter(writer));
  return writer.toString();
}
 
开发者ID:inferjay,项目名称:r8,代码行数:10,代码来源:JarCode.java

示例12: traceMethod

import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
public void traceMethod(String className, final String method) {
	new ClassReader(inMemoryClassFileManager.classBytes(className)).accept(
			new ClassVisitor(Opcodes.ASM5) {
				PrintWriter pw = new PrintWriter(System.out);
				Textifier p = new Textifier();

				@Override
				public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
					if(name.equals(method)) {
						p.visitMethod(access, name, desc, signature, exceptions);
						return new TraceMethodVisitor(p);
					}
					return null;
				}

				@Override
				public void visitEnd() {
					p.visitClassEnd();
					if (pw != null) {
						p.print(pw);
						pw.flush();
					}
				}
			},
			ClassReader.SKIP_FRAMES
	);

}
 
开发者ID:jkschneider,项目名称:java-power-assert,代码行数:29,代码来源:JavaCompilerHelper.java

示例13: toString

import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
public String toString() {
    Textifier t = new Textifier();
    accept(new TraceMethodVisitor(t));
    StringWriter sw = new StringWriter();
    t.print(new PrintWriter(sw));
    return sw.toString();
}
 
开发者ID:4Space,项目名称:4Space-5,代码行数:8,代码来源:InsnListSection.java

示例14: visitMethod

import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if (method.matches(name, desc)) {
        Printer localPrinter = asmifier.visitMethod(access, name, desc, signature, exceptions);
        return new TraceMethodVisitor(null, localPrinter);
    }

    return null;
}
 
开发者ID:4Space,项目名称:4Space-5,代码行数:10,代码来源:MethodASMifier.java

示例15: toString

import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
public static String toString(MethodNode mn) {
	TraceMethodVisitor tcv = new TraceMethodVisitor(null, new Textifier());
	mn.accept(tcv);

	StringWriter sw = new StringWriter();
	PrintWriter pw = new PrintWriter(sw);
	pw.println(mn.name + " " + mn.desc);

	tcv.p.print(pw);
	pw.flush();

	return sw.toString();
}
 
开发者ID:junkdog,项目名称:constexpr-java,代码行数:14,代码来源:TestUtil.java


注:本文中的org.objectweb.asm.util.TraceMethodVisitor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。