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

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/local_computer.dart

Issue 684183002: Refactor CompletionSuggestionKind (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 1 month 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 | Annotate | Revision Log
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 services.completion.computer.dart.local; 5 library services.completion.computer.dart.local;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element,
10 ElementKind; 10 ElementKind;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 _addClassSuggestion(declaration); 128 _addClassSuggestion(declaration);
129 } else if (declaration is EnumDeclaration) { 129 } else if (declaration is EnumDeclaration) {
130 // _addSuggestion(d.name, CompletionSuggestionKind.ENUM); 130 // _addSuggestion(d.name, CompletionSuggestionKind.ENUM);
131 } else if (declaration is FunctionDeclaration) { 131 } else if (declaration is FunctionDeclaration) {
132 _addFunctionSuggestion(declaration); 132 _addFunctionSuggestion(declaration);
133 } else if (declaration is TopLevelVariableDeclaration) { 133 } else if (declaration is TopLevelVariableDeclaration) {
134 _addTopLevelVarSuggestions(declaration.variables); 134 _addTopLevelVarSuggestions(declaration.variables);
135 } else if (declaration is ClassTypeAlias) { 135 } else if (declaration is ClassTypeAlias) {
136 CompletionSuggestion suggestion = _addSuggestion( 136 CompletionSuggestion suggestion = _addSuggestion(
137 declaration.name, 137 declaration.name,
138 CompletionSuggestionKind.CLASS_ALIAS,
139 null, 138 null,
140 null); 139 null);
141 if (suggestion != null) { 140 if (suggestion != null) {
142 suggestion.element = _createElement( 141 suggestion.element = _createElement(
143 protocol.ElementKind.CLASS_TYPE_ALIAS, 142 protocol.ElementKind.CLASS_TYPE_ALIAS,
144 declaration.name, 143 declaration.name,
145 null, 144 null,
146 NO_RETURN_TYPE, 145 NO_RETURN_TYPE,
147 true, 146 true,
148 _isDeprecated(declaration.metadata)); 147 _isDeprecated(declaration.metadata));
149 } 148 }
150 } else if (declaration is FunctionTypeAlias) { 149 } else if (declaration is FunctionTypeAlias) {
151 CompletionSuggestion suggestion = _addSuggestion( 150 CompletionSuggestion suggestion = _addSuggestion(
152 declaration.name, 151 declaration.name,
153 CompletionSuggestionKind.FUNCTION_TYPE_ALIAS,
154 declaration.returnType, 152 declaration.returnType,
155 null); 153 null);
156 if (suggestion != null) { 154 if (suggestion != null) {
157 suggestion.element = _createElement( 155 suggestion.element = _createElement(
158 protocol.ElementKind.FUNCTION_TYPE_ALIAS, 156 protocol.ElementKind.FUNCTION_TYPE_ALIAS,
159 declaration.name, 157 declaration.name,
160 null, // TODO (danrubel) determine parameters 158 null,
161 NO_RETURN_TYPE, // TODO (danrubel) determine return type 159 // TODO (danrubel) determine parameters
162 true, 160 NO_RETURN_TYPE, // TODO (danrubel) determine return type
163 _isDeprecated(declaration.metadata)); 161 true, _isDeprecated(declaration.metadata));
164 } 162 }
165 } 163 }
166 }); 164 });
167 } 165 }
168 166
169 @override 167 @override
170 visitExpressionStatement(ExpressionStatement node) { 168 visitExpressionStatement(ExpressionStatement node) {
171 Expression expression = node.expression; 169 Expression expression = node.expression;
172 if (expression is SimpleIdentifier) { 170 if (expression is SimpleIdentifier) {
173 if (expression.end < request.offset) { 171 if (expression.end < request.offset) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 if (classMbr is FieldDeclaration) { 300 if (classMbr is FieldDeclaration) {
303 _addFieldSuggestions(node, classMbr); 301 _addFieldSuggestions(node, classMbr);
304 } else if (classMbr is MethodDeclaration) { 302 } else if (classMbr is MethodDeclaration) {
305 _addMethodSuggestion(node, classMbr); 303 _addMethodSuggestion(node, classMbr);
306 } 304 }
307 }); 305 });
308 } 306 }
309 307
310 void _addClassSuggestion(ClassDeclaration declaration) { 308 void _addClassSuggestion(ClassDeclaration declaration) {
311 CompletionSuggestion suggestion = 309 CompletionSuggestion suggestion =
312 _addSuggestion(declaration.name, CompletionSuggestionKind.CLASS, null, n ull); 310 _addSuggestion(declaration.name, null, null);
313 if (suggestion != null) { 311 if (suggestion != null) {
314 suggestion.element = _createElement( 312 suggestion.element = _createElement(
315 protocol.ElementKind.CLASS, 313 protocol.ElementKind.CLASS,
316 declaration.name, 314 declaration.name,
317 null, 315 null,
318 NO_RETURN_TYPE, 316 NO_RETURN_TYPE,
319 declaration.isAbstract, 317 declaration.isAbstract,
320 _isDeprecated(declaration.metadata)); 318 _isDeprecated(declaration.metadata));
321 } 319 }
322 } 320 }
323 321
324 void _addFieldSuggestions(ClassDeclaration node, FieldDeclaration fieldDecl) { 322 void _addFieldSuggestions(ClassDeclaration node, FieldDeclaration fieldDecl) {
325 if (typesOnly) { 323 if (typesOnly) {
326 return; 324 return;
327 } 325 }
328 bool isDeprecated = _isDeprecated(fieldDecl.metadata); 326 bool isDeprecated = _isDeprecated(fieldDecl.metadata);
329 fieldDecl.fields.variables.forEach((VariableDeclaration varDecl) { 327 fieldDecl.fields.variables.forEach((VariableDeclaration varDecl) {
330 CompletionSuggestion suggestion = _addSuggestion( 328 CompletionSuggestion suggestion = _addSuggestion(
331 varDecl.name, 329 varDecl.name,
332 CompletionSuggestionKind.GETTER,
333 fieldDecl.fields.type, 330 fieldDecl.fields.type,
334 node); 331 node);
335 if (suggestion != null) { 332 if (suggestion != null) {
336 suggestion.element = _createElement( 333 suggestion.element = _createElement(
337 protocol.ElementKind.GETTER, 334 protocol.ElementKind.GETTER,
338 varDecl.name, 335 varDecl.name,
339 '()', 336 '()',
340 fieldDecl.fields.type, 337 fieldDecl.fields.type,
341 false, 338 false,
342 isDeprecated || _isDeprecated(varDecl.metadata)); 339 isDeprecated || _isDeprecated(varDecl.metadata));
343 } 340 }
344 }); 341 });
345 } 342 }
346 343
347 void _addFunctionSuggestion(FunctionDeclaration declaration) { 344 void _addFunctionSuggestion(FunctionDeclaration declaration) {
348 if (typesOnly) { 345 if (typesOnly) {
349 return; 346 return;
350 } 347 }
351 if (excludeVoidReturn && _isVoid(declaration.returnType)) { 348 if (excludeVoidReturn && _isVoid(declaration.returnType)) {
352 return; 349 return;
353 } 350 }
354 CompletionSuggestion suggestion = _addSuggestion( 351 CompletionSuggestion suggestion = _addSuggestion(
355 declaration.name, 352 declaration.name,
356 CompletionSuggestionKind.FUNCTION,
357 declaration.returnType, 353 declaration.returnType,
358 null); 354 null);
359 if (suggestion != null) { 355 if (suggestion != null) {
360 suggestion.element = _createElement( 356 suggestion.element = _createElement(
361 protocol.ElementKind.FUNCTION, 357 protocol.ElementKind.FUNCTION,
362 declaration.name, 358 declaration.name,
363 declaration.functionExpression.parameters.toSource(), 359 declaration.functionExpression.parameters.toSource(),
364 declaration.returnType, 360 declaration.returnType,
365 false, 361 false,
366 _isDeprecated(declaration.metadata)); 362 _isDeprecated(declaration.metadata));
367 } 363 }
368 } 364 }
369 365
370 void _addLocalVarSuggestion(SimpleIdentifier id, TypeName returnType) { 366 void _addLocalVarSuggestion(SimpleIdentifier id, TypeName returnType) {
371 if (typesOnly) { 367 if (typesOnly) {
372 return; 368 return;
373 } 369 }
374 CompletionSuggestion suggestion = 370 CompletionSuggestion suggestion =
375 _addSuggestion(id, CompletionSuggestionKind.LOCAL_VARIABLE, returnType, null); 371 _addSuggestion(id, returnType, null);
376 if (suggestion != null) { 372 if (suggestion != null) {
377 suggestion.element = _createElement( 373 suggestion.element = _createElement(
378 protocol.ElementKind.LOCAL_VARIABLE, 374 protocol.ElementKind.LOCAL_VARIABLE,
379 id, 375 id,
380 null, 376 null,
381 returnType, 377 returnType,
382 false, 378 false,
383 false); 379 false);
384 } 380 }
385 } 381 }
386 382
387 void _addMethodSuggestion(ClassDeclaration node, MethodDeclaration classMbr) { 383 void _addMethodSuggestion(ClassDeclaration node, MethodDeclaration classMbr) {
388 if (typesOnly) { 384 if (typesOnly) {
389 return; 385 return;
390 } 386 }
391 protocol.ElementKind kind; 387 protocol.ElementKind kind;
392 CompletionSuggestionKind csKind;
393 String parameters; 388 String parameters;
394 if (classMbr.isGetter) { 389 if (classMbr.isGetter) {
395 kind = protocol.ElementKind.GETTER; 390 kind = protocol.ElementKind.GETTER;
396 csKind = CompletionSuggestionKind.GETTER;
397 parameters = '()'; 391 parameters = '()';
398 } else if (classMbr.isSetter) { 392 } else if (classMbr.isSetter) {
399 if (excludeVoidReturn) { 393 if (excludeVoidReturn) {
400 return; 394 return;
401 } 395 }
402 kind = protocol.ElementKind.SETTER; 396 kind = protocol.ElementKind.SETTER;
403 csKind = CompletionSuggestionKind.SETTER;
404 parameters = '(${classMbr.returnType.toSource()} value)'; 397 parameters = '(${classMbr.returnType.toSource()} value)';
405 } else { 398 } else {
406 if (excludeVoidReturn && _isVoid(classMbr.returnType)) { 399 if (excludeVoidReturn && _isVoid(classMbr.returnType)) {
407 return; 400 return;
408 } 401 }
409 kind = protocol.ElementKind.METHOD; 402 kind = protocol.ElementKind.METHOD;
410 csKind = CompletionSuggestionKind.METHOD;
411 parameters = classMbr.parameters.toSource(); 403 parameters = classMbr.parameters.toSource();
412 } 404 }
413 CompletionSuggestion suggestion = 405 CompletionSuggestion suggestion = _addSuggestion(
414 _addSuggestion(classMbr.name, csKind, classMbr.returnType, node); 406 classMbr.name,
407 classMbr.returnType,
408 node);
415 if (suggestion != null) { 409 if (suggestion != null) {
416 suggestion.element = _createElement( 410 suggestion.element = _createElement(
417 kind, 411 kind,
418 classMbr.name, 412 classMbr.name,
419 parameters, 413 parameters,
420 classMbr.returnType, 414 classMbr.returnType,
421 classMbr.isAbstract, 415 classMbr.isAbstract,
422 _isDeprecated(classMbr.metadata)); 416 _isDeprecated(classMbr.metadata));
423 } 417 }
424 } 418 }
(...skipping 21 matching lines...) Expand all
446 _addParamSuggestion(param.identifier, type); 440 _addParamSuggestion(param.identifier, type);
447 }); 441 });
448 } 442 }
449 } 443 }
450 444
451 void _addParamSuggestion(SimpleIdentifier identifier, TypeName type) { 445 void _addParamSuggestion(SimpleIdentifier identifier, TypeName type) {
452 if (typesOnly) { 446 if (typesOnly) {
453 return; 447 return;
454 } 448 }
455 CompletionSuggestion suggestion = 449 CompletionSuggestion suggestion =
456 _addSuggestion(identifier, CompletionSuggestionKind.PARAMETER, type, nul l); 450 _addSuggestion(identifier, type, null);
457 if (suggestion != null) { 451 if (suggestion != null) {
458 suggestion.element = _createElement( 452 suggestion.element = _createElement(
459 protocol.ElementKind.PARAMETER, 453 protocol.ElementKind.PARAMETER,
460 identifier, 454 identifier,
461 null, 455 null,
462 type, 456 type,
463 false, 457 false,
464 false); 458 false);
465 } 459 }
466 } 460 }
467 461
468 CompletionSuggestion _addSuggestion(SimpleIdentifier id, 462 CompletionSuggestion _addSuggestion(SimpleIdentifier id,
469 CompletionSuggestionKind kind, TypeName typeName, ClassDeclaration classDe cl) { 463 TypeName typeName, ClassDeclaration classDecl) {
470 if (id != null) { 464 if (id != null) {
471 String completion = id.name; 465 String completion = id.name;
472 if (completion != null && completion.length > 0 && completion != '_') { 466 if (completion != null && completion.length > 0 && completion != '_') {
473 CompletionSuggestion suggestion = new CompletionSuggestion( 467 CompletionSuggestion suggestion = new CompletionSuggestion(
474 kind, 468 CompletionSuggestionKind.INVOCATION,
475 CompletionRelevance.DEFAULT, 469 CompletionRelevance.DEFAULT,
476 completion, 470 completion,
477 completion.length, 471 completion.length,
478 0, 472 0,
479 false, 473 false,
480 false); 474 false);
481 if (classDecl != null) { 475 if (classDecl != null) {
482 SimpleIdentifier identifier = classDecl.name; 476 SimpleIdentifier identifier = classDecl.name;
483 if (identifier != null) { 477 if (identifier != null) {
484 String name = identifier.name; 478 String name = identifier.name;
(...skipping 20 matching lines...) Expand all
505 499
506 void _addTopLevelVarSuggestions(VariableDeclarationList varList) { 500 void _addTopLevelVarSuggestions(VariableDeclarationList varList) {
507 if (typesOnly) { 501 if (typesOnly) {
508 return; 502 return;
509 } 503 }
510 if (varList != null) { 504 if (varList != null) {
511 bool isDeprecated = _isDeprecated(varList.metadata); 505 bool isDeprecated = _isDeprecated(varList.metadata);
512 varList.variables.forEach((VariableDeclaration varDecl) { 506 varList.variables.forEach((VariableDeclaration varDecl) {
513 CompletionSuggestion suggestion = _addSuggestion( 507 CompletionSuggestion suggestion = _addSuggestion(
514 varDecl.name, 508 varDecl.name,
515 CompletionSuggestionKind.TOP_LEVEL_VARIABLE,
516 varList.type, 509 varList.type,
517 null); 510 null);
518 if (suggestion != null) { 511 if (suggestion != null) {
519 suggestion.element = _createElement( 512 suggestion.element = _createElement(
520 protocol.ElementKind.TOP_LEVEL_VARIABLE, 513 protocol.ElementKind.TOP_LEVEL_VARIABLE,
521 varDecl.name, 514 varDecl.name,
522 null, 515 null,
523 varList.type, 516 varList.type,
524 false, 517 false,
525 isDeprecated || _isDeprecated(varDecl.metadata)); 518 isDeprecated || _isDeprecated(varDecl.metadata));
526 } 519 }
527 }); 520 });
528 } 521 }
529 } 522 }
530 523
531 bool _computeExcludeVoidReturn(AstNode node) { 524 bool _computeExcludeVoidReturn(AstNode node) {
532 if (node is Block) { 525 if (node is Block) {
533 return false; 526 return false;
534 } else if (node is SimpleIdentifier) { 527 } else if (node is SimpleIdentifier) {
535 return node.parent is ExpressionStatement ? false : true; 528 return node.parent is ExpressionStatement ? false : true;
536 } else { 529 } else {
537 return true; 530 return true;
538 } 531 }
539 } 532 }
540 533
541 /** 534 /**
542 * Create a new protocol Element for inclusion in a completion suggestion. 535 * Create a new protocol Element for inclusion in a completion suggestion.
543 */ 536 */
544 protocol.Element _createElement(protocol.ElementKind kind, 537 protocol.Element _createElement(protocol.ElementKind kind,
545 SimpleIdentifier id, String parameters, TypeName returnType, 538 SimpleIdentifier id, String parameters, TypeName returnType, bool isAbstra ct,
546 bool isAbstract, bool isDeprecated) { 539 bool isDeprecated) {
547 String name = id.name; 540 String name = id.name;
548 int flags = protocol.Element.makeFlags( 541 int flags = protocol.Element.makeFlags(
549 isAbstract: isAbstract, 542 isAbstract: isAbstract,
550 isDeprecated: isDeprecated, 543 isDeprecated: isDeprecated,
551 isPrivate: Identifier.isPrivateName(name)); 544 isPrivate: Identifier.isPrivateName(name));
552 return new protocol.Element( 545 return new protocol.Element(
553 kind, 546 kind,
554 name, 547 name,
555 flags, 548 flags,
556 parameters: parameters, 549 parameters: parameters,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 if (name == null || name.length <= 0) { 586 if (name == null || name.length <= 0) {
594 return DYNAMIC; 587 return DYNAMIC;
595 } 588 }
596 TypeArgumentList typeArgs = type.typeArguments; 589 TypeArgumentList typeArgs = type.typeArguments;
597 if (typeArgs != null) { 590 if (typeArgs != null) {
598 //TODO (danrubel) include type arguments 591 //TODO (danrubel) include type arguments
599 } 592 }
600 return name; 593 return name;
601 } 594 }
602 } 595 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698