KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jas > ArrayElemValPair


1 /**
2  * ElemValPairs 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 ArrayElemValPair extends ElemValPair {
14
15     ArrayList list;
16
17     void resolve(ClassEnv e){
18         super.resolve(e);
19         if (list != null){
20             Iterator it = list.iterator();
21             while (it.hasNext()){
22                 ((ElemValPair)it.next()).resolve(e);
23             }
24         }
25     }
26
27     /**
28     * Note: An annotation attr is associated with a <em>class</em>,
29     * method or field so you need to create a new VisibilityAnnotationAttr for
30     */

31     public ArrayElemValPair(String JavaDoc name, char kind, ArrayList list) { //
32
super(name, kind);
33         this.list = list;
34     }
35
36     public void setNoName(){
37         if (list == null) return;
38         Iterator it = list.iterator();
39         while (it.hasNext()){
40             ((ElemValPair)it.next()).setNoName();
41         }
42     }
43
44     public ArrayElemValPair(String JavaDoc name, char kind) { //
45
super(name, kind);
46     }
47
48     public void addElemValPair(ElemValPair elem){
49         if (list == null){
50             list = new ArrayList();
51         }
52         list.add(elem);
53     }
54
55     int size(){
56         int i = super.size();
57         i += 2; // array elem count short
58
if (list != null){
59             Iterator it = list.iterator();
60             while (it.hasNext()){
61                 i += ((ElemValPair)it.next()).size();
62             }
63         }
64         return i;
65     }
66
67
68     void write(ClassEnv e, DataOutputStream out)
69         throws IOException, jasError
70         {
71         super.write(e, out);
72         if (list != null){
73             out.writeShort(list.size());
74         }
75         else {
76             out.writeShort(0);
77         }
78         if (list != null){
79             Iterator it = list.iterator();
80             while (it.hasNext()){
81                 ((ElemValPair)it.next()).write(e, out);
82             }
83         }
84     }
85 }
86
Popular Tags