| 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.toplevel; | 5 library services.completion.computer.dart.toplevel; |
| 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' hide Element, | 10 import 'package:analysis_server/src/protocol_server.dart' hide Element, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 return builder.computeFull(request.node); | 47 return builder.computeFull(request.node); |
| 48 } | 48 } |
| 49 return new Future.value(false); | 49 return new Future.value(false); |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * [_ImportedSuggestionBuilder] traverses the imports and builds suggestions | 54 * [_ImportedSuggestionBuilder] traverses the imports and builds suggestions |
| 55 * based upon imported elements. | 55 * based upon imported elements. |
| 56 */ | 56 */ |
| 57 class _ImportedSuggestionBuilder implements SuggestionBuilder { | 57 class _ImportedSuggestionBuilder extends ElementSuggestionBuilder implements |
| 58 SuggestionBuilder { |
| 58 bool shouldWaitForLowPrioritySuggestions; | 59 bool shouldWaitForLowPrioritySuggestions; |
| 59 final DartCompletionRequest request; | 60 final DartCompletionRequest request; |
| 60 final bool typesOnly; | 61 final bool typesOnly; |
| 61 final bool excludeVoidReturn; | 62 final bool excludeVoidReturn; |
| 62 DartCompletionCache cache; | 63 DartCompletionCache cache; |
| 63 | 64 |
| 64 _ImportedSuggestionBuilder(this.request, {this.typesOnly: false, | 65 _ImportedSuggestionBuilder(this.request, {this.typesOnly: false, |
| 65 this.excludeVoidReturn: false}) { | 66 this.excludeVoidReturn: false}) { |
| 66 cache = request.cache; | 67 cache = request.cache; |
| 67 } | 68 } |
| 68 | 69 |
| 70 @override |
| 71 CompletionSuggestionKind get kind => CompletionSuggestionKind.INVOCATION; |
| 72 |
| 69 /** | 73 /** |
| 70 * If the needed information is cached, then add suggestions and return `true` | 74 * If the needed information is cached, then add suggestions and return `true` |
| 71 * else return `false` indicating that additional work is necessary. | 75 * else return `false` indicating that additional work is necessary. |
| 72 */ | 76 */ |
| 73 bool computeFast(AstNode node) { | 77 bool computeFast(AstNode node) { |
| 74 CompilationUnit unit = request.unit; | 78 CompilationUnit unit = request.unit; |
| 75 if (cache.isImportInfoCached(unit)) { | 79 if (cache.isImportInfoCached(unit)) { |
| 76 _addInheritedSuggestions(node); | 80 _addInheritedSuggestions(node); |
| 77 _addTopLevelSuggestions(); | 81 _addTopLevelSuggestions(); |
| 78 return true; | 82 return true; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 107 /** | 111 /** |
| 108 * Add imported element suggestions. | 112 * Add imported element suggestions. |
| 109 */ | 113 */ |
| 110 void _addElementSuggestions(List<Element> elements) { | 114 void _addElementSuggestions(List<Element> elements) { |
| 111 elements.forEach((Element elem) { | 115 elements.forEach((Element elem) { |
| 112 if (elem is! ClassElement) { | 116 if (elem is! ClassElement) { |
| 113 if (typesOnly) { | 117 if (typesOnly) { |
| 114 return; | 118 return; |
| 115 } | 119 } |
| 116 if (elem is ExecutableElement) { | 120 if (elem is ExecutableElement) { |
| 117 if (elem.isOperator) { | |
| 118 return; | |
| 119 } | |
| 120 DartType returnType = elem.returnType; | 121 DartType returnType = elem.returnType; |
| 121 if (returnType != null && returnType.isVoid) { | 122 if (returnType != null && returnType.isVoid) { |
| 122 if (excludeVoidReturn) { | 123 if (excludeVoidReturn) { |
| 123 return; | 124 return; |
| 124 } | 125 } |
| 125 } | 126 } |
| 126 } | 127 } |
| 127 if (elem.isSynthetic) { | |
| 128 if (elem is PropertyAccessorElement || elem is FieldElement) { | |
| 129 return; | |
| 130 } | |
| 131 } | |
| 132 } | 128 } |
| 133 request.suggestions.add( | 129 addSuggestion(elem); |
| 134 createElementSuggestion(elem, relevance: COMPLETION_RELEVANCE_DEFAULT)
); | |
| 135 }); | 130 }); |
| 136 } | 131 } |
| 137 | 132 |
| 138 /** | 133 /** |
| 139 * Add suggestions for any inherited imported members. | 134 * Add suggestions for any inherited imported members. |
| 140 */ | 135 */ |
| 141 void _addInheritedSuggestions(AstNode node) { | 136 void _addInheritedSuggestions(AstNode node) { |
| 142 var classDecl = node.getAncestor((p) => p is ClassDeclaration); | 137 var classDecl = node.getAncestor((p) => p is ClassDeclaration); |
| 143 if (classDecl is ClassDeclaration) { | 138 if (classDecl is ClassDeclaration) { |
| 144 // Build a list of inherited types that are imported | 139 // Build a list of inherited types that are imported |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 addFilteredSuggestions(cache.importedTypeSuggestions); | 196 addFilteredSuggestions(cache.importedTypeSuggestions); |
| 202 addFilteredSuggestions(cache.libraryPrefixSuggestions); | 197 addFilteredSuggestions(cache.libraryPrefixSuggestions); |
| 203 if (!typesOnly) { | 198 if (!typesOnly) { |
| 204 addFilteredSuggestions(cache.otherImportedSuggestions); | 199 addFilteredSuggestions(cache.otherImportedSuggestions); |
| 205 if (!excludeVoidReturn) { | 200 if (!excludeVoidReturn) { |
| 206 addFilteredSuggestions(cache.importedVoidReturnSuggestions); | 201 addFilteredSuggestions(cache.importedVoidReturnSuggestions); |
| 207 } | 202 } |
| 208 } | 203 } |
| 209 } | 204 } |
| 210 } | 205 } |
| OLD | NEW |