| 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.invocation; | 5 library services.completion.contributor.dart.invocation; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 9 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| 10 import 'package:analysis_server/src/services/completion/local_declaration_visito
r.dart'; | 10 import 'package:analysis_server/src/services/completion/local_declaration_visito
r.dart'; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 * A suggestion builder for 'this.' constructor arguments. | 84 * A suggestion builder for 'this.' constructor arguments. |
| 85 */ | 85 */ |
| 86 class _FieldFormalSuggestionBuilder implements SuggestionBuilder { | 86 class _FieldFormalSuggestionBuilder implements SuggestionBuilder { |
| 87 final DartCompletionRequest request; | 87 final DartCompletionRequest request; |
| 88 | 88 |
| 89 _FieldFormalSuggestionBuilder(this.request); | 89 _FieldFormalSuggestionBuilder(this.request); |
| 90 | 90 |
| 91 @override | 91 @override |
| 92 bool computeFast(AstNode node) { | 92 bool computeFast(AstNode node) { |
| 93 if (node is FieldFormalParameter) { | 93 if (node is FieldFormalParameter) { |
| 94 | |
| 95 // Compute fields already referenced | |
| 96 ConstructorDeclaration constructorDecl = | 94 ConstructorDeclaration constructorDecl = |
| 97 node.getAncestor((p) => p is ConstructorDeclaration); | 95 node.getAncestor((p) => p is ConstructorDeclaration); |
| 98 List<String> referencedFields = new List<String>(); | 96 if (constructorDecl != null) { |
| 99 for (FormalParameter param in constructorDecl.parameters.parameters) { | 97 |
| 100 if (param is FieldFormalParameter) { | 98 // Compute fields already referenced |
| 101 SimpleIdentifier fieldId = param.identifier; | 99 List<String> referencedFields = new List<String>(); |
| 102 if (fieldId != null && fieldId != request.target.entity) { | 100 for (FormalParameter param in constructorDecl.parameters.parameters) { |
| 103 String fieldName = fieldId.name; | 101 if (param is FieldFormalParameter) { |
| 104 if (fieldName != null && fieldName.length > 0) { | 102 SimpleIdentifier fieldId = param.identifier; |
| 105 referencedFields.add(fieldName); | 103 if (fieldId != null && fieldId != request.target.entity) { |
| 104 String fieldName = fieldId.name; |
| 105 if (fieldName != null && fieldName.length > 0) { |
| 106 referencedFields.add(fieldName); |
| 107 } |
| 106 } | 108 } |
| 107 } | 109 } |
| 108 } | 110 } |
| 109 } | |
| 110 | 111 |
| 111 // Add suggestions for fields that are not already referenced | 112 // Add suggestions for fields that are not already referenced |
| 112 ClassDeclaration classDecl = | 113 ClassDeclaration classDecl = |
| 113 constructorDecl.getAncestor((p) => p is ClassDeclaration); | 114 constructorDecl.getAncestor((p) => p is ClassDeclaration); |
| 114 for (ClassMember member in classDecl.members) { | 115 for (ClassMember member in classDecl.members) { |
| 115 if (member is FieldDeclaration) { | 116 if (member is FieldDeclaration) { |
| 116 for (VariableDeclaration varDecl in member.fields.variables) { | 117 for (VariableDeclaration varDecl in member.fields.variables) { |
| 117 SimpleIdentifier fieldId = varDecl.name; | 118 SimpleIdentifier fieldId = varDecl.name; |
| 118 if (fieldId != null) { | 119 if (fieldId != null) { |
| 119 String fieldName = fieldId.name; | 120 String fieldName = fieldId.name; |
| 120 if (fieldName != null && fieldName.length > 0) { | 121 if (fieldName != null && fieldName.length > 0) { |
| 121 if (!referencedFields.contains(fieldName)) { | 122 if (!referencedFields.contains(fieldName)) { |
| 122 CompletionSuggestion suggestion = | 123 CompletionSuggestion suggestion = |
| 123 createFieldSuggestion(member, varDecl); | 124 createFieldSuggestion(member, varDecl); |
| 124 if (suggestion != null) { | 125 if (suggestion != null) { |
| 125 request.addSuggestion(suggestion); | 126 request.addSuggestion(suggestion); |
| 127 } |
| 126 } | 128 } |
| 127 } | 129 } |
| 128 } | 130 } |
| 129 } | 131 } |
| 130 } | 132 } |
| 131 } | 133 } |
| 132 } | 134 } |
| 133 } else { | 135 } else { |
| 134 // This should never be called with a case not handled above. | 136 // This should never be called with a case not handled above. |
| 135 assert(false); | 137 assert(false); |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 } | 425 } |
| 424 return new Future.value(false); | 426 return new Future.value(false); |
| 425 } | 427 } |
| 426 | 428 |
| 427 @override | 429 @override |
| 428 Future<bool> visitVariableElement(VariableElement element) { | 430 Future<bool> visitVariableElement(VariableElement element) { |
| 429 InterfaceTypeSuggestionBuilder.suggestionsFor(request, element.type); | 431 InterfaceTypeSuggestionBuilder.suggestionsFor(request, element.type); |
| 430 return new Future.value(true); | 432 return new Future.value(true); |
| 431 } | 433 } |
| 432 } | 434 } |
| OLD | NEW |