Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: pkg/analysis_server/test/src/plugin/protocol_test_utilities.dart

Issue 2696853002: Extract object creation methods for use by a future test class (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'package:analysis_server/plugin/protocol/protocol.dart' as server;
6 import 'package:analyzer_plugin/protocol/protocol.dart' as plugin;
7 import 'package:analyzer_plugin/protocol/protocol_constants.dart' as plugin;
8 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
9
10 class ProtocolTestUtilities {
11 static const List<String> strings = const <String>[
12 'aa',
13 'ab',
14 'ac',
15 'ad',
16 'ae',
17 'af',
18 'ag',
19 'ah',
20 'ai',
21 'aj',
22 'ak',
23 'al',
24 'am',
25 'an',
26 'ao',
27 'ap',
28 'aq',
29 'ar',
30 'as',
31 'at',
32 'au',
33 'av',
34 'aw',
35 'ax',
36 'ay',
37 'az',
38 'ba',
39 'bb',
40 'bc',
41 'bd',
42 'be',
43 'bf',
44 'bg',
45 'bh',
46 'bi',
47 'bj',
48 'bk',
49 'bl',
50 'bm',
51 'bn',
52 'bo',
53 'bp',
54 'bq',
55 'br',
56 'bs',
57 'bt',
58 'bu',
59 'bv',
60 'bw',
61 'bx',
62 'by',
63 'bz',
64 ];
65
66 String fileName(int stringIndex) => '${strings[stringIndex]}.dart';
67
68 /**
69 * On return, increment [stringIndex] by 3 (or 4 if no [file] name is
70 * provided) and [intIndex] by 4.
71 */
72 plugin.AnalysisError pluginAnalysisError(int stringIndex, int intIndex,
73 {String file}) {
74 return new plugin.AnalysisError(
75 plugin.AnalysisErrorSeverity.ERROR,
76 plugin.AnalysisErrorType.COMPILE_TIME_ERROR,
77 pluginLocation(stringIndex, intIndex, file: file),
78 strings[stringIndex++],
79 strings[stringIndex++],
80 correction: strings[stringIndex++],
81 hasFix: true);
82 }
83
84 /**
85 * On return, increment [stringIndex] by 5 and [intIndex] by 5.
86 */
87 plugin.Element pluginElement(int stringIndex, int intIndex,
88 {plugin.ElementKind kind}) =>
89 new plugin.Element(
90 kind ?? plugin.ElementKind.CLASS, strings[stringIndex++], intIndex++,
91 location: new plugin.Location(fileName(stringIndex++), intIndex++,
92 intIndex++, intIndex++, intIndex++),
93 parameters: strings[stringIndex++],
94 returnType: strings[stringIndex++],
95 typeParameters: strings[stringIndex++]);
96
97 plugin.FoldingRegion pluginFoldingRegion(int offset, int length) =>
98 new plugin.FoldingRegion(plugin.FoldingKind.COMMENT, offset, length);
99
100 plugin.HighlightRegion pluginHighlightRegion(int offset, int length) =>
101 new plugin.HighlightRegion(
102 plugin.HighlightRegionType.FIELD, offset, length);
103
104 /**
105 * On return, increment [stringIndex] by 1 and [intIndex] by 4.
106 */
107 plugin.Location pluginLocation(int stringIndex, int intIndex,
108 {String file}) =>
109 new plugin.Location(file ?? fileName(stringIndex), intIndex++, intIndex++,
110 intIndex++, intIndex++);
111
112 /**
113 * On return, increment [stringIndex] by 2 (or 3 if no [file] name is
114 * provided) and [intIndex] by 6.
115 */
116 plugin.AnalysisNavigationParams pluginNavigationParams(
117 int stringIndex, int intIndex, {String file}) =>
118 new plugin.AnalysisNavigationParams(
119 file ?? fileName(stringIndex++), <plugin.NavigationRegion>[
120 new plugin.NavigationRegion(intIndex++, intIndex++, <int>[0])
121 ], <plugin.NavigationTarget>[
122 new plugin.NavigationTarget(plugin.ElementKind.FIELD, 0, intIndex++,
123 intIndex++, intIndex++, intIndex++)
124 ], <String>[
125 strings[stringIndex++],
126 strings[stringIndex++]
127 ]);
128
129 /**
130 * On return, increment [stringIndex] by 5 and [intIndex] by 7.
131 */
132 plugin.Occurrences pluginOccurrences(int stringIndex, int intIndex) {
133 plugin.Element element = pluginElement(stringIndex, intIndex);
134 return new plugin.Occurrences(
135 element, <int>[intIndex + 5, intIndex + 6], element.name.length);
136 }
137
138 /**
139 * On return, increment [stringIndex] by 10 and [intIndex] by 14.
140 */
141 plugin.Outline pluginOutline(int stringIndex, int intIndex) =>
142 new plugin.Outline(
143 pluginElement(stringIndex, intIndex), intIndex + 5, intIndex + 6,
144 children: <plugin.Outline>[
145 new plugin.Outline(
146 pluginElement(stringIndex + 5, intIndex + 7,
147 kind: plugin.ElementKind.METHOD),
148 intIndex + 12,
149 intIndex + 13)
150 ]);
151
152 /**
153 * On return, increment [stringIndex] by 2 and [intIndex] by 4.
154 */
155 plugin.RefactoringProblem pluginRefactoringProblem(
156 int stringIndex, int intIndex) {
157 return new plugin.RefactoringProblem(
158 plugin.RefactoringProblemSeverity.FATAL, strings[stringIndex++],
159 location: pluginLocation(stringIndex, intIndex));
160 }
161
162 /**
163 * On return, increment [stringIndex] by 6 and [intIndex] by 6.
164 */
165 plugin.SourceChange pluginSourceChange(int stringIndex, int intIndex) =>
166 new plugin.SourceChange(strings[stringIndex++],
167 edits: <plugin.SourceFileEdit>[
168 new plugin.SourceFileEdit(fileName(stringIndex), intIndex++,
169 edits: <plugin.SourceEdit>[
170 new plugin.SourceEdit(
171 intIndex++, intIndex++, strings[stringIndex++])
172 ])
173 ],
174 linkedEditGroups: <plugin.LinkedEditGroup>[
175 new plugin.LinkedEditGroup(
176 <plugin.Position>[
177 new plugin.Position(fileName(stringIndex), intIndex++)
178 ],
179 intIndex++,
180 <plugin.LinkedEditSuggestion>[
181 new plugin.LinkedEditSuggestion(strings[stringIndex++],
182 plugin.LinkedEditSuggestionKind.METHOD)
183 ])
184 ],
185 selection: new plugin.Position(fileName(stringIndex), intIndex++));
186
187 /**
188 * On return, increment [stringIndex] by 3 (or 4 if no [file] name is
189 * provided) and [intIndex] by 4.
190 */
191 server.AnalysisError serverAnalysisError(int stringIndex, int intIndex,
192 {String file}) {
193 return new server.AnalysisError(
194 server.AnalysisErrorSeverity.ERROR,
195 server.AnalysisErrorType.COMPILE_TIME_ERROR,
196 serverLocation(stringIndex, intIndex, file: file),
197 strings[stringIndex++],
198 strings[stringIndex++],
199 correction: strings[stringIndex++],
200 hasFix: true);
201 }
202
203 /**
204 * On return, increment [stringIndex] by 5 and [intIndex] by 5.
205 */
206 server.Element serverElement(int stringIndex, int intIndex,
207 {server.ElementKind kind}) =>
208 new server.Element(
209 kind ?? server.ElementKind.CLASS, strings[stringIndex++], intIndex++,
210 location: new server.Location(fileName(stringIndex++), intIndex++,
211 intIndex++, intIndex++, intIndex++),
212 parameters: strings[stringIndex++],
213 returnType: strings[stringIndex++],
214 typeParameters: strings[stringIndex++]);
215
216 server.FoldingRegion serverFoldingRegion(int offset, int length) =>
217 new server.FoldingRegion(server.FoldingKind.COMMENT, offset, length);
218
219 server.HighlightRegion serverHighlightRegion(int offset, int length) =>
220 new server.HighlightRegion(
221 server.HighlightRegionType.FIELD, offset, length);
222
223 /**
224 * On return, increment [stringIndex] by 1 and [intIndex] by 4.
225 */
226 server.Location serverLocation(int stringIndex, int intIndex,
227 {String file}) =>
228 new server.Location(file ?? fileName(stringIndex), intIndex++, intIndex++,
229 intIndex++, intIndex++);
230
231 /**
232 * On return, increment [stringIndex] by 2 (or 3 if no [file] name is
233 * provided) and [intIndex] by 6.
234 */
235 server.AnalysisNavigationParams serverNavigationParams(
236 int stringIndex, int intIndex, {String file}) =>
237 new server.AnalysisNavigationParams(
238 file ?? fileName(stringIndex++), <server.NavigationRegion>[
239 new server.NavigationRegion(intIndex++, intIndex++, <int>[0])
240 ], <server.NavigationTarget>[
241 new server.NavigationTarget(server.ElementKind.FIELD, 0, intIndex++,
242 intIndex++, intIndex++, intIndex++)
243 ], <String>[
244 strings[stringIndex++],
245 strings[stringIndex++]
246 ]);
247
248 /**
249 * On return, increment [stringIndex] by 5 and [intIndex] by 7.
250 */
251 server.Occurrences serverOccurrences(int stringIndex, int intIndex) {
252 server.Element element = serverElement(stringIndex, intIndex);
253 return new server.Occurrences(
254 element, <int>[intIndex + 5, intIndex + 6], element.name.length);
255 }
256
257 /**
258 * On return, increment [stringIndex] by 10 and [intIndex] by 14.
259 */
260 server.Outline serverOutline(int stringIndex, int intIndex) =>
261 new server.Outline(
262 serverElement(stringIndex, intIndex), intIndex + 5, intIndex + 6,
263 children: <server.Outline>[
264 new server.Outline(
265 serverElement(stringIndex + 5, intIndex + 7,
266 kind: server.ElementKind.METHOD),
267 intIndex + 12,
268 intIndex + 13)
269 ]);
270
271 /**
272 * On return, increment [stringIndex] by 2 and [intIndex] by 4.
273 */
274 server.RefactoringProblem serverRefactoringProblem(
275 int stringIndex, int intIndex) =>
276 new server.RefactoringProblem(
277 server.RefactoringProblemSeverity.FATAL, strings[stringIndex++],
278 location: serverLocation(stringIndex, intIndex));
279
280 /**
281 * On return, increment [stringIndex] by 6 and [intIndex] by 6.
282 */
283 server.SourceChange serverSourceChange(int stringIndex, int intIndex) =>
284 new server.SourceChange(strings[stringIndex++],
285 edits: <server.SourceFileEdit>[
286 new server.SourceFileEdit(fileName(stringIndex), intIndex++,
287 edits: <server.SourceEdit>[
288 new server.SourceEdit(
289 intIndex++, intIndex++, strings[stringIndex++])
290 ])
291 ],
292 linkedEditGroups: <server.LinkedEditGroup>[
293 new server.LinkedEditGroup(
294 <server.Position>[
295 new server.Position(fileName(stringIndex), intIndex++)
296 ],
297 intIndex++,
298 <server.LinkedEditSuggestion>[
299 new server.LinkedEditSuggestion(strings[stringIndex++],
300 server.LinkedEditSuggestionKind.METHOD)
301 ])
302 ],
303 selection: new server.Position(fileName(stringIndex), intIndex++));
304 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/plugin/result_merger.dart ('k') | pkg/analysis_server/test/src/plugin/result_converter_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698