1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel.generic;
18
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21
22 import org.apache.bcel.util.ByteSequence;
23
24
25
26
27
28
29 public class LOOKUPSWITCH extends Select {
30
31
32
33
34 LOOKUPSWITCH() {
35 }
36
37 public LOOKUPSWITCH(final int[] match, final InstructionHandle[] targets, final InstructionHandle defaultTarget) {
38 super(org.apache.bcel.Const.LOOKUPSWITCH, match, targets, defaultTarget);
39
40 final short length = (short) (9 + getMatchLength() * 8);
41 super.setLength(length);
42 setFixedLength(length);
43 }
44
45
46
47
48
49
50
51 @Override
52 public void accept(final Visitor v) {
53 v.visitVariableLengthInstruction(this);
54 v.visitStackConsumer(this);
55 v.visitBranchInstruction(this);
56 v.visitSelect(this);
57 v.visitLOOKUPSWITCH(this);
58 }
59
60
61
62
63
64
65 @Override
66 public void dump(final DataOutputStream out) throws IOException {
67 super.dump(out);
68 final int matchLength = getMatchLength();
69 out.writeInt(matchLength);
70 for (int i = 0; i < matchLength; i++) {
71 out.writeInt(super.getMatch(i));
72 out.writeInt(setIndices(i, getTargetOffset(super.getTarget(i))));
73 }
74 }
75
76
77
78
79 @Override
80 protected void initFromFile(final ByteSequence bytes, final boolean wide) throws IOException {
81 super.initFromFile(bytes, wide);
82 final int matchLength = bytes.readInt();
83 setMatchLength(matchLength);
84 final short fixedLength = (short) (9 + matchLength * 8);
85 setFixedLength(fixedLength);
86 final short length = (short) (matchLength + super.getPadding());
87 super.setLength(length);
88 super.setMatches(new int[matchLength]);
89 super.setIndices(new int[matchLength]);
90 super.setTargets(new InstructionHandle[matchLength]);
91 for (int i = 0; i < matchLength; i++) {
92 super.setMatch(i, bytes.readInt());
93 super.setIndices(i, bytes.readInt());
94 }
95 }
96 }