Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/prefixed_element_contributor.dart

Issue 1291283002: suggest prefixed constructors - fixes #23210 (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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';
11 import 'package:analysis_server/src/services/completion/local_suggestion_builder .dart' 11 import 'package:analysis_server/src/services/completion/local_suggestion_builder .dart'
12 hide createSuggestion; 12 hide createSuggestion;
13 import 'package:analysis_server/src/services/completion/optype.dart'; 13 import 'package:analysis_server/src/services/completion/optype.dart';
14 import 'package:analysis_server/src/services/completion/suggestion_builder.dart' ; 14 import 'package:analysis_server/src/services/completion/suggestion_builder.dart' ;
15 import 'package:analysis_server/src/services/completion/suggestion_builder.dart' 15 import 'package:analysis_server/src/services/completion/suggestion_builder.dart'
16 show createSuggestion; 16 show createSuggestion;
17 import 'package:analyzer/src/generated/ast.dart'; 17 import 'package:analyzer/src/generated/ast.dart';
18 import 'package:analyzer/src/generated/element.dart'; 18 import 'package:analyzer/src/generated/element.dart';
19 19
20 import '../../protocol_server.dart' 20 import '../../protocol_server.dart'
21 show CompletionSuggestion, CompletionSuggestionKind; 21 show CompletionSuggestion, CompletionSuggestionKind;
22 import '../../protocol_server.dart' as protocol;
23 22
24 /** 23 /**
25 * A contributor for calculating invocation / access suggestions 24 * A contributor for calculating invocation / access suggestions
26 * `completion.getSuggestions` request results. 25 * `completion.getSuggestions` request results.
27 */ 26 */
28 class PrefixedElementContributor extends DartCompletionContributor { 27 class PrefixedElementContributor extends DartCompletionContributor {
29 SuggestionBuilder builder; 28 SuggestionBuilder builder;
30 29
31 @override 30 @override
32 bool computeFast(DartCompletionRequest request) { 31 bool computeFast(DartCompletionRequest request) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 final DartCompletionRequest request; 102 final DartCompletionRequest request;
104 103
105 _FieldFormalSuggestionBuilder(this.request); 104 _FieldFormalSuggestionBuilder(this.request);
106 105
107 @override 106 @override
108 bool computeFast(AstNode node) { 107 bool computeFast(AstNode node) {
109 if (node is FieldFormalParameter) { 108 if (node is FieldFormalParameter) {
110 ConstructorDeclaration constructorDecl = 109 ConstructorDeclaration constructorDecl =
111 node.getAncestor((p) => p is ConstructorDeclaration); 110 node.getAncestor((p) => p is ConstructorDeclaration);
112 if (constructorDecl != null) { 111 if (constructorDecl != null) {
113
114 // Compute fields already referenced 112 // Compute fields already referenced
115 List<String> referencedFields = new List<String>(); 113 List<String> referencedFields = new List<String>();
116 for (FormalParameter param in constructorDecl.parameters.parameters) { 114 for (FormalParameter param in constructorDecl.parameters.parameters) {
117 if (param is FieldFormalParameter) { 115 if (param is FieldFormalParameter) {
118 SimpleIdentifier fieldId = param.identifier; 116 SimpleIdentifier fieldId = param.identifier;
119 if (fieldId != null && fieldId != request.target.entity) { 117 if (fieldId != null && fieldId != request.target.entity) {
120 String fieldName = fieldId.name; 118 String fieldName = fieldId.name;
121 if (fieldName != null && fieldName.length > 0) { 119 if (fieldName != null && fieldName.length > 0) {
122 referencedFields.add(fieldName); 120 referencedFields.add(fieldName);
123 } 121 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 SuggestionBuilder visitPropertyAccess(PropertyAccess node) { 204 SuggestionBuilder visitPropertyAccess(PropertyAccess node) {
207 return new _ExpressionSuggestionBuilder(request); 205 return new _ExpressionSuggestionBuilder(request);
208 } 206 }
209 } 207 }
210 208
211 /** 209 /**
212 * An [AstVisitor] which looks for a declaration with the given name 210 * An [AstVisitor] which looks for a declaration with the given name
213 * and if found, tries to determine a type for that declaration. 211 * and if found, tries to determine a type for that declaration.
214 */ 212 */
215 class _LocalBestTypeVisitor extends LocalDeclarationVisitor { 213 class _LocalBestTypeVisitor extends LocalDeclarationVisitor {
216
217 /** 214 /**
218 * The name for the declaration to be found. 215 * The name for the declaration to be found.
219 */ 216 */
220 final String targetName; 217 final String targetName;
221 218
222 /** 219 /**
223 * The best type for the found declaration, 220 * The best type for the found declaration,
224 * or `null` if no declaration found or failed to determine a type. 221 * or `null` if no declaration found or failed to determine a type.
225 */ 222 */
226 DartType typeFound; 223 DartType typeFound;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 @override 393 @override
397 Future<bool> visitPrefixElement(PrefixElement element) { 394 Future<bool> visitPrefixElement(PrefixElement element) {
398 bool modified = false; 395 bool modified = false;
399 // Find the import directive with the given prefix 396 // Find the import directive with the given prefix
400 for (Directive directive in request.unit.directives) { 397 for (Directive directive in request.unit.directives) {
401 if (directive is ImportDirective) { 398 if (directive is ImportDirective) {
402 if (directive.prefix != null) { 399 if (directive.prefix != null) {
403 if (directive.prefix.name == element.name) { 400 if (directive.prefix.name == element.name) {
404 // Suggest elements from the imported library 401 // Suggest elements from the imported library
405 LibraryElement library = directive.uriElement; 402 LibraryElement library = directive.uriElement;
403 AstNode node = request.target.containingNode;
404 bool typesOnly = node.parent is TypeName;
405 bool instCreation =
406 typesOnly && node.parent.parent is ConstructorName;
406 LibraryElementSuggestionBuilder.suggestionsFor(request, 407 LibraryElementSuggestionBuilder.suggestionsFor(request,
407 CompletionSuggestionKind.INVOCATION, library, 408 CompletionSuggestionKind.INVOCATION, library, typesOnly,
408 request.target.containingNode.parent is TypeName); 409 instCreation);
409 modified = true; 410 modified = true;
410 if (directive.deferredKeyword != null) { 411 if (directive.deferredKeyword != null) {
411 FunctionElement loadLibFunct = library.loadLibraryFunction; 412 FunctionElement loadLibFunct = library.loadLibraryFunction;
412 request.addSuggestion(createSuggestion(loadLibFunct)); 413 request.addSuggestion(createSuggestion(loadLibFunct));
413 } 414 }
414 } 415 }
415 } 416 }
416 } 417 }
417 } 418 }
418 return new Future.value(modified); 419 return new Future.value(modified);
(...skipping 10 matching lines...) Expand all
429 } 430 }
430 return new Future.value(false); 431 return new Future.value(false);
431 } 432 }
432 433
433 @override 434 @override
434 Future<bool> visitVariableElement(VariableElement element) { 435 Future<bool> visitVariableElement(VariableElement element) {
435 InterfaceTypeSuggestionBuilder.suggestionsFor(request, element.type); 436 InterfaceTypeSuggestionBuilder.suggestionsFor(request, element.type);
436 return new Future.value(true); 437 return new Future.value(true);
437 } 438 }
438 } 439 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698