|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| package edu.rice.cs.drjava.model; |
|
38 |
| |
|
39 |
| import java.util.Arrays; |
|
40 |
| |
|
41 |
| import static edu.rice.cs.plt.object.ObjectUtil.hash; |
|
42 |
| |
|
43 |
| public interface Query { |
|
44 |
| |
|
45 |
| abstract static class Pos implements Query { |
|
46 |
| private final int _pos; |
|
47 |
| |
|
48 |
45775
| Pos(final int pos) { _pos = pos; }
|
|
49 |
| |
|
50 |
3655
| public boolean equals(Object other) {
|
|
51 |
0
| if (other == null || other.getClass() != this.getClass()) return false;
|
|
52 |
3655
| Pos o = (Pos) other;
|
|
53 |
3655
| return o._pos == _pos;
|
|
54 |
| } |
|
55 |
| |
|
56 |
6605
| public int hashCode() { return hash(getClass().hashCode(), _pos); }
|
|
57 |
| } |
|
58 |
| |
|
59 |
| public static class IndentInformation extends Pos { |
|
60 |
0
| public IndentInformation(int pos) { super(pos); }
|
|
61 |
| } |
|
62 |
| |
|
63 |
| abstract static class AbstractEnclosingBrace implements Query { |
|
64 |
| private final int _pos; |
|
65 |
| private final char _opening; |
|
66 |
| private final char _closing; |
|
67 |
| |
|
68 |
16168
| public AbstractEnclosingBrace(final int pos, final char opening, final char closing) {
|
|
69 |
16168
| _pos = pos;
|
|
70 |
16168
| _opening = opening;
|
|
71 |
16168
| _closing = closing;
|
|
72 |
| } |
|
73 |
| |
|
74 |
0
| public boolean equals(Object other) {
|
|
75 |
0
| if (other == null || other.getClass() != getClass()) return false;
|
|
76 |
0
| AbstractEnclosingBrace o = (AbstractEnclosingBrace) other;
|
|
77 |
0
| return o._pos == _pos && o._opening == _opening && o._closing == _closing;
|
|
78 |
| } |
|
79 |
| |
|
80 |
0
| public int hashCode() { return hash(getClass().hashCode(), _pos, _opening, _closing); }
|
|
81 |
| } |
|
82 |
| |
|
83 |
| public static class PrevEnclosingBrace extends AbstractEnclosingBrace { |
|
84 |
12210
| public PrevEnclosingBrace(int pos, char opening, char closing) { super(pos, opening, closing); }
|
|
85 |
| } |
|
86 |
| |
|
87 |
| public static class NextEnclosingBrace extends AbstractEnclosingBrace { |
|
88 |
3958
| public NextEnclosingBrace(int pos, char opening, char closing) { super(pos, opening, closing); }
|
|
89 |
| } |
|
90 |
| |
|
91 |
| abstract static class CharArrayAndFlag implements Query { |
|
92 |
| private final int _pos; |
|
93 |
| private final char[] _chars; |
|
94 |
| private final boolean _flag; |
|
95 |
| |
|
96 |
37261
| public CharArrayAndFlag(int pos, char[] chars, boolean flag) {
|
|
97 |
37261
| _pos = pos;
|
|
98 |
37261
| _chars = chars;
|
|
99 |
37261
| _flag = flag;
|
|
100 |
| } |
|
101 |
| |
|
102 |
240
| public boolean equals(Object other) {
|
|
103 |
0
| if (other == null || other.getClass() != getClass()) return false;
|
|
104 |
240
| CharArrayAndFlag o = (CharArrayAndFlag) other;
|
|
105 |
240
| return o._pos == _pos && Arrays.equals(o._chars, _chars) && o._flag == _flag;
|
|
106 |
| } |
|
107 |
| |
|
108 |
2003
| public int hashCode() {
|
|
109 |
2003
| int[] intArray = new int[] { getClass().hashCode(), _pos, (int)_chars[0], (int)_chars[_chars.length-1], (_flag ? 1 : 0) };
|
|
110 |
2003
| return hash(intArray);
|
|
111 |
| } |
|
112 |
| } |
|
113 |
| |
|
114 |
| public static class PrevDelimiter extends CharArrayAndFlag { |
|
115 |
13299
| public PrevDelimiter(int pos, char[] delims, boolean skipParenPhrases) { super(pos, delims, skipParenPhrases); }
|
|
116 |
| } |
|
117 |
| |
|
118 |
| public static class PrevCharPos implements Query { |
|
119 |
| private final int _pos; |
|
120 |
| private final char[] _whitespace; |
|
121 |
| |
|
122 |
6353
| public PrevCharPos(int pos, final char[] whitespace) {
|
|
123 |
6353
| _pos = pos;
|
|
124 |
6353
| _whitespace = whitespace;
|
|
125 |
| } |
|
126 |
| |
|
127 |
37
| public boolean equals(Object other) {
|
|
128 |
0
| if (other == null || other.getClass() != getClass()) return false;
|
|
129 |
37
| PrevCharPos o = (PrevCharPos) other;
|
|
130 |
37
| return o._pos == _pos && Arrays.equals(o._whitespace, _whitespace);
|
|
131 |
| } |
|
132 |
| |
|
133 |
135
| public int hashCode() {
|
|
134 |
135
| return hash(getClass().hashCode(), _pos, _whitespace[0], _whitespace[_whitespace.length-1]);
|
|
135 |
| } |
|
136 |
| } |
|
137 |
| |
|
138 |
| public static class IndentOfCurrStmt implements Query { |
|
139 |
| private final int _pos; |
|
140 |
| private final char[] _delims; |
|
141 |
| private final char[] _whitespace; |
|
142 |
| |
|
143 |
197
| public IndentOfCurrStmt(int pos, char[] delims, char[] whitespace) {
|
|
144 |
197
| _pos = pos;
|
|
145 |
197
| _delims = delims;
|
|
146 |
197
| _whitespace = whitespace;
|
|
147 |
| } |
|
148 |
| |
|
149 |
47
| public boolean equals(Object other) {
|
|
150 |
0
| if (other == null || other.getClass() != getClass()) return false;
|
|
151 |
47
| IndentOfCurrStmt o = (IndentOfCurrStmt) other;
|
|
152 |
47
| return o._pos == _pos && Arrays.equals(o._delims, _delims) && Arrays.equals(o._whitespace, _whitespace);
|
|
153 |
| } |
|
154 |
| |
|
155 |
217
| public int hashCode() {
|
|
156 |
217
| int[] intArray = new int[] { getClass().hashCode(), _pos ^_delims[0], _delims[_delims.length-1], _whitespace[0],
|
|
157 |
| _whitespace[_whitespace.length-1] }; |
|
158 |
217
| return hash(intArray);
|
|
159 |
| } |
|
160 |
| } |
|
161 |
| |
|
162 |
| public static class CharOnLine implements Query { |
|
163 |
| private final int _pos; |
|
164 |
| private final char _findChar; |
|
165 |
| |
|
166 |
129
| public CharOnLine(int pos, char findChar) {
|
|
167 |
129
| _pos = pos;
|
|
168 |
129
| _findChar = findChar;
|
|
169 |
| } |
|
170 |
| |
|
171 |
5
| public boolean equals(Object other) {
|
|
172 |
0
| if (other == null || other.getClass() != getClass()) return false;
|
|
173 |
5
| CharOnLine o = (CharOnLine) other;
|
|
174 |
5
| return o._pos == _pos && o._findChar == _findChar;
|
|
175 |
| } |
|
176 |
| |
|
177 |
172
| public int hashCode() { return hash(getClass().hashCode(), _pos, _findChar); }
|
|
178 |
| } |
|
179 |
| |
|
180 |
| public static class LineStartPos extends Pos { |
|
181 |
17527
| public LineStartPos(int pos) { super(pos); }
|
|
182 |
| } |
|
183 |
| |
|
184 |
| public static class LineEndPos extends Pos { |
|
185 |
25165
| public LineEndPos(int pos) { super(pos); }
|
|
186 |
| } |
|
187 |
| |
|
188 |
| public static class LineFirstCharPos extends Pos { |
|
189 |
930
| public LineFirstCharPos(int pos) { super(pos); }
|
|
190 |
| } |
|
191 |
| |
|
192 |
| public static class FirstNonWSCharPos extends CharArrayAndFlag { |
|
193 |
23962
| FirstNonWSCharPos(int pos, char[] whitespace, boolean acceptComments) { super(pos, whitespace, acceptComments); }
|
|
194 |
| } |
|
195 |
| |
|
196 |
| public static class PosInParenPhrase extends Pos { |
|
197 |
2
| public PosInParenPhrase(int pos) { super(pos); }
|
|
198 |
| } |
|
199 |
| |
|
200 |
| public static class LineEnclosingBrace extends Pos { |
|
201 |
1210
| public LineEnclosingBrace(int pos) { super(pos); }
|
|
202 |
| } |
|
203 |
| |
|
204 |
| public static class EnclosingBrace extends Pos { |
|
205 |
28
| public EnclosingBrace(int pos) { super(pos); }
|
|
206 |
| } |
|
207 |
| |
|
208 |
| public static class PosNotInBlock extends Pos { |
|
209 |
324
| public PosNotInBlock(int pos) { super(pos); }
|
|
210 |
| } |
|
211 |
| |
|
212 |
| public static class PosInBlockComment extends Pos { |
|
213 |
0
| public PosInBlockComment(int pos) { super(pos); }
|
|
214 |
| } |
|
215 |
| |
|
216 |
| public static class AnonymousInnerClass implements Query { |
|
217 |
| private final int _pos; |
|
218 |
| private final int _openCurlyPos; |
|
219 |
| |
|
220 |
4783
| public AnonymousInnerClass(int pos, int openCurlyPos) {
|
|
221 |
4783
| _pos = pos;
|
|
222 |
4783
| _openCurlyPos = openCurlyPos;
|
|
223 |
| } |
|
224 |
| |
|
225 |
0
| public boolean equals(Object other) {
|
|
226 |
0
| if (other == null || other.getClass() != getClass()) return false;
|
|
227 |
0
| AnonymousInnerClass o = (AnonymousInnerClass) other;
|
|
228 |
0
| return o._pos == _pos && o._openCurlyPos == _openCurlyPos;
|
|
229 |
| } |
|
230 |
| |
|
231 |
0
| public int hashCode() { return hash(getClass().hashCode(), _pos, _openCurlyPos); }
|
|
232 |
| } |
|
233 |
| |
|
234 |
| public static class AnonymousInnerClassIndex extends Pos { |
|
235 |
589
| public AnonymousInnerClassIndex(int pos) { super(pos); }
|
|
236 |
| } |
|
237 |
| |
|
238 |
| public static class EnclosingClassName implements Query { |
|
239 |
| private int _pos; |
|
240 |
| private boolean _qual; |
|
241 |
2171
| public EnclosingClassName(int pos, boolean qual) {
|
|
242 |
2171
| _pos = pos;
|
|
243 |
2171
| _qual = qual;
|
|
244 |
| } |
|
245 |
0
| public boolean equals(Object other) {
|
|
246 |
0
| if (other == null || other.getClass() != getClass()) return false;
|
|
247 |
0
| EnclosingClassName o = (EnclosingClassName) other;
|
|
248 |
0
| return o._pos == _pos && o._qual == _qual;
|
|
249 |
| } |
|
250 |
| |
|
251 |
0
| public int hashCode() { return hash(getClass().hashCode(), _pos, (_qual ? 1 : 0)); }
|
|
252 |
| } |
|
253 |
| } |