KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jas > ParameterVisibilityAnnotationAttr


1 /**
2  * Visibility 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 ParameterVisibilityAnnotationAttr {
14
15     AsciiCP attr;
16     ArrayList list = new ArrayList();
17
18     void resolve(ClassEnv e){
19         e.addCPItem(attr);
20         if (list != null){
21             Iterator it = list.iterator();
22             while (it.hasNext()){
23                 ((VisibilityAnnotationAttr)it.next()).resolve(e);
24             }
25         }
26     }
27
28     /**
29     * Note: A visibility 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 ParameterVisibilityAnnotationAttr(String JavaDoc kind, ArrayList vis_annotations) { //
33
attr = new AsciiCP(kind+"Annotations");
34         list = vis_annotations;
35     }
36
37     public ParameterVisibilityAnnotationAttr() { //
38
}
39
40     public void setKind(String JavaDoc k){
41         attr = new AsciiCP(k+"Annotations");
42     }
43     
44     public void addAnnotation(VisibilityAnnotationAttr annot){
45         list.add(annot);
46     }
47
48     int size(){
49         int i = 2;
50         if (list != null){
51             Iterator it = list.iterator();
52             while (it.hasNext()){
53                 i += ((VisibilityAnnotationAttr)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(attr));
65         out.writeInt(size()); // fixed length
66
if (list == null){
67             out.writeShort(0);
68         }
69         else {
70             out.writeShort(list.size());
71             //System.out.println("num params: "+list.size());
72
}
73         if (list != null){
74             Iterator it = list.iterator();
75             while (it.hasNext()){
76                 VisibilityAnnotationAttr vAttr = (VisibilityAnnotationAttr)it.next();
77                 if (vAttr.getList() == null){
78                     out.writeShort(0);
79                 }
80                 else {
81                     out.writeShort(vAttr.getList().size());
82                     //System.out.println("num annots: "+vAttr.getList().size());
83
}
84
85                 if (vAttr.getList() != null){
86                     Iterator ait = vAttr.getList().iterator();
87                     while (ait.hasNext()){
88                         ((AnnotationAttr)ait.next()).write(e,out);
89                     }
90                 }
91             }
92         }
93     }
94 }
95
Popular Tags