Return-Path: X-Original-To: apmail-tapestry-dev-archive@www.apache.org Delivered-To: apmail-tapestry-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E65DC99C7 for ; Thu, 31 May 2012 12:24:20 +0000 (UTC) Received: (qmail 73539 invoked by uid 500); 31 May 2012 12:24:18 -0000 Delivered-To: apmail-tapestry-dev-archive@tapestry.apache.org Received: (qmail 72753 invoked by uid 500); 31 May 2012 12:24:17 -0000 Mailing-List: contact commits-help@tapestry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tapestry.apache.org Delivered-To: mailing list commits@tapestry.apache.org Received: (qmail 71927 invoked by uid 99); 31 May 2012 12:24:11 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 May 2012 12:24:11 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id DC03FF0B1; Thu, 31 May 2012 12:24:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hlship@apache.org To: commits@tapestry.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [12/17] TAP5-1852: Upgrade Plastic to use ASM 4.0 - Remove unused utility classes Message-Id: <20120531122410.DC03FF0B1@tyr.zones.apache.org> Date: Thu, 31 May 2012 12:24:10 +0000 (UTC) http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/89a761eb/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/package.html ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/package.html b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/package.html deleted file mode 100644 index 3c69348..0000000 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/package.html +++ /dev/null @@ -1,67 +0,0 @@ - - - - -

-Provides a framework for static code analysis based on the asm.tree package. -

- -

-Basic usage: -

- -
-ClassReader cr = new ClassReader(bytecode);
-ClassNode cn = new ClassNode();
-cr.accept(cn, ClassReader.SKIP_DEBUG);
-
-List methods = cn.methods;
-for (int i = 0; i < methods.size(); ++i) {
-    MethodNode method = (MethodNode) methods.get(i);
-    if (method.instructions.size() > 0) {
-        Analyzer a = new Analyzer(new BasicInterpreter());
-        a.analyze(cn.name, method);
-        Frame[] frames = a.getFrames();
-        // Elements of the frames arrray now contains info for each instruction 
-        // from the analyzed method. BasicInterpreter creates BasicValue, that
-        // is using simplified type system that distinguishes the UNINITIALZED, 
-        // INT, FLOAT, LONG, DOUBLE, REFERENCE and RETURNADDRESS types.
-        ...
-    }
-}   
-
- -

-@since ASM 1.4.3 -

- - - http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/89a761eb/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/package.html ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/package.html b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/package.html index db68645..940b876 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/package.html +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/package.html @@ -1,7 +1,7 @@ - -

+ +

Provides an ASM visitor that constructs a tree representation of the classes it visits. This class adapter can be useful to implement "complex" class manipulation operations, i.e., operations that would be very hard to implement without using a tree representation (such as optimizing the number of local variables used by a method).

- +

However, this class adapter has a cost: it makes ASM bigger and slower. Indeed it requires more than twenty new classes, and multiplies the time needed to transform a class by almost two (it is almost two times faster to read, "modify" -and write a class with a ClassAdapter than with a ClassNode). This is why +and write a class with a ClassVisitor than with a ClassNode). This is why this package is bundled in an optional asm-tree.jar library that is separated from (but requires) the asm.jar library, which contains the core ASM framework. This is also why it is recommended @@ -52,7 +52,7 @@ not to use this class adapter when it is possible.

The root class is the ClassNode, that can be created from existing bytecode. For example:

- +
   ClassReader cr = new ClassReader(source);
   ClassNode cn = new ClassNode();
@@ -60,41 +60,41 @@ The root class is the ClassNode, that can be created from existing bytecode. For
 

-Now content of ClassNode can be modified and then +Now the content of ClassNode can be modified and then serialized back into bytecode:

   ClassWriter cw = new ClassWriter(true);
   cn.accept(cw);
-
+

-Using simple ClassAdapter it is possible to create MethodNode instances per-method. +Using a simple ClassVisitor it is possible to create MethodNode instances per-method. In this example MethodNode is acting as a buffer that is flushed out at visitEnd() call:

   ClassReader cr = new ClassReader(source);
   ClassWriter cw = new ClassWriter();
-  ClassAdapter ca = new ClassAdapter(cw) {
-      public MethodVisitor visitMethod(int access, String name, 
-          String desc, String signature, String[] exceptions) {
-        final MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
-        MethodNode mn = new MethodNode(access, name, desc, signature, exceptions) {
-            public void visitEnd() {
-              // transform or analyze method code using tree API
-              accept(mv);
-            }
-          };
-      }
-    };
-  cr.accept(ca, true);
+  ClassVisitor cv = new ClassVisitor(cw) {
+    public MethodVisitor visitMethod(int access, String name,
+        String desc, String signature, String[] exceptions) {
+      final MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
+      MethodNode mn = new MethodNode(access, name, desc, signature, exceptions) {
+        public void visitEnd() {
+          // transform or analyze method code using tree API
+          accept(mv);
+        }
+      };
+    }
+  };
+  cr.accept(cv, true);
 
-

+

Several strategies can be used to construct method code from scratch. The first -option is to create a MethodNode, and then create XXXInsnNode instances and +option is to create a MethodNode, and then create XxxInsnNode instances and add them to the instructions list:

@@ -106,8 +106,8 @@ m.instructions.add(new VarInsnNode(ALOAD, 0));

Alternatively, you can use the fact that MethodNode is a MethodVisitor, and use -that to create the XXXInsnNode and add them to the instructions list through -the standard MethodVisitor interface: +that to create the XxxInsnNode and add them to the instructions list through +the standard MethodVisitor methods:

@@ -117,10 +117,10 @@ m.visitVarInsn(ALOAD, 0);
 

-If you cannot generate all the instructions in sequential order, i.e. if you +If you cannot generate all the instructions in sequential order, i.e. if you need to save some pointer in the instruction list and then insert instructions -at that place after other instructions have been generated, you can use InsnList -methods insert() and insertBefore() to insert instructions at saved pointer. +at that place after other instructions have been generated, you can use InsnList +methods insert() and insertBefore() to insert instructions at a saved pointer.

@@ -134,8 +134,8 @@ m.instructions.insert(ptr, new VarInsnNode(ALOAD, 0));
 

-If you need to insert instructions while iterating over an existing instruction -list, you can also use several strategies. The first one is to use a +If you need to insert instructions while iterating over an existing instruction +list, you can also use several strategies. The first one is to use a ListIterator over the instruction list:

