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