Search in sources :

Example 1 with TraceClassVisitor

use of org.apache.tapestry5.internal.plastic.asm.util.TraceClassVisitor in project tapestry-5 by apache.

the class PlasticInternalUtils method dissasembleBytecode.

public static String dissasembleBytecode(ClassNode classNode) {
    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);
    TraceClassVisitor visitor = new TraceClassVisitor(writer);
    classNode.accept(visitor);
    writer.close();
    return stringWriter.toString();
}
Also used : TraceClassVisitor(org.apache.tapestry5.internal.plastic.asm.util.TraceClassVisitor)

Example 2 with TraceClassVisitor

use of org.apache.tapestry5.internal.plastic.asm.util.TraceClassVisitor in project tapestry-5 by apache.

the class Printer method main.

/**
 * Prints a the given class to the given output.
 *
 * <p>Command line arguments: [-nodebug] &lt;binary class name or class file name &gt;
 *
 * @param args the command line arguments.
 * @param usage the help message to show when command line arguments are incorrect.
 * @param printer the printer to convert the class into text.
 * @param output where to print the result.
 * @param logger where to log errors.
 * @throws IOException if the class cannot be found, or if an IOException occurs.
 */
static void main(final String[] args, final String usage, final Printer printer, final PrintWriter output, final PrintWriter logger) throws IOException {
    if (args.length < 1 || args.length > 2 || ((args[0].equals("-debug") || args[0].equals("-nodebug")) && args.length != 2)) {
        logger.println(usage);
        return;
    }
    TraceClassVisitor traceClassVisitor = new TraceClassVisitor(null, printer, output);
    String className;
    int parsingOptions;
    if (args[0].equals("-nodebug")) {
        className = args[1];
        parsingOptions = ClassReader.SKIP_DEBUG;
    } else {
        className = args[0];
        parsingOptions = 0;
    }
    if (className.endsWith(".class") || className.indexOf('\\') != -1 || className.indexOf('/') != -1) {
        // Can't fix PMD warning for 1.5 compatibility.
        try (InputStream inputStream = new FileInputStream(className)) {
            // NOPMD(AvoidFileStream)
            new ClassReader(inputStream).accept(traceClassVisitor, parsingOptions);
        }
    } else {
        new ClassReader(className).accept(traceClassVisitor, parsingOptions);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ClassReader(org.apache.tapestry5.internal.plastic.asm.ClassReader) FileInputStream(java.io.FileInputStream)

Aggregations

FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ClassReader (org.apache.tapestry5.internal.plastic.asm.ClassReader)1 TraceClassVisitor (org.apache.tapestry5.internal.plastic.asm.util.TraceClassVisitor)1