1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel.classfile;
18
19 import java.io.DataInput;
20 import java.io.DataOutputStream;
21 import java.io.IOException;
22
23 import org.apache.bcel.Const;
24
25
26
27
28
29
30
31 public final class InnerClass implements Cloneable, Node {
32
33 private int innerClassIndex;
34 private int outerClassIndex;
35 private int innerNameIndex;
36 private int innerAccessFlags;
37
38
39
40
41
42
43
44 InnerClass(final DataInput file) throws IOException {
45 this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort());
46 }
47
48
49
50
51
52
53 public InnerClass(final InnerClass c) {
54 this(c.getInnerClassIndex(), c.getOuterClassIndex(), c.getInnerNameIndex(), c.getInnerAccessFlags());
55 }
56
57
58
59
60
61
62
63 public InnerClass(final int innerClassIndex, final int outerClassIndex, final int innerNameIndex, final int innerAccessFlags) {
64 this.innerClassIndex = innerClassIndex;
65 this.outerClassIndex = outerClassIndex;
66 this.innerNameIndex = innerNameIndex;
67 this.innerAccessFlags = innerAccessFlags;
68 }
69
70
71
72
73
74
75
76 @Override
77 public void accept(final Visitor v) {
78 v.visitInnerClass(this);
79 }
80
81
82
83
84 public InnerClass copy() {
85 try {
86 return (InnerClass) clone();
87 } catch (final CloneNotSupportedException e) {
88
89 }
90 return null;
91 }
92
93
94
95
96
97
98
99 public void dump(final DataOutputStream file) throws IOException {
100 file.writeShort(innerClassIndex);
101 file.writeShort(outerClassIndex);
102 file.writeShort(innerNameIndex);
103 file.writeShort(innerAccessFlags);
104 }
105
106
107
108
109 public int getInnerAccessFlags() {
110 return innerAccessFlags;
111 }
112
113
114
115
116 public int getInnerClassIndex() {
117 return innerClassIndex;
118 }
119
120
121
122
123 public int getInnerNameIndex() {
124 return innerNameIndex;
125 }
126
127
128
129
130 public int getOuterClassIndex() {
131 return outerClassIndex;
132 }
133
134
135
136
137 public void setInnerAccessFlags(final int innerAccessFlags) {
138 this.innerAccessFlags = innerAccessFlags;
139 }
140
141
142
143
144 public void setInnerClassIndex(final int innerClassIndex) {
145 this.innerClassIndex = innerClassIndex;
146 }
147
148
149
150
151 public void setInnerNameIndex(final int innerNameIndex) {
152 this.innerNameIndex = innerNameIndex;
153 }
154
155
156
157
158 public void setOuterClassIndex(final int outerClassIndex) {
159 this.outerClassIndex = outerClassIndex;
160 }
161
162
163
164
165 @Override
166 public String toString() {
167 return "InnerClass(" + innerClassIndex + ", " + outerClassIndex + ", " + innerNameIndex + ", " + innerAccessFlags + ")";
168 }
169
170
171
172
173 public String toString(final ConstantPool constantPool) {
174 String outerClassName;
175 String innerName;
176 String innerClassName = constantPool.getConstantString(innerClassIndex, Const.CONSTANT_Class);
177 innerClassName = Utility.compactClassName(innerClassName, false);
178 if (outerClassIndex != 0) {
179 outerClassName = constantPool.getConstantString(outerClassIndex, Const.CONSTANT_Class);
180 outerClassName = " of class " + Utility.compactClassName(outerClassName, false);
181 } else {
182 outerClassName = "";
183 }
184 if (innerNameIndex != 0) {
185 innerName = constantPool.getConstantUtf8(innerNameIndex).getBytes();
186 } else {
187 innerName = "(anonymous)";
188 }
189 String access = Utility.accessToString(innerAccessFlags, true);
190 access = access.isEmpty() ? "" : access + " ";
191 return " " + access + innerName + "=class " + innerClassName + outerClassName;
192 }
193 }