Example usage for org.objectweb.asm.util Textifier getText

List of usage examples for org.objectweb.asm.util Textifier getText

Introduction

In this page you can find the example usage for org.objectweb.asm.util Textifier getText.

Prototype

public List<Object> getText() 

Source Link

Document

Returns the text constructed by this visitor.

Usage

From source file:com.android.build.gradle.internal.incremental.ByteCodeUtils.java

License:Apache License

/**
 * Converts the given method to a String.
 *///from  w  ww.j  av a2  s . co  m
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:jaspex.speculation.newspec.FlowFrame.java

License:Open Source License

static void printCode(MethodNode mn, List<? extends Frame<?>> frames, Collection<FlowFrame> highlight,
        FlowFrame specialHighlight) {/*  w w  w . j a v a 2 s.c om*/
    if (!Log.isTraceEnabled())
        return;

    Textifier textifier = new Textifier();
    TraceMethodVisitor tmv = new TraceMethodVisitor(textifier);
    mn.accept(tmv);

    highlight = highlight != null ? highlight : new ArrayList<FlowFrame>();

    List<String> instructions = listGenericCast(textifier.getText());
    InsnList il = mn.instructions;

    int offset = mn.tryCatchBlocks.size();
    for (int i = 0; i < instructions.size(); i++) {
        int pos = i - offset;
        Frame<?> f = pos >= 0 && pos < frames.size() ? frames.get(pos) : null;
        String insn = pos < il.size() && pos >= 0
                ? il.get(pos).toString().replace("org.objectweb.asm.tree.", "")
                : null;
        String highlightColor = specialHighlight != null && specialHighlight.equals(f) ? "45"
                : highlight.contains(f) ? "41" : "32";
        Log.trace(pos + instructions.get(i).replace("\n", "") + " "
                + (f != null ? color(f.toString(), highlightColor) : "") + " (" + insn + ")");
    }
}