|
1 |
| package edu.rice.cs.javalanglevels.tree; |
|
2 |
| |
|
3 |
| import edu.rice.cs.javalanglevels.SourceInfo; |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| public class SwitchStatement extends Statement { |
|
11 |
| private final Expression _test; |
|
12 |
| private final SwitchCase[] _cases; |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
17
| public SwitchStatement(SourceInfo in_sourceInfo, Expression in_test, SwitchCase[] in_cases) {
|
|
19 |
17
| super(in_sourceInfo);
|
|
20 |
| |
|
21 |
17
| if (in_test == null) {
|
|
22 |
0
| throw new java.lang.IllegalArgumentException("Parameter 'test' to the SwitchStatement constructor was null. This class may not have null field values.");
|
|
23 |
| } |
|
24 |
17
| _test = in_test;
|
|
25 |
| |
|
26 |
17
| if (in_cases == null) {
|
|
27 |
0
| throw new java.lang.IllegalArgumentException("Parameter 'cases' to the SwitchStatement constructor was null. This class may not have null field values.");
|
|
28 |
| } |
|
29 |
17
| _cases = in_cases;
|
|
30 |
| } |
|
31 |
| |
|
32 |
33
| final public Expression getTest() { return _test; }
|
|
33 |
155
| final public SwitchCase[] getCases() { return _cases; }
|
|
34 |
| |
|
35 |
19
| public <RetType> RetType visit(JExpressionIFVisitor<RetType> visitor) { return visitor.forSwitchStatement(this); }
|
|
36 |
0
| public void visit(JExpressionIFVisitor_void visitor) { visitor.forSwitchStatement(this); }
|
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
0
| public java.lang.String toString() {
|
|
43 |
0
| java.io.StringWriter w = new java.io.StringWriter();
|
|
44 |
0
| output(w);
|
|
45 |
0
| return w.toString();
|
|
46 |
| } |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
0
| public void output(java.io.Writer writer) {
|
|
52 |
0
| outputHelp(new TabPrintWriter(writer, 2));
|
|
53 |
| } |
|
54 |
| |
|
55 |
2
| public void outputHelp(TabPrintWriter writer) {
|
|
56 |
2
| writer.print("SwitchStatement" + ":");
|
|
57 |
2
| writer.indent();
|
|
58 |
| |
|
59 |
2
| writer.startLine("");
|
|
60 |
2
| writer.print("sourceInfo = ");
|
|
61 |
2
| SourceInfo temp_sourceInfo = getSourceInfo();
|
|
62 |
2
| if (temp_sourceInfo == null) {
|
|
63 |
0
| writer.print("null");
|
|
64 |
| } else { |
|
65 |
2
| writer.print(temp_sourceInfo);
|
|
66 |
| } |
|
67 |
| |
|
68 |
2
| writer.startLine("");
|
|
69 |
2
| writer.print("test = ");
|
|
70 |
2
| Expression temp_test = getTest();
|
|
71 |
2
| if (temp_test == null) {
|
|
72 |
0
| writer.print("null");
|
|
73 |
| } else { |
|
74 |
2
| temp_test.outputHelp(writer);
|
|
75 |
| } |
|
76 |
| |
|
77 |
2
| writer.startLine("");
|
|
78 |
2
| writer.print("cases = ");
|
|
79 |
2
| writer.print("{");
|
|
80 |
2
| writer.indent();
|
|
81 |
2
| for (int i = 0; i < getCases().length; i++) {
|
|
82 |
6
| SwitchCase temp_cases = getCases()[i];
|
|
83 |
6
| writer.startLine("#" + i + ": ");
|
|
84 |
6
| if (temp_cases == null) {
|
|
85 |
0
| writer.print("null");
|
|
86 |
| } else { |
|
87 |
6
| temp_cases.outputHelp(writer);
|
|
88 |
| } |
|
89 |
| } |
|
90 |
2
| writer.unindent();
|
|
91 |
2
| if (getCases().length > 0) {
|
|
92 |
2
| writer.startLine("");
|
|
93 |
| } |
|
94 |
2
| writer.print("}");
|
|
95 |
2
| writer.unindent();
|
|
96 |
| } |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
0
| public boolean equals(java.lang.Object obj) {
|
|
104 |
0
| if (obj == null) return false;
|
|
105 |
0
| if ((obj.getClass() != this.getClass()) || (obj.hashCode() != this.hashCode())) {
|
|
106 |
0
| return false;
|
|
107 |
| } else { |
|
108 |
0
| SwitchStatement casted = (SwitchStatement) obj;
|
|
109 |
0
| if (! (getTest().equals(casted.getTest()))) return false;
|
|
110 |
0
| if (this.getCases().length != casted.getCases().length) return false;
|
|
111 |
0
| for (int i = 0; i < getCases().length; i++) if (! getCases()[i].equals(casted.getCases()[i])) return false;
|
|
112 |
0
| return true;
|
|
113 |
| } |
|
114 |
| } |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
0
| protected int generateHashCode() {
|
|
123 |
0
| int code = getClass().hashCode();
|
|
124 |
0
| code ^= 0;
|
|
125 |
0
| code ^= getTest().hashCode();
|
|
126 |
0
| for (int i = 0; i < getCases().length; i++) code ^= getCases()[i].hashCode();
|
|
127 |
0
| return code;
|
|
128 |
| } |
|
129 |
| } |