< prev index next >

src/java.base/share/classes/jdk/internal/org/objectweb/asm/tree/AnnotationNode.java

Print this page
rev 47452 : imported patch jdk-new-asmv6.patch


  48  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  49  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  51  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  52  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  53  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  54  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  55  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  56  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  57  * THE POSSIBILITY OF SUCH DAMAGE.
  58  */
  59 package jdk.internal.org.objectweb.asm.tree;
  60 
  61 import java.util.ArrayList;
  62 import java.util.List;
  63 
  64 import jdk.internal.org.objectweb.asm.AnnotationVisitor;
  65 import jdk.internal.org.objectweb.asm.Opcodes;
  66 
  67 /**
  68  * A node that represents an annotationn.
  69  *
  70  * @author Eric Bruneton
  71  */
  72 public class AnnotationNode extends AnnotationVisitor {
  73 
  74     /**
  75      * The class descriptor of the annotation class.
  76      */
  77     public String desc;
  78 
  79     /**
  80      * The name value pairs of this annotation. Each name value pair is stored
  81      * as two consecutive elements in the list. The name is a {@link String},
  82      * and the value may be a {@link Byte}, {@link Boolean}, {@link Character},
  83      * {@link Short}, {@link Integer}, {@link Long}, {@link Float},
  84      * {@link Double}, {@link String} or {@link jdk.internal.org.objectweb.asm.Type}, or an
  85      * two elements String array (for enumeration values), a
  86      * {@link AnnotationNode}, or a {@link List} of values of one of the
  87      * preceding types. The list may be <tt>null</tt> if there is no name value
  88      * pair.
  89      */
  90     public List<Object> values;
  91 
  92     /**
  93      * Constructs a new {@link AnnotationNode}. <i>Subclasses must not use this
  94      * constructor</i>. Instead, they must use the
  95      * {@link #AnnotationNode(int, String)} version.
  96      *
  97      * @param desc
  98      *            the class descriptor of the annotation class.
  99      * @throws IllegalStateException
 100      *             If a subclass calls this constructor.
 101      */
 102     public AnnotationNode(final String desc) {
 103         this(Opcodes.ASM5, desc);
 104         if (getClass() != AnnotationNode.class) {
 105             throw new IllegalStateException();
 106         }
 107     }
 108 
 109     /**
 110      * Constructs a new {@link AnnotationNode}.
 111      *
 112      * @param api
 113      *            the ASM API version implemented by this visitor. Must be one
 114      *            of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.
 115      * @param desc
 116      *            the class descriptor of the annotation class.
 117      */
 118     public AnnotationNode(final int api, final String desc) {
 119         super(api);
 120         this.desc = desc;
 121     }
 122 
 123     /**
 124      * Constructs a new {@link AnnotationNode} to visit an array value.
 125      *
 126      * @param values
 127      *            where the visited values must be stored.
 128      */
 129     AnnotationNode(final List<Object> values) {
 130         super(Opcodes.ASM5);
 131         this.values = values;
 132     }
 133 
 134     // ------------------------------------------------------------------------
 135     // Implementation of the AnnotationVisitor abstract class
 136     // ------------------------------------------------------------------------
 137 
 138     @Override
 139     public void visit(final String name, final Object value) {
 140         if (values == null) {
 141             values = new ArrayList<Object>(this.desc != null ? 2 : 1);
 142         }
 143         if (this.desc != null) {
 144             values.add(name);
 145         }

























































 146         values.add(value);
 147     }

 148 
 149     @Override
 150     public void visitEnum(final String name, final String desc,
 151             final String value) {
 152         if (values == null) {
 153             values = new ArrayList<Object>(this.desc != null ? 2 : 1);
 154         }
 155         if (this.desc != null) {
 156             values.add(name);
 157         }
 158         values.add(new String[] { desc, value });
 159     }
 160 
 161     @Override
 162     public AnnotationVisitor visitAnnotation(final String name,
 163             final String desc) {
 164         if (values == null) {
 165             values = new ArrayList<Object>(this.desc != null ? 2 : 1);
 166         }
 167         if (this.desc != null) {


 183         List<Object> array = new ArrayList<Object>();
 184         values.add(array);
 185         return new AnnotationNode(array);
 186     }
 187 
 188     @Override
 189     public void visitEnd() {
 190     }
 191 
 192     // ------------------------------------------------------------------------
 193     // Accept methods
 194     // ------------------------------------------------------------------------
 195 
 196     /**
 197      * Checks that this annotation node is compatible with the given ASM API
 198      * version. This methods checks that this node, and all its nodes
 199      * recursively, do not contain elements that were introduced in more recent
 200      * versions of the ASM API than the given version.
 201      *
 202      * @param api
 203      *            an ASM API version. Must be one of {@link Opcodes#ASM4} or
 204      *            {@link Opcodes#ASM5}.
 205      */
 206     public void check(final int api) {
 207         // nothing to do
 208     }
 209 
 210     /**
 211      * Makes the given visitor visit this annotation.
 212      *
 213      * @param av
 214      *            an annotation visitor. Maybe <tt>null</tt>.
 215      */
 216     public void accept(final AnnotationVisitor av) {
 217         if (av != null) {
 218             if (values != null) {
 219                 for (int i = 0; i < values.size(); i += 2) {
 220                     String name = (String) values.get(i);
 221                     Object value = values.get(i + 1);
 222                     accept(av, name, value);
 223                 }
 224             }




  48  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  49  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  51  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  52  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  53  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  54  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  55  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  56  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  57  * THE POSSIBILITY OF SUCH DAMAGE.
  58  */
  59 package jdk.internal.org.objectweb.asm.tree;
  60 
  61 import java.util.ArrayList;
  62 import java.util.List;
  63 
  64 import jdk.internal.org.objectweb.asm.AnnotationVisitor;
  65 import jdk.internal.org.objectweb.asm.Opcodes;
  66 
  67 /**
  68  * A node that represents an annotation.
  69  *
  70  * @author Eric Bruneton
  71  */
  72 public class AnnotationNode extends AnnotationVisitor {
  73 
  74     /**
  75      * The class descriptor of the annotation class.
  76      */
  77     public String desc;
  78 
  79     /**
  80      * The name value pairs of this annotation. Each name value pair is stored
  81      * as two consecutive elements in the list. The name is a {@link String},
  82      * and the value may be a {@link Byte}, {@link Boolean}, {@link Character},
  83      * {@link Short}, {@link Integer}, {@link Long}, {@link Float},
  84      * {@link Double}, {@link String} or {@link jdk.internal.org.objectweb.asm.Type}, or a
  85      * two elements String array (for enumeration values), an
  86      * {@link AnnotationNode}, or a {@link List} of values of one of the
  87      * preceding types. The list may be <tt>null</tt> if there is no name value
  88      * pair.
  89      */
  90     public List<Object> values;
  91 
  92     /**
  93      * Constructs a new {@link AnnotationNode}. <i>Subclasses must not use this
  94      * constructor</i>. Instead, they must use the
  95      * {@link #AnnotationNode(int, String)} version.
  96      *
  97      * @param desc
  98      *            the class descriptor of the annotation class.
  99      * @throws IllegalStateException
 100      *             If a subclass calls this constructor.
 101      */
 102     public AnnotationNode(final String desc) {
 103         this(Opcodes.ASM6, desc);
 104         if (getClass() != AnnotationNode.class) {
 105             throw new IllegalStateException();
 106         }
 107     }
 108 
 109     /**
 110      * Constructs a new {@link AnnotationNode}.
 111      *
 112      * @param api
 113      *            the ASM API version implemented by this visitor. Must be one
 114      *            of {@link Opcodes#ASM4}, {@link Opcodes#ASM5} or {@link Opcodes#ASM6}.
 115      * @param desc
 116      *            the class descriptor of the annotation class.
 117      */
 118     public AnnotationNode(final int api, final String desc) {
 119         super(api);
 120         this.desc = desc;
 121     }
 122 
 123     /**
 124      * Constructs a new {@link AnnotationNode} to visit an array value.
 125      *
 126      * @param values
 127      *            where the visited values must be stored.
 128      */
 129     AnnotationNode(final List<Object> values) {
 130         super(Opcodes.ASM6);
 131         this.values = values;
 132     }
 133 
 134     // ------------------------------------------------------------------------
 135     // Implementation of the AnnotationVisitor abstract class
 136     // ------------------------------------------------------------------------
 137 
 138     @Override
 139     public void visit(final String name, final Object value) {
 140         if (values == null) {
 141             values = new ArrayList<Object>(this.desc != null ? 2 : 1);
 142         }
 143         if (this.desc != null) {
 144             values.add(name);
 145         }
 146         if (value instanceof byte[]) {
 147             byte[] v = (byte[]) value;
 148             ArrayList<Byte> l = new ArrayList<Byte>(v.length);
 149             for (byte b : v) {
 150                 l.add(b);
 151             }
 152             values.add(l);
 153         } else if (value instanceof boolean[]) {
 154             boolean[] v = (boolean[]) value;
 155             ArrayList<Boolean> l = new ArrayList<Boolean>(v.length);
 156             for (boolean b : v) {
 157                 l.add(b);
 158             }
 159             values.add(l);
 160         } else if (value instanceof short[]) {
 161             short[] v = (short[]) value;
 162             ArrayList<Short> l = new ArrayList<Short>(v.length);
 163             for (short s : v) {
 164                 l.add(s);
 165             }
 166             values.add(l);
 167         } else if (value instanceof char[]) {
 168             char[] v = (char[]) value;
 169             ArrayList<Character> l = new ArrayList<Character>(v.length);
 170             for (char c : v) {
 171                 l.add(c);
 172             }
 173             values.add(l);
 174         } else if (value instanceof int[]) {
 175             int[] v = (int[]) value;
 176             ArrayList<Integer> l = new ArrayList<Integer>(v.length);
 177             for (int i : v) {
 178                 l.add(i);
 179             }
 180             values.add(l);
 181         } else if (value instanceof long[]) {
 182             long[] v = (long[]) value;
 183             ArrayList<Long> l = new ArrayList<Long>(v.length);
 184             for (long lng : v) {
 185                 l.add(lng);
 186             }
 187             values.add(l);
 188         } else if (value instanceof float[]) {
 189             float[] v = (float[]) value;
 190             ArrayList<Float> l = new ArrayList<Float>(v.length);
 191             for (float f : v) {
 192                 l.add(f);
 193             }
 194             values.add(l);
 195         } else if (value instanceof double[]) {
 196             double[] v = (double[]) value;
 197             ArrayList<Double> l = new ArrayList<Double>(v.length);
 198             for (double d : v) {
 199                 l.add(d);
 200             }
 201             values.add(l);
 202         } else {
 203             values.add(value);
 204         }
 205     }
 206 
 207     @Override
 208     public void visitEnum(final String name, final String desc,
 209             final String value) {
 210         if (values == null) {
 211             values = new ArrayList<Object>(this.desc != null ? 2 : 1);
 212         }
 213         if (this.desc != null) {
 214             values.add(name);
 215         }
 216         values.add(new String[] { desc, value });
 217     }
 218 
 219     @Override
 220     public AnnotationVisitor visitAnnotation(final String name,
 221             final String desc) {
 222         if (values == null) {
 223             values = new ArrayList<Object>(this.desc != null ? 2 : 1);
 224         }
 225         if (this.desc != null) {


 241         List<Object> array = new ArrayList<Object>();
 242         values.add(array);
 243         return new AnnotationNode(array);
 244     }
 245 
 246     @Override
 247     public void visitEnd() {
 248     }
 249 
 250     // ------------------------------------------------------------------------
 251     // Accept methods
 252     // ------------------------------------------------------------------------
 253 
 254     /**
 255      * Checks that this annotation node is compatible with the given ASM API
 256      * version. This methods checks that this node, and all its nodes
 257      * recursively, do not contain elements that were introduced in more recent
 258      * versions of the ASM API than the given version.
 259      *
 260      * @param api
 261      *            an ASM API version. Must be one of {@link Opcodes#ASM4},
 262      *            {@link Opcodes#ASM5} or {@link Opcodes#ASM6}.
 263      */
 264     public void check(final int api) {
 265         // nothing to do
 266     }
 267 
 268     /**
 269      * Makes the given visitor visit this annotation.
 270      *
 271      * @param av
 272      *            an annotation visitor. Maybe <tt>null</tt>.
 273      */
 274     public void accept(final AnnotationVisitor av) {
 275         if (av != null) {
 276             if (values != null) {
 277                 for (int i = 0; i < values.size(); i += 2) {
 278                     String name = (String) values.get(i);
 279                     Object value = values.get(i + 1);
 280                     accept(av, name, value);
 281                 }
 282             }


< prev index next >