KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jas > VisibilityAnnotationAttr


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 VisibilityAnnotationAttr {
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                 ((AnnotationAttr)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 VisibilityAnnotationAttr(String JavaDoc kind, ArrayList annotations) { //
33
attr = new AsciiCP(kind+"Annotations");
34         list = annotations;
35     }
36
37     public VisibilityAnnotationAttr() { //
38
}
39
40     public void setKind(String JavaDoc k){
41         attr = new AsciiCP(k+"Annotations");
42     }
43     
44     public void addAnnotation(AnnotationAttr annot){
45         list.add(annot);
46     }
47
48     public ArrayList getList(){
49         return list;
50     }
51     
52     int size(){
53         int i = 2;
54         if (list != null){
55             Iterator it = list.iterator();
56             while (it.hasNext()){
57                 i += ((AnnotationAttr)it.next()).size();
58             }
59         }
60         return i;
61     }
62
63
64     void write(ClassEnv e, DataOutputStream out)
65         throws IOException, jasError
66         {
67        
68         out.writeShort(e.getCPIndex(attr));
69         out.writeInt(size()); // fixed length
70
if (list == null){
71             out.writeShort(0);
72         }
73         else {
74             out.writeShort(list.size());
75         }
76         if (list != null){
77             Iterator it = list.iterator();
78             while (it.hasNext()){
79                 ((AnnotationAttr)it.next()).write(e, out);
80             }
81         }
82     }
83 }
84
Popular Tags