| OLD | NEW |
| 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.combinator; | 5 library services.completion.computer.dart.combinator; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol_server.dart' hide Element, | 9 import 'package:analysis_server/src/protocol_server.dart' hide Element, |
| 10 ElementKind; | 10 ElementKind; |
| 11 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 11 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| 12 import 'package:analysis_server/src/services/completion/suggestion_builder.dart'
; | 12 import 'package:analysis_server/src/services/completion/suggestion_builder.dart'
; |
| 13 import 'package:analyzer/src/generated/ast.dart'; | 13 import 'package:analyzer/src/generated/ast.dart'; |
| 14 import 'package:analyzer/src/generated/element.dart'; | 14 import 'package:analyzer/src/generated/element.dart'; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * A computer for calculating `completion.getSuggestions` request results | 17 * A computer for calculating `completion.getSuggestions` request results |
| 18 * for the import combinators show and hide. | 18 * for the import combinators show and hide. |
| 19 */ | 19 */ |
| 20 | |
| 21 class CombinatorComputer extends DartCompletionComputer { | 20 class CombinatorComputer extends DartCompletionComputer { |
| 21 _CombinatorSuggestionBuilder builder; |
| 22 | 22 |
| 23 @override | 23 @override |
| 24 bool computeFast(DartCompletionRequest request) { | 24 bool computeFast(DartCompletionRequest request) { |
| 25 return false; | 25 builder = request.node.accept(new _CombinatorAstVisitor(request)); |
| 26 return builder == null; |
| 26 } | 27 } |
| 27 | 28 |
| 28 @override | 29 @override |
| 29 Future<bool> computeFull(DartCompletionRequest request) { | 30 Future<bool> computeFull(DartCompletionRequest request) { |
| 30 return request.node.accept(new _CombinatorAstVisitor(request)); | 31 if (builder != null) { |
| 32 return builder.execute(request.node); |
| 33 } |
| 34 return new Future.value(false); |
| 31 } | 35 } |
| 32 } | 36 } |
| 33 | 37 |
| 34 /** | 38 /** |
| 35 * A visitor for determining which imported classes and top level variables | 39 * A visitor for determining which imported classes and top level variables |
| 36 * should be suggested and building those suggestions. | 40 * should be suggested and building those suggestions. |
| 37 */ | 41 */ |
| 38 class _CombinatorAstVisitor extends GeneralizingAstVisitor<Future<bool>> { | 42 class _CombinatorAstVisitor extends |
| 43 GeneralizingAstVisitor<_CombinatorSuggestionBuilder> { |
| 39 final DartCompletionRequest request; | 44 final DartCompletionRequest request; |
| 40 | 45 |
| 41 _CombinatorAstVisitor(this.request); | 46 _CombinatorAstVisitor(this.request); |
| 42 | 47 |
| 43 @override | 48 @override |
| 44 Future<bool> visitCombinator(Combinator node) { | 49 _CombinatorSuggestionBuilder visitCombinator(Combinator node) { |
| 45 return _addCombinatorSuggestions(node); | 50 return new _CombinatorSuggestionBuilder( |
| 51 request, |
| 52 CompletionSuggestionKind.IDENTIFIER); |
| 46 } | 53 } |
| 47 | 54 |
| 48 @override | 55 @override |
| 49 Future<bool> visitNode(AstNode node) { | 56 _CombinatorSuggestionBuilder visitNode(AstNode node) { |
| 50 return new Future.value(false); | 57 return null; |
| 51 } | 58 } |
| 52 | 59 |
| 53 @override | 60 @override |
| 54 Future<bool> visitSimpleIdentifier(SimpleIdentifier node) { | 61 _CombinatorSuggestionBuilder visitSimpleIdentifier(SimpleIdentifier node) { |
| 55 return node.parent.accept(this); | 62 return node.parent.accept(this); |
| 56 } | 63 } |
| 64 } |
| 57 | 65 |
| 58 Future _addCombinatorSuggestions(Combinator node) { | 66 /** |
| 67 * A `_CombinatorSuggestionBuilder` determines which imported classes |
| 68 * and top level variables should be suggested and builds those suggestions. |
| 69 * This operation is instantiated during `computeFast` |
| 70 * and calculates the suggestions during `computeFull`. |
| 71 */ |
| 72 class _CombinatorSuggestionBuilder extends LibraryElementSuggestionBuilder { |
| 73 |
| 74 _CombinatorSuggestionBuilder(DartCompletionRequest request, |
| 75 CompletionSuggestionKind kind) |
| 76 : super(request, kind); |
| 77 |
| 78 Future<bool> execute(AstNode node) { |
| 59 var directive = node.getAncestor((parent) => parent is NamespaceDirective); | 79 var directive = node.getAncestor((parent) => parent is NamespaceDirective); |
| 60 if (directive is NamespaceDirective) { | 80 if (directive is NamespaceDirective) { |
| 61 LibraryElement library = directive.uriElement; | 81 LibraryElement library = directive.uriElement; |
| 62 LibraryElementSuggestionBuilder.suggestionsFor( | 82 if (library != null) { |
| 63 request, | 83 library.visitChildren(this); |
| 64 CompletionSuggestionKind.IDENTIFIER, | 84 } |
| 65 library); | |
| 66 return new Future.value(true); | |
| 67 } | 85 } |
| 68 return new Future.value(false); | 86 return new Future.value(false); |
| 69 } | 87 } |
| 70 } | 88 } |
| OLD | NEW |