@@ -150,7 +150,7 @@ while (it.hasNext()) {

-It is also possible to convert instruction list into the array and iterate trough +It is also possible to convert an instruction list into an array and iterate trough array elements:

@@ -165,9 +165,9 @@ for(int i = 0; i<insns.length; i++) {

-If you want to insert these instructions through the MethodVisitor interface, -you can use another instance of MethodNode as a MethodVisitor and then -insert instructions collected by that instance into the instruction list. +If you want to insert these instructions through the MethodVisitor methods, +you can use another instance of MethodNode as a MethodVisitor and then +insert instructions collected by that instance into the instruction list. For example:

@@ -184,9 +184,9 @@ for(int i = 0; i<insns.length; i++) { } -

+

@since ASM 1.3.3

- + http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/89a761eb/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifiable.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifiable.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifiable.java index 0f2253d..e1fec58 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifiable.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifiable.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 @@ -29,25 +29,25 @@ */ package org.apache.tapestry5.internal.plastic.asm.util; +import org.apache.tapestry5.internal.plastic.asm.Label; + import java.util.Map; /** - * An attribute that can print the ASM code to create an equivalent attribute. - * - * Implementation should print the ASM code that generates attribute data - * structures for current attribute state. - * + * An {@link org.apache.tapestry5.internal.plastic.asm.Attribute Attribute} that can print the ASM code + * to create an equivalent attribute. + * * @author Eugene Kuleshov */ public interface ASMifiable { /** * Prints the ASM code to create an attribute equal to this attribute. - * - * @param buf A buffer used for printing Java code. + * + * @param buf a buffer used for printing Java code. * @param varName name of the variable in a printed code used to store * attribute instance. * @param labelNames map of label instances to their names. */ - void asmify(StringBuffer buf, String varName, Map labelNames); + void asmify(StringBuffer buf, String varName, Map labelNames); } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/89a761eb/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierAbstractVisitor.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierAbstractVisitor.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierAbstractVisitor.java deleted file mode 100644 index 8d54f9d..0000000 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierAbstractVisitor.java +++ /dev/null @@ -1,222 +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 org.apache.tapestry5.internal.plastic.asm.AnnotationVisitor; -import org.apache.tapestry5.internal.plastic.asm.Attribute; -import org.apache.tapestry5.internal.plastic.asm.Type; - -import java.util.Map; - -/** - * An abstract ASMifier visitor. - * - * @author Eric Bruneton - */ -public class ASMifierAbstractVisitor extends AbstractVisitor { - - /** - * The name of the variable for this visitor in the produced code. - */ - protected String name; - - /** - * The label names. This map associates String values to Label keys. It is - * used only in ASMifierMethodVisitor. - */ - Map labelNames; - - /** - * Constructs a new {@link ASMifierAbstractVisitor}. - * - * @param name the name of the variable for this visitor in the produced - * code. - */ - protected ASMifierAbstractVisitor(final String name) { - this.name = name; - } - - /** - * Prints the ASM code that generates the given annotation. - * - * @param desc the class descriptor of the annotation class. - * @param visible true if the annotation is visible at runtime. - * @return a visitor to visit the annotation values. - */ - public AnnotationVisitor visitAnnotation( - final String desc, - final boolean visible) - { - buf.setLength(0); - buf.append("{\n") - .append("av0 = ") - .append(name) - .append(".visitAnnotation("); - appendConstant(desc); - buf.append(", ").append(visible).append(");\n"); - text.add(buf.toString()); - ASMifierAnnotationVisitor av = new ASMifierAnnotationVisitor(0); - text.add(av.getText()); - text.add("}\n"); - return av; - } - - /** - * Prints the ASM code that generates the given attribute. - * - * @param attr an attribute. - */ - public void visitAttribute(final Attribute attr) { - buf.setLength(0); - buf.append("// ATTRIBUTE ").append(attr.type).append('\n'); - if (attr instanceof ASMifiable) { - buf.append("{\n"); - ((ASMifiable) attr).asmify(buf, "attr", labelNames); - buf.append(name).append(".visitAttribute(attr);\n"); - buf.append("}\n"); - } - text.add(buf.toString()); - } - - /** - * Prints the ASM code to end the visit. - */ - public void visitEnd() { - buf.setLength(0); - buf.append(name).append(".visitEnd();\n"); - text.add(buf.toString()); - } - - /** - * Appends a string representation of the given constant to the given - * buffer. - * - * @param cst an {@link Integer}, {@link Float}, {@link Long}, - * {@link Double} or {@link String} object. May be null. - */ - void appendConstant(final Object cst) { - appendConstant(buf, cst); - } - - /** - * Appends a string representation of the given constant to the given - * buffer. - * - * @param buf a string buffer. - * @param cst an {@link Integer}, {@link Float}, {@link Long}, - * {@link Double} or {@link String} object. May be null. - */ - static void appendConstant(final StringBuffer buf, final Object cst) { - if (cst == null) { - buf.append("null"); - } else if (cst instanceof String) { - appendString(buf, (String) cst); - } else if (cst instanceof Type) { - buf.append("Type.getType(\""); - buf.append(((Type) cst).getDescriptor()); - buf.append("\")"); - } else if (cst instanceof Byte) { - buf.append("new Byte((byte)").append(cst).append(')'); - } else if (cst instanceof Boolean) { - buf.append(((Boolean) cst).booleanValue() ? "Boolean.TRUE" : "Boolean.FALSE"); - } else if (cst instanceof Short) { - buf.append("new Short((short)").append(cst).append(')'); - } else if (cst instanceof Character) { - int c = ((Character) cst).charValue(); - buf.append("new Character((char)").append(c).append(')'); - } else if (cst instanceof Integer) { - buf.append("new Integer(").append(cst).append(')'); - } else if (cst instanceof Float) { - buf.append("new Float(\"").append(cst).append("\")"); - } else if (cst instanceof Long) { - buf.append("new Long(").append(cst).append("L)"); - } else if (cst instanceof Double) { - buf.append("new Double(\"").append(cst).append("\")"); - } else if (cst instanceof byte[]) { - byte[] v = (byte[]) cst; - buf.append("new byte[] {"); - for (int i = 0; i < v.length; i++) { - buf.append(i == 0 ? "" : ",").append(v[i]); - } - buf.append('}'); - } else if (cst instanceof boolean[]) { - boolean[] v = (boolean[]) cst; - buf.append("new boolean[] {"); - for (int i = 0; i < v.length; i++) { - buf.append(i == 0 ? "" : ",").append(v[i]); - } - buf.append('}'); - } else if (cst instanceof short[]) { - short[] v = (short[]) cst; - buf.append("new short[] {"); - for (int i = 0; i < v.length; i++) { - buf.append(i == 0 ? "" : ",").append("(short)").append(v[i]); - } - buf.append('}'); - } else if (cst instanceof char[]) { - char[] v = (char[]) cst; - buf.append("new char[] {"); - for (int i = 0; i < v.length; i++) { - buf.append(i == 0 ? "" : ",") - .append("(char)") - .append((int) v[i]); - } - buf.append('}'); - } else if (cst instanceof int[]) { - int[] v = (int[]) cst; - buf.append("new int[] {"); - for (int i = 0; i < v.length; i++) { - buf.append(i == 0 ? "" : ",").append(v[i]); - } - buf.append('}'); - } else if (cst instanceof long[]) { - long[] v = (long[]) cst; - buf.append("new long[] {"); - for (int i = 0; i < v.length; i++) { - buf.append(i == 0 ? "" : ",").append(v[i]).append('L'); - } - buf.append('}'); - } else if (cst instanceof float[]) { - float[] v = (float[]) cst; - buf.append("new float[] {"); - for (int i = 0; i < v.length; i++) { - buf.append(i == 0 ? "" : ",").append(v[i]).append('f'); - } - buf.append('}'); - } else if (cst instanceof double[]) { - double[] v = (double[]) cst; - buf.append("new double[] {"); - for (int i = 0; i < v.length; i++) { - buf.append(i == 0 ? "" : ",").append(v[i]).append('d'); - } - buf.append('}'); - } - } -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/89a761eb/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierAnnotationVisitor.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierAnnotationVisitor.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierAnnotationVisitor.java deleted file mode 100644 index 049db5c..0000000 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierAnnotationVisitor.java +++ /dev/null @@ -1,127 +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 org.apache.tapestry5.internal.plastic.asm.AnnotationVisitor; - -/** - * An {@link AnnotationVisitor} that prints the ASM code that generates the - * annotations it visits. - * - * @author Eric Bruneton - */ -public class ASMifierAnnotationVisitor extends AbstractVisitor implements - AnnotationVisitor -{ - - /** - * Identifier of the annotation visitor variable in the produced code. - */ - protected final int id; - - /** - * Constructs a new {@link ASMifierAnnotationVisitor}. - * - * @param id identifier of the annotation visitor variable in the produced - * code. - */ - public ASMifierAnnotationVisitor(final int id) { - this.id = id; - } - - // ------------------------------------------------------------------------ - // Implementation of the AnnotationVisitor interface - // ------------------------------------------------------------------------ - - public void visit(final String name, final Object value) { - buf.setLength(0); - buf.append("av").append(id).append(".visit("); - ASMifierAbstractVisitor.appendConstant(buf, name); - buf.append(", "); - ASMifierAbstractVisitor.appendConstant(buf, value); - buf.append(");\n"); - text.add(buf.toString()); - } - - public void visitEnum( - final String name, - final String desc, - final String value) - { - buf.setLength(0); - buf.append("av").append(id).append(".visitEnum("); - ASMifierAbstractVisitor.appendConstant(buf, name); - buf.append(", "); - ASMifierAbstractVisitor.appendConstant(buf, desc); - buf.append(", "); - ASMifierAbstractVisitor.appendConstant(buf, value); - buf.append(");\n"); - text.add(buf.toString()); - } - - public AnnotationVisitor visitAnnotation( - final String name, - final String desc) - { - buf.setLength(0); - buf.append("{\n"); - buf.append("AnnotationVisitor av").append(id + 1).append(" = av"); - buf.append(id).append(".visitAnnotation("); - ASMifierAbstractVisitor.appendConstant(buf, name); - buf.append(", "); - ASMifierAbstractVisitor.appendConstant(buf, desc); - buf.append(");\n"); - text.add(buf.toString()); - ASMifierAnnotationVisitor av = new ASMifierAnnotationVisitor(id + 1); - text.add(av.getText()); - text.add("}\n"); - return av; - } - - public AnnotationVisitor visitArray(final String name) { - buf.setLength(0); - buf.append("{\n"); - buf.append("AnnotationVisitor av").append(id + 1).append(" = av"); - buf.append(id).append(".visitArray("); - ASMifierAbstractVisitor.appendConstant(buf, name); - buf.append(");\n"); - text.add(buf.toString()); - ASMifierAnnotationVisitor av = new ASMifierAnnotationVisitor(id + 1); - text.add(av.getText()); - text.add("}\n"); - return av; - } - - public void visitEnd() { - buf.setLength(0); - buf.append("av").append(id).append(".visitEnd();\n"); - text.add(buf.toString()); - } -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/89a761eb/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierClassVisitor.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierClassVisitor.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierClassVisitor.java deleted file mode 100644 index 03cecbc..0000000 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierClassVisitor.java +++ /dev/null @@ -1,575 +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.io.FileInputStream; -import java.io.PrintWriter; - -import org.apache.tapestry5.internal.plastic.asm.AnnotationVisitor; -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; - -/** - * A {@link ClassVisitor} that prints the ASM code that generates the classes it - * visits. This class visitor can be used to quickly write ASM code to generate - * some given bytecode:
  • write the Java source code equivalent to the - * bytecode you want to generate;
  • compile it with javac;
  • - *
  • make a {@link ASMifierClassVisitor} visit this compiled class (see the - * {@link #main main} method);
  • edit the generated source code, if - * necessary.
The source code printed when visiting the - * Hello class is the following:

- * - *
- * import org.objectweb.asm.*;
- *
- * public class HelloDump implements Opcodes {
- *
- *     public static byte[] dump() throws Exception {
- *
- *         ClassWriter cw = new ClassWriter(0);
- *         FieldVisitor fv;
- *         MethodVisitor mv;
- *         AnnotationVisitor av0;
- *
- *         cw.visit(49,
- *                 ACC_PUBLIC + ACC_SUPER,
- *                 "Hello",
- *                 null,
- *                 "java/lang/Object",
- *                 null);
- *
- *         cw.visitSource("Hello.java", null);
- *
- *         {
- *             mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
- *             mv.visitVarInsn(ALOAD, 0);
- *             mv.visitMethodInsn(INVOKESPECIAL,
- *                     "java/lang/Object",
- *                     "<init>",
- *                     "()V");
- *             mv.visitInsn(RETURN);
- *             mv.visitMaxs(1, 1);
- *             mv.visitEnd();
- *         }
- *         {
- *             mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC,
- *                     "main",
- *                     "([Ljava/lang/String;)V",
- *                     null,
- *                     null);
- *             mv.visitFieldInsn(GETSTATIC,
- *                     "java/lang/System",
- *                     "out",
- *                     "Ljava/io/PrintStream;");
- *             mv.visitLdcInsn("hello");
- *             mv.visitMethodInsn(INVOKEVIRTUAL,
- *                     "java/io/PrintStream",
- *                     "println",
- *                     "(Ljava/lang/String;)V");
- *             mv.visitInsn(RETURN);
- *             mv.visitMaxs(2, 1);
- *             mv.visitEnd();
- *         }
- *         cw.visitEnd();
- *
- *         return cw.toByteArray();
- *     }
- * }
- *
- * 
- * - *
where Hello is defined by:

- * - *
- * public class Hello {
- *
- *     public static void main(String[] args) {
- *         System.out.println("hello");
- *     }
- * }
- * 
- * - *
- * - * @author Eric Bruneton - * @author Eugene Kuleshov - */ -public class ASMifierClassVisitor extends ASMifierAbstractVisitor implements - ClassVisitor -{ - - /** - * Pseudo access flag used to distinguish class access flags. - */ - private static final int ACCESS_CLASS = 262144; - - /** - * Pseudo access flag used to distinguish field access flags. - */ - private static final int ACCESS_FIELD = 524288; - - /** - * Pseudo access flag used to distinguish inner class flags. - */ - private static final int ACCESS_INNER = 1048576; - - /** - * The print writer to be used to print the class. - */ - protected final PrintWriter pw; - - /** - * Prints the ASM source code to generate the given class to the standard - * output.

Usage: ASMifierClassVisitor [-debug] <fully qualified - * class name or class file name> - * - * @param args the command line arguments. - * - * @throws Exception if the class cannot be found, or if an IO exception - * occurs. - */ - 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 the ASM code to generate the given class."); - System.err.println("Usage: ASMifierClassVisitor [-debug] " - + ""); - 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 ASMifierClassVisitor(new PrintWriter(System.out)), - getDefaultAttributes(), - flags); - } - - /** - * Constructs a new {@link ASMifierClassVisitor} object. - * - * @param pw the print writer to be used to print the class. - */ - public ASMifierClassVisitor(final PrintWriter pw) { - super("cw"); - this.pw = pw; - } - - // ------------------------------------------------------------------------ - // Implementation of the ClassVisitor interface - // ------------------------------------------------------------------------ - - public void visit( - final int version, - final int access, - final String name, - final String signature, - final String superName, - final String[] interfaces) - { - String simpleName; - int n = name.lastIndexOf('/'); - if (n == -1) { - simpleName = name; - } else { - text.add("package asm." + name.substring(0, n).replace('/', '.') - + ";\n"); - simpleName = name.substring(n + 1); - } - text.add("import java.util.*;\n"); - text.add("import org.objectweb.asm.*;\n"); - text.add("import org.objectweb.asm.attrs.*;\n"); - text.add("public class " + simpleName + "Dump implements Opcodes {\n\n"); - text.add("public static byte[] dump () throws Exception {\n\n"); - text.add("ClassWriter cw = new ClassWriter(0);\n"); - text.add("FieldVisitor fv;\n"); - text.add("MethodVisitor mv;\n"); - text.add("AnnotationVisitor av0;\n\n"); - - buf.setLength(0); - buf.append("cw.visit("); - switch (version) { - case Opcodes.V1_1: - buf.append("V1_1"); - break; - case Opcodes.V1_2: - buf.append("V1_2"); - break; - case Opcodes.V1_3: - buf.append("V1_3"); - break; - case Opcodes.V1_4: - buf.append("V1_4"); - break; - case Opcodes.V1_5: - buf.append("V1_5"); - break; - case Opcodes.V1_6: - buf.append("V1_6"); - break; - default: - buf.append(version); - break; - } - buf.append(", "); - appendAccess(access | ACCESS_CLASS); - buf.append(", "); - appendConstant(name); - buf.append(", "); - appendConstant(signature); - buf.append(", "); - appendConstant(superName); - buf.append(", "); - if (interfaces != null && interfaces.length > 0) { - buf.append("new String[] {"); - for (int i = 0; i < interfaces.length; ++i) { - buf.append(i == 0 ? " " : ", "); - appendConstant(interfaces[i]); - } - buf.append(" }"); - } else { - buf.append("null"); - } - buf.append(");\n\n"); - text.add(buf.toString()); - } - - public void visitSource(final String file, final String debug) { - buf.setLength(0); - buf.append("cw.visitSource("); - appendConstant(file); - buf.append(", "); - appendConstant(debug); - buf.append(");\n\n"); - text.add(buf.toString()); - } - - public void visitOuterClass( - final String owner, - final String name, - final String desc) - { - buf.setLength(0); - buf.append("cw.visitOuterClass("); - appendConstant(owner); - buf.append(", "); - appendConstant(name); - buf.append(", "); - appendConstant(desc); - buf.append(");\n\n"); - text.add(buf.toString()); - } - - public void visitInnerClass( - final String name, - final String outerName, - final String innerName, - final int access) - { - buf.setLength(0); - buf.append("cw.visitInnerClass("); - appendConstant(name); - buf.append(", "); - appendConstant(outerName); - buf.append(", "); - appendConstant(innerName); - buf.append(", "); - appendAccess(access | ACCESS_INNER); - buf.append(");\n\n"); - text.add(buf.toString()); - } - - public FieldVisitor visitField( - final int access, - final String name, - final String desc, - final String signature, - final Object value) - { - buf.setLength(0); - buf.append("{\n"); - buf.append("fv = cw.visitField("); - appendAccess(access | ACCESS_FIELD); - buf.append(", "); - appendConstant(name); - buf.append(", "); - appendConstant(desc); - buf.append(", "); - appendConstant(signature); - buf.append(", "); - appendConstant(value); - buf.append(");\n"); - text.add(buf.toString()); - ASMifierFieldVisitor aav = new ASMifierFieldVisitor(); - text.add(aav.getText()); - text.add("}\n"); - return aav; - } - - public MethodVisitor visitMethod( - final int access, - final String name, - final String desc, - final String signature, - final String[] exceptions) - { - buf.setLength(0); - buf.append("{\n"); - buf.append("mv = cw.visitMethod("); - appendAccess(access); - buf.append(", "); - appendConstant(name); - buf.append(", "); - appendConstant(desc); - buf.append(", "); - appendConstant(signature); - buf.append(", "); - if (exceptions != null && exceptions.length > 0) { - buf.append("new String[] {"); - for (int i = 0; i < exceptions.length; ++i) { - buf.append(i == 0 ? " " : ", "); - appendConstant(exceptions[i]); - } - buf.append(" }"); - } else { - buf.append("null"); - } - buf.append(");\n"); - text.add(buf.toString()); - ASMifierMethodVisitor acv = createASMifierMethodVisitor(); - text.add(acv.getText()); - text.add("}\n"); - return acv; - } - - protected ASMifierMethodVisitor createASMifierMethodVisitor() { - return new ASMifierMethodVisitor(); - } - - public AnnotationVisitor visitAnnotation( - final String desc, - final boolean visible) - { - buf.setLength(0); - buf.append("{\n"); - buf.append("av0 = cw.visitAnnotation("); - appendConstant(desc); - buf.append(", "); - buf.append(visible); - buf.append(");\n"); - text.add(buf.toString()); - ASMifierAnnotationVisitor av = new ASMifierAnnotationVisitor(0); - text.add(av.getText()); - text.add("}\n"); - return av; - } - - public void visitEnd() { - text.add("cw.visitEnd();\n\n"); - text.add("return cw.toByteArray();\n"); - text.add("}\n"); - text.add("}\n"); - printList(pw, text); - pw.flush(); - } - - // ------------------------------------------------------------------------ - // Utility methods - // ------------------------------------------------------------------------ - - /** - * Appends a string representation of the given access modifiers to {@link - * #buf buf}. - * - * @param access some access modifiers. - */ - void appendAccess(final int access) { - boolean first = true; - if ((access & Opcodes.ACC_PUBLIC) != 0) { - buf.append("ACC_PUBLIC"); - first = false; - } - if ((access & Opcodes.ACC_PRIVATE) != 0) { - buf.append("ACC_PRIVATE"); - first = false; - } - if ((access & Opcodes.ACC_PROTECTED) != 0) { - buf.append("ACC_PROTECTED"); - first = false; - } - if ((access & Opcodes.ACC_FINAL) != 0) { - if (!first) { - buf.append(" + "); - } - buf.append("ACC_FINAL"); - first = false; - } - if ((access & Opcodes.ACC_STATIC) != 0) { - if (!first) { - buf.append(" + "); - } - buf.append("ACC_STATIC"); - first = false; - } - if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) { - if (!first) { - buf.append(" + "); - } - if ((access & ACCESS_CLASS) == 0) { - buf.append("ACC_SYNCHRONIZED"); - } else { - buf.append("ACC_SUPER"); - } - first = false; - } - if ((access & Opcodes.ACC_VOLATILE) != 0 - && (access & ACCESS_FIELD) != 0) - { - if (!first) { - buf.append(" + "); - } - buf.append("ACC_VOLATILE"); - first = false; - } - if ((access & Opcodes.ACC_BRIDGE) != 0 && (access & ACCESS_CLASS) == 0 - && (access & ACCESS_FIELD) == 0) - { - if (!first) { - buf.append(" + "); - } - buf.append("ACC_BRIDGE"); - first = false; - } - if ((access & Opcodes.ACC_VARARGS) != 0 && (access & ACCESS_CLASS) == 0 - && (access & ACCESS_FIELD) == 0) - { - if (!first) { - buf.append(" + "); - } - buf.append("ACC_VARARGS"); - first = false; - } - if ((access & Opcodes.ACC_TRANSIENT) != 0 - && (access & ACCESS_FIELD) != 0) - { - if (!first) { - buf.append(" + "); - } - buf.append("ACC_TRANSIENT"); - first = false; - } - if ((access & Opcodes.ACC_NATIVE) != 0 && (access & ACCESS_CLASS) == 0 - && (access & ACCESS_FIELD) == 0) - { - if (!first) { - buf.append(" + "); - } - buf.append("ACC_NATIVE"); - first = false; - } - if ((access & Opcodes.ACC_ENUM) != 0 - && ((access & ACCESS_CLASS) != 0 - || (access & ACCESS_FIELD) != 0 || (access & ACCESS_INNER) != 0)) - { - if (!first) { - buf.append(" + "); - } - buf.append("ACC_ENUM"); - first = false; - } - if ((access & Opcodes.ACC_ANNOTATION) != 0 - && (access & ACCESS_CLASS) != 0) - { - if (!first) { - buf.append(" + "); - } - buf.append("ACC_ANNOTATION"); - first = false; - } - if ((access & Opcodes.ACC_ABSTRACT) != 0) { - if (!first) { - buf.append(" + "); - } - buf.append("ACC_ABSTRACT"); - first = false; - } - if ((access & Opcodes.ACC_INTERFACE) != 0) { - if (!first) { - buf.append(" + "); - } - buf.append("ACC_INTERFACE"); - first = false; - } - if ((access & Opcodes.ACC_STRICT) != 0) { - if (!first) { - buf.append(" + "); - } - buf.append("ACC_STRICT"); - first = false; - } - if ((access & Opcodes.ACC_SYNTHETIC) != 0) { - if (!first) { - buf.append(" + "); - } - buf.append("ACC_SYNTHETIC"); - first = false; - } - if ((access & Opcodes.ACC_DEPRECATED) != 0) { - if (!first) { - buf.append(" + "); - } - buf.append("ACC_DEPRECATED"); - first = false; - } - if (first) { - buf.append('0'); - } - } -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/89a761eb/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierFieldVisitor.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierFieldVisitor.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierFieldVisitor.java deleted file mode 100644 index 6f0dd5e..0000000 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierFieldVisitor.java +++ /dev/null @@ -1,50 +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 org.apache.tapestry5.internal.plastic.asm.FieldVisitor; - -/** - * A {@link FieldVisitor} that prints the ASM code that generates the fields it - * visits. - * - * @author Eric Bruneton - */ -public class ASMifierFieldVisitor extends ASMifierAbstractVisitor implements - FieldVisitor -{ - - /** - * Constructs a new {@link ASMifierFieldVisitor}. - */ - public ASMifierFieldVisitor() { - super("fv"); - } -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/89a761eb/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierMethodVisitor.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierMethodVisitor.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierMethodVisitor.java deleted file mode 100644 index 7e2600f..0000000 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifierMethodVisitor.java +++ /dev/null @@ -1,443 +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 org.apache.tapestry5.internal.plastic.asm.AnnotationVisitor; -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 java.util.HashMap; - -/** - * A {@link MethodVisitor} that prints the ASM code that generates the methods - * it visits. - * - * @author Eric Bruneton - * @author Eugene Kuleshov - */ -public class ASMifierMethodVisitor extends ASMifierAbstractVisitor implements - MethodVisitor -{ - - /** - * Constructs a new {@link ASMifierMethodVisitor} object. - */ - public ASMifierMethodVisitor() { - super("mv"); - this.labelNames = new HashMap(); - } - - public AnnotationVisitor visitAnnotationDefault() { - buf.setLength(0); - buf.append("{\n").append("av0 = mv.visitAnnotationDefault();\n"); - text.add(buf.toString()); - ASMifierAnnotationVisitor av = new ASMifierAnnotationVisitor(0); - text.add(av.getText()); - text.add("}\n"); - return av; - } - - public AnnotationVisitor visitParameterAnnotation( - final int parameter, - final String desc, - final boolean visible) - { - buf.setLength(0); - buf.append("{\n") - .append("av0 = mv.visitParameterAnnotation(") - .append(parameter) - .append(", "); - appendConstant(desc); - buf.append(", ").append(visible).append(");\n"); - text.add(buf.toString()); - ASMifierAnnotationVisitor av = new ASMifierAnnotationVisitor(0); - text.add(av.getText()); - text.add("}\n"); - return av; - } - - public void visitCode() { - text.add("mv.visitCode();\n"); - } - - public void visitFrame( - final int type, - final int nLocal, - final Object[] local, - final int nStack, - final Object[] stack) - { - buf.setLength(0); - switch (type) { - case Opcodes.F_NEW: - case Opcodes.F_FULL: - declareFrameTypes(nLocal, local); - declareFrameTypes(nStack, stack); - if (type == Opcodes.F_NEW) { - buf.append("mv.visitFrame(Opcodes.F_NEW, "); - } else { - buf.append("mv.visitFrame(Opcodes.F_FULL, "); - } - buf.append(nLocal).append(", new Object[] {"); - appendFrameTypes(nLocal, local); - buf.append("}, ").append(nStack).append(", new Object[] {"); - appendFrameTypes(nStack, stack); - buf.append('}'); - break; - case Opcodes.F_APPEND: - declareFrameTypes(nLocal, local); - buf.append("mv.visitFrame(Opcodes.F_APPEND,") - .append(nLocal) - .append(", new Object[] {"); - appendFrameTypes(nLocal, local); - buf.append("}, 0, null"); - break; - case Opcodes.F_CHOP: - buf.append("mv.visitFrame(Opcodes.F_CHOP,") - .append(nLocal) - .append(", null, 0, null"); - break; - case Opcodes.F_SAME: - buf.append("mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null"); - break; - case Opcodes.F_SAME1: - declareFrameTypes(1, stack); - buf.append("mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"); - appendFrameTypes(1, stack); - buf.append('}'); - break; - } - buf.append(");\n"); - text.add(buf.toString()); - } - - public void visitInsn(final int opcode) { - buf.setLength(0); - buf.append("mv.visitInsn(").append(OPCODES[opcode]).append(");\n"); - text.add(buf.toString()); - } - - public void visitIntInsn(final int opcode, final int operand) { - buf.setLength(0); - buf.append("mv.visitIntInsn(") - .append(OPCODES[opcode]) - .append(", ") - .append(opcode == Opcodes.NEWARRAY - ? TYPES[operand] - : Integer.toString(operand)) - .append(");\n"); - text.add(buf.toString()); - } - - public void visitVarInsn(final int opcode, final int var) { - buf.setLength(0); - buf.append("mv.visitVarInsn(") - .append(OPCODES[opcode]) - .append(", ") - .append(var) - .append(");\n"); - text.add(buf.toString()); - } - - public void visitTypeInsn(final int opcode, final String type) { - buf.setLength(0); - buf.append("mv.visitTypeInsn(").append(OPCODES[opcode]).append(", "); - appendConstant(type); - buf.append(");\n"); - text.add(buf.toString()); - } - - public void visitFieldInsn( - final int opcode, - final String owner, - final String name, - final String desc) - { - buf.setLength(0); - buf.append("mv.visitFieldInsn(").append(OPCODES[opcode]).append(", "); - appendConstant(owner); - buf.append(", "); - appendConstant(name); - buf.append(", "); - appendConstant(desc); - buf.append(");\n"); - text.add(buf.toString()); - } - - public void visitMethodInsn( - final int opcode, - final String owner, - final String name, - final String desc) - { - buf.setLength(0); - buf.append("mv.visitMethodInsn(").append(OPCODES[opcode]).append(", "); - appendConstant(owner); - buf.append(", "); - appendConstant(name); - buf.append(", "); - appendConstant(desc); - buf.append(");\n"); - text.add(buf.toString()); - } - - public void visitJumpInsn(final int opcode, final Label label) { - buf.setLength(0); - declareLabel(label); - buf.append("mv.visitJumpInsn(").append(OPCODES[opcode]).append(", "); - appendLabel(label); - buf.append(");\n"); - text.add(buf.toString()); - } - - public void visitLabel(final Label label) { - buf.setLength(0); - declareLabel(label); - buf.append("mv.visitLabel("); - appendLabel(label); - buf.append(");\n"); - text.add(buf.toString()); - } - - public void visitLdcInsn(final Object cst) { - buf.setLength(0); - buf.append("mv.visitLdcInsn("); - appendConstant(cst); - buf.append(");\n"); - text.add(buf.toString()); - } - - public void visitIincInsn(final int var, final int increment) { - buf.setLength(0); - buf.append("mv.visitIincInsn(") - .append(var) - .append(", ") - .append(increment) - .append(");\n"); - text.add(buf.toString()); - } - - public void visitTableSwitchInsn( - final int min, - final int max, - final Label dflt, - final Label[] labels) - { - buf.setLength(0); - for (int i = 0; i < labels.length; ++i) { - declareLabel(labels[i]); - } - declareLabel(dflt); - - buf.append("mv.visitTableSwitchInsn(") - .append(min) - .append(", ") - .append(max) - .append(", "); - appendLabel(dflt); - buf.append(", new Label[] {"); - for (int i = 0; i < labels.length; ++i) { - buf.append(i == 0 ? " " : ", "); - appendLabel(labels[i]); - } - buf.append(" });\n"); - text.add(buf.toString()); - } - - public void visitLookupSwitchInsn( - final Label dflt, - final int[] keys, - final Label[] labels) - { - buf.setLength(0); - for (int i = 0; i < labels.length; ++i) { - declareLabel(labels[i]); - } - declareLabel(dflt); - - buf.append("mv.visitLookupSwitchInsn("); - appendLabel(dflt); - buf.append(", new int[] {"); - for (int i = 0; i < keys.length; ++i) { - buf.append(i == 0 ? " " : ", ").append(keys[i]); - } - buf.append(" }, new Label[] {"); - for (int i = 0; i < labels.length; ++i) { - buf.append(i == 0 ? " " : ", "); - appendLabel(labels[i]); - } - buf.append(" });\n"); - text.add(buf.toString()); - } - - public void visitMultiANewArrayInsn(final String desc, final int dims) { - buf.setLength(0); - buf.append("mv.visitMultiANewArrayInsn("); - appendConstant(desc); - buf.append(", ").append(dims).append(");\n"); - text.add(buf.toString()); - } - - public void visitTryCatchBlock( - final Label start, - final Label end, - final Label handler, - final String type) - { - buf.setLength(0); - declareLabel(start); - declareLabel(end); - declareLabel(handler); - buf.append("mv.visitTryCatchBlock("); - appendLabel(start); - buf.append(", "); - appendLabel(end); - buf.append(", "); - appendLabel(handler); - buf.append(", "); - appendConstant(type); - buf.append(");\n"); - text.add(buf.toString()); - } - - public void visitLocalVariable( - final String name, - final String desc, - final String signature, - final Label start, - final Label end, - final int index) - { - buf.setLength(0); - buf.append("mv.visitLocalVariable("); - appendConstant(name); - buf.append(", "); - appendConstant(desc); - buf.append(", "); - appendConstant(signature); - buf.append(", "); - appendLabel(start); - buf.append(", "); - appendLabel(end); - buf.append(", ").append(index).append(");\n"); - text.add(buf.toString()); - } - - public void visitLineNumber(final int line, final Label start) { - buf.setLength(0); - buf.append("mv.visitLineNumber(").append(line).append(", "); - appendLabel(start); - buf.append(");\n"); - text.add(buf.toString()); - } - - public void visitMaxs(final int maxStack, final int maxLocals) { - buf.setLength(0); - buf.append("mv.visitMaxs(") - .append(maxStack) - .append(", ") - .append(maxLocals) - .append(");\n"); - text.add(buf.toString()); - } - - private void declareFrameTypes(final int n, final Object[] o) { - for (int i = 0; i < n; ++i) { - if (o[i] instanceof Label) { - declareLabel((Label) o[i]); - } - } - } - - 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) { - appendConstant(o[i]); - } else if (o[i] instanceof Integer) { - switch (((Integer) o[i]).intValue()) { - case 0: - buf.append("Opcodes.TOP"); - break; - case 1: - buf.append("Opcodes.INTEGER"); - break; - case 2: - buf.append("Opcodes.FLOAT"); - break; - case 3: - buf.append("Opcodes.DOUBLE"); - break; - case 4: - buf.append("Opcodes.LONG"); - break; - case 5: - buf.append("Opcodes.NULL"); - break; - case 6: - buf.append("Opcodes.UNINITIALIZED_THIS"); - break; - } - } else { - appendLabel((Label) o[i]); - } - } - } - - /** - * Appends a declaration of the given label to {@link #buf buf}. This - * declaration is of the form "Label lXXX = new Label();". Does nothing if - * the given label has already been declared. - * - * @param l a label. - */ - private void declareLabel(final Label l) { - String name = (String) labelNames.get(l); - if (name == null) { - name = "l" + labelNames.size(); - labelNames.put(l, name); - buf.append("Label ").append(name).append(" = new Label();\n"); - } - } - - /** - * Appends the name of the given label to {@link #buf buf}. The given label - * must already have a name. One way to ensure this is to always - * call {@link #declareLabel declared} before calling this method. - * - * @param l a label. - */ - private void appendLabel(final Label l) { - buf.append((String) labelNames.get(l)); - } -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/89a761eb/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/AbstractVisitor.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/AbstractVisitor.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/AbstractVisitor.java deleted file mode 100644 index 1948df6..0000000 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/AbstractVisitor.java +++ /dev/null @@ -1,202 +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.io.PrintWriter; -import java.util.ArrayList; -import java.util.List; - -import org.apache.tapestry5.internal.plastic.asm.Attribute; - -/** - * An abstract visitor. - * - * @author Eric Bruneton - */ -public abstract class AbstractVisitor { - - /** - * The names of the Java Virtual Machine opcodes. - */ - public static final String[] OPCODES; - /** - * Types for operand parameter of the - * {@link org.apache.tapestry5.internal.plastic.asm.MethodVisitor#visitIntInsn} method when - * opcode is NEWARRAY. - */ - public static final String[] TYPES; - - static { - String s = "NOP,ACONST_NULL,ICONST_M1,ICONST_0,ICONST_1,ICONST_2," - + "ICONST_3,ICONST_4,ICONST_5,LCONST_0,LCONST_1,FCONST_0," - + "FCONST_1,FCONST_2,DCONST_0,DCONST_1,BIPUSH,SIPUSH,LDC,,," - + "ILOAD,LLOAD,FLOAD,DLOAD,ALOAD,,,,,,,,,,,,,,,,,,,,,IALOAD," - + "LALOAD,FALOAD,DALOAD,AALOAD,BALOAD,CALOAD,SALOAD,ISTORE," - + "LSTORE,FSTORE,DSTORE,ASTORE,,,,,,,,,,,,,,,,,,,,,IASTORE," - + "LASTORE,FASTORE,DASTORE,AASTORE,BASTORE,CASTORE,SASTORE,POP," - + "POP2,DUP,DUP_X1,DUP_X2,DUP2,DUP2_X1,DUP2_X2,SWAP,IADD,LADD," - + "FADD,DADD,ISUB,LSUB,FSUB,DSUB,IMUL,LMUL,FMUL,DMUL,IDIV,LDIV," - + "FDIV,DDIV,IREM,LREM,FREM,DREM,INEG,LNEG,FNEG,DNEG,ISHL,LSHL," - + "ISHR,LSHR,IUSHR,LUSHR,IAND,LAND,IOR,LOR,IXOR,LXOR,IINC,I2L," - + "I2F,I2D,L2I,L2F,L2D,F2I,F2L,F2D,D2I,D2L,D2F,I2B,I2C,I2S,LCMP," - + "FCMPL,FCMPG,DCMPL,DCMPG,IFEQ,IFNE,IFLT,IFGE,IFGT,IFLE," - + "IF_ICMPEQ,IF_ICMPNE,IF_ICMPLT,IF_ICMPGE,IF_ICMPGT,IF_ICMPLE," - + "IF_ACMPEQ,IF_ACMPNE,GOTO,JSR,RET,TABLESWITCH,LOOKUPSWITCH," - + "IRETURN,LRETURN,FRETURN,DRETURN,ARETURN,RETURN,GETSTATIC," - + "PUTSTATIC,GETFIELD,PUTFIELD,INVOKEVIRTUAL,INVOKESPECIAL," - + "INVOKESTATIC,INVOKEINTERFACE,INVOKEDYNAMIC,NEW,NEWARRAY," - + "ANEWARRAY,ARRAYLENGTH,ATHROW,CHECKCAST,INSTANCEOF," - + "MONITORENTER,MONITOREXIT,,MULTIANEWARRAY,IFNULL,IFNONNULL,"; - OPCODES = new String[200]; - int i = 0; - int j = 0; - int l; - while ((l = s.indexOf(',', j)) > 0) { - OPCODES[i++] = j + 1 == l ? null : s.substring(j, l); - j = l + 1; - } - - s = "T_BOOLEAN,T_CHAR,T_FLOAT,T_DOUBLE,T_BYTE,T_SHORT,T_INT,T_LONG,"; - TYPES = new String[12]; - j = 0; - i = 4; - while ((l = s.indexOf(',', j)) > 0) { - TYPES[i++] = s.substring(j, l); - j = l + 1; - } - } - - /** - * The text to be printed. Since the code of methods is not necessarily - * visited in sequential order, one method after the other, but can be - * interlaced (some instructions from method one, then some instructions - * from method two, then some instructions from method one again...), it is - * not possible to print the visited instructions directly to a sequential - * stream. A class is therefore printed in a two steps process: a string - * tree is constructed during the visit, and printed to a sequential stream - * at the end of the visit. This string tree is stored in this field, as a - * string list that can contain other string lists, which can themselves - * contain other string lists, and so on. - */ - public final List text; - - /** - * A buffer that can be used to create strings. - */ - protected final StringBuffer buf; - - /** - * Constructs a new {@link AbstractVisitor}. - */ - protected AbstractVisitor() { - this.text = new ArrayList(); - this.buf = new StringBuffer(); - } - - /** - * Returns the text constructed by this visitor. - * - * @return the text constructed by this visitor. - */ - public List getText() { - return text; - } - - /** - * Prints the text constructed by this visitor. - * - * @param pw the print writer to be used. - */ - public void print(final PrintWriter pw) { - printList(pw, text); - } - - /** - * Appends a quoted string to a given buffer. - * - * @param buf the buffer where the string must be added. - * @param s the string to be added. - */ - public static void appendString(final StringBuffer buf, final String s) { - buf.append('\"'); - for (int i = 0; i < s.length(); ++i) { - char c = s.charAt(i); - if (c == '\n') { - buf.append("\\n"); - } else if (c == '\r') { - buf.append("\\r"); - } else if (c == '\\') { - buf.append("\\\\"); - } else if (c == '"') { - buf.append("\\\""); - } else if (c < 0x20 || c > 0x7f) { - buf.append("\\u"); - if (c < 0x10) { - buf.append("000"); - } else if (c < 0x100) { - buf.append("00"); - } else if (c < 0x1000) { - buf.append('0'); - } - buf.append(Integer.toString(c, 16)); - } else { - buf.append(c); - } - } - buf.append('\"'); - } - - /** - * Prints the given string tree. - * - * @param pw the writer to be used to print the tree. - * @param l a string tree, i.e., a string list that can contain other string - * lists, and so on recursively. - */ - static void printList(final PrintWriter pw, final List l) { - for (int i = 0; i < l.size(); ++i) { - Object o = l.get(i); - if (o instanceof List) { - printList(pw, (List) o); - } else { - pw.print(o.toString()); - } - } - } - - /** - * Returns the default {@link ASMifiable} prototypes. - * - * @return the default {@link ASMifiable} prototypes. - */ - public static Attribute[] getDefaultAttributes() { - return new Attribute[0]; - } -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/89a761eb/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckAnnotationAdapter.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckAnnotationAdapter.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckAnnotationAdapter.java deleted file mode 100644 index 2b1f53c..0000000 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckAnnotationAdapter.java +++ /dev/null @@ -1,132 +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 org.apache.tapestry5.internal.plastic.asm.AnnotationVisitor; -import org.apache.tapestry5.internal.plastic.asm.Type; - -/** - * An {@link AnnotationVisitor} that checks that its methods are properly used. - * - * @author Eric Bruneton - */ -public class CheckAnnotationAdapter implements AnnotationVisitor { - - private final AnnotationVisitor av; - - private final boolean named; - - private boolean end; - - public CheckAnnotationAdapter(final AnnotationVisitor av) { - this(av, true); - } - - CheckAnnotationAdapter(final AnnotationVisitor av, final boolean named) { - this.av = av; - this.named = named; - } - - public void visit(final String name, final Object value) { - checkEnd(); - checkName(name); - if (!(value instanceof Byte || value instanceof Boolean - || value instanceof Character || value instanceof Short - || value instanceof Integer || value instanceof Long - || value instanceof Float || value instanceof Double - || value instanceof String || value instanceof Type - || value instanceof byte[] || value instanceof boolean[] - || value instanceof char[] || value instanceof short[] - || value instanceof int[] || value instanceof long[] - || value instanceof float[] || value instanceof double[])) - { - throw new IllegalArgumentException("Invalid annotation value"); - } - if (av != null) { - av.visit(name, value); - } - } - - public void visitEnum( - final String name, - final String desc, - final String value) - { - checkEnd(); - checkName(name); - CheckMethodAdapter.checkDesc(desc, false); - if (value == null) { - throw new IllegalArgumentException("Invalid enum value"); - } - if (av != null) { - av.visitEnum(name, desc, value); - } - } - - public AnnotationVisitor visitAnnotation( - final String name, - final String desc) - { - checkEnd(); - checkName(name); - CheckMethodAdapter.checkDesc(desc, false); - return new CheckAnnotationAdapter(av == null - ? null - : av.visitAnnotation(name, desc)); - } - - public AnnotationVisitor visitArray(final String name) { - checkEnd(); - checkName(name); - return new CheckAnnotationAdapter(av == null - ? null - : av.visitArray(name), false); - } - - public void visitEnd() { - checkEnd(); - end = true; - if (av != null) { - av.visitEnd(); - } - } - - private void checkEnd() { - if (end) { - throw new IllegalStateException("Cannot call a visit method after visitEnd has been called"); - } - } - - private void checkName(final String name) { - if (named && name == null) { - throw new IllegalArgumentException("Annotation value name must not be null"); - } - } -}