1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.jdo.impl.enhancer.classfile;
19
20 import java.io.*;
21
22 /***
23 * ClassField models the static and non-static fields of a class within
24 * a class file.
25 */
26
27 final public class ClassField extends ClassMember {
28
29 private int accessFlags;
30
31
32 private ConstUtf8 fieldName;
33
34
35 private ConstUtf8 fieldSignature;
36
37
38 private AttributeVector fieldAttributes;
39
40
41
42
43 /***
44 * Is the field transient?
45 */
46 public boolean isTransient() {
47 return (accessFlags & ACCTransient) != 0;
48 }
49
50 /***
51 * Return the access flags for the field - see VMConstants
52 */
53 public int access() {
54 return accessFlags;
55 }
56
57 /***
58 * Update the access flags for the field - see VMConstants
59 */
60 public void setAccess(int newFlags) {
61 accessFlags = newFlags;
62 }
63
64 /***
65 * Return the name of the field
66 */
67 public ConstUtf8 name() {
68 return fieldName;
69 }
70
71 /***
72 * Change the name of the field
73 */
74 public void changeName(ConstUtf8 name) {
75 fieldName = name;
76 }
77
78 /***
79 * Return the type signature of the field
80 */
81 public ConstUtf8 signature() {
82 return fieldSignature;
83 }
84
85 /***
86 * Change the type signature of the field
87 */
88 public void changeSignature(ConstUtf8 newSig) {
89 fieldSignature = newSig;
90 }
91
92 /***
93 * Return the attributes associated with the field
94 */
95 public AttributeVector attributes() {
96 return fieldAttributes;
97 }
98
99 /***
100 * Construct a class field object
101 */
102 public ClassField(int accFlags, ConstUtf8 name, ConstUtf8 sig,
103 AttributeVector field_attrs) {
104 accessFlags = accFlags;
105 fieldName = name;
106 fieldSignature = sig;
107 fieldAttributes = field_attrs;
108 }
109
110 </* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">em class="comment">/* package local methods *//package-summary.html">class="comment"> package local methods */
111
112 static ClassField read(DataInputStream data, ConstantPool pool)
113 throws IOException {
114 ClassField f = null;
115 int accessFlags = data.readUnsignedShort();
116 int name_index = data.readUnsignedShort();
117 int sig_index = data.readUnsignedShort();
118 AttributeVector fieldAttribs = AttributeVector.readAttributes(data, pool);
119 f = new ClassField(accessFlags,
120 (ConstUtf8) pool.constantAt(name_index),
121 (ConstUtf8) pool.constantAt(sig_index),
122 fieldAttribs);
123 return f;
124 }
125
126 void write (DataOutputStream data) throws IOException {
127 data.writeShort(accessFlags);
128 data.writeShort(fieldName.getIndex());
129 data.writeShort(fieldSignature.getIndex());
130 fieldAttributes.write(data);
131 }
132
133 void print(PrintStream out, int indent) {
134 ClassPrint.spaces(out, indent);
135 out.print("'" + fieldName.asString() + "'");
136 out.print(" sig = " + fieldSignature.asString());
137 out.print(" access_flags = " + Integer.toString(accessFlags));
138 out.println(" attributes:");
139 fieldAttributes.print(out, indent+2);
140 }
141 }
142