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

Unified Diff: pkg/analysis_server/lib/src/services/correction/assist_internal.dart

Issue 908503004: Quick Assist to add explicit types to formal parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweak and add TODO Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/correction/assist_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/correction/assist_internal.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
index 71f55ba2aad96ba8fda5e2baa30b9e7bb71bf212..31b05871a513f424a71b2a283175df9ac0fb53f5 100644
--- a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
@@ -81,6 +81,7 @@ class AssistProcessor {
}
// try to add proposals
_addProposal_addTypeAnnotation_DeclaredIdentifier();
+ _addProposal_addTypeAnnotation_SimpleFormalParameter();
_addProposal_addTypeAnnotation_VariableDeclaration();
_addProposal_assignToLocalVariable();
_addProposal_convertToBlockFunctionBody();
@@ -314,6 +315,44 @@ class AssistProcessor {
_addAssist(AssistKind.ADD_TYPE_ANNOTATION, []);
}
+ void _addProposal_addTypeAnnotation_SimpleFormalParameter() {
+ AstNode node = this.node;
+ // should be the name of a simple parameter
+ if (node is! SimpleIdentifier || node.parent is! SimpleFormalParameter) {
+ _coverageMarker();
+ return;
+ }
+ SimpleIdentifier name = node;
+ SimpleFormalParameter parameter = node.parent;
+ // the parameter should not have a type
+ if (parameter.type != null) {
+ _coverageMarker();
+ return;
+ }
+ // prepare propagated type
+ DartType type = name.propagatedType;
+ // TODO(scheglov) If the parameter is in a method declaration, and if the
+ // method overrides a method that has a type for the corresponding
+ // parameter, it would be nice to copy down the type from the overridden
+ // method.
+ if (type is! InterfaceType) {
+ _coverageMarker();
+ return;
+ }
+ // prepare type source
+ String typeSource;
+ {
+ _configureTargetLocation(node);
+ Set<LibraryElement> librariesToImport = new Set<LibraryElement>();
+ typeSource = utils.getTypeSource(type, librariesToImport);
+ _addLibraryImports(librariesToImport);
+ }
+ // add edit
+ _addInsertEdit(name.offset, '$typeSource ');
+ // add proposal
+ _addAssist(AssistKind.ADD_TYPE_ANNOTATION, []);
+ }
+
void _addProposal_assignToLocalVariable() {
// prepare enclosing ExpressionStatement
Statement statement = node.getAncestor((node) => node is Statement);
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/correction/assist_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698