KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jas > AnnotationAttr


1 /**
2  * Annotation attributes are embedded into class files
3  * and used for further ???
4  * @author $Author: Jennifer Lhotak$
5  * @version $Revision: 1.1 $
6  */

7
8 package jas;
9
10 import java.io.*;
11 import java.util.*;
12
13 public class AnnotationAttr {
14
15     AsciiCP type;
16     ArrayList list = new ArrayList();
17
18     void resolve(ClassEnv e){
19         e.addCPItem(type);
20         if (list != null){
21             Iterator it = list.iterator();
22             while (it.hasNext()){
23                 ((ElemValPair)it.next()).resolve(e);
24             }
25         }
26     }
27
28     /**
29     * Note: An annotation attr is associated with a <em>class</em>,
30     * method or field so you need to create a new VisibilityAnnotationAttr for
31     */

32     public AnnotationAttr(String JavaDoc type, ArrayList elems) { //
33
this.type = new AsciiCP(type);
34         this.list = elems;
35     }
36     
37     public AnnotationAttr() { //
38
}
39
40     public void setType(String JavaDoc type){
41         this.type = new AsciiCP(type);
42     }
43
44     public void addElemValPair(ElemValPair pair){
45         list.add(pair);
46     }
47
48     int size(){
49         int i = 4;
50         if (list != null){
51             Iterator it = list.iterator();
52             while (it.hasNext()){
53                 i += ((ElemValPair)it.next()).size();
54             }
55         }
56         return i;
57     }
58
59
60     void write(ClassEnv e, DataOutputStream out)
61         throws IOException, jasError
62         {
63         
64         out.writeShort(e.getCPIndex(type));
65         if (list == null){
66             out.writeShort(0);
67         }
68         else {
69             out.writeShort(list.size()); // fixed length
70
}
71         if (list != null){
72             Iterator it = list.iterator();
73             while (it.hasNext()){
74                 ((ElemValPair)it.next()).write(e, out);
75             }
76         }
77     }
78 }
79
Popular Tags