http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d6e5f413/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceClassVisitor.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceClassVisitor.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceClassVisitor.java index ad1d0d7..ae06852 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceClassVisitor.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceClassVisitor.java @@ -1,6 +1,7 @@ /*** * ASM: a very small and fast Java bytecode manipulation framework - * Copyright (c) 2000-2007 INRIA, France Telecom + * Copyright (c) 2000-2011 INRIA, France Telecom + * Copyright (c) 2011 Google * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,134 +30,71 @@ */ package org.apache.tapestry5.internal.plastic.asm.util; -import java.io.FileInputStream; -import java.io.PrintWriter; +import org.apache.tapestry5.internal.plastic.asm.*; -import org.apache.tapestry5.internal.plastic.asm.AnnotationVisitor; -import org.apache.tapestry5.internal.plastic.asm.Attribute; -import org.apache.tapestry5.internal.plastic.asm.ClassReader; -import org.apache.tapestry5.internal.plastic.asm.ClassVisitor; -import org.apache.tapestry5.internal.plastic.asm.FieldVisitor; -import org.apache.tapestry5.internal.plastic.asm.MethodVisitor; -import org.apache.tapestry5.internal.plastic.asm.Opcodes; -import org.apache.tapestry5.internal.plastic.asm.signature.SignatureReader; +import java.io.PrintWriter; /** - * A {@link ClassVisitor} that prints a disassembled view of the classes it - * visits. This class visitor can be used alone (see the {@link #main main} - * method) to disassemble a class. It can also be used in the middle of class + * A {@link ClassVisitor} that prints the classes it visits with a + * {@link Printer}. This class visitor can be used in the middle of a class * visitor chain to trace the class that is visited at a given point in this - * chain. This may be uselful for debugging purposes. <p> The trace printed when + * chain. This may be useful for debugging purposes. <p> The trace printed when * visiting the <tt>Hello</tt> class is the following: <p> <blockquote> * - * <pre> - * // class version 49.0 (49) - * // access flags 0x21 - * public class Hello { - * - * // compiled from: Hello.java - * - * // access flags 0x1 - * public <init> ()V - * ALOAD 0 - * INVOKESPECIAL java/lang/Object <init> ()V - * RETURN - * MAXSTACK = 1 - * MAXLOCALS = 1 - * - * // access flags 0x9 - * public static main ([Ljava/lang/String;)V - * GETSTATIC java/lang/System out Ljava/io/PrintStream; - * LDC "hello" - * INVOKEVIRTUAL java/io/PrintStream println (Ljava/lang/String;)V - * RETURN - * MAXSTACK = 2 - * MAXLOCALS = 1 - * } - * </pre> + * <pre> // class version 49.0 (49) // access flags 0x21 public class Hello { + * + * // compiled from: Hello.java + * + * // access flags 0x1 public <init> ()V ALOAD 0 INVOKESPECIAL + * java/lang/Object <init> ()V RETURN MAXSTACK = 1 MAXLOCALS = 1 + * + * // access flags 0x9 public static main ([Ljava/lang/String;)V GETSTATIC + * java/lang/System out Ljava/io/PrintStream; LDC "hello" + * INVOKEVIRTUAL java/io/PrintStream println (Ljava/lang/String;)V RETURN + * MAXSTACK = 2 MAXLOCALS = 1 } </pre> * * </blockquote> where <tt>Hello</tt> is defined by: <p> <blockquote> * - * <pre> - * public class Hello { - * - * public static void main(String[] args) { - * System.out.println("hello"); - * } - * } - * </pre> + * <pre> public class Hello { + * + * public static void main(String[] args) { + * System.out.println("hello"); } } </pre> * * </blockquote> * * @author Eric Bruneton * @author Eugene Kuleshov */ -public class TraceClassVisitor extends TraceAbstractVisitor implements - ClassVisitor -{ +public final class TraceClassVisitor extends ClassVisitor { /** - * The {@link ClassVisitor} to which this visitor delegates calls. May be - * <tt>null</tt>. + * The print writer to be used to print the class. May be null. */ - protected final ClassVisitor cv; + private final PrintWriter pw; /** - * The print writer to be used to print the class. + * The object that actually converts visit events into text. */ - protected final PrintWriter pw; + public final Printer p; /** - * Prints a disassembled view of the given class to the standard output. <p> - * Usage: TraceClassVisitor [-debug] <fully qualified class name or class - * file name > - * - * @param args the command line arguments. + * Constructs a new {@link TraceClassVisitor}. * - * @throws Exception if the class cannot be found, or if an IO exception - * occurs. + * @param pw the print writer to be used to print the class. */ - public static void main(final String[] args) throws Exception { - int i = 0; - int flags = ClassReader.SKIP_DEBUG; - - boolean ok = true; - if (args.length < 1 || args.length > 2) { - ok = false; - } - if (ok && "-debug".equals(args[0])) { - i = 1; - flags = 0; - if (args.length != 2) { - ok = false; - } - } - if (!ok) { - System.err.println("Prints a disassembled view of the given class."); - System.err.println("Usage: TraceClassVisitor [-debug] " - + "<fully qualified class name or class file name>"); - return; - } - ClassReader cr; - if (args[i].endsWith(".class") || args[i].indexOf('\\') > -1 - || args[i].indexOf('/') > -1) - { - cr = new ClassReader(new FileInputStream(args[i])); - } else { - cr = new ClassReader(args[i]); - } - cr.accept(new TraceClassVisitor(new PrintWriter(System.out)), - getDefaultAttributes(), - flags); + public TraceClassVisitor(final PrintWriter pw) { + this(null, pw); } /** * Constructs a new {@link TraceClassVisitor}. * + * @param cv the {@link ClassVisitor} to which this visitor delegates calls. + * May be <tt>null</tt>. * @param pw the print writer to be used to print the class. */ - public TraceClassVisitor(final PrintWriter pw) { - this(null, pw); + public TraceClassVisitor(final ClassVisitor cv, final PrintWriter pw) { + this(cv, new Textifier(), pw); } /** @@ -164,17 +102,22 @@ public class TraceClassVisitor extends TraceAbstractVisitor implements * * @param cv the {@link ClassVisitor} to which this visitor delegates calls. * May be <tt>null</tt>. - * @param pw the print writer to be used to print the class. + * @param p the object that actually converts visit events into text. + * @param pw the print writer to be used to print the class. May be null if + * you simply want to use the result via + * {@link Printer#getText()}, instead of printing it. */ - public TraceClassVisitor(final ClassVisitor cv, final PrintWriter pw) { - this.cv = cv; + public TraceClassVisitor( + final ClassVisitor cv, + final Printer p, + final PrintWriter pw) + { + super(Opcodes.ASM4, cv); this.pw = pw; + this.p = p; } - // ------------------------------------------------------------------------ - // Implementation of the ClassVisitor interface - // ------------------------------------------------------------------------ - + @Override public void visit( final int version, final int access, @@ -183,154 +126,55 @@ public class TraceClassVisitor extends TraceAbstractVisitor implements final String superName, final String[] interfaces) { - int major = version & 0xFFFF; - int minor = version >>> 16; - buf.setLength(0); - buf.append("// class version ") - .append(major) - .append('.') - .append(minor) - .append(" (") - .append(version) - .append(")\n"); - if ((access & Opcodes.ACC_DEPRECATED) != 0) { - buf.append("// DEPRECATED\n"); - } - buf.append("// access flags 0x").append(Integer.toHexString(access).toUpperCase()).append('\n'); - - appendDescriptor(CLASS_SIGNATURE, signature); - if (signature != null) { - TraceSignatureVisitor sv = new TraceSignatureVisitor(access); - SignatureReader r = new SignatureReader(signature); - r.accept(sv); - buf.append("// declaration: ") - .append(name) - .append(sv.getDeclaration()) - .append('\n'); - } - - appendAccess(access & ~Opcodes.ACC_SUPER); - if ((access & Opcodes.ACC_ANNOTATION) != 0) { - buf.append("@interface "); - } else if ((access & Opcodes.ACC_INTERFACE) != 0) { - buf.append("interface "); - } else if ((access & Opcodes.ACC_ENUM) == 0) { - buf.append("class "); - } - appendDescriptor(INTERNAL_NAME, name); - - if (superName != null && !"java/lang/Object".equals(superName)) { - buf.append(" extends "); - appendDescriptor(INTERNAL_NAME, superName); - buf.append(' '); - } - if (interfaces != null && interfaces.length > 0) { - buf.append(" implements "); - for (int i = 0; i < interfaces.length; ++i) { - appendDescriptor(INTERNAL_NAME, interfaces[i]); - buf.append(' '); - } - } - buf.append(" {\n\n"); - - text.add(buf.toString()); - - if (cv != null) { - cv.visit(version, access, name, signature, superName, interfaces); - } + p.visit(version, access, name, signature, superName, interfaces); + super.visit(version, access, name, signature, superName, interfaces); } + @Override public void visitSource(final String file, final String debug) { - buf.setLength(0); - if (file != null) { - buf.append(tab) - .append("// compiled from: ") - .append(file) - .append('\n'); - } - if (debug != null) { - buf.append(tab) - .append("// debug info: ") - .append(debug) - .append('\n'); - } - if (buf.length() > 0) { - text.add(buf.toString()); - } - - if (cv != null) { - cv.visitSource(file, debug); - } + p.visitSource(file, debug); + super.visitSource(file, debug); } + @Override public void visitOuterClass( final String owner, final String name, final String desc) { - buf.setLength(0); - buf.append(tab).append("OUTERCLASS "); - appendDescriptor(INTERNAL_NAME, owner); - buf.append(' '); - if (name != null) { - buf.append(name).append(' '); - } - appendDescriptor(METHOD_DESCRIPTOR, desc); - buf.append('\n'); - text.add(buf.toString()); - - if (cv != null) { - cv.visitOuterClass(owner, name, desc); - } + p.visitOuterClass(owner, name, desc); + super.visitOuterClass(owner, name, desc); } + @Override public AnnotationVisitor visitAnnotation( final String desc, final boolean visible) { - text.add("\n"); - AnnotationVisitor tav = super.visitAnnotation(desc, visible); - if (cv != null) { - ((TraceAnnotationVisitor) tav).av = cv.visitAnnotation(desc, - visible); - } - return tav; + Printer p = this.p.visitClassAnnotation(desc, visible); + AnnotationVisitor av = cv == null ? null : cv.visitAnnotation(desc, + visible); + return new TraceAnnotationVisitor(av, p); } + @Override public void visitAttribute(final Attribute attr) { - text.add("\n"); + p.visitClassAttribute(attr); super.visitAttribute(attr); - - if (cv != null) { - cv.visitAttribute(attr); - } } + @Override public void visitInnerClass( final String name, final String outerName, final String innerName, final int access) { - buf.setLength(0); - buf.append(tab).append("// access flags 0x"); - buf.append(Integer.toHexString(access & ~Opcodes.ACC_SUPER).toUpperCase()).append('\n'); - buf.append(tab); - appendAccess(access); - buf.append("INNERCLASS "); - appendDescriptor(INTERNAL_NAME, name); - buf.append(' '); - appendDescriptor(INTERNAL_NAME, outerName); - buf.append(' '); - appendDescriptor(INTERNAL_NAME, innerName); - buf.append('\n'); - text.add(buf.toString()); - - if (cv != null) { - cv.visitInnerClass(name, outerName, innerName, access); - } + p.visitInnerClass(name, outerName, innerName, access); + super.visitInnerClass(name, outerName, innerName, access); } + @Override public FieldVisitor visitField( final int access, final String name, @@ -338,52 +182,20 @@ public class TraceClassVisitor extends TraceAbstractVisitor implements final String signature, final Object value) { - buf.setLength(0); - buf.append('\n'); - if ((access & Opcodes.ACC_DEPRECATED) != 0) { - buf.append(tab).append("// DEPRECATED\n"); - } - buf.append(tab).append("// access flags 0x").append(Integer.toHexString(access).toUpperCase()).append('\n'); - if (signature != null) { - buf.append(tab); - appendDescriptor(FIELD_SIGNATURE, signature); - - TraceSignatureVisitor sv = new TraceSignatureVisitor(0); - SignatureReader r = new SignatureReader(signature); - r.acceptType(sv); - buf.append(tab) - .append("// declaration: ") - .append(sv.getDeclaration()) - .append('\n'); - } - - buf.append(tab); - appendAccess(access); - - appendDescriptor(FIELD_DESCRIPTOR, desc); - buf.append(' ').append(name); - if (value != null) { - buf.append(" = "); - if (value instanceof String) { - buf.append('\"').append(value).append('\"'); - } else { - buf.append(value); - } - } - - buf.append('\n'); - text.add(buf.toString()); - - TraceFieldVisitor tav = createTraceFieldVisitor(); - text.add(tav.getText()); - - if (cv != null) { - tav.fv = cv.visitField(access, name, desc, signature, value); - } - - return tav; + Printer p = this.p.visitField(access, + name, + desc, + signature, + value); + FieldVisitor fv = cv == null ? null : cv.visitField(access, + name, + desc, + signature, + value); + return new TraceFieldVisitor(fv, p); } + @Override public MethodVisitor visitMethod( final int access, final String name, @@ -391,133 +203,26 @@ public class TraceClassVisitor extends TraceAbstractVisitor implements final String signature, final String[] exceptions) { - buf.setLength(0); - buf.append('\n'); - if ((access & Opcodes.ACC_DEPRECATED) != 0) { - buf.append(tab).append("// DEPRECATED\n"); - } - buf.append(tab).append("// access flags 0x").append(Integer.toHexString(access).toUpperCase()).append('\n'); - - if (signature != null) { - buf.append(tab); - appendDescriptor(METHOD_SIGNATURE, signature); - - TraceSignatureVisitor v = new TraceSignatureVisitor(0); - SignatureReader r = new SignatureReader(signature); - r.accept(v); - String genericDecl = v.getDeclaration(); - String genericReturn = v.getReturnType(); - String genericExceptions = v.getExceptions(); - - buf.append(tab) - .append("// declaration: ") - .append(genericReturn) - .append(' ') - .append(name) - .append(genericDecl); - if (genericExceptions != null) { - buf.append(" throws ").append(genericExceptions); - } - buf.append('\n'); - } - - buf.append(tab); - appendAccess(access); - if ((access & Opcodes.ACC_NATIVE) != 0) { - buf.append("native "); - } - if ((access & Opcodes.ACC_VARARGS) != 0) { - buf.append("varargs "); - } - if ((access & Opcodes.ACC_BRIDGE) != 0) { - buf.append("bridge "); - } - - buf.append(name); - appendDescriptor(METHOD_DESCRIPTOR, desc); - if (exceptions != null && exceptions.length > 0) { - buf.append(" throws "); - for (int i = 0; i < exceptions.length; ++i) { - appendDescriptor(INTERNAL_NAME, exceptions[i]); - buf.append(' '); - } - } - - buf.append('\n'); - text.add(buf.toString()); - - TraceMethodVisitor tcv = createTraceMethodVisitor(); - text.add(tcv.getText()); - - if (cv != null) { - tcv.mv = cv.visitMethod(access, name, desc, signature, exceptions); - } - - return tcv; + Printer p = this.p.visitMethod(access, + name, + desc, + signature, + exceptions); + MethodVisitor mv = cv == null ? null : cv.visitMethod(access, + name, + desc, + signature, + exceptions); + return new TraceMethodVisitor(mv, p); } + @Override public void visitEnd() { - text.add("}\n"); - - print(pw); - pw.flush(); - - if (cv != null) { - cv.visitEnd(); - } - } - - // ------------------------------------------------------------------------ - // Utility methods - // ------------------------------------------------------------------------ - - protected TraceFieldVisitor createTraceFieldVisitor() { - return new TraceFieldVisitor(); - } - - protected TraceMethodVisitor createTraceMethodVisitor() { - return new TraceMethodVisitor(); - } - - /** - * Appends a string representation of the given access modifiers to {@link - * #buf buf}. - * - * @param access some access modifiers. - */ - private void appendAccess(final int access) { - if ((access & Opcodes.ACC_PUBLIC) != 0) { - buf.append("public "); - } - if ((access & Opcodes.ACC_PRIVATE) != 0) { - buf.append("private "); - } - if ((access & Opcodes.ACC_PROTECTED) != 0) { - buf.append("protected "); - } - if ((access & Opcodes.ACC_FINAL) != 0) { - buf.append("final "); - } - if ((access & Opcodes.ACC_STATIC) != 0) { - buf.append("static "); - } - if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) { - buf.append("synchronized "); - } - if ((access & Opcodes.ACC_VOLATILE) != 0) { - buf.append("volatile "); - } - if ((access & Opcodes.ACC_TRANSIENT) != 0) { - buf.append("transient "); - } - if ((access & Opcodes.ACC_ABSTRACT) != 0) { - buf.append("abstract "); - } - if ((access & Opcodes.ACC_STRICT) != 0) { - buf.append("strictfp "); - } - if ((access & Opcodes.ACC_ENUM) != 0) { - buf.append("enum "); + p.visitClassEnd(); + if (pw != null) { + p.print(pw); + pw.flush(); } + super.visitEnd(); } }
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d6e5f413/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceFieldVisitor.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceFieldVisitor.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceFieldVisitor.java index a46b38e..d75b04b 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceFieldVisitor.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceFieldVisitor.java @@ -1,6 +1,7 @@ /*** * ASM: a very small and fast Java bytecode manipulation framework - * Copyright (c) 2000-2007 INRIA, France Telecom + * Copyright (c) 2000-2011 INRIA, France Telecom + * Copyright (c) 2011 Google * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,47 +33,48 @@ package org.apache.tapestry5.internal.plastic.asm.util; import org.apache.tapestry5.internal.plastic.asm.AnnotationVisitor; import org.apache.tapestry5.internal.plastic.asm.Attribute; import org.apache.tapestry5.internal.plastic.asm.FieldVisitor; +import org.apache.tapestry5.internal.plastic.asm.Opcodes; /** - * A {@link FieldVisitor} that prints a disassembled view of the fields it - * visits. + * A {@link org.apache.tapestry5.internal.plastic.asm.FieldVisitor} that prints the fields it visits with a + * {@link Printer}. * * @author Eric Bruneton */ -public class TraceFieldVisitor extends TraceAbstractVisitor implements - FieldVisitor +public final class TraceFieldVisitor extends FieldVisitor { - /** - * The {@link FieldVisitor} to which this visitor delegates calls. May be - * <tt>null</tt>. - */ - protected FieldVisitor fv; + public final Printer p; + public TraceFieldVisitor(final Printer p) { + this(null, p); + } + + public TraceFieldVisitor(final FieldVisitor fv, final Printer p) { + super(Opcodes.ASM4, fv); + this.p = p; + } + + @Override public AnnotationVisitor visitAnnotation( final String desc, final boolean visible) { - AnnotationVisitor av = super.visitAnnotation(desc, visible); - if (fv != null) { - ((TraceAnnotationVisitor) av).av = fv.visitAnnotation(desc, visible); - } - return av; + Printer p = this.p.visitFieldAnnotation(desc, visible); + AnnotationVisitor av = fv == null ? null : fv.visitAnnotation(desc, + visible); + return new TraceAnnotationVisitor(av, p); } + @Override public void visitAttribute(final Attribute attr) { + p.visitFieldAttribute(attr); super.visitAttribute(attr); - - if (fv != null) { - fv.visitAttribute(attr); - } } + @Override public void visitEnd() { + p.visitFieldEnd(); super.visitEnd(); - - if (fv != null) { - fv.visitEnd(); - } } } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d6e5f413/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceMethodVisitor.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceMethodVisitor.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceMethodVisitor.java index ee53b5f..0d7fe3f 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceMethodVisitor.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceMethodVisitor.java @@ -1,6 +1,7 @@ /*** * ASM: a very small and fast Java bytecode manipulation framework - * Copyright (c) 2000-2007 INRIA, France Telecom + * Copyright (c) 2000-2011 INRIA, France Telecom + * Copyright (c) 2011 Google * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,141 +30,73 @@ */ package org.apache.tapestry5.internal.plastic.asm.util; -import org.apache.tapestry5.internal.plastic.asm.AnnotationVisitor; -import org.apache.tapestry5.internal.plastic.asm.Attribute; -import org.apache.tapestry5.internal.plastic.asm.Label; -import org.apache.tapestry5.internal.plastic.asm.MethodVisitor; -import org.apache.tapestry5.internal.plastic.asm.Opcodes; -import org.apache.tapestry5.internal.plastic.asm.Type; -import org.apache.tapestry5.internal.plastic.asm.signature.SignatureReader; - -import java.util.HashMap; -import java.util.Map; +import org.apache.tapestry5.internal.plastic.asm.*; /** - * A {@link MethodVisitor} that prints a disassembled view of the methods it - * visits. - * + * A {@link MethodVisitor} that prints the methods it visits with a + * {@link Printer}. + * * @author Eric Bruneton */ -public class TraceMethodVisitor extends TraceAbstractVisitor implements - MethodVisitor -{ - - /** - * The {@link MethodVisitor} to which this visitor delegates calls. May be - * <tt>null</tt>. - */ - protected MethodVisitor mv; - - /** - * Tab for bytecode instructions. - */ - protected String tab2 = " "; - - /** - * Tab for table and lookup switch instructions. - */ - protected String tab3 = " "; +public final class TraceMethodVisitor extends MethodVisitor { - /** - * Tab for labels. - */ - protected String ltab = " "; + public final Printer p; - /** - * The label names. This map associate String values to Label keys. - */ - protected final Map labelNames; - - /** - * Constructs a new {@link TraceMethodVisitor}. - */ - public TraceMethodVisitor() { - this(null); + public TraceMethodVisitor(final Printer p) { + this(null, p); } - /** - * Constructs a new {@link TraceMethodVisitor}. - * - * @param mv the {@link MethodVisitor} to which this visitor delegates - * calls. May be <tt>null</tt>. - */ - public TraceMethodVisitor(final MethodVisitor mv) { - this.labelNames = new HashMap(); - this.mv = mv; + public TraceMethodVisitor(final MethodVisitor mv, final Printer p) { + super(Opcodes.ASM4, mv); + this.p = p; } - // ------------------------------------------------------------------------ - // Implementation of the MethodVisitor interface - // ------------------------------------------------------------------------ - + @Override public AnnotationVisitor visitAnnotation( final String desc, final boolean visible) { - AnnotationVisitor av = super.visitAnnotation(desc, visible); - if (mv != null) { - ((TraceAnnotationVisitor) av).av = mv.visitAnnotation(desc, visible); - } - return av; + Printer p = this.p.visitMethodAnnotation(desc, visible); + AnnotationVisitor av = mv == null ? null : mv.visitAnnotation(desc, + visible); + return new TraceAnnotationVisitor(av, p); } + @Override public void visitAttribute(final Attribute attr) { - buf.setLength(0); - buf.append(tab).append("ATTRIBUTE "); - appendDescriptor(-1, attr.type); - - if (attr instanceof Traceable) { - ((Traceable) attr).trace(buf, labelNames); - } else { - buf.append(" : unknown\n"); - } - - text.add(buf.toString()); - if (mv != null) { - mv.visitAttribute(attr); - } + p.visitMethodAttribute(attr); + super.visitAttribute(attr); } + @Override public AnnotationVisitor visitAnnotationDefault() { - text.add(tab2 + "default="); - TraceAnnotationVisitor tav = createTraceAnnotationVisitor(); - text.add(tav.getText()); - text.add("\n"); - if (mv != null) { - tav.av = mv.visitAnnotationDefault(); - } - return tav; + Printer p = this.p.visitAnnotationDefault(); + AnnotationVisitor av = mv == null ? null : mv.visitAnnotationDefault(); + return new TraceAnnotationVisitor(av, p); } + @Override public AnnotationVisitor visitParameterAnnotation( final int parameter, final String desc, final boolean visible) { - buf.setLength(0); - buf.append(tab2).append('@'); - appendDescriptor(FIELD_DESCRIPTOR, desc); - buf.append('('); - text.add(buf.toString()); - TraceAnnotationVisitor tav = createTraceAnnotationVisitor(); - text.add(tav.getText()); - text.add(visible ? ") // parameter " : ") // invisible, parameter "); - text.add(new Integer(parameter)); - text.add("\n"); - if (mv != null) { - tav.av = mv.visitParameterAnnotation(parameter, desc, visible); - } - return tav; + Printer p = this.p.visitParameterAnnotation(parameter, + desc, + visible); + AnnotationVisitor av = mv == null + ? null + : mv.visitParameterAnnotation(parameter, desc, visible); + return new TraceAnnotationVisitor(av, p); } + @Override public void visitCode() { - if (mv != null) { - mv.visitCode(); - } + p.visitCode(); + super.visitCode(); } + @Override public void visitFrame( final int type, final int nLocal, @@ -171,269 +104,130 @@ public class TraceMethodVisitor extends TraceAbstractVisitor implements final int nStack, final Object[] stack) { - buf.setLength(0); - buf.append(ltab); - buf.append("FRAME "); - switch (type) { - case Opcodes.F_NEW: - case Opcodes.F_FULL: - buf.append("FULL ["); - appendFrameTypes(nLocal, local); - buf.append("] ["); - appendFrameTypes(nStack, stack); - buf.append(']'); - break; - case Opcodes.F_APPEND: - buf.append("APPEND ["); - appendFrameTypes(nLocal, local); - buf.append(']'); - break; - case Opcodes.F_CHOP: - buf.append("CHOP ").append(nLocal); - break; - case Opcodes.F_SAME: - buf.append("SAME"); - break; - case Opcodes.F_SAME1: - buf.append("SAME1 "); - appendFrameTypes(1, stack); - break; - } - buf.append('\n'); - text.add(buf.toString()); - - if (mv != null) { - mv.visitFrame(type, nLocal, local, nStack, stack); - } + p.visitFrame(type, nLocal, local, nStack, stack); + super.visitFrame(type, nLocal, local, nStack, stack); } + @Override public void visitInsn(final int opcode) { - buf.setLength(0); - buf.append(tab2).append(OPCODES[opcode]).append('\n'); - text.add(buf.toString()); - - if (mv != null) { - mv.visitInsn(opcode); - } + p.visitInsn(opcode); + super.visitInsn(opcode); } + @Override public void visitIntInsn(final int opcode, final int operand) { - buf.setLength(0); - buf.append(tab2) - .append(OPCODES[opcode]) - .append(' ') - .append(opcode == Opcodes.NEWARRAY - ? TYPES[operand] - : Integer.toString(operand)) - .append('\n'); - text.add(buf.toString()); - - if (mv != null) { - mv.visitIntInsn(opcode, operand); - } + p.visitIntInsn(opcode, operand); + super.visitIntInsn(opcode, operand); } + @Override public void visitVarInsn(final int opcode, final int var) { - buf.setLength(0); - buf.append(tab2) - .append(OPCODES[opcode]) - .append(' ') - .append(var) - .append('\n'); - text.add(buf.toString()); - - if (mv != null) { - mv.visitVarInsn(opcode, var); - } + p.visitVarInsn(opcode, var); + super.visitVarInsn(opcode, var); } + @Override public void visitTypeInsn(final int opcode, final String type) { - buf.setLength(0); - buf.append(tab2).append(OPCODES[opcode]).append(' '); - appendDescriptor(INTERNAL_NAME, type); - buf.append('\n'); - text.add(buf.toString()); - - if (mv != null) { - mv.visitTypeInsn(opcode, type); - } + p.visitTypeInsn(opcode, type); + super.visitTypeInsn(opcode, type); } + @Override public void visitFieldInsn( final int opcode, final String owner, final String name, final String desc) { - buf.setLength(0); - buf.append(tab2).append(OPCODES[opcode]).append(' '); - appendDescriptor(INTERNAL_NAME, owner); - buf.append('.').append(name).append(" : "); - appendDescriptor(FIELD_DESCRIPTOR, desc); - buf.append('\n'); - text.add(buf.toString()); - - if (mv != null) { - mv.visitFieldInsn(opcode, owner, name, desc); - } + p.visitFieldInsn(opcode, owner, name, desc); + super.visitFieldInsn(opcode, owner, name, desc); } + @Override public void visitMethodInsn( final int opcode, final String owner, final String name, final String desc) { - buf.setLength(0); - buf.append(tab2).append(OPCODES[opcode]).append(' '); - appendDescriptor(INTERNAL_NAME, owner); - buf.append('.').append(name).append(' '); - appendDescriptor(METHOD_DESCRIPTOR, desc); - buf.append('\n'); - text.add(buf.toString()); + p.visitMethodInsn(opcode, owner, name, desc); + super.visitMethodInsn(opcode, owner, name, desc); + } - if (mv != null) { - mv.visitMethodInsn(opcode, owner, name, desc); - } + @Override + public void visitInvokeDynamicInsn( + String name, + String desc, + Handle bsm, + Object... bsmArgs) + { + p.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs); + super.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs); } + @Override public void visitJumpInsn(final int opcode, final Label label) { - buf.setLength(0); - buf.append(tab2).append(OPCODES[opcode]).append(' '); - appendLabel(label); - buf.append('\n'); - text.add(buf.toString()); - - if (mv != null) { - mv.visitJumpInsn(opcode, label); - } + p.visitJumpInsn(opcode, label); + super.visitJumpInsn(opcode, label); } + @Override public void visitLabel(final Label label) { - buf.setLength(0); - buf.append(ltab); - appendLabel(label); - buf.append('\n'); - text.add(buf.toString()); - - if (mv != null) { - mv.visitLabel(label); - } + p.visitLabel(label); + super.visitLabel(label); } + @Override public void visitLdcInsn(final Object cst) { - buf.setLength(0); - buf.append(tab2).append("LDC "); - if (cst instanceof String) { - AbstractVisitor.appendString(buf, (String) cst); - } else if (cst instanceof Type) { - buf.append(((Type) cst).getDescriptor()).append(".class"); - } else { - buf.append(cst); - } - buf.append('\n'); - text.add(buf.toString()); - - if (mv != null) { - mv.visitLdcInsn(cst); - } + p.visitLdcInsn(cst); + super.visitLdcInsn(cst); } + @Override public void visitIincInsn(final int var, final int increment) { - buf.setLength(0); - buf.append(tab2) - .append("IINC ") - .append(var) - .append(' ') - .append(increment) - .append('\n'); - text.add(buf.toString()); - - if (mv != null) { - mv.visitIincInsn(var, increment); - } + p.visitIincInsn(var, increment); + super.visitIincInsn(var, increment); } + @Override public void visitTableSwitchInsn( final int min, final int max, final Label dflt, - final Label[] labels) + final Label... labels) { - buf.setLength(0); - buf.append(tab2).append("TABLESWITCH\n"); - for (int i = 0; i < labels.length; ++i) { - buf.append(tab3).append(min + i).append(": "); - appendLabel(labels[i]); - buf.append('\n'); - } - buf.append(tab3).append("default: "); - appendLabel(dflt); - buf.append('\n'); - text.add(buf.toString()); - - if (mv != null) { - mv.visitTableSwitchInsn(min, max, dflt, labels); - } + p.visitTableSwitchInsn(min, max, dflt, labels); + super.visitTableSwitchInsn(min, max, dflt, labels); } + @Override public void visitLookupSwitchInsn( final Label dflt, final int[] keys, final Label[] labels) { - buf.setLength(0); - buf.append(tab2).append("LOOKUPSWITCH\n"); - for (int i = 0; i < labels.length; ++i) { - buf.append(tab3).append(keys[i]).append(": "); - appendLabel(labels[i]); - buf.append('\n'); - } - buf.append(tab3).append("default: "); - appendLabel(dflt); - buf.append('\n'); - text.add(buf.toString()); - - if (mv != null) { - mv.visitLookupSwitchInsn(dflt, keys, labels); - } + p.visitLookupSwitchInsn(dflt, keys, labels); + super.visitLookupSwitchInsn(dflt, keys, labels); } + @Override public void visitMultiANewArrayInsn(final String desc, final int dims) { - buf.setLength(0); - buf.append(tab2).append("MULTIANEWARRAY "); - appendDescriptor(FIELD_DESCRIPTOR, desc); - buf.append(' ').append(dims).append('\n'); - text.add(buf.toString()); - - if (mv != null) { - mv.visitMultiANewArrayInsn(desc, dims); - } + p.visitMultiANewArrayInsn(desc, dims); + super.visitMultiANewArrayInsn(desc, dims); } + @Override public void visitTryCatchBlock( final Label start, final Label end, final Label handler, final String type) { - buf.setLength(0); - buf.append(tab2).append("TRYCATCHBLOCK "); - appendLabel(start); - buf.append(' '); - appendLabel(end); - buf.append(' '); - appendLabel(handler); - buf.append(' '); - appendDescriptor(INTERNAL_NAME, type); - buf.append('\n'); - text.add(buf.toString()); - - if (mv != null) { - mv.visitTryCatchBlock(start, end, handler, type); - } + p.visitTryCatchBlock(start, end, handler, type); + super.visitTryCatchBlock(start, end, handler, type); } + @Override public void visitLocalVariable( final String name, final String desc, @@ -442,126 +236,25 @@ public class TraceMethodVisitor extends TraceAbstractVisitor implements final Label end, final int index) { - buf.setLength(0); - buf.append(tab2).append("LOCALVARIABLE ").append(name).append(' '); - appendDescriptor(FIELD_DESCRIPTOR, desc); - buf.append(' '); - appendLabel(start); - buf.append(' '); - appendLabel(end); - buf.append(' ').append(index).append('\n'); - - if (signature != null) { - buf.append(tab2); - appendDescriptor(FIELD_SIGNATURE, signature); - - TraceSignatureVisitor sv = new TraceSignatureVisitor(0); - SignatureReader r = new SignatureReader(signature); - r.acceptType(sv); - buf.append(tab2) - .append("// declaration: ") - .append(sv.getDeclaration()) - .append('\n'); - } - text.add(buf.toString()); - - if (mv != null) { - mv.visitLocalVariable(name, desc, signature, start, end, index); - } + p.visitLocalVariable(name, desc, signature, start, end, index); + super.visitLocalVariable(name, desc, signature, start, end, index); } + @Override public void visitLineNumber(final int line, final Label start) { - buf.setLength(0); - buf.append(tab2).append("LINENUMBER ").append(line).append(' '); - appendLabel(start); - buf.append('\n'); - text.add(buf.toString()); - - if (mv != null) { - mv.visitLineNumber(line, start); - } + p.visitLineNumber(line, start); + super.visitLineNumber(line, start); } + @Override public void visitMaxs(final int maxStack, final int maxLocals) { - buf.setLength(0); - buf.append(tab2).append("MAXSTACK = ").append(maxStack).append('\n'); - text.add(buf.toString()); - - buf.setLength(0); - buf.append(tab2).append("MAXLOCALS = ").append(maxLocals).append('\n'); - text.add(buf.toString()); - - if (mv != null) { - mv.visitMaxs(maxStack, maxLocals); - } + p.visitMaxs(maxStack, maxLocals); + super.visitMaxs(maxStack, maxLocals); } + @Override public void visitEnd() { + p.visitMethodEnd(); super.visitEnd(); - - if (mv != null) { - mv.visitEnd(); - } - } - - // ------------------------------------------------------------------------ - // Utility methods - // ------------------------------------------------------------------------ - - private void appendFrameTypes(final int n, final Object[] o) { - for (int i = 0; i < n; ++i) { - if (i > 0) { - buf.append(' '); - } - if (o[i] instanceof String) { - String desc = (String) o[i]; - if (desc.startsWith("[")) { - appendDescriptor(FIELD_DESCRIPTOR, desc); - } else { - appendDescriptor(INTERNAL_NAME, desc); - } - } else if (o[i] instanceof Integer) { - switch (((Integer) o[i]).intValue()) { - case 0: - appendDescriptor(FIELD_DESCRIPTOR, "T"); - break; - case 1: - appendDescriptor(FIELD_DESCRIPTOR, "I"); - break; - case 2: - appendDescriptor(FIELD_DESCRIPTOR, "F"); - break; - case 3: - appendDescriptor(FIELD_DESCRIPTOR, "D"); - break; - case 4: - appendDescriptor(FIELD_DESCRIPTOR, "J"); - break; - case 5: - appendDescriptor(FIELD_DESCRIPTOR, "N"); - break; - case 6: - appendDescriptor(FIELD_DESCRIPTOR, "U"); - break; - } - } else { - appendLabel((Label) o[i]); - } - } - } - - /** - * Appends the name of the given label to {@link #buf buf}. Creates a new - * label name if the given label does not yet have one. - * - * @param l a label. - */ - protected void appendLabel(final Label l) { - String name = (String) labelNames.get(l); - if (name == null) { - name = "L" + labelNames.size(); - labelNames.put(l, name); - } - buf.append(name); } } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d6e5f413/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceSignatureVisitor.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceSignatureVisitor.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceSignatureVisitor.java index 3ac7181..3b0a178 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceSignatureVisitor.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/TraceSignatureVisitor.java @@ -1,6 +1,6 @@ /*** * ASM: a very small and fast Java bytecode manipulation framework - * Copyright (c) 2000-2007 INRIA, France Telecom + * Copyright (c) 2000-2011 INRIA, France Telecom * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,13 +33,14 @@ import org.apache.tapestry5.internal.plastic.asm.Opcodes; import org.apache.tapestry5.internal.plastic.asm.signature.SignatureVisitor; /** - * A {@link SignatureVisitor} that prints a disassembled view of the signature + * A {@link org.apache.tapestry5.internal.plastic.asm.signature.SignatureVisitor} that prints a disassembled view of the signature * it visits. - * + * * @author Eugene Kuleshov * @author Eric Bruneton */ -public class TraceSignatureVisitor implements SignatureVisitor { +public final class TraceSignatureVisitor extends SignatureVisitor +{ private final StringBuffer declaration; @@ -75,26 +76,31 @@ public class TraceSignatureVisitor implements SignatureVisitor { private String separator = ""; public TraceSignatureVisitor(final int access) { + super(Opcodes.ASM4); isInterface = (access & Opcodes.ACC_INTERFACE) != 0; this.declaration = new StringBuffer(); } private TraceSignatureVisitor(final StringBuffer buf) { + super(Opcodes.ASM4); this.declaration = buf; } + @Override public void visitFormalTypeParameter(final String name) { declaration.append(seenFormalParameter ? ", " : "<").append(name); seenFormalParameter = true; seenInterfaceBound = false; } + @Override public SignatureVisitor visitClassBound() { separator = " extends "; startType(); return this; } + @Override public SignatureVisitor visitInterfaceBound() { separator = seenInterfaceBound ? ", " : " extends "; seenInterfaceBound = true; @@ -102,6 +108,7 @@ public class TraceSignatureVisitor implements SignatureVisitor { return this; } + @Override public SignatureVisitor visitSuperclass() { endFormals(); separator = " extends "; @@ -109,6 +116,7 @@ public class TraceSignatureVisitor implements SignatureVisitor { return this; } + @Override public SignatureVisitor visitInterface() { separator = seenInterface ? ", " : isInterface ? " extends " @@ -118,6 +126,7 @@ public class TraceSignatureVisitor implements SignatureVisitor { return this; } + @Override public SignatureVisitor visitParameterType() { endFormals(); if (seenParameter) { @@ -130,6 +139,7 @@ public class TraceSignatureVisitor implements SignatureVisitor { return this; } + @Override public SignatureVisitor visitReturnType() { endFormals(); if (seenParameter) { @@ -142,6 +152,7 @@ public class TraceSignatureVisitor implements SignatureVisitor { return new TraceSignatureVisitor(returnType); } + @Override public SignatureVisitor visitExceptionType() { if (exceptions == null) { exceptions = new StringBuffer(); @@ -152,6 +163,7 @@ public class TraceSignatureVisitor implements SignatureVisitor { return new TraceSignatureVisitor(exceptions); } + @Override public void visitBaseType(final char descriptor) { switch (descriptor) { case 'V': @@ -186,17 +198,20 @@ public class TraceSignatureVisitor implements SignatureVisitor { endType(); } + @Override public void visitTypeVariable(final String name) { declaration.append(name); endType(); } + @Override public SignatureVisitor visitArrayType() { startType(); arrayStack |= 1; return this; } + @Override public void visitClassType(final String name) { if ("java/lang/Object".equals(name)) { // Map<java.lang.Object,java.util.List> @@ -215,6 +230,7 @@ public class TraceSignatureVisitor implements SignatureVisitor { argumentStack *= 2; } + @Override public void visitInnerClassType(final String name) { if (argumentStack % 2 != 0) { declaration.append('>'); @@ -226,6 +242,7 @@ public class TraceSignatureVisitor implements SignatureVisitor { argumentStack *= 2; } + @Override public void visitTypeArgument() { if (argumentStack % 2 == 0) { ++argumentStack; @@ -236,6 +253,7 @@ public class TraceSignatureVisitor implements SignatureVisitor { declaration.append('?'); } + @Override public SignatureVisitor visitTypeArgument(final char tag) { if (argumentStack % 2 == 0) { ++argumentStack; @@ -254,6 +272,7 @@ public class TraceSignatureVisitor implements SignatureVisitor { return this; } + @Override public void visitEnd() { if (argumentStack % 2 != 0) { declaration.append('>'); http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d6e5f413/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/Traceable.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/Traceable.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/Traceable.java deleted file mode 100644 index 73408d1..0000000 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/Traceable.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * ASM: a very small and fast Java bytecode manipulation framework - * Copyright (c) 2000-2007 INRIA, France Telecom - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.apache.tapestry5.internal.plastic.asm.util; - -import java.util.Map; - -/** - * An attribute that can print eadable representation of the attribute. - * - * Implementation should construct readable output from an attribute data - * structures for current attribute state. Such representation could be used in - * unit test assertions. - * - * @author Eugene Kuleshov - */ -public interface Traceable { - - /** - * Build a human readable representation of the attribute. - * - * @param buf A buffer used for printing Java code. - * @param labelNames map of label instances to their names. - */ - void trace(StringBuffer buf, Map labelNames); -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d6e5f413/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/package.html ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/package.html b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/package.html index e967b8b..91d7420 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/package.html +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/package.html @@ -1,7 +1,7 @@ <html> <!-- * ASM: a very small and fast Java bytecode manipulation framework - * Copyright (c) 2000-2005 INRIA, France Telecom + * Copyright (c) 2000-2011 INRIA, France Telecom * All rights reserved. * * Redistribution and use in source and binary forms, with or without
