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

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

Issue 1507633002: extract named constructor suggestions 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 services.completion.suggestion.builder; 5 library services.completion.suggestion.builder;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analysis_server/src/protocol_server.dart' 10 import 'package:analysis_server/src/protocol_server.dart'
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 bool instCreation) { 461 bool instCreation) {
462 if (library != null) { 462 if (library != null) {
463 library.visitChildren(new LibraryElementSuggestionBuilder( 463 library.visitChildren(new LibraryElementSuggestionBuilder(
464 request, kind, typesOnly, instCreation)); 464 request, kind, typesOnly, instCreation));
465 } 465 }
466 } 466 }
467 } 467 }
468 468
469 /** 469 /**
470 * This class visits elements in a class and provides suggestions based upon 470 * This class visits elements in a class and provides suggestions based upon
471 * the visible named constructors in that class.
472 */
473 class NamedConstructorSuggestionBuilder extends GeneralizingElementVisitor
474 with ElementSuggestionBuilder
475 implements SuggestionBuilder {
476 final DartCompletionRequest request;
477
478 NamedConstructorSuggestionBuilder(this.request);
479
480 @override
481 CompletionSuggestionKind get kind => CompletionSuggestionKind.INVOCATION;
482
483 @override
484 bool computeFast(AstNode node) {
485 return false;
486 }
487
488 @override
489 Future<bool> computeFull(AstNode node) {
490 if (node is SimpleIdentifier) {
491 node = node.parent;
492 }
493 if (node is ConstructorName) {
494 TypeName typeName = node.type;
495 if (typeName != null) {
496 DartType type = typeName.type;
497 if (type != null) {
498 if (type.element is ClassElement) {
499 type.element.accept(this);
500 }
501 return new Future.value(true);
502 }
503 }
504 }
505 return new Future.value(false);
506 }
507
508 @override
509 visitClassElement(ClassElement element) {
510 element.visitChildren(this);
511 }
512
513 @override
514 visitConstructorElement(ConstructorElement element) {
515 addSuggestion(element);
516 }
517
518 @override
519 visitElement(Element element) {
520 // ignored
521 }
522 }
523
524 /**
525 * This class visits elements in a class and provides suggestions based upon
526 * the visible static members in that class. Clients should call 471 * the visible static members in that class. Clients should call
527 * [StaticClassElementSuggestionBuilder.suggestionsFor]. 472 * [StaticClassElementSuggestionBuilder.suggestionsFor].
528 */ 473 */
529 class StaticClassElementSuggestionBuilder extends GeneralizingElementVisitor 474 class StaticClassElementSuggestionBuilder extends GeneralizingElementVisitor
530 with ElementSuggestionBuilder { 475 with ElementSuggestionBuilder {
531 final DartCompletionRequest request; 476 final DartCompletionRequest request;
532 477
533 StaticClassElementSuggestionBuilder(this.request); 478 StaticClassElementSuggestionBuilder(this.request);
534 479
535 @override 480 @override
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 * or `false` if [computeFull] should be called. 542 * or `false` if [computeFull] should be called.
598 */ 543 */
599 bool computeFast(AstNode node); 544 bool computeFast(AstNode node);
600 545
601 /** 546 /**
602 * Return a future that computes the suggestions given a fully resolved AST. 547 * Return a future that computes the suggestions given a fully resolved AST.
603 * The future returns `true` if suggestions were added, else `false`. 548 * The future returns `true` if suggestions were added, else `false`.
604 */ 549 */
605 Future<bool> computeFull(AstNode node); 550 Future<bool> computeFull(AstNode node);
606 } 551 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698