| 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.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; |
| 11 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; | 11 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; |
| 12 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 12 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| 13 import 'package:analysis_server/src/services/completion/suggestion_builder.dart'
; |
| 13 import 'package:analyzer/src/generated/ast.dart'; | 14 import 'package:analyzer/src/generated/ast.dart'; |
| 14 import 'package:analyzer/src/generated/scanner.dart'; | 15 import 'package:analyzer/src/generated/scanner.dart'; |
| 15 | 16 |
| 16 /** | 17 /** |
| 17 * A computer for calculating `completion.getSuggestions` request results | 18 * A computer for calculating `completion.getSuggestions` request results |
| 18 * for the local library in which the completion is requested. | 19 * for the local library in which the completion is requested. |
| 19 */ | 20 */ |
| 20 class LocalComputer extends DartCompletionComputer { | 21 class LocalComputer extends DartCompletionComputer { |
| 21 | 22 |
| 22 @override | 23 @override |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 @override | 98 @override |
| 98 visitCatchClause(CatchClause node) { | 99 visitCatchClause(CatchClause node) { |
| 99 _addParamSuggestion(node.exceptionParameter, node.exceptionType); | 100 _addParamSuggestion(node.exceptionParameter, node.exceptionType); |
| 100 _addParamSuggestion(node.stackTraceParameter, STACKTRACE_TYPE); | 101 _addParamSuggestion(node.stackTraceParameter, STACKTRACE_TYPE); |
| 101 visitNode(node); | 102 visitNode(node); |
| 102 } | 103 } |
| 103 | 104 |
| 104 @override | 105 @override |
| 105 visitClassDeclaration(ClassDeclaration node) { | 106 visitClassDeclaration(ClassDeclaration node) { |
| 106 _addClassDeclarationMembers(node); | 107 _addClassDeclarationMembers(node); |
| 107 _addInheritedTypeMembers(node); | 108 visitInheritedTypes(node, (ClassDeclaration classNode) { |
| 109 _addClassDeclarationMembers(classNode); |
| 110 }, (String typeName) { |
| 111 // ignored |
| 112 }); |
| 108 visitNode(node); | 113 visitNode(node); |
| 109 } | 114 } |
| 110 | 115 |
| 111 void _addInheritedTypeMembers(ClassDeclaration node) { | |
| 112 ExtendsClause extendsClause = node.extendsClause; | |
| 113 if (extendsClause != null) { | |
| 114 _addLocalTypeMembers(extendsClause.superclass, node); | |
| 115 } | |
| 116 ImplementsClause implementsClause = node.implementsClause; | |
| 117 if (implementsClause != null) { | |
| 118 NodeList<TypeName> interfaces = implementsClause.interfaces; | |
| 119 if (interfaces != null) { | |
| 120 interfaces.forEach((TypeName type) { | |
| 121 _addLocalTypeMembers(type, node); | |
| 122 }); | |
| 123 } | |
| 124 } | |
| 125 WithClause withClause = node.withClause; | |
| 126 if (withClause != null) { | |
| 127 NodeList<TypeName> mixinTypes = withClause.mixinTypes; | |
| 128 if (mixinTypes != null) { | |
| 129 mixinTypes.forEach((TypeName type) { | |
| 130 _addLocalTypeMembers(type, node); | |
| 131 }); | |
| 132 } | |
| 133 } | |
| 134 } | |
| 135 | |
| 136 void _addLocalTypeMembers(TypeName type, ClassDeclaration node) { | |
| 137 if (type == null) { | |
| 138 return; | |
| 139 } | |
| 140 Identifier typeId = type.name; | |
| 141 if (typeId == null) { | |
| 142 return; | |
| 143 } | |
| 144 String typeName = typeId.name; | |
| 145 if (typeName == null || typeName.length == 0) { | |
| 146 return; | |
| 147 } | |
| 148 CompilationUnit unit = node.getAncestor((p) => p is CompilationUnit); | |
| 149 if (unit == null) { | |
| 150 return; | |
| 151 } | |
| 152 unit.declarations.forEach((CompilationUnitMember m) { | |
| 153 if (m is ClassDeclaration) { | |
| 154 SimpleIdentifier id = m.name; | |
| 155 if (id != null) { | |
| 156 if (id.name == typeName) { | |
| 157 _addClassDeclarationMembers(m); | |
| 158 _addInheritedTypeMembers(m); | |
| 159 } | |
| 160 } | |
| 161 } | |
| 162 }); | |
| 163 } | |
| 164 | |
| 165 void _addClassDeclarationMembers(ClassDeclaration node) { | |
| 166 node.members.forEach((ClassMember classMbr) { | |
| 167 if (classMbr is FieldDeclaration) { | |
| 168 _addFieldSuggestions(node, classMbr); | |
| 169 } else if (classMbr is MethodDeclaration) { | |
| 170 _addMethodSuggestion(node, classMbr); | |
| 171 } | |
| 172 }); | |
| 173 } | |
| 174 | |
| 175 @override | 116 @override |
| 176 visitCombinator(Combinator node) { | 117 visitCombinator(Combinator node) { |
| 177 // Handled by ImportedComputer | 118 // Handled by ImportedComputer |
| 178 } | 119 } |
| 179 | 120 |
| 180 @override | 121 @override |
| 181 visitCompilationUnit(CompilationUnit node) { | 122 visitCompilationUnit(CompilationUnit node) { |
| 182 node.declarations.forEach((Declaration declaration) { | 123 node.declarations.forEach((Declaration declaration) { |
| 183 if (declaration is ClassDeclaration) { | 124 if (declaration is ClassDeclaration) { |
| 184 _addClassSuggestion(declaration); | 125 _addClassSuggestion(declaration); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 visitVariableDeclaration(VariableDeclaration node) { | 256 visitVariableDeclaration(VariableDeclaration node) { |
| 316 // Do not add suggestions if editing the name in a var declaration | 257 // Do not add suggestions if editing the name in a var declaration |
| 317 SimpleIdentifier name = node.name; | 258 SimpleIdentifier name = node.name; |
| 318 if (name == null || | 259 if (name == null || |
| 319 name.offset < request.offset || | 260 name.offset < request.offset || |
| 320 request.offset > name.end) { | 261 request.offset > name.end) { |
| 321 visitNode(node); | 262 visitNode(node); |
| 322 } | 263 } |
| 323 } | 264 } |
| 324 | 265 |
| 266 void _addClassDeclarationMembers(ClassDeclaration node) { |
| 267 node.members.forEach((ClassMember classMbr) { |
| 268 if (classMbr is FieldDeclaration) { |
| 269 _addFieldSuggestions(node, classMbr); |
| 270 } else if (classMbr is MethodDeclaration) { |
| 271 _addMethodSuggestion(node, classMbr); |
| 272 } |
| 273 }); |
| 274 } |
| 275 |
| 325 void _addClassSuggestion(ClassDeclaration declaration) { | 276 void _addClassSuggestion(ClassDeclaration declaration) { |
| 326 CompletionSuggestion suggestion = | 277 CompletionSuggestion suggestion = |
| 327 _addSuggestion(declaration.name, CompletionSuggestionKind.CLASS, null, n
ull); | 278 _addSuggestion(declaration.name, CompletionSuggestionKind.CLASS, null, n
ull); |
| 328 if (suggestion != null) { | 279 if (suggestion != null) { |
| 329 suggestion.element = _createElement( | 280 suggestion.element = _createElement( |
| 330 protocol.ElementKind.CLASS, | 281 protocol.ElementKind.CLASS, |
| 331 declaration.name, | 282 declaration.name, |
| 332 NO_RETURN_TYPE, | 283 NO_RETURN_TYPE, |
| 333 declaration.isAbstract, | 284 declaration.isAbstract, |
| 334 _isDeprecated(declaration.metadata)); | 285 _isDeprecated(declaration.metadata)); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 if (name == null || name.length <= 0) { | 511 if (name == null || name.length <= 0) { |
| 561 return DYNAMIC; | 512 return DYNAMIC; |
| 562 } | 513 } |
| 563 TypeArgumentList typeArgs = type.typeArguments; | 514 TypeArgumentList typeArgs = type.typeArguments; |
| 564 if (typeArgs != null) { | 515 if (typeArgs != null) { |
| 565 //TODO (danrubel) include type arguments | 516 //TODO (danrubel) include type arguments |
| 566 } | 517 } |
| 567 return name; | 518 return name; |
| 568 } | 519 } |
| 569 } | 520 } |
| OLD | NEW |