KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > libraries > asm > attrs > RuntimeVisibleAnnotations


1 /**
2  * ASM: a very small and fast Java bytecode manipulation framework
3  * Copyright (c) 2000,2002,2003 INRIA, France Telecom
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holders nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28  * THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package oracle.toplink.libraries.asm.attrs;
32
33 import java.util.ArrayList JavaDoc;
34 import java.util.List JavaDoc;
35
36 import oracle.toplink.libraries.asm.Attribute;
37 import oracle.toplink.libraries.asm.ByteVector;
38 import oracle.toplink.libraries.asm.ClassReader;
39 import oracle.toplink.libraries.asm.ClassWriter;
40 import oracle.toplink.libraries.asm.Label;
41
42
43 /**
44  * The RuntimeVisibleAnnotations attribute is a variable length attribute in the
45  * attributes table of the ClassFile, field_info, and method_info structures. The
46  * RuntimeVisibleAnnotations attribute records runtime-visible Java programming
47  * language annotations on the corresponding class, method, or field. Each
48  * ClassFile, field_info, and method_info structure may contain at most one
49  * RuntimeVisibleAnnotations attribute, which records all the runtime-visible Java
50  * programming language annotations on the corresponding program element. The JVM
51  * must make these annotations available so they can be returned by the
52  * appropriate reflective APIs.
53  * <p>
54  * The RuntimeVisibleAnnotations attribute has the following format:
55  * <pre>
56  * RuntimeVisibleAnnotations_attribute {
57  * u2 attribute_name_index;
58  * u4 attribute_length;
59  * u2 num_annotations;
60  * annotation annotations[num_annotations];
61  * }
62  * </pre>
63  * The items of the RuntimeVisibleAnnotations structure are as follows:
64  * <dl>
65  * <dt>attribute_name_index</dt>
66  * <dd>The value of the attribute_name_index item must be a valid index into the
67  * constant_pool table. The constant_pool entry at that index must be a
68  * CONSTANT_Utf8_info structure representing the string
69  * "RuntimeVisibleAnnotations".</dd>
70  * <dt>attribute_length</dt>
71  * <dd>The value of the attribute_length item indicates the length of the attribute,
72  * excluding the initial six bytes. The value of the attribute_length item is
73  * thus dependent on the number of runtime-visible annotations represented by
74  * the structure, and their values.</dd>
75  * <dt>num_annotations</dt>
76  * <dd>The value of the num_annotations item gives the number of runtime-visible
77  * annotations represented by the structure. Note that a maximum of 65535
78  * runtime-visible Java programming language annotations may be directly
79  * attached to a program element.</dd>
80  * <dt>annotations</dt>
81  * <dd>Each value of the annotations table represents a single runtime-visible
82  * {@link Annotation annotation} on a program element.</dd>
83  * </dl>
84  *
85  * @see <a HREF="http://www.jcp.org/en/jsr/detail?id=175">JSR 175 : A Metadata
86  * Facility for the Java Programming Language</a>
87  *
88  * @author Eugene Kuleshov
89  */

90
91 public class RuntimeVisibleAnnotations extends Attribute {
92
93   /**
94    * <code>List</code> of <code>Annotation</code>.
95    *
96    * @associates <{oracle.toplink.libraries.asm.attrs.Annotation}>
97    * @label annotations
98    */

99   public List JavaDoc annotations = new ArrayList JavaDoc();
100
101   public RuntimeVisibleAnnotations () {
102     super("RuntimeVisibleAnnotations");
103   }
104
105   protected Attribute read (ClassReader cr, int off,
106                             int len, char[] buf, int codeOff, Label[] labels) {
107     RuntimeVisibleAnnotations atr = new RuntimeVisibleAnnotations();
108     Annotation.readAnnotations(atr.annotations, cr, off, buf);
109     return atr;
110   }
111
112   protected ByteVector write (ClassWriter cw, byte[] code,
113                               int len, int maxStack, int maxLocals) {
114     return Annotation.writeAnnotations(new ByteVector(), annotations, cw);
115   }
116
117   /**
118    * Returns value in the format described in JSR-175 for Java source code.
119    *
120    * @return value in the format described in JSR-175 for Java source code.
121    */

122
123   public String JavaDoc toString () {
124     return Annotation.stringAnnotations(annotations);
125   }
126 }
127
Popular Tags