1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.bcel.generic;
20
21 import java.io.DataOutputStream;
22 import java.io.IOException;
23
24 import org.apache.bcel.ExceptionConst;
25 import org.apache.bcel.classfile.ConstantPool;
26 import org.apache.bcel.util.ByteSequence;
27
28
29
30
31
32
33
34
35 public class MULTIANEWARRAY extends CPInstruction implements LoadClass, AllocationInstruction, ExceptionThrower {
36
37 private short dimensions;
38
39
40
41
42 MULTIANEWARRAY() {
43 }
44
45 public MULTIANEWARRAY(final int index, final short dimensions) {
46 super(org.apache.bcel.Const.MULTIANEWARRAY, index);
47 if (dimensions < 1) {
48 throw new ClassGenException("Invalid dimensions value: " + dimensions);
49 }
50 this.dimensions = dimensions;
51 super.setLength(4);
52 }
53
54
55
56
57
58
59
60 @Override
61 public void accept(final Visitor v) {
62 v.visitLoadClass(this);
63 v.visitAllocationInstruction(this);
64 v.visitExceptionThrower(this);
65 v.visitTypedInstruction(this);
66 v.visitCPInstruction(this);
67 v.visitMULTIANEWARRAY(this);
68 }
69
70
71
72
73
74
75 @Override
76 public int consumeStack(final ConstantPoolGen cpg) {
77 return dimensions;
78 }
79
80
81
82
83
84
85 @Override
86 public void dump(final DataOutputStream out) throws IOException {
87 out.writeByte(super.getOpcode());
88 out.writeShort(super.getIndex());
89 out.writeByte(dimensions);
90 }
91
92
93
94
95 public final short getDimensions() {
96 return dimensions;
97 }
98
99 @Override
100 public Class<?>[] getExceptions() {
101 return ExceptionConst.createExceptions(ExceptionConst.EXCS.EXCS_CLASS_AND_INTERFACE_RESOLUTION, ExceptionConst.ILLEGAL_ACCESS_ERROR,
102 ExceptionConst.NEGATIVE_ARRAY_SIZE_EXCEPTION);
103 }
104
105 @Override
106 public ObjectType getLoadClassType(final ConstantPoolGen cpg) {
107 Type t = getType(cpg);
108 if (t instanceof ArrayType) {
109 t = ((ArrayType) t).getBasicType();
110 }
111 return t instanceof ObjectType ? (ObjectType) t : null;
112 }
113
114
115
116
117 @Override
118 protected void initFromFile(final ByteSequence bytes, final boolean wide) throws IOException {
119 super.initFromFile(bytes, wide);
120 dimensions = bytes.readByte();
121 super.setLength(4);
122 }
123
124
125
126
127 @Override
128 public String toString(final boolean verbose) {
129 return super.toString(verbose) + " " + super.getIndex() + " " + dimensions;
130 }
131
132
133
134
135 @Override
136 public String toString(final ConstantPool cp) {
137 return super.toString(cp) + " " + dimensions;
138 }
139 }