cp cleanup, setsourcefile
[org.ibex.classgen.git] / src / org / ibex / classgen / FieldGen.java
1 package org.ibex.classgen;
2
3 import java.io.*;
4
5 public class FieldGen implements CGConst {
6     private final CPGen cp;
7     private final String name;
8     private final Type type;
9     private final int flags;
10     private final ClassGen.AttrGen attrs;
11     
12     FieldGen(ClassGen owner, String name,Type type, int flags) {
13         if((flags & ~(ACC_PUBLIC|ACC_PRIVATE|ACC_PROTECTED|ACC_VOLATILE|ACC_TRANSIENT|ACC_STATIC|ACC_FINAL)) != 0)
14             throw new IllegalArgumentException("invalid flags");
15         this.cp = owner.cp;
16         this.name = name;
17         this.type = type;
18         this.flags = flags;
19         this.attrs = new ClassGen.AttrGen(cp);
20         
21         cp.addUtf8(name);
22         cp.addUtf8(type.getDescriptor());
23     }
24     
25     public void dump(DataOutput o) throws IOException {
26         o.writeShort(flags);
27         o.writeShort(cp.getUtf8Index(name));
28         o.writeShort(cp.getUtf8Index(type.getDescriptor()));
29         o.writeShort(attrs.size());
30         attrs.dump(o);
31     }
32 }