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

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

Issue 1492053004: Issue 25095. Add 'Change X to Y type annotation' Quick Fix. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Additional test. Created 5 years 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
Index: pkg/analysis_server/lib/src/services/correction/fix_internal.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
index eba635ff26ffc439c35e353eef55e1e949635319..f068b3bd1e5317403078091d4f23614afba7b6b5 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -292,6 +292,9 @@ class FixProcessor {
_addFix_useStaticAccess_method();
_addFix_useStaticAccess_property();
}
+ if (errorCode == StaticTypeWarningCode.INVALID_ASSIGNMENT) {
+ _addFix_changeTypeAnnotation();
+ }
if (errorCode == StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION) {
_addFix_removeParentheses_inGetterInvocation();
}
@@ -493,6 +496,29 @@ class FixProcessor {
}
}
+ void _addFix_changeTypeAnnotation() {
+ AstNode declaration = coveredNode.parent;
+ if (declaration is VariableDeclaration &&
+ declaration.initializer == coveredNode) {
+ AstNode variableList = declaration.parent;
+ if (variableList is VariableDeclarationList &&
+ variableList.variables.length == 1) {
+ TypeName typeNode = variableList.type;
+ if (typeNode != null) {
+ Expression initializer = coveredNode;
+ DartType newType = initializer.bestType;
+ if (newType is InterfaceType || newType is FunctionType) {
+ String newTypeSource =
+ utils.getTypeSource(newType, librariesToImport);
+ _addReplaceEdit(rf.rangeNode(typeNode), newTypeSource);
+ _addFix(DartFixKind.CHANGE_TYPE_ANNOTATION,
+ [typeNode.type.displayName, newTypeSource]);
+ }
+ }
+ }
+ }
+ }
+
void _addFix_createClass() {
Element prefixElement = null;
String name = null;
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix.dart ('k') | pkg/analysis_server/test/services/correction/fix_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698