| 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.contributor.dart.local; | 5 library services.completion.contributor.dart.local; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol | 9 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol |
| 10 show Element, ElementKind; | 10 show Element, ElementKind; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 // Collect suggestions from the specific child [AstNode] that contains | 34 // Collect suggestions from the specific child [AstNode] that contains |
| 35 // the completion offset and all of its parents recursively. | 35 // the completion offset and all of its parents recursively. |
| 36 if (!optype.isPrefixed) { | 36 if (!optype.isPrefixed) { |
| 37 if (optype.includeReturnValueSuggestions || | 37 if (optype.includeReturnValueSuggestions || |
| 38 optype.includeTypeNameSuggestions || | 38 optype.includeTypeNameSuggestions || |
| 39 optype.includeVoidReturnSuggestions) { | 39 optype.includeVoidReturnSuggestions) { |
| 40 _LocalVisitor localVisitor = | 40 _LocalVisitor localVisitor = |
| 41 new _LocalVisitor(request, request.offset, optype); | 41 new _LocalVisitor(request, request.offset, optype); |
| 42 localVisitor.visit(request.target.containingNode); | 42 localVisitor.visit(request.target.containingNode); |
| 43 } | 43 } |
| 44 if (optype.includeStatementLabelSuggestions || | |
| 45 optype.includeCaseLabelSuggestions) { | |
| 46 _LabelVisitor labelVisitor = new _LabelVisitor( | |
| 47 request, | |
| 48 optype.includeStatementLabelSuggestions, | |
| 49 optype.includeCaseLabelSuggestions); | |
| 50 labelVisitor.visit(request.target.containingNode); | |
| 51 } | |
| 52 if (optype.includeConstructorSuggestions) { | 44 if (optype.includeConstructorSuggestions) { |
| 53 new _ConstructorVisitor(request).visit(request.target.containingNode); | 45 new _ConstructorVisitor(request).visit(request.target.containingNode); |
| 54 } | 46 } |
| 55 } | 47 } |
| 56 | 48 |
| 57 // If target is an argument in an argument list | 49 // If target is an argument in an argument list |
| 58 // then suggestions may need to be adjusted | 50 // then suggestions may need to be adjusted |
| 59 return request.target.argIndex == null; | 51 return request.target.argIndex == null; |
| 60 } | 52 } |
| 61 | 53 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 } | 223 } |
| 232 } | 224 } |
| 233 } | 225 } |
| 234 } | 226 } |
| 235 } | 227 } |
| 236 return DYNAMIC; | 228 return DYNAMIC; |
| 237 } | 229 } |
| 238 } | 230 } |
| 239 | 231 |
| 240 /** | 232 /** |
| 241 * A visitor for collecting suggestions for break and continue labels. | |
| 242 */ | |
| 243 class _LabelVisitor extends LocalDeclarationVisitor { | |
| 244 final DartCompletionRequest request; | |
| 245 | |
| 246 /** | |
| 247 * True if statement labels should be included as suggestions. | |
| 248 */ | |
| 249 final bool includeStatementLabels; | |
| 250 | |
| 251 /** | |
| 252 * True if case labels should be included as suggestions. | |
| 253 */ | |
| 254 final bool includeCaseLabels; | |
| 255 | |
| 256 _LabelVisitor(DartCompletionRequest request, this.includeStatementLabels, | |
| 257 this.includeCaseLabels) | |
| 258 : super(request.offset), | |
| 259 request = request; | |
| 260 | |
| 261 @override | |
| 262 void declaredClass(ClassDeclaration declaration) { | |
| 263 // ignored | |
| 264 } | |
| 265 | |
| 266 @override | |
| 267 void declaredClassTypeAlias(ClassTypeAlias declaration) { | |
| 268 // ignored | |
| 269 } | |
| 270 | |
| 271 @override | |
| 272 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) { | |
| 273 // ignored | |
| 274 } | |
| 275 | |
| 276 @override | |
| 277 void declaredFunction(FunctionDeclaration declaration) { | |
| 278 // ignored | |
| 279 } | |
| 280 | |
| 281 @override | |
| 282 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) { | |
| 283 // ignored | |
| 284 } | |
| 285 | |
| 286 @override | |
| 287 void declaredLabel(Label label, bool isCaseLabel) { | |
| 288 if (isCaseLabel ? includeCaseLabels : includeStatementLabels) { | |
| 289 CompletionSuggestion suggestion = _addSuggestion(label.label); | |
| 290 if (suggestion != null) { | |
| 291 suggestion.element = createElement( | |
| 292 request.source, protocol.ElementKind.LABEL, label.label, | |
| 293 returnType: NO_RETURN_TYPE); | |
| 294 } | |
| 295 } | |
| 296 } | |
| 297 | |
| 298 @override | |
| 299 void declaredLocalVar(SimpleIdentifier name, TypeName type) { | |
| 300 // ignored | |
| 301 } | |
| 302 | |
| 303 @override | |
| 304 void declaredMethod(MethodDeclaration declaration) { | |
| 305 // ignored | |
| 306 } | |
| 307 | |
| 308 @override | |
| 309 void declaredParam(SimpleIdentifier name, TypeName type) { | |
| 310 // ignored | |
| 311 } | |
| 312 | |
| 313 @override | |
| 314 void declaredTopLevelVar( | |
| 315 VariableDeclarationList varList, VariableDeclaration varDecl) { | |
| 316 // ignored | |
| 317 } | |
| 318 | |
| 319 @override | |
| 320 void visitFunctionExpression(FunctionExpression node) { | |
| 321 // Labels are only accessible within the local function, so stop visiting | |
| 322 // once we reach a function boundary. | |
| 323 finished(); | |
| 324 } | |
| 325 | |
| 326 @override | |
| 327 void visitMethodDeclaration(MethodDeclaration node) { | |
| 328 // Labels are only accessible within the local function, so stop visiting | |
| 329 // once we reach a function boundary. | |
| 330 finished(); | |
| 331 } | |
| 332 | |
| 333 CompletionSuggestion _addSuggestion(SimpleIdentifier id) { | |
| 334 if (id != null) { | |
| 335 String completion = id.name; | |
| 336 if (completion != null && completion.length > 0 && completion != '_') { | |
| 337 CompletionSuggestion suggestion = new CompletionSuggestion( | |
| 338 CompletionSuggestionKind.IDENTIFIER, | |
| 339 DART_RELEVANCE_DEFAULT, | |
| 340 completion, | |
| 341 completion.length, | |
| 342 0, | |
| 343 false, | |
| 344 false); | |
| 345 request.addSuggestion(suggestion); | |
| 346 return suggestion; | |
| 347 } | |
| 348 } | |
| 349 return null; | |
| 350 } | |
| 351 } | |
| 352 | |
| 353 /** | |
| 354 * A visitor for collecting suggestions from the most specific child [AstNode] | 233 * A visitor for collecting suggestions from the most specific child [AstNode] |
| 355 * that contains the completion offset to the [CompilationUnit]. | 234 * that contains the completion offset to the [CompilationUnit]. |
| 356 */ | 235 */ |
| 357 class _LocalVisitor extends LocalDeclarationVisitor { | 236 class _LocalVisitor extends LocalDeclarationVisitor { |
| 358 final DartCompletionRequest request; | 237 final DartCompletionRequest request; |
| 359 final OpType optype; | 238 final OpType optype; |
| 360 int privateMemberRelevance = DART_RELEVANCE_DEFAULT; | 239 int privateMemberRelevance = DART_RELEVANCE_DEFAULT; |
| 361 | 240 |
| 362 _LocalVisitor(this.request, int offset, this.optype) : super(offset) { | 241 _LocalVisitor(this.request, int offset, this.optype) : super(offset) { |
| 363 includeLocalInheritedTypes = !optype.inStaticMethodBody; | 242 includeLocalInheritedTypes = !optype.inStaticMethodBody; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 bool _isVoid(TypeName returnType) { | 471 bool _isVoid(TypeName returnType) { |
| 593 if (returnType != null) { | 472 if (returnType != null) { |
| 594 Identifier id = returnType.name; | 473 Identifier id = returnType.name; |
| 595 if (id != null && id.name == 'void') { | 474 if (id != null && id.name == 'void') { |
| 596 return true; | 475 return true; |
| 597 } | 476 } |
| 598 } | 477 } |
| 599 return false; | 478 return false; |
| 600 } | 479 } |
| 601 } | 480 } |
| OLD | NEW |