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

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

Issue 2879273002: Make server use the common protocol classes (Closed)
Patch Set: Created 3 years, 7 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
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:analysis_server/protocol/protocol_generated.dart' as server; 5 import 'package:analysis_server/protocol/protocol_generated.dart' as server;
6 import 'package:analyzer_plugin/protocol/protocol.dart' as plugin; 6 import 'package:analyzer_plugin/protocol/protocol.dart' as plugin;
7 import 'package:analyzer_plugin/protocol/protocol_common.dart' as plugin; 7 import 'package:analyzer_plugin/protocol/protocol_common.dart';
8 import 'package:analyzer_plugin/protocol/protocol_constants.dart' as plugin; 8 import 'package:analyzer_plugin/protocol/protocol_constants.dart' as plugin;
9 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; 9 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
10 10
11 class ProtocolTestUtilities { 11 class ProtocolTestUtilities {
12 static const List<String> strings = const <String>[ 12 static const List<String> strings = const <String>[
13 'aa', 13 'aa',
14 'ab', 14 'ab',
15 'ac', 15 'ac',
16 'ad', 16 'ad',
17 'ae', 17 'ae',
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 'by', 63 'by',
64 'bz', 64 'bz',
65 ]; 65 ];
66 66
67 String fileName(int stringIndex) => '${strings[stringIndex]}.dart'; 67 String fileName(int stringIndex) => '${strings[stringIndex]}.dart';
68 68
69 /** 69 /**
70 * On return, increment [stringIndex] by 3 (or 4 if no [file] name is 70 * On return, increment [stringIndex] by 3 (or 4 if no [file] name is
71 * provided) and [intIndex] by 4. 71 * provided) and [intIndex] by 4.
72 */ 72 */
73 plugin.AnalysisError pluginAnalysisError(int stringIndex, int intIndex, 73 AnalysisError pluginAnalysisError(int stringIndex, int intIndex,
74 {String file}) { 74 {String file}) {
75 return new plugin.AnalysisError( 75 // TODO(brianwilkerson) Unify the "plugin" and "server" methods when the ret urn type is common.
76 plugin.AnalysisErrorSeverity.ERROR, 76 return new AnalysisError(
77 plugin.AnalysisErrorType.COMPILE_TIME_ERROR, 77 AnalysisErrorSeverity.ERROR,
78 AnalysisErrorType.COMPILE_TIME_ERROR,
78 pluginLocation(stringIndex, intIndex, file: file), 79 pluginLocation(stringIndex, intIndex, file: file),
79 strings[stringIndex++], 80 strings[stringIndex++],
80 strings[stringIndex++], 81 strings[stringIndex++],
81 correction: strings[stringIndex++], 82 correction: strings[stringIndex++],
82 hasFix: true); 83 hasFix: true);
83 } 84 }
84 85
85 /** 86 /**
86 * On return, increment [stringIndex] by 5 and [intIndex] by 5. 87 * On return, increment [stringIndex] by 5 and [intIndex] by 5.
87 */ 88 */
88 plugin.Element pluginElement(int stringIndex, int intIndex, 89 Element pluginElement(int stringIndex, int intIndex, {ElementKind kind}) =>
89 {plugin.ElementKind kind}) => 90 new Element(kind ?? ElementKind.CLASS, strings[stringIndex++], intIndex++,
90 new plugin.Element( 91 location: new Location(fileName(stringIndex++), intIndex++,
91 kind ?? plugin.ElementKind.CLASS, strings[stringIndex++], intIndex++,
92 location: new plugin.Location(fileName(stringIndex++), intIndex++,
93 intIndex++, intIndex++, intIndex++), 92 intIndex++, intIndex++, intIndex++),
94 parameters: strings[stringIndex++], 93 parameters: strings[stringIndex++],
95 returnType: strings[stringIndex++], 94 returnType: strings[stringIndex++],
96 typeParameters: strings[stringIndex++]); 95 typeParameters: strings[stringIndex++]);
97 96
98 plugin.FoldingRegion pluginFoldingRegion(int offset, int length) => 97 FoldingRegion pluginFoldingRegion(int offset, int length) =>
99 new plugin.FoldingRegion(plugin.FoldingKind.COMMENT, offset, length); 98 new FoldingRegion(FoldingKind.COMMENT, offset, length);
100 99
101 plugin.HighlightRegion pluginHighlightRegion(int offset, int length) => 100 HighlightRegion pluginHighlightRegion(int offset, int length) =>
102 new plugin.HighlightRegion( 101 new HighlightRegion(HighlightRegionType.FIELD, offset, length);
103 plugin.HighlightRegionType.FIELD, offset, length);
104 102
105 /** 103 /**
106 * On return, increment [stringIndex] by 1 and [intIndex] by 4. 104 * On return, increment [stringIndex] by 1 and [intIndex] by 4.
107 */ 105 */
108 plugin.Location pluginLocation(int stringIndex, int intIndex, 106 Location pluginLocation(int stringIndex, int intIndex, {String file}) =>
109 {String file}) => 107 new Location(file ?? fileName(stringIndex), intIndex++, intIndex++,
110 new plugin.Location(file ?? fileName(stringIndex), intIndex++, intIndex++,
111 intIndex++, intIndex++); 108 intIndex++, intIndex++);
112 109
113 /** 110 /**
114 * On return, increment [stringIndex] by 2 (or 3 if no [file] name is 111 * On return, increment [stringIndex] by 2 (or 3 if no [file] name is
115 * provided) and [intIndex] by 4. 112 * provided) and [intIndex] by 4.
116 */ 113 */
117 plugin.AnalysisNavigationParams pluginNavigationParams( 114 plugin.AnalysisNavigationParams pluginNavigationParams(
118 int stringIndex, int intIndex, {String file}) => 115 int stringIndex, int intIndex, {String file}) =>
119 new plugin.AnalysisNavigationParams( 116 new plugin.AnalysisNavigationParams(
120 file ?? fileName(stringIndex++), <plugin.NavigationRegion>[ 117 file ?? fileName(stringIndex++), <NavigationRegion>[
121 new plugin.NavigationRegion(intIndex++, 2, <int>[0]) 118 new NavigationRegion(intIndex++, 2, <int>[0])
122 ], <plugin.NavigationTarget>[ 119 ], <NavigationTarget>[
123 new plugin.NavigationTarget( 120 new NavigationTarget(
124 plugin.ElementKind.FIELD, 0, intIndex++, 2, intIndex++, intIndex++) 121 ElementKind.FIELD, 0, intIndex++, 2, intIndex++, intIndex++)
125 ], <String>[ 122 ], <String>[
126 strings[stringIndex++], 123 strings[stringIndex++],
127 strings[stringIndex++] 124 strings[stringIndex++]
128 ]); 125 ]);
129 126
130 /** 127 /**
131 * On return, increment [stringIndex] by 5 and [intIndex] by 7. 128 * On return, increment [stringIndex] by 5 and [intIndex] by 7.
132 */ 129 */
133 plugin.Occurrences pluginOccurrences(int stringIndex, int intIndex) { 130 Occurrences pluginOccurrences(int stringIndex, int intIndex) {
134 plugin.Element element = pluginElement(stringIndex, intIndex); 131 Element element = pluginElement(stringIndex, intIndex);
135 return new plugin.Occurrences( 132 return new Occurrences(
136 element, <int>[intIndex + 5, intIndex + 6], element.name.length); 133 element, <int>[intIndex + 5, intIndex + 6], element.name.length);
137 } 134 }
138 135
139 /** 136 /**
140 * On return, increment [stringIndex] by 10 and [intIndex] by 14. 137 * On return, increment [stringIndex] by 10 and [intIndex] by 14.
141 */ 138 */
142 plugin.Outline pluginOutline(int stringIndex, int intIndex) => 139 Outline pluginOutline(int stringIndex, int intIndex) => new Outline(
143 new plugin.Outline(
144 pluginElement(stringIndex, intIndex), intIndex + 5, intIndex + 6, 140 pluginElement(stringIndex, intIndex), intIndex + 5, intIndex + 6,
145 children: <plugin.Outline>[ 141 children: <Outline>[
146 new plugin.Outline( 142 new Outline(
147 pluginElement(stringIndex + 5, intIndex + 7, 143 pluginElement(stringIndex + 5, intIndex + 7,
148 kind: plugin.ElementKind.METHOD), 144 kind: ElementKind.METHOD),
149 intIndex + 12, 145 intIndex + 12,
150 intIndex + 13) 146 intIndex + 13)
151 ]); 147 ]);
152 148
153 /** 149 /**
154 * On return, increment [stringIndex] by 2 and [intIndex] by 4. 150 * On return, increment [stringIndex] by 2 and [intIndex] by 4.
155 */ 151 */
156 plugin.RefactoringProblem pluginRefactoringProblem( 152 RefactoringProblem pluginRefactoringProblem(int stringIndex, int intIndex) {
157 int stringIndex, int intIndex) { 153 return new RefactoringProblem(
158 return new plugin.RefactoringProblem( 154 RefactoringProblemSeverity.FATAL, strings[stringIndex++],
159 plugin.RefactoringProblemSeverity.FATAL, strings[stringIndex++],
160 location: pluginLocation(stringIndex, intIndex)); 155 location: pluginLocation(stringIndex, intIndex));
161 } 156 }
162 157
163 /** 158 /**
164 * On return, increment [stringIndex] by 6 and [intIndex] by 6. 159 * On return, increment [stringIndex] by 6 and [intIndex] by 6.
165 */ 160 */
166 plugin.SourceChange pluginSourceChange(int stringIndex, int intIndex) => 161 SourceChange pluginSourceChange(int stringIndex, int intIndex) =>
167 new plugin.SourceChange(strings[stringIndex++], 162 new SourceChange(strings[stringIndex++],
168 edits: <plugin.SourceFileEdit>[ 163 edits: <SourceFileEdit>[
169 new plugin.SourceFileEdit(fileName(stringIndex), intIndex++, 164 new SourceFileEdit(fileName(stringIndex), intIndex++,
170 edits: <plugin.SourceEdit>[ 165 edits: <SourceEdit>[
171 new plugin.SourceEdit( 166 new SourceEdit(intIndex++, intIndex++, strings[stringIndex++])
172 intIndex++, intIndex++, strings[stringIndex++])
173 ]) 167 ])
174 ], 168 ],
175 linkedEditGroups: <plugin.LinkedEditGroup>[ 169 linkedEditGroups: <LinkedEditGroup>[
176 new plugin.LinkedEditGroup( 170 new LinkedEditGroup(
177 <plugin.Position>[ 171 <Position>[new Position(fileName(stringIndex), intIndex++)],
178 new plugin.Position(fileName(stringIndex), intIndex++)
179 ],
180 intIndex++, 172 intIndex++,
181 <plugin.LinkedEditSuggestion>[ 173 <LinkedEditSuggestion>[
182 new plugin.LinkedEditSuggestion(strings[stringIndex++], 174 new LinkedEditSuggestion(
183 plugin.LinkedEditSuggestionKind.METHOD) 175 strings[stringIndex++], LinkedEditSuggestionKind.METHOD)
184 ]) 176 ])
185 ], 177 ],
186 selection: new plugin.Position(fileName(stringIndex), intIndex++)); 178 selection: new Position(fileName(stringIndex), intIndex++));
187 179
188 /** 180 /**
189 * On return, increment [stringIndex] by 3 (or 4 if no [file] name is 181 * On return, increment [stringIndex] by 3 (or 4 if no [file] name is
190 * provided) and [intIndex] by 4. 182 * provided) and [intIndex] by 4.
191 */ 183 */
192 server.AnalysisError serverAnalysisError(int stringIndex, int intIndex, 184 AnalysisError serverAnalysisError(int stringIndex, int intIndex,
193 {String file}) { 185 {String file}) {
194 return new server.AnalysisError( 186 return new AnalysisError(
195 server.AnalysisErrorSeverity.ERROR, 187 AnalysisErrorSeverity.ERROR,
196 server.AnalysisErrorType.COMPILE_TIME_ERROR, 188 AnalysisErrorType.COMPILE_TIME_ERROR,
197 serverLocation(stringIndex, intIndex, file: file), 189 serverLocation(stringIndex, intIndex, file: file),
198 strings[stringIndex++], 190 strings[stringIndex++],
199 strings[stringIndex++], 191 strings[stringIndex++],
200 correction: strings[stringIndex++], 192 correction: strings[stringIndex++],
201 hasFix: true); 193 hasFix: true);
202 } 194 }
203 195
204 /** 196 /**
205 * On return, increment [stringIndex] by 5 and [intIndex] by 5. 197 * On return, increment [stringIndex] by 5 and [intIndex] by 5.
206 */ 198 */
207 server.Element serverElement(int stringIndex, int intIndex, 199 Element serverElement(int stringIndex, int intIndex, {ElementKind kind}) =>
208 {server.ElementKind kind}) => 200 new Element(kind ?? ElementKind.CLASS, strings[stringIndex++], intIndex++,
209 new server.Element( 201 location: new Location(fileName(stringIndex++), intIndex++,
210 kind ?? server.ElementKind.CLASS, strings[stringIndex++], intIndex++,
211 location: new server.Location(fileName(stringIndex++), intIndex++,
212 intIndex++, intIndex++, intIndex++), 202 intIndex++, intIndex++, intIndex++),
213 parameters: strings[stringIndex++], 203 parameters: strings[stringIndex++],
214 returnType: strings[stringIndex++], 204 returnType: strings[stringIndex++],
215 typeParameters: strings[stringIndex++]); 205 typeParameters: strings[stringIndex++]);
216 206
217 server.FoldingRegion serverFoldingRegion(int offset, int length) => 207 FoldingRegion serverFoldingRegion(int offset, int length) =>
218 new server.FoldingRegion(server.FoldingKind.COMMENT, offset, length); 208 new FoldingRegion(FoldingKind.COMMENT, offset, length);
219 209
220 server.HighlightRegion serverHighlightRegion(int offset, int length) => 210 HighlightRegion serverHighlightRegion(int offset, int length) =>
221 new server.HighlightRegion( 211 new HighlightRegion(HighlightRegionType.FIELD, offset, length);
222 server.HighlightRegionType.FIELD, offset, length);
223 212
224 /** 213 /**
225 * On return, increment [stringIndex] by 1 and [intIndex] by 4. 214 * On return, increment [stringIndex] by 1 and [intIndex] by 4.
226 */ 215 */
227 server.Location serverLocation(int stringIndex, int intIndex, 216 Location serverLocation(int stringIndex, int intIndex, {String file}) =>
228 {String file}) => 217 new Location(file ?? fileName(stringIndex), intIndex++, intIndex++,
229 new server.Location(file ?? fileName(stringIndex), intIndex++, intIndex++,
230 intIndex++, intIndex++); 218 intIndex++, intIndex++);
231 219
232 /** 220 /**
233 * On return, increment [stringIndex] by 2 (or 3 if no [file] name is 221 * On return, increment [stringIndex] by 2 (or 3 if no [file] name is
234 * provided) and [intIndex] by 4. 222 * provided) and [intIndex] by 4.
235 */ 223 */
236 server.AnalysisNavigationParams serverNavigationParams( 224 server.AnalysisNavigationParams serverNavigationParams(
237 int stringIndex, int intIndex, {String file}) => 225 int stringIndex, int intIndex, {String file}) =>
238 new server.AnalysisNavigationParams( 226 new server.AnalysisNavigationParams(
239 file ?? fileName(stringIndex++), <server.NavigationRegion>[ 227 file ?? fileName(stringIndex++), <NavigationRegion>[
240 new server.NavigationRegion(intIndex++, 2, <int>[0]) 228 new NavigationRegion(intIndex++, 2, <int>[0])
241 ], <server.NavigationTarget>[ 229 ], <NavigationTarget>[
242 new server.NavigationTarget( 230 new NavigationTarget(
243 server.ElementKind.FIELD, 0, intIndex++, 2, intIndex++, intIndex++) 231 ElementKind.FIELD, 0, intIndex++, 2, intIndex++, intIndex++)
244 ], <String>[ 232 ], <String>[
245 strings[stringIndex++], 233 strings[stringIndex++],
246 strings[stringIndex++] 234 strings[stringIndex++]
247 ]); 235 ]);
248 236
249 /** 237 /**
250 * On return, increment [stringIndex] by 5 and [intIndex] by 7. 238 * On return, increment [stringIndex] by 5 and [intIndex] by 7.
251 */ 239 */
252 server.Occurrences serverOccurrences(int stringIndex, int intIndex) { 240 Occurrences serverOccurrences(int stringIndex, int intIndex) {
253 server.Element element = serverElement(stringIndex, intIndex); 241 Element element = serverElement(stringIndex, intIndex);
254 return new server.Occurrences( 242 return new Occurrences(
255 element, <int>[intIndex + 5, intIndex + 6], element.name.length); 243 element, <int>[intIndex + 5, intIndex + 6], element.name.length);
256 } 244 }
257 245
258 /** 246 /**
259 * On return, increment [stringIndex] by 10 and [intIndex] by 14. 247 * On return, increment [stringIndex] by 10 and [intIndex] by 14.
260 */ 248 */
261 server.Outline serverOutline(int stringIndex, int intIndex) => 249 Outline serverOutline(int stringIndex, int intIndex) => new Outline(
262 new server.Outline(
263 serverElement(stringIndex, intIndex), intIndex + 5, intIndex + 6, 250 serverElement(stringIndex, intIndex), intIndex + 5, intIndex + 6,
264 children: <server.Outline>[ 251 children: <Outline>[
265 new server.Outline( 252 new Outline(
266 serverElement(stringIndex + 5, intIndex + 7, 253 serverElement(stringIndex + 5, intIndex + 7,
267 kind: server.ElementKind.METHOD), 254 kind: ElementKind.METHOD),
268 intIndex + 12, 255 intIndex + 12,
269 intIndex + 13) 256 intIndex + 13)
270 ]); 257 ]);
271 258
272 /** 259 /**
273 * On return, increment [stringIndex] by 2 and [intIndex] by 4. 260 * On return, increment [stringIndex] by 2 and [intIndex] by 4.
274 */ 261 */
275 server.RefactoringProblem serverRefactoringProblem( 262 RefactoringProblem serverRefactoringProblem(int stringIndex, int intIndex) =>
276 int stringIndex, int intIndex) => 263 new RefactoringProblem(
277 new server.RefactoringProblem( 264 RefactoringProblemSeverity.FATAL, strings[stringIndex++],
278 server.RefactoringProblemSeverity.FATAL, strings[stringIndex++],
279 location: serverLocation(stringIndex, intIndex)); 265 location: serverLocation(stringIndex, intIndex));
280 266
281 /** 267 /**
282 * On return, increment [stringIndex] by 6 and [intIndex] by 6. 268 * On return, increment [stringIndex] by 6 and [intIndex] by 6.
283 */ 269 */
284 server.SourceChange serverSourceChange(int stringIndex, int intIndex) => 270 SourceChange serverSourceChange(int stringIndex, int intIndex) =>
285 new server.SourceChange(strings[stringIndex++], 271 new SourceChange(strings[stringIndex++],
286 edits: <server.SourceFileEdit>[ 272 edits: <SourceFileEdit>[
287 new server.SourceFileEdit(fileName(stringIndex), intIndex++, 273 new SourceFileEdit(fileName(stringIndex), intIndex++,
288 edits: <server.SourceEdit>[ 274 edits: <SourceEdit>[
289 new server.SourceEdit( 275 new SourceEdit(intIndex++, intIndex++, strings[stringIndex++])
290 intIndex++, intIndex++, strings[stringIndex++])
291 ]) 276 ])
292 ], 277 ],
293 linkedEditGroups: <server.LinkedEditGroup>[ 278 linkedEditGroups: <LinkedEditGroup>[
294 new server.LinkedEditGroup( 279 new LinkedEditGroup(
295 <server.Position>[ 280 <Position>[new Position(fileName(stringIndex), intIndex++)],
296 new server.Position(fileName(stringIndex), intIndex++)
297 ],
298 intIndex++, 281 intIndex++,
299 <server.LinkedEditSuggestion>[ 282 <LinkedEditSuggestion>[
300 new server.LinkedEditSuggestion(strings[stringIndex++], 283 new LinkedEditSuggestion(
301 server.LinkedEditSuggestionKind.METHOD) 284 strings[stringIndex++], LinkedEditSuggestionKind.METHOD)
302 ]) 285 ])
303 ], 286 ],
304 selection: new server.Position(fileName(stringIndex), intIndex++)); 287 selection: new Position(fileName(stringIndex), intIndex++));
305 } 288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698