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

Side by Side Diff: pkg/analysis_server/test/services/completion/dart/completion_contributor_util.dart

Issue 1507513002: extract field formal contributor from prefixed element contributor (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library test.services.completion.dart.util; 5 library test.services.completion.dart.util;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol 9 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol
10 show Element, ElementKind; 10 show Element, ElementKind;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 protocol.Element element = cs.element; 153 protocol.Element element = cs.element;
154 expect(element, isNotNull); 154 expect(element, isNotNull);
155 expect(element.kind, equals(protocol.ElementKind.CLASS)); 155 expect(element.kind, equals(protocol.ElementKind.CLASS));
156 expect(element.name, equals(name)); 156 expect(element.name, equals(name));
157 expect(element.parameters, isNull); 157 expect(element.parameters, isNull);
158 expect(element.returnType, isNull); 158 expect(element.returnType, isNull);
159 assertHasNoParameterInfo(cs); 159 assertHasNoParameterInfo(cs);
160 return cs; 160 return cs;
161 } 161 }
162 162
163 CompletionSuggestion assertSuggestConstructor(String name,
164 {int relevance: DART_RELEVANCE_DEFAULT,
165 String importUri,
166 int elemOffset}) {
167 CompletionSuggestion cs = assertSuggest(name,
168 relevance: relevance, importUri: importUri, elemOffset: elemOffset);
169 protocol.Element element = cs.element;
170 expect(element, isNotNull);
171 expect(element.kind, equals(protocol.ElementKind.CONSTRUCTOR));
172 int index = name.indexOf('.');
173 expect(element.name, index >= 0 ? name.substring(index + 1) : '');
174 return cs;
175 }
176
177 CompletionSuggestion assertSuggestEnum(String completion,
178 {bool isDeprecated: false}) {
179 CompletionSuggestion suggestion =
180 assertSuggest(completion, isDeprecated: isDeprecated);
181 expect(suggestion.isDeprecated, isDeprecated);
182 expect(suggestion.element.kind, protocol.ElementKind.ENUM);
183 return suggestion;
184 }
185
186 CompletionSuggestion assertSuggestEnumConst(String completion,
187 {bool isDeprecated: false}) {
188 CompletionSuggestion suggestion =
189 assertSuggest(completion, isDeprecated: isDeprecated);
190 expect(suggestion.isDeprecated, isDeprecated);
191 expect(suggestion.element.kind, protocol.ElementKind.ENUM_CONSTANT);
192 return suggestion;
193 }
194
195 CompletionSuggestion assertSuggestField(String name, String type,
196 {int relevance: DART_RELEVANCE_DEFAULT,
197 String importUri,
198 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
199 bool isDeprecated: false}) {
200 CompletionSuggestion cs = assertSuggest(name,
201 csKind: kind,
202 relevance: relevance,
203 importUri: importUri,
204 elemKind: protocol.ElementKind.FIELD,
205 isDeprecated: isDeprecated);
206 // The returnType represents the type of a field
207 expect(cs.returnType, type != null ? type : 'dynamic');
208 protocol.Element element = cs.element;
209 expect(element, isNotNull);
210 expect(element.kind, equals(protocol.ElementKind.FIELD));
211 expect(element.name, equals(name));
212 expect(element.parameters, isNull);
213 // The returnType represents the type of a field
214 expect(element.returnType, type != null ? type : 'dynamic');
215 assertHasNoParameterInfo(cs);
216 return cs;
217 }
218
163 CompletionSuggestion assertSuggestFunction(String name, String returnType, 219 CompletionSuggestion assertSuggestFunction(String name, String returnType,
164 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, 220 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
165 bool deprecated: false, 221 bool deprecated: false,
166 int relevance: DART_RELEVANCE_DEFAULT, 222 int relevance: DART_RELEVANCE_DEFAULT,
167 String importUri}) { 223 String importUri}) {
168 CompletionSuggestion cs = assertSuggest(name, 224 CompletionSuggestion cs = assertSuggest(name,
169 csKind: kind, 225 csKind: kind,
170 relevance: relevance, 226 relevance: relevance,
171 importUri: importUri, 227 importUri: importUri,
172 isDeprecated: deprecated); 228 isDeprecated: deprecated);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // expect(param, isNotNull); 263 // expect(param, isNotNull);
208 // expect(param[0], equals('(')); 264 // expect(param[0], equals('('));
209 // expect(param[param.length - 1], equals(')')); 265 // expect(param[param.length - 1], equals(')'));
210 expect(element.returnType, 266 expect(element.returnType,
211 equals(returnType != null ? returnType : 'dynamic')); 267 equals(returnType != null ? returnType : 'dynamic'));
212 // TODO (danrubel) Determine why param info is missing 268 // TODO (danrubel) Determine why param info is missing
213 // assertHasParameterInfo(cs); 269 // assertHasParameterInfo(cs);
214 return cs; 270 return cs;
215 } 271 }
216 272
273 CompletionSuggestion assertSuggestGetter(String name, String returnType,
274 {int relevance: DART_RELEVANCE_DEFAULT,
275 String importUri,
276 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
277 bool isDeprecated: false}) {
278 CompletionSuggestion cs = assertSuggest(name,
279 csKind: kind,
280 relevance: relevance,
281 importUri: importUri,
282 elemKind: protocol.ElementKind.GETTER,
283 isDeprecated: isDeprecated);
284 expect(cs.returnType, returnType != null ? returnType : 'dynamic');
285 protocol.Element element = cs.element;
286 expect(element, isNotNull);
287 expect(element.kind, equals(protocol.ElementKind.GETTER));
288 expect(element.name, equals(name));
289 expect(element.parameters, isNull);
290 expect(element.returnType,
291 equals(returnType != null ? returnType : 'dynamic'));
292 assertHasNoParameterInfo(cs);
293 return cs;
294 }
295
296 CompletionSuggestion assertSuggestMethod(
297 String name, String declaringType, String returnType,
298 {int relevance: DART_RELEVANCE_DEFAULT,
299 String importUri,
300 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
301 bool isDeprecated: false}) {
302 CompletionSuggestion cs = assertSuggest(name,
303 csKind: kind,
304 relevance: relevance,
305 importUri: importUri,
306 isDeprecated: isDeprecated);
307 expect(cs.declaringType, equals(declaringType));
308 expect(cs.returnType, returnType != null ? returnType : 'dynamic');
309 protocol.Element element = cs.element;
310 expect(element, isNotNull);
311 expect(element.kind, equals(protocol.ElementKind.METHOD));
312 expect(element.name, equals(name));
313 String param = element.parameters;
314 expect(param, isNotNull);
315 expect(param[0], equals('('));
316 expect(param[param.length - 1], equals(')'));
317 expect(element.returnType, returnType != null ? returnType : 'dynamic');
318 assertHasParameterInfo(cs);
319 return cs;
320 }
321
322 CompletionSuggestion assertSuggestSetter(String name,
323 [int relevance = DART_RELEVANCE_DEFAULT,
324 String importUri,
325 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) {
326 CompletionSuggestion cs = assertSuggest(name,
327 csKind: kind,
328 relevance: relevance,
329 importUri: importUri,
330 elemKind: protocol.ElementKind.SETTER);
331 protocol.Element element = cs.element;
332 expect(element, isNotNull);
333 expect(element.kind, equals(protocol.ElementKind.SETTER));
334 expect(element.name, equals(name));
335 // TODO (danrubel) assert setter param
336 //expect(element.parameters, isNull);
337 // TODO (danrubel) it would be better if this was always null
338 if (element.returnType != null) {
339 expect(element.returnType, 'dynamic');
340 }
341 assertHasNoParameterInfo(cs);
342 return cs;
343 }
344
217 CompletionSuggestion assertSuggestTopLevelVar(String name, String returnType, 345 CompletionSuggestion assertSuggestTopLevelVar(String name, String returnType,
218 {int relevance: DART_RELEVANCE_DEFAULT, 346 {int relevance: DART_RELEVANCE_DEFAULT,
219 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, 347 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
220 String importUri}) { 348 String importUri}) {
221 CompletionSuggestion cs = assertSuggest(name, 349 CompletionSuggestion cs = assertSuggest(name,
222 csKind: kind, relevance: relevance, importUri: importUri); 350 csKind: kind, relevance: relevance, importUri: importUri);
223 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); 351 expect(cs.returnType, returnType != null ? returnType : 'dynamic');
224 protocol.Element element = cs.element; 352 protocol.Element element = cs.element;
225 expect(element, isNotNull); 353 expect(element, isNotNull);
226 expect(element.kind, equals(protocol.ElementKind.TOP_LEVEL_VARIABLE)); 354 expect(element.kind, equals(protocol.ElementKind.TOP_LEVEL_VARIABLE));
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 } 459 }
332 460
333 @override 461 @override
334 void setUp() { 462 void setUp() {
335 super.setUp(); 463 super.setUp();
336 index = createLocalMemoryIndex(); 464 index = createLocalMemoryIndex();
337 searchEngine = new SearchEngineImpl(index); 465 searchEngine = new SearchEngineImpl(index);
338 contributor = createContributor(); 466 contributor = createContributor();
339 } 467 }
340 } 468 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698