http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/LocalVariableAnnotationNode.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/LocalVariableAnnotationNode.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/LocalVariableAnnotationNode.java index 27f6e09..8da8627 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/LocalVariableAnnotationNode.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/LocalVariableAnnotationNode.java @@ -93,7 +93,7 @@ public class LocalVariableAnnotationNode extends TypeAnnotationNode { */ public LocalVariableAnnotationNode(int typeRef, TypePath typePath, LabelNode[] start, LabelNode[] end, int[] index, String desc) { - this(Opcodes.ASM5, typeRef, typePath, start, end, index, desc); + this(Opcodes.ASM6, typeRef, typePath, start, end, index, desc); } /** @@ -101,7 +101,7 @@ public class LocalVariableAnnotationNode extends TypeAnnotationNode { * * @param api * the ASM API version implemented by this visitor. Must be one - * of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}. + * of {@link Opcodes#ASM4}, {@link Opcodes#ASM5} or {@link Opcodes#ASM6}. * @param typeRef * a reference to the annotated type. See {@link TypeReference}. * @param start @@ -152,6 +152,6 @@ public class LocalVariableAnnotationNode extends TypeAnnotationNode { index[i] = this.index.get(i); } accept(mv.visitLocalVariableAnnotation(typeRef, typePath, start, end, - index, desc, true)); + index, desc, visible)); } }
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/MethodInsnNode.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/MethodInsnNode.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/MethodInsnNode.java index bc90ddd..8d86df7 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/MethodInsnNode.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/MethodInsnNode.java @@ -44,7 +44,7 @@ public class MethodInsnNode extends AbstractInsnNode { /** * The internal name of the method's owner class (see - * {@link org.apache.tapestry5.internal.plastic.asm.Type#getInternalName() getInternalName}). + * {@link org.objectweb.asm.Type#getInternalName() getInternalName}). */ public String owner; @@ -54,7 +54,7 @@ public class MethodInsnNode extends AbstractInsnNode { public String name; /** - * The method's descriptor (see {@link org.apache.tapestry5.internal.plastic.asm.Type}). + * The method's descriptor (see {@link org.objectweb.asm.Type}). */ public String desc; @@ -72,12 +72,12 @@ public class MethodInsnNode extends AbstractInsnNode { * INVOKEINTERFACE. * @param owner * the internal name of the method's owner class (see - * {@link org.apache.tapestry5.internal.plastic.asm.Type#getInternalName() + * {@link org.objectweb.asm.Type#getInternalName() * getInternalName}). * @param name * the method's name. * @param desc - * the method's descriptor (see {@link org.apache.tapestry5.internal.plastic.asm.Type}). + * the method's descriptor (see {@link org.objectweb.asm.Type}). */ @Deprecated public MethodInsnNode(final int opcode, final String owner, @@ -94,12 +94,12 @@ public class MethodInsnNode extends AbstractInsnNode { * INVOKEINTERFACE. * @param owner * the internal name of the method's owner class (see - * {@link org.apache.tapestry5.internal.plastic.asm.Type#getInternalName() + * {@link org.objectweb.asm.Type#getInternalName() * getInternalName}). * @param name * the method's name. * @param desc - * the method's descriptor (see {@link org.apache.tapestry5.internal.plastic.asm.Type}). + * the method's descriptor (see {@link org.objectweb.asm.Type}). * @param itf * if the method's owner class is an interface. */ http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/MethodNode.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/MethodNode.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/MethodNode.java index 3827653..68b4e31 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/MethodNode.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/MethodNode.java @@ -29,7 +29,6 @@ */ package org.apache.tapestry5.internal.plastic.asm.tree; -import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -88,7 +87,7 @@ public class MethodNode extends MethodVisitor { * The runtime visible annotations of this method. This list is a list of * {@link AnnotationNode} objects. May be <tt>null</tt>. * - * @associates org.apache.tapestry5.internal.plastic.asm.tree.AnnotationNode + * @associates org.objectweb.asm.tree.AnnotationNode * @label visible */ public List<AnnotationNode> visibleAnnotations; @@ -97,7 +96,7 @@ public class MethodNode extends MethodVisitor { * The runtime invisible annotations of this method. This list is a list of * {@link AnnotationNode} objects. May be <tt>null</tt>. * - * @associates org.apache.tapestry5.internal.plastic.asm.tree.AnnotationNode + * @associates org.objectweb.asm.tree.AnnotationNode * @label invisible */ public List<AnnotationNode> invisibleAnnotations; @@ -106,7 +105,7 @@ public class MethodNode extends MethodVisitor { * The runtime visible type annotations of this method. This list is a list * of {@link TypeAnnotationNode} objects. May be <tt>null</tt>. * - * @associates org.apache.tapestry5.internal.plastic.asm.tree.TypeAnnotationNode + * @associates org.objectweb.asm.tree.TypeAnnotationNode * @label visible */ public List<TypeAnnotationNode> visibleTypeAnnotations; @@ -115,7 +114,7 @@ public class MethodNode extends MethodVisitor { * The runtime invisible type annotations of this method. This list is a * list of {@link TypeAnnotationNode} objects. May be <tt>null</tt>. * - * @associates org.apache.tapestry5.internal.plastic.asm.tree.TypeAnnotationNode + * @associates org.objectweb.asm.tree.TypeAnnotationNode * @label invisible */ public List<TypeAnnotationNode> invisibleTypeAnnotations; @@ -124,7 +123,7 @@ public class MethodNode extends MethodVisitor { * The non standard attributes of this method. This list is a list of * {@link Attribute} objects. May be <tt>null</tt>. * - * @associates org.apache.tapestry5.internal.plastic.asm.Attribute + * @associates org.objectweb.asm.Attribute */ public List<Attribute> attrs; @@ -142,7 +141,7 @@ public class MethodNode extends MethodVisitor { * The runtime visible parameter annotations of this method. These lists are * lists of {@link AnnotationNode} objects. May be <tt>null</tt>. * - * @associates org.apache.tapestry5.internal.plastic.asm.tree.AnnotationNode + * @associates org.objectweb.asm.tree.AnnotationNode * @label invisible parameters */ public List<AnnotationNode>[] visibleParameterAnnotations; @@ -151,7 +150,7 @@ public class MethodNode extends MethodVisitor { * The runtime invisible parameter annotations of this method. These lists * are lists of {@link AnnotationNode} objects. May be <tt>null</tt>. * - * @associates org.apache.tapestry5.internal.plastic.asm.tree.AnnotationNode + * @associates org.objectweb.asm.tree.AnnotationNode * @label visible parameters */ public List<AnnotationNode>[] invisibleParameterAnnotations; @@ -160,7 +159,7 @@ public class MethodNode extends MethodVisitor { * The instructions of this method. This list is a list of * {@link AbstractInsnNode} objects. * - * @associates org.apache.tapestry5.internal.plastic.asm.tree.AbstractInsnNode + * @associates org.objectweb.asm.tree.AbstractInsnNode * @label instructions */ public InsnList instructions; @@ -169,7 +168,7 @@ public class MethodNode extends MethodVisitor { * The try catch blocks of this method. This list is a list of * {@link TryCatchBlockNode} objects. * - * @associates org.apache.tapestry5.internal.plastic.asm.tree.TryCatchBlockNode + * @associates org.objectweb.asm.tree.TryCatchBlockNode */ public List<TryCatchBlockNode> tryCatchBlocks; @@ -187,7 +186,7 @@ public class MethodNode extends MethodVisitor { * The local variables of this method. This list is a list of * {@link LocalVariableNode} objects. May be <tt>null</tt> * - * @associates org.apache.tapestry5.internal.plastic.asm.tree.LocalVariableNode + * @associates org.objectweb.asm.tree.LocalVariableNode */ public List<LocalVariableNode> localVariables; @@ -195,7 +194,7 @@ public class MethodNode extends MethodVisitor { * The visible local variable annotations of this method. This list is a * list of {@link LocalVariableAnnotationNode} objects. May be <tt>null</tt> * - * @associates org.apache.tapestry5.internal.plastic.asm.tree.LocalVariableAnnotationNode + * @associates org.objectweb.asm.tree.LocalVariableAnnotationNode */ public List<LocalVariableAnnotationNode> visibleLocalVariableAnnotations; @@ -203,7 +202,7 @@ public class MethodNode extends MethodVisitor { * The invisible local variable annotations of this method. This list is a * list of {@link LocalVariableAnnotationNode} objects. May be <tt>null</tt> * - * @associates org.apache.tapestry5.internal.plastic.asm.tree.LocalVariableAnnotationNode + * @associates org.objectweb.asm.tree.LocalVariableAnnotationNode */ public List<LocalVariableAnnotationNode> invisibleLocalVariableAnnotations; @@ -221,7 +220,7 @@ public class MethodNode extends MethodVisitor { * If a subclass calls this constructor. */ public MethodNode() { - this(Opcodes.ASM5); + this(Opcodes.ASM6); if (getClass() != MethodNode.class) { throw new IllegalStateException(); } @@ -232,7 +231,7 @@ public class MethodNode extends MethodVisitor { * * @param api * the ASM API version implemented by this visitor. Must be one - * of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}. + * of {@link Opcodes#ASM4}, {@link Opcodes#ASM5} or {@link Opcodes#ASM6}. */ public MethodNode(final int api) { super(api); @@ -263,7 +262,7 @@ public class MethodNode extends MethodVisitor { */ public MethodNode(final int access, final String name, final String desc, final String signature, final String[] exceptions) { - this(Opcodes.ASM5, access, name, desc, signature, exceptions); + this(Opcodes.ASM6, access, name, desc, signature, exceptions); if (getClass() != MethodNode.class) { throw new IllegalStateException(); } @@ -274,7 +273,7 @@ public class MethodNode extends MethodVisitor { * * @param api * the ASM API version implemented by this visitor. Must be one - * of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}. + * of {@link Opcodes#ASM4}, {@link Opcodes#ASM5} or {@link Opcodes#ASM6}. * @param access * the method's access flags (see {@link Opcodes}). This * parameter also indicates if the method is synthetic and/or @@ -660,8 +659,8 @@ public class MethodNode extends MethodVisitor { * versions of the ASM API than the given version. * * @param api - * an ASM API version. Must be one of {@link Opcodes#ASM4} or - * {@link Opcodes#ASM5}. + * an ASM API version. Must be one of {@link Opcodes#ASM4}, + * {@link Opcodes#ASM5} or {@link Opcodes#ASM6}. */ public void check(final int api) { if (api == Opcodes.ASM4) { @@ -838,11 +837,4 @@ public class MethodNode extends MethodVisitor { } mv.visitEnd(); } - - @Override - public String toString() { - return "MethodNode [name=" + name + ", bridge=" + Modifier.isVolatile(access) - + ", desc=" + desc + "]"; - } - } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleExportNode.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleExportNode.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleExportNode.java new file mode 100644 index 0000000..946872d --- /dev/null +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleExportNode.java @@ -0,0 +1,82 @@ +/*** + * ASM: a very small and fast Java bytecode manipulation framework + * Copyright (c) 2000-2011 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.tree; + +import java.util.List; + +import org.apache.tapestry5.internal.plastic.asm.ModuleVisitor; + +/** + * A node that represents an exported package with its name and the module that can access to it. + * + * @author Remi Forax + */ +public class ModuleExportNode { + /** + * The package name. + */ + public String packaze; + + /** + * The access flags (see {@link org.objectweb.asm.Opcodes}). + * Valid values are {@code ACC_SYNTHETIC} and {@code ACC_MANDATED}. + */ + public int access; + + /** + * A list of modules that can access to this exported package. + * May be <tt>null</tt>. + */ + public List<String> modules; + + /** + * Constructs a new {@link ModuleExportNode}. + * + * @param packaze + * the parameter's name. + * @param modules + * a list of modules that can access to this exported package. + */ + public ModuleExportNode(final String packaze, final int access, final List<String> modules) { + this.packaze = packaze; + this.access = access; + this.modules = modules; + } + + /** + * Makes the given module visitor visit this export declaration. + * + * @param mv + * a module visitor. + */ + public void accept(final ModuleVisitor mv) { + mv.visitExport(packaze, access, (modules == null) ? null : modules.toArray(new String[0])); + } +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleNode.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleNode.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleNode.java new file mode 100644 index 0000000..e76dbf1 --- /dev/null +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleNode.java @@ -0,0 +1,251 @@ +/*** + * ASM: a very small and fast Java bytecode manipulation framework + * Copyright (c) 2000-2011 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.tree; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tapestry5.internal.plastic.asm.ClassVisitor; +import org.apache.tapestry5.internal.plastic.asm.ModuleVisitor; +import org.apache.tapestry5.internal.plastic.asm.Opcodes; + +/** + * A node that represents a module declaration. + * + * @author Remi Forax + */ +public class ModuleNode extends ModuleVisitor { + /** + * Module name + */ + public String name; + + /** + * Module access flags, among {@code ACC_OPEN}, {@code ACC_SYNTHETIC} + * and {@code ACC_MANDATED}. + */ + public int access; + + /** + * Version of the module. + * May be <tt>null</tt>. + */ + public String version; + + /** + * Name of the main class in internal form + * May be <tt>null</tt>. + */ + public String mainClass; + + /** + * A list of packages that are declared by the current module. + * May be <tt>null</tt>. + */ + public List<String> packages; + + /** + * A list of modules can are required by the current module. + * May be <tt>null</tt>. + */ + public List<ModuleRequireNode> requires; + + /** + * A list of packages that are exported by the current module. + * May be <tt>null</tt>. + */ + public List<ModuleExportNode> exports; + + /** + * A list of packages that are opened by the current module. + * May be <tt>null</tt>. + */ + public List<ModuleOpenNode> opens; + + /** + * A list of classes in their internal forms that are used + * as a service by the current module. May be <tt>null</tt>. + */ + public List<String> uses; + + /** + * A list of services along with their implementations provided + * by the current module. May be <tt>null</tt>. + */ + public List<ModuleProvideNode> provides; + + public ModuleNode(final String name, final int access, + final String version) { + super(Opcodes.ASM6); + this.name = name; + this.access = access; + this.version = version; + } + + public ModuleNode(final int api, + final String name, + final int access, + final String version, + final List<ModuleRequireNode> requires, + final List<ModuleExportNode> exports, + final List<ModuleOpenNode> opens, + final List<String> uses, + final List<ModuleProvideNode> provides) { + super(api); + this.name = name; + this.access = access; + this.version = version; + this.requires = requires; + this.exports = exports; + this.opens = opens; + this.uses = uses; + this.provides = provides; + if (getClass() != ModuleNode.class) { + throw new IllegalStateException(); + } + } + + @Override + public void visitMainClass(String mainClass) { + this.mainClass = mainClass; + } + + @Override + public void visitPackage(String packaze) { + if (packages == null) { + packages = new ArrayList<String>(5); + } + packages.add(packaze); + } + + @Override + public void visitRequire(String module, int access, String version) { + if (requires == null) { + requires = new ArrayList<ModuleRequireNode>(5); + } + requires.add(new ModuleRequireNode(module, access, version)); + } + + @Override + public void visitExport(String packaze, int access, String... modules) { + if (exports == null) { + exports = new ArrayList<ModuleExportNode>(5); + } + List<String> moduleList = null; + if (modules != null) { + moduleList = new ArrayList<String>(modules.length); + for (int i = 0; i < modules.length; i++) { + moduleList.add(modules[i]); + } + } + exports.add(new ModuleExportNode(packaze, access, moduleList)); + } + + @Override + public void visitOpen(String packaze, int access, String... modules) { + if (opens == null) { + opens = new ArrayList<ModuleOpenNode>(5); + } + List<String> moduleList = null; + if (modules != null) { + moduleList = new ArrayList<String>(modules.length); + for (int i = 0; i < modules.length; i++) { + moduleList.add(modules[i]); + } + } + opens.add(new ModuleOpenNode(packaze, access, moduleList)); + } + + @Override + public void visitUse(String service) { + if (uses == null) { + uses = new ArrayList<String>(5); + } + uses.add(service); + } + + @Override + public void visitProvide(String service, String... providers) { + if (provides == null) { + provides = new ArrayList<ModuleProvideNode>(5); + } + ArrayList<String> providerList = + new ArrayList<String>(providers.length); + for (int i = 0; i < providers.length; i++) { + providerList.add(providers[i]); + } + provides.add(new ModuleProvideNode(service, providerList)); + } + + @Override + public void visitEnd() { + } + + public void accept(final ClassVisitor cv) { + ModuleVisitor mv = cv.visitModule(name, access, version); + if (mv == null) { + return; + } + if (mainClass != null) { + mv.visitMainClass(mainClass); + } + if (packages != null) { + for (int i = 0; i < packages.size(); i++) { + mv.visitPackage(packages.get(i)); + } + } + + if (requires != null) { + for (int i = 0; i < requires.size(); i++) { + requires.get(i).accept(mv); + } + } + if (exports != null) { + for (int i = 0; i < exports.size(); i++) { + exports.get(i).accept(mv); + } + } + if (opens != null) { + for (int i = 0; i < opens.size(); i++) { + opens.get(i).accept(mv); + } + } + if (uses != null) { + for (int i = 0; i < uses.size(); i++) { + mv.visitUse(uses.get(i)); + } + } + if (provides != null) { + for (int i = 0; i < provides.size(); i++) { + provides.get(i).accept(mv); + } + } + } +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleOpenNode.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleOpenNode.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleOpenNode.java new file mode 100644 index 0000000..957340d --- /dev/null +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleOpenNode.java @@ -0,0 +1,82 @@ +/*** + * ASM: a very small and fast Java bytecode manipulation framework + * Copyright (c) 2000-2011 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.tree; + +import java.util.List; + +import org.apache.tapestry5.internal.plastic.asm.ModuleVisitor; + +/** + * A node that represents an opened package with its name and the module that can access to it. + * + * @author Remi Forax + */ +public class ModuleOpenNode { + /** + * The package name. + */ + public String packaze; + + /** + * The access flags (see {@link org.objectweb.asm.Opcodes}). + * Valid values are {@code ACC_SYNTHETIC} and {@code ACC_MANDATED}. + */ + public int access; + + /** + * A list of modules that can access to this exported package. + * May be <tt>null</tt>. + */ + public List<String> modules; + + /** + * Constructs a new {@link ModuleOpenNode}. + * + * @param packaze + * the parameter's name. + * @param modules + * a list of modules that can access to this open package. + */ + public ModuleOpenNode(final String packaze, final int access, final List<String> modules) { + this.packaze = packaze; + this.access = access; + this.modules = modules; + } + + /** + * Makes the given module visitor visit this open declaration. + * + * @param mv + * a module visitor. + */ + public void accept(final ModuleVisitor mv) { + mv.visitExport(packaze, access, (modules == null) ? null : modules.toArray(new String[0])); + } +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleProvideNode.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleProvideNode.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleProvideNode.java new file mode 100644 index 0000000..4225f56 --- /dev/null +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleProvideNode.java @@ -0,0 +1,74 @@ +/*** + * ASM: a very small and fast Java bytecode manipulation framework + * Copyright (c) 2000-2011 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.tree; + +import java.util.List; + +import org.apache.tapestry5.internal.plastic.asm.ModuleVisitor; + +/** + * A node that represents a service and its implementation provided by the current module. + * + * @author Remi Forax + */ +public class ModuleProvideNode { + /** + * The service name (in its internal form). + */ + public String service; + + /** + * The service provider names (in their internal form). + */ + public List<String> providers; + + /** + * Constructs a new {@link ModuleProvideNode}. + * + * @param service + * the service name (in its internal form). + * @param providers + * the service provider names (in their internal form). + */ + public ModuleProvideNode(final String service, final List<String> providers) { + this.service = service; + this.providers = providers; + } + + /** + * Makes the given module visitor visit this require declaration. + * + * @param mv + * a module visitor. + */ + public void accept(final ModuleVisitor mv) { + mv.visitProvide(service, providers.toArray(new String[0])); + } +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleRequireNode.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleRequireNode.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleRequireNode.java new file mode 100644 index 0000000..83e8897 --- /dev/null +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ModuleRequireNode.java @@ -0,0 +1,87 @@ +/*** + * ASM: a very small and fast Java bytecode manipulation framework + * Copyright (c) 2000-2011 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.tree; + +import org.apache.tapestry5.internal.plastic.asm.ModuleVisitor; + +/** + * A node that represents a required module with its name and access of a module descriptor. + * + * @author Remi Forax + */ +public class ModuleRequireNode { + /** + * The name of the required module. + */ + public String module; + + /** + * The access flags (see {@link org.objectweb.asm.Opcodes}). + * Valid values are <tt>ACC_TRANSITIVE</tt>, <tt>ACC_STATIC_PHASE</tt>, + * <tt>ACC_SYNTHETIC</tt> and <tt>ACC_MANDATED</tt>. + */ + public int access; + + /** + * Version at compile time of the required module or null. + */ + public String version; + + /** + * Constructs a new {@link ModuleRequireNode}. + * + * @param module + * the name of the required module. + * @param access + * The access flags. Valid values are + * <tt>ACC_TRANSITIVE</tt>, <tt>ACC_STATIC_PHASE</tt>, + * <tt>ACC_SYNTHETIC</tt> and <tt>ACC_MANDATED</tt> + * (see {@link org.objectweb.asm.Opcodes}). + * @param version + * Version of the required module at compile time, + * null if not defined. + */ + public ModuleRequireNode(final String module, final int access, + final String version) { + this.module = module; + this.access = access; + this.version = version; + } + + /** + * Makes the given module visitor visit this require directive. + * + * @param mv + * a module visitor. + */ + public void accept(final ModuleVisitor mv) { + mv.visitRequire(module, access, version); + } +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/MultiANewArrayInsnNode.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/MultiANewArrayInsnNode.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/MultiANewArrayInsnNode.java index f0d2b6b..065ad59 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/MultiANewArrayInsnNode.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/MultiANewArrayInsnNode.java @@ -42,7 +42,7 @@ import org.apache.tapestry5.internal.plastic.asm.Opcodes; public class MultiANewArrayInsnNode extends AbstractInsnNode { /** - * An array type descriptor (see {@link org.apache.tapestry5.internal.plastic.asm.Type}). + * An array type descriptor (see {@link org.objectweb.asm.Type}). */ public String desc; @@ -55,7 +55,7 @@ public class MultiANewArrayInsnNode extends AbstractInsnNode { * Constructs a new {@link MultiANewArrayInsnNode}. * * @param desc - * an array type descriptor (see {@link org.apache.tapestry5.internal.plastic.asm.Type}). + * an array type descriptor (see {@link org.objectweb.asm.Type}). * @param dims * number of dimensions of the array to allocate. */ http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ParameterNode.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ParameterNode.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ParameterNode.java index d5435de..001ddb9 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ParameterNode.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/ParameterNode.java @@ -43,7 +43,7 @@ public class ParameterNode { public String name; /** - * The parameter's access flags (see {@link org.apache.tapestry5.internal.plastic.asm.Opcodes}). + * The parameter's access flags (see {@link org.objectweb.asm.Opcodes}). * Valid values are <tt>ACC_FINAL</tt>, <tt>ACC_SYNTHETIC</tt> and * <tt>ACC_MANDATED</tt>. */ @@ -55,7 +55,7 @@ public class ParameterNode { * @param access * The parameter's access flags. Valid values are * <tt>ACC_FINAL</tt>, <tt>ACC_SYNTHETIC</tt> or/and - * <tt>ACC_MANDATED</tt> (see {@link org.apache.tapestry5.internal.plastic.asm.Opcodes}). + * <tt>ACC_MANDATED</tt> (see {@link org.objectweb.asm.Opcodes}). * @param name * the parameter's name. */ http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/TryCatchBlockNode.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/TryCatchBlockNode.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/TryCatchBlockNode.java index 2609dda..a4c8dde 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/TryCatchBlockNode.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/TryCatchBlockNode.java @@ -66,7 +66,7 @@ public class TryCatchBlockNode { * list is a list of {@link TypeAnnotationNode} objects. May be * <tt>null</tt>. * - * @associates org.apache.tapestry5.internal.plastic.asm.tree.TypeAnnotationNode + * @associates org.objectweb.asm.tree.TypeAnnotationNode * @label visible */ public List<TypeAnnotationNode> visibleTypeAnnotations; @@ -76,7 +76,7 @@ public class TryCatchBlockNode { * This list is a list of {@link TypeAnnotationNode} objects. May be * <tt>null</tt>. * - * @associates org.apache.tapestry5.internal.plastic.asm.tree.TypeAnnotationNode + * @associates org.objectweb.asm.tree.TypeAnnotationNode * @label invisible */ public List<TypeAnnotationNode> invisibleTypeAnnotations; http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/TypeAnnotationNode.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/TypeAnnotationNode.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/TypeAnnotationNode.java index 66ec2d3..43445ae 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/TypeAnnotationNode.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/TypeAnnotationNode.java @@ -70,7 +70,7 @@ public class TypeAnnotationNode extends AnnotationNode { */ public TypeAnnotationNode(final int typeRef, final TypePath typePath, final String desc) { - this(Opcodes.ASM5, typeRef, typePath, desc); + this(Opcodes.ASM6, typeRef, typePath, desc); if (getClass() != TypeAnnotationNode.class) { throw new IllegalStateException(); } @@ -81,7 +81,7 @@ public class TypeAnnotationNode extends AnnotationNode { * * @param api * the ASM API version implemented by this visitor. Must be one - * of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}. + * of {@link Opcodes#ASM4}, {@link Opcodes#ASM5} or {@link Opcodes#ASM6}. * @param typeRef * a reference to the annotated type. See {@link TypeReference}. * @param typePath http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/TypeInsnNode.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/TypeInsnNode.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/TypeInsnNode.java index b4572e5..9811d25 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/TypeInsnNode.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/TypeInsnNode.java @@ -43,7 +43,7 @@ public class TypeInsnNode extends AbstractInsnNode { /** * The operand of this instruction. This operand is an internal name (see - * {@link org.apache.tapestry5.internal.plastic.asm.Type}). + * {@link org.objectweb.asm.Type}). */ public String desc; @@ -55,7 +55,7 @@ public class TypeInsnNode extends AbstractInsnNode { * opcode must be NEW, ANEWARRAY, CHECKCAST or INSTANCEOF. * @param desc * the operand of the instruction to be constructed. This operand - * is an internal name (see {@link org.apache.tapestry5.internal.plastic.asm.Type}). + * is an internal name (see {@link org.objectweb.asm.Type}). */ public TypeInsnNode(final int opcode, final String desc) { super(opcode); http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/BasicInterpreter.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/BasicInterpreter.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/BasicInterpreter.java index 0656c65..b025094 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/BasicInterpreter.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/BasicInterpreter.java @@ -53,7 +53,7 @@ public class BasicInterpreter extends Interpreter<BasicValue> implements Opcodes { public BasicInterpreter() { - super(ASM5); + super(ASM6); } protected BasicInterpreter(final int api) { http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/BasicVerifier.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/BasicVerifier.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/BasicVerifier.java index 50f4a84..c856b14 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/BasicVerifier.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/BasicVerifier.java @@ -47,7 +47,7 @@ import org.apache.tapestry5.internal.plastic.asm.tree.MethodInsnNode; public class BasicVerifier extends BasicInterpreter { public BasicVerifier() { - super(ASM5); + super(ASM6); } protected BasicVerifier(final int api) { http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/SimpleVerifier.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/SimpleVerifier.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/SimpleVerifier.java index c53beb4..0cc2f28 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/SimpleVerifier.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/SimpleVerifier.java @@ -107,7 +107,7 @@ public class SimpleVerifier extends BasicVerifier { public SimpleVerifier(final Type currentClass, final Type currentSuperClass, final List<Type> currentClassInterfaces, final boolean isInterface) { - this(ASM5, currentClass, currentSuperClass, currentClassInterfaces, + this(ASM6, currentClass, currentSuperClass, currentClassInterfaces, isInterface); } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/SourceInterpreter.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/SourceInterpreter.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/SourceInterpreter.java index 284fbef..7a257e7 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/SourceInterpreter.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/tree/analysis/SourceInterpreter.java @@ -50,7 +50,7 @@ public class SourceInterpreter extends Interpreter<SourceValue> implements Opcodes { public SourceInterpreter() { - super(ASM5); + super(ASM6); } protected SourceInterpreter(final int api) { http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/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 f8b0b0d..9395df4 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 @@ -34,7 +34,7 @@ import java.util.Map; import org.apache.tapestry5.internal.plastic.asm.Label; /** - * An {@link org.apache.tapestry5.internal.plastic.asm.Attribute Attribute} that can print the ASM code + * An {@link org.objectweb.asm.Attribute Attribute} that can print the ASM code * to create an equivalent attribute. * * @author Eugene Kuleshov http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifier.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifier.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifier.java index c7b8f7f..b71c186 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifier.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/ASMifier.java @@ -29,13 +29,19 @@ */ package org.apache.tapestry5.internal.plastic.asm.util; -import org.apache.tapestry5.internal.plastic.asm.*; - import java.io.FileInputStream; import java.io.PrintWriter; import java.util.HashMap; import java.util.Map; +import org.apache.tapestry5.internal.plastic.asm.Attribute; +import org.apache.tapestry5.internal.plastic.asm.ClassReader; +import org.apache.tapestry5.internal.plastic.asm.Handle; +import org.apache.tapestry5.internal.plastic.asm.Label; +import org.apache.tapestry5.internal.plastic.asm.Opcodes; +import org.apache.tapestry5.internal.plastic.asm.Type; +import org.apache.tapestry5.internal.plastic.asm.TypePath; + /** * A {@link Printer} that prints the ASM code to generate the classes if visits. * @@ -73,6 +79,11 @@ public class ASMifier extends Printer { * Pseudo access flag used to distinguish inner class flags. */ private static final int ACCESS_INNER = 1048576; + + /** + * Pseudo access flag used to distinguish module requires/exports flags. + */ + private static final int ACCESS_MODULE = 2097152; /** * Constructs a new {@link ASMifier}. <i>Subclasses must not use this @@ -83,7 +94,7 @@ public class ASMifier extends Printer { * If a subclass calls this constructor. */ public ASMifier() { - this(Opcodes.ASM5, "cw", 0); + this(Opcodes.ASM6, "cw", 0); if (getClass() != ASMifier.class) { throw new IllegalStateException(); } @@ -94,7 +105,7 @@ public class ASMifier extends Printer { * * @param api * the ASM API version implemented by this class. Must be one of - * {@link Opcodes#ASM4} or {@link Opcodes#ASM5}. + * {@link Opcodes#ASM4}, {@link Opcodes#ASM5} or {@link Opcodes#ASM6}. * @param name * the name of the visitor variable in the produced code. * @param id @@ -110,7 +121,7 @@ public class ASMifier extends Printer { /** * Prints the ASM source code to generate the given class to the standard * output. - * + * <p> * Usage: ASMifier [-debug] <binary class name or class file name> * * @param args @@ -161,13 +172,17 @@ public class ASMifier extends Printer { final String signature, final String superName, final String[] interfaces) { String simpleName; - int n = name.lastIndexOf('/'); - if (n == -1) { - simpleName = name; + if (name == null) { + simpleName = "module-info"; } else { - text.add("package asm." + name.substring(0, n).replace('/', '.') - + ";\n"); - simpleName = name.substring(n + 1); + 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).replace('-', '_'); + } } text.add("import java.util.*;\n"); text.add("import org.apache.tapestry5.internal.plastic.asm.*;\n"); @@ -202,6 +217,12 @@ public class ASMifier extends Printer { case Opcodes.V1_7: buf.append("V1_7"); break; + case Opcodes.V1_8: + buf.append("V1_8"); + break; + case Opcodes.V9: + buf.append("V9"); + break; default: buf.append(version); break; @@ -239,6 +260,24 @@ public class ASMifier extends Printer { buf.append(");\n\n"); text.add(buf.toString()); } + + @Override + public Printer visitModule(final String name, final int flags, + final String version) { + buf.setLength(0); + buf.append("ModuleVisitor mdv = cw.visitModule("); + appendConstant(name); + buf.append(", "); + appendAccess(flags | ACCESS_MODULE); + buf.append(", "); + appendConstant(version); + buf.append(");\n\n"); + text.add(buf.toString()); + ASMifier a = createASMifier("mdv", 0); + text.add(a.getText()); + text.add("}\n"); + return a; + } @Override public void visitOuterClass(final String owner, final String name, @@ -351,6 +390,108 @@ public class ASMifier extends Printer { } // ------------------------------------------------------------------------ + // Module + // ------------------------------------------------------------------------ + + @Override + public void visitMainClass(String mainClass) { + buf.setLength(0); + buf.append("mdv.visitMainClass("); + appendConstant(buf, mainClass); + buf.append(");\n"); + text.add(buf.toString()); + } + + @Override + public void visitPackage(String packaze) { + buf.setLength(0); + buf.append("mdv.visitPackage("); + appendConstant(buf, packaze); + buf.append(");\n"); + text.add(buf.toString()); + } + + @Override + public void visitRequire(String module, int access, String version) { + buf.setLength(0); + buf.append("mdv.visitRequire("); + appendConstant(buf, module); + buf.append(", "); + appendAccess(access | ACCESS_MODULE); + buf.append(", "); + appendConstant(buf, version); + buf.append(");\n"); + text.add(buf.toString()); + } + + @Override + public void visitExport(String packaze, int access, String... modules) { + buf.setLength(0); + buf.append("mdv.visitExport("); + appendConstant(buf, packaze); + buf.append(", "); + appendAccess(access | ACCESS_MODULE); + if (modules != null && modules.length > 0) { + buf.append(", new String[] {"); + for (int i = 0; i < modules.length; ++i) { + buf.append(i == 0 ? " " : ", "); + appendConstant(modules[i]); + } + buf.append(" }"); + } + buf.append(");\n"); + text.add(buf.toString()); + } + + @Override + public void visitOpen(String packaze, int access, String... modules) { + buf.setLength(0); + buf.append("mdv.visitOpen("); + appendConstant(buf, packaze); + buf.append(", "); + appendAccess(access | ACCESS_MODULE); + if (modules != null && modules.length > 0) { + buf.append(", new String[] {"); + for (int i = 0; i < modules.length; ++i) { + buf.append(i == 0 ? " " : ", "); + appendConstant(modules[i]); + } + buf.append(" }"); + } + buf.append(");\n"); + text.add(buf.toString()); + } + + @Override + public void visitUse(String service) { + buf.setLength(0); + buf.append("mdv.visitUse("); + appendConstant(buf, service); + buf.append(");\n"); + text.add(buf.toString()); + } + + @Override + public void visitProvide(String service, String... providers) { + buf.setLength(0); + buf.append("mdv.visitProvide("); + appendConstant(buf, service); + buf.append(", new String[] {"); + for (int i = 0; i < providers.length; ++i) { + buf.append(i == 0 ? " " : ", "); + appendConstant(providers[i]); + } + buf.append(" });\n"); + text.add(buf.toString()); + } + + @Override + public void visitModuleEnd() { + text.add("mdv.visitEnd();\n"); + } + + + // ------------------------------------------------------------------------ // Annotations // ------------------------------------------------------------------------ @@ -821,7 +962,11 @@ public class ASMifier extends Printer { buf.append("{\n").append("av0 = ").append(name) .append(".visitLocalVariableAnnotation("); buf.append(typeRef); - buf.append(", TypePath.fromString(\"").append(typePath).append("\"), "); + if (typePath == null) { + buf.append(", null, "); + } else { + buf.append(", TypePath.fromString(\"").append(typePath).append("\"), "); + } buf.append("new Label[] {"); for (int i = 0; i < start.length; ++i) { buf.append(i == 0 ? " " : ", "); @@ -896,10 +1041,14 @@ public class ASMifier extends Printer { public ASMifier visitTypeAnnotation(final String method, final int typeRef, final TypePath typePath, final String desc, final boolean visible) { buf.setLength(0); - buf.append("{\n").append("av0 = ").append(name).append('.') - .append(method).append('('); + buf.append("{\n").append("av0 = ").append(name).append(".") + .append(method).append("("); buf.append(typeRef); - buf.append(", TypePath.fromString(\"").append(typePath).append("\"), "); + if (typePath == null) { + buf.append(", null, "); + } else { + buf.append(", TypePath.fromString(\"").append(typePath).append("\"), "); + } appendConstant(desc); buf.append(", ").append(visible).append(");\n"); text.add(buf.toString()); @@ -929,7 +1078,7 @@ public class ASMifier extends Printer { // ------------------------------------------------------------------------ protected ASMifier createASMifier(final String name, final int id) { - return new ASMifier(Opcodes.ASM5, name, id); + return new ASMifier(Opcodes.ASM6, name, id); } /** @@ -957,7 +1106,11 @@ public class ASMifier extends Printer { if (!first) { buf.append(" + "); } - buf.append("ACC_FINAL"); + if ((access & ACCESS_MODULE) == 0) { + buf.append("ACC_FINAL"); + } else { + buf.append("ACC_TRANSITIVE"); + } first = false; } if ((access & Opcodes.ACC_STATIC) != 0) { @@ -967,31 +1120,35 @@ public class ASMifier extends Printer { buf.append("ACC_STATIC"); first = false; } - if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) { + if ((access & (Opcodes.ACC_SYNCHRONIZED | Opcodes.ACC_SUPER | Opcodes.ACC_TRANSITIVE)) != 0) { if (!first) { buf.append(" + "); } if ((access & ACCESS_CLASS) == 0) { - buf.append("ACC_SYNCHRONIZED"); + if ((access & ACCESS_MODULE) == 0) { + buf.append("ACC_SYNCHRONIZED"); + } else { + buf.append("ACC_TRANSITIVE"); + } } else { buf.append("ACC_SUPER"); } first = false; } - if ((access & Opcodes.ACC_VOLATILE) != 0 - && (access & ACCESS_FIELD) != 0) { + if ((access & (Opcodes.ACC_VOLATILE | Opcodes.ACC_BRIDGE | Opcodes.ACC_STATIC_PHASE)) != 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(" + "); + if ((access & ACCESS_FIELD) == 0) { + if ((access & ACCESS_MODULE) == 0) { + buf.append("ACC_BRIDGE"); + } else { + buf.append("ACC_STATIC_PHASE"); + } + } else { + buf.append("ACC_VOLATILE"); } - buf.append("ACC_BRIDGE"); + first = false; } if ((access & Opcodes.ACC_VARARGS) != 0 && (access & ACCESS_CLASS) == 0 @@ -1070,11 +1227,15 @@ public class ASMifier extends Printer { buf.append("ACC_DEPRECATED"); first = false; } - if ((access & Opcodes.ACC_MANDATED) != 0) { + if ((access & (Opcodes.ACC_MANDATED | Opcodes.ACC_MODULE)) != 0) { if (!first) { buf.append(" + "); } - buf.append("ACC_MANDATED"); + if ((access & ACCESS_CLASS) == 0) { + buf.append("ACC_MANDATED"); + } else { + buf.append("ACC_MODULE"); + } first = false; } if (first) { @@ -1120,7 +1281,8 @@ public class ASMifier extends Printer { .append(", \""); buf.append(h.getOwner()).append("\", \""); buf.append(h.getName()).append("\", \""); - buf.append(h.getDesc()).append("\")"); + buf.append(h.getDesc()).append("\", "); + buf.append(h.isInterface()).append(")"); } else if (cst instanceof Byte) { buf.append("new Byte((byte)").append(cst).append(')'); } else if (cst instanceof Boolean) { http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/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 index 56580d1..029c464 100644 --- 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 @@ -49,7 +49,7 @@ public class CheckAnnotationAdapter extends AnnotationVisitor { } CheckAnnotationAdapter(final AnnotationVisitor av, final boolean named) { - super(Opcodes.ASM5, av); + super(Opcodes.ASM6, av); this.named = named; } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckClassAdapter.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckClassAdapter.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckClassAdapter.java index 5b7d217..f66971c 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckClassAdapter.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckClassAdapter.java @@ -29,7 +29,26 @@ */ package org.apache.tapestry5.internal.plastic.asm.util; -import org.apache.tapestry5.internal.plastic.asm.*; +import java.io.FileInputStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +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.Label; +import org.apache.tapestry5.internal.plastic.asm.MethodVisitor; +import org.apache.tapestry5.internal.plastic.asm.ModuleVisitor; +import org.apache.tapestry5.internal.plastic.asm.Opcodes; +import org.apache.tapestry5.internal.plastic.asm.Type; +import org.apache.tapestry5.internal.plastic.asm.TypePath; +import org.apache.tapestry5.internal.plastic.asm.TypeReference; import org.apache.tapestry5.internal.plastic.asm.tree.ClassNode; import org.apache.tapestry5.internal.plastic.asm.tree.MethodNode; import org.apache.tapestry5.internal.plastic.asm.tree.analysis.Analyzer; @@ -37,10 +56,6 @@ import org.apache.tapestry5.internal.plastic.asm.tree.analysis.BasicValue; import org.apache.tapestry5.internal.plastic.asm.tree.analysis.Frame; import org.apache.tapestry5.internal.plastic.asm.tree.analysis.SimpleVerifier; -import java.io.FileInputStream; -import java.io.PrintWriter; -import java.util.*; - /** * A {@link ClassVisitor} that checks that its methods are properly used. More * precisely this class adapter checks each method call individually, based @@ -49,7 +64,7 @@ import java.util.*; * <tt>visitField(ACC_PUBLIC, "i", "I", null)</tt> <tt>visitField(ACC_PUBLIC, * "i", "D", null)</tt> will <i>not</i> be detected by this class adapter. * - * + * <p> * <code>CheckClassAdapter</code> can be also used to verify bytecode * transformations in order to make sure transformed bytecode is sane. For * example: @@ -72,16 +87,16 @@ import java.util.*; * JVM does, but it run data flow analysis for the code of each method and * checks that expectations are met for each method instruction. * - * + * <p> * If method bytecode has errors, assertion text will show the erroneous * instruction number and dump of the failed method with information about * locals and stack slot for each instruction. For example (format is - * insnNumber locals : stack): * * <pre> - * org.apache.tapestry5.internal.plastic.asm.tree.analysis.AnalyzerException: Error at instruction 71: Expected I, but found . - * at org.apache.tapestry5.internal.plastic.asm.tree.analysis.Analyzer.analyze(Analyzer.java:289) - * at org.apache.tapestry5.internal.plastic.asm.util.CheckClassAdapter.verify(CheckClassAdapter.java:135) + * org.objectweb.asm.tree.analysis.AnalyzerException: Error at instruction 71: Expected I, but found . + * at org.objectweb.asm.tree.analysis.Analyzer.analyze(Analyzer.java:289) + * at org.objectweb.asm.util.CheckClassAdapter.verify(CheckClassAdapter.java:135) * ... * remove()V * 00000 LinkedBlockingQueue$Itr . . . . . . . . : @@ -103,7 +118,7 @@ import java.util.*; * initialized. You can also see that at the beginning of the method (code * inserted by the transformation) variable 2 is initialized. * - * + * <p> * Note that when used like that, <code>CheckClassAdapter.verify()</code> can * trigger additional class loading, because it is using * <code>SimpleVerifier</code>. @@ -136,6 +151,11 @@ public class CheckClassAdapter extends ClassVisitor { * <tt>true</tt> if the visitEnd method has been called. */ private boolean end; + + /** + * <tt>true</tt> if the visitModule method has been called. + */ + private boolean module; /** * The already visited labels. This map associate Integer values to Label @@ -150,7 +170,7 @@ public class CheckClassAdapter extends ClassVisitor { /** * Checks a given class. - * + * <p> * Usage: CheckClassAdapter <binary class name or class file name> * * @param args @@ -320,7 +340,7 @@ public class CheckClassAdapter extends ClassVisitor { * If a subclass calls this constructor. */ public CheckClassAdapter(final ClassVisitor cv, final boolean checkDataFlow) { - this(Opcodes.ASM5, cv, checkDataFlow); + this(Opcodes.ASM6, cv, checkDataFlow); if (getClass() != CheckClassAdapter.class) { throw new IllegalStateException(); } @@ -331,7 +351,7 @@ public class CheckClassAdapter extends ClassVisitor { * * @param api * the ASM API version implemented by this visitor. Must be one - * of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}. + * of {@link Opcodes#ASM4}, {@link Opcodes#ASM5} or {@link Opcodes#ASM6}. * @param cv * the class visitor to which this adapter must delegate calls. * @param checkDataFlow @@ -364,8 +384,12 @@ public class CheckClassAdapter extends ClassVisitor { + Opcodes.ACC_SUPER + Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT + Opcodes.ACC_SYNTHETIC + Opcodes.ACC_ANNOTATION + Opcodes.ACC_ENUM - + Opcodes.ACC_DEPRECATED + 0x40000); // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE - if (name == null || !name.endsWith("package-info")) { + + Opcodes.ACC_DEPRECATED + Opcodes.ACC_MODULE + + 0x40000); // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE + if (name == null) { + throw new IllegalArgumentException("Illegal class name (null)"); + } + if (!name.endsWith("package-info")) { CheckMethodAdapter.checkInternalName(name, "class name"); } if ("java/lang/Object".equals(name)) { @@ -407,6 +431,22 @@ public class CheckClassAdapter extends ClassVisitor { } @Override + public ModuleVisitor visitModule(String name, int access, String version) { + checkState(); + if (module) { + throw new IllegalStateException( + "visitModule can be called only once."); + } + module = true; + if (name == null) { + throw new IllegalArgumentException("Illegal module name (null)"); + } + checkAccess(access, Opcodes.ACC_OPEN | Opcodes.ACC_SYNTHETIC); + return new CheckModuleAdapter(super.visitModule(name, access, version), + (access & Opcodes.ACC_OPEN) != 0); + } + + @Override public void visitOuterClass(final String owner, final String name, final String desc) { checkState(); http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckFieldAdapter.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckFieldAdapter.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckFieldAdapter.java index 753025b..af4fb52 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckFieldAdapter.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckFieldAdapter.java @@ -54,7 +54,7 @@ public class CheckFieldAdapter extends FieldVisitor { * If a subclass calls this constructor. */ public CheckFieldAdapter(final FieldVisitor fv) { - this(Opcodes.ASM5, fv); + this(Opcodes.ASM6, fv); if (getClass() != CheckFieldAdapter.class) { throw new IllegalStateException(); } @@ -65,7 +65,7 @@ public class CheckFieldAdapter extends FieldVisitor { * * @param api * the ASM API version implemented by this visitor. Must be one - * of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}. + * of {@link Opcodes#ASM4}, {@link Opcodes#ASM5} or {@link Opcodes#ASM6}. * @param fv * the field visitor to which this adapter must delegate calls. */ http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckMethodAdapter.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckMethodAdapter.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckMethodAdapter.java index f1cf285..931a73d 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckMethodAdapter.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckMethodAdapter.java @@ -60,7 +60,7 @@ import org.apache.tapestry5.internal.plastic.asm.tree.analysis.BasicVerifier; * arguments - such as the fact that the given opcode is correct for a given * visit method. This adapter can also perform some basic data flow checks (more * precisely those that can be performed without the full class hierarchy - see - * {@link org.apache.tapestry5.internal.plastic.asm.tree.analysis.BasicVerifier}). For instance in a + * {@link org.objectweb.asm.tree.analysis.BasicVerifier}). For instance in a * method whose signature is <tt>void m ()</tt>, the invalid instruction * IRETURN, or the invalid sequence IADD L2I will be detected if the data flow * checks are enabled. These checks are enabled by using the @@ -397,7 +397,7 @@ public class CheckMethodAdapter extends MethodVisitor { */ public CheckMethodAdapter(final MethodVisitor mv, final Map<Label, Integer> labels) { - this(Opcodes.ASM5, mv, labels); + this(Opcodes.ASM6, mv, labels); if (getClass() != CheckMethodAdapter.class) { throw new IllegalStateException(); } @@ -408,6 +408,10 @@ public class CheckMethodAdapter extends MethodVisitor { * will not perform any data flow check (see * {@link #CheckMethodAdapter(int,String,String,MethodVisitor,Map)}). * + * @param api + * the ASM API version implemented by this CheckMethodAdapter. + * Must be one of {@link Opcodes#ASM4}, {@link Opcodes#ASM5} + * or {@link Opcodes#ASM6}. * @param mv * the method visitor to which this adapter must delegate calls. * @param labels @@ -724,6 +728,12 @@ public class CheckMethodAdapter extends MethodVisitor { throw new IllegalArgumentException( "INVOKEINTERFACE can't be used with classes"); } + if (opcode == Opcodes.INVOKESPECIAL && itf + && (version & 0xFFFF) < Opcodes.V1_8) { + throw new IllegalArgumentException( + "INVOKESPECIAL can't be used with interfaces prior to Java 8"); + } + // Calling super.visitMethodInsn requires to call the correct version // depending on this.api (otherwise infinite loops can occur). To // simplify and to make it easier to automatically remove the backward http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckModuleAdapter.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckModuleAdapter.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckModuleAdapter.java new file mode 100644 index 0000000..cdc2531 --- /dev/null +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckModuleAdapter.java @@ -0,0 +1,151 @@ +/*** + * ASM: a very small and fast Java bytecode manipulation framework + * Copyright (c) 2000-2011 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.HashSet; + +import org.apache.tapestry5.internal.plastic.asm.ModuleVisitor; +import org.apache.tapestry5.internal.plastic.asm.Opcodes; + +/** + * @author Remi Forax + */ +public final class CheckModuleAdapter extends ModuleVisitor { + private boolean end; + private final boolean isOpen; + + private final HashSet<String> requireNames = new HashSet<String>(); + private final HashSet<String> exportNames = new HashSet<String>(); + private final HashSet<String> openNames = new HashSet<String>(); + private final HashSet<String> useNames = new HashSet<String>(); + private final HashSet<String> provideNames = new HashSet<String>(); + + public CheckModuleAdapter(final ModuleVisitor mv, final boolean isOpen) { + super(Opcodes.ASM6, mv); + this.isOpen = isOpen; + } + + @Override + public void visitRequire(String module, int access, String version) { + checkEnd(); + if (module == null) { + throw new IllegalArgumentException("require cannot be null"); + } + checkDeclared("requires", requireNames, module); + CheckClassAdapter.checkAccess(access, Opcodes.ACC_STATIC_PHASE + + Opcodes.ACC_TRANSITIVE + Opcodes.ACC_SYNTHETIC + Opcodes.ACC_MANDATED); + super.visitRequire(module, access, version); + } + + @Override + public void visitExport(String packaze, int access, String... modules) { + checkEnd(); + if (packaze == null) { + throw new IllegalArgumentException("packaze cannot be null"); + } + CheckMethodAdapter.checkInternalName(packaze, "package name"); + checkDeclared("exports", exportNames, packaze); + CheckClassAdapter.checkAccess(access, Opcodes.ACC_SYNTHETIC + + Opcodes.ACC_MANDATED); + if (modules != null) { + for (int i = 0; i < modules.length; i++) { + if (modules[i] == null) { + throw new IllegalArgumentException("module at index " + i + " cannot be null"); + } + } + } + super.visitExport(packaze, access, modules); + } + + @Override + public void visitOpen(String packaze, int access, String... modules) { + checkEnd(); + if (isOpen) { + throw new IllegalArgumentException("an open module can not use open directive"); + } + if (packaze == null) { + throw new IllegalArgumentException("packaze cannot be null"); + } + CheckMethodAdapter.checkInternalName(packaze, "package name"); + checkDeclared("opens", openNames, packaze); + CheckClassAdapter.checkAccess(access, Opcodes.ACC_SYNTHETIC + + Opcodes.ACC_MANDATED); + if (modules != null) { + for (int i = 0; i < modules.length; i++) { + if (modules[i] == null) { + throw new IllegalArgumentException("module at index " + i + " cannot be null"); + } + } + } + super.visitOpen(packaze, access, modules); + } + + @Override + public void visitUse(String service) { + checkEnd(); + CheckMethodAdapter.checkInternalName(service, "service"); + checkDeclared("uses", useNames, service); + super.visitUse(service); + } + + @Override + public void visitProvide(String service, String... providers) { + checkEnd(); + CheckMethodAdapter.checkInternalName(service, "service"); + checkDeclared("provides", provideNames, service); + if (providers == null || providers.length == 0) { + throw new IllegalArgumentException("providers cannot be null or empty"); + } + for (int i = 0; i < providers.length; i++) { + CheckMethodAdapter.checkInternalName(providers[i], "provider"); + } + super.visitProvide(service, providers); + } + + @Override + public void visitEnd() { + checkEnd(); + end = true; + super.visitEnd(); + } + + private void checkEnd() { + if (end) { + throw new IllegalStateException( + "Cannot call a visit method after visitEnd has been called"); + } + } + + private static void checkDeclared(String directive, HashSet<String> names, String name) { + if (!names.add(name)) { + throw new IllegalArgumentException(directive + " " + name + " already declared"); + } + } +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/74324b31/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckSignatureAdapter.java ---------------------------------------------------------------------- diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckSignatureAdapter.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckSignatureAdapter.java index cf1f98b..bca5dd7 100644 --- a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckSignatureAdapter.java +++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/util/CheckSignatureAdapter.java @@ -113,7 +113,7 @@ public class CheckSignatureAdapter extends SignatureVisitor { * <tt>null</tt>. */ public CheckSignatureAdapter(final int type, final SignatureVisitor sv) { - this(Opcodes.ASM5, type, sv); + this(Opcodes.ASM6, type, sv); } /** @@ -121,7 +121,7 @@ public class CheckSignatureAdapter extends SignatureVisitor { * * @param api * the ASM API version implemented by this visitor. Must be one - * of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}. + * of {@link Opcodes#ASM4}, {@link Opcodes#ASM5} or {@link Opcodes#ASM6}. * @param type * the type of signature to be checked. See * {@link #CLASS_SIGNATURE}, {@link #METHOD_SIGNATURE} and @@ -146,7 +146,7 @@ public class CheckSignatureAdapter extends SignatureVisitor { || (state != EMPTY && state != FORMAL && state != BOUND)) { throw new IllegalStateException(); } - CheckMethodAdapter.checkIdentifier(name, "formal type parameter"); + checkIdentifier(name, "formal type parameter"); state = FORMAL; if (sv != null) { sv.visitFormalTypeParameter(name); @@ -255,7 +255,7 @@ public class CheckSignatureAdapter extends SignatureVisitor { if (type != TYPE_SIGNATURE || state != EMPTY) { throw new IllegalStateException(); } - CheckMethodAdapter.checkIdentifier(name, "type variable"); + checkIdentifier(name, "type variable"); state = SIMPLE_TYPE; if (sv != null) { sv.visitTypeVariable(name); @@ -277,7 +277,7 @@ public class CheckSignatureAdapter extends SignatureVisitor { if (type != TYPE_SIGNATURE || state != EMPTY) { throw new IllegalStateException(); } - CheckMethodAdapter.checkInternalName(name, "class name"); + checkClassName(name, "class name"); state = CLASS_TYPE; if (sv != null) { sv.visitClassType(name); @@ -289,7 +289,7 @@ public class CheckSignatureAdapter extends SignatureVisitor { if (state != CLASS_TYPE) { throw new IllegalStateException(); } - CheckMethodAdapter.checkIdentifier(name, "inner class name"); + checkIdentifier(name, "inner class name"); if (sv != null) { sv.visitInnerClassType(name); } @@ -327,4 +327,30 @@ public class CheckSignatureAdapter extends SignatureVisitor { sv.visitEnd(); } } + + private void checkClassName(final String name, final String msg) { + if (name == null || name.length() == 0) { + throw new IllegalArgumentException("Invalid " + msg + + " (must not be null or empty)"); + } + for (int i = 0; i < name.length(); ++i) { + if (".;[<>:".indexOf(name.charAt(i)) != -1) { + throw new IllegalArgumentException("Invalid " + msg + + " (must not contain . ; [ < > or :): " + name); + } + } + } + + private void checkIdentifier(final String name, final String msg) { + if (name == null || name.length() == 0) { + throw new IllegalArgumentException("Invalid " + msg + + " (must not be null or empty)"); + } + for (int i = 0; i < name.length(); ++i) { + if (".;[/<>:".indexOf(name.charAt(i)) != -1) { + throw new IllegalArgumentException("Invalid " + msg + + " (must not contain . ; [ / < > or :): " + name); + } + } + } }
