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

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

Issue 1545323002: Issue 25316. Quick Fix for removing 'final' keyword. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: 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 50d437c1d2bca3ad96513c593e64682ede3b5a5b..fa16435cc086168fed1848b55c8c87e69ec507ee 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -230,6 +230,9 @@ class FixProcessor {
if (errorCode == ParserErrorCode.VAR_AS_TYPE_NAME) {
_addFix_replaceVarWithDynamic();
}
+ if (errorCode == StaticWarningCode.ASSIGNMENT_TO_FINAL) {
+ _addFix_makeFieldNotFinal();
+ }
if (errorCode == StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER) {
_addFix_makeEnclosingClassAbstract();
}
@@ -1590,6 +1593,41 @@ class FixProcessor {
_addFix(DartFixKind.MAKE_CLASS_ABSTRACT, [className]);
}
+ void _addFix_makeFieldNotFinal() {
+ AstNode node = this.node;
+ if (node is SimpleIdentifier &&
+ node.bestElement is PropertyAccessorElement) {
+ PropertyAccessorElement getter = node.bestElement;
+ if (getter.isGetter &&
+ getter.isSynthetic &&
+ !getter.variable.isSynthetic &&
+ getter.variable.setter == null &&
+ getter.enclosingElement is ClassElement) {
+ AstNode variable = getter.variable.computeNode();
+ if (variable is VariableDeclaration &&
+ variable.parent is VariableDeclarationList &&
+ variable.parent.parent is FieldDeclaration) {
+ VariableDeclarationList declarationList = variable.parent;
+ Token keywordToken = declarationList.keyword;
+ if (declarationList.variables.length == 1 &&
+ keywordToken is KeywordToken &&
+ keywordToken.keyword == Keyword.FINAL) {
+ if (declarationList.type != null) {
+ SourceRange range =
+ rf.rangeStartStart(keywordToken, declarationList.type);
+ _addRemoveEdit(range);
+ } else {
+ SourceRange range = rf.rangeStartStart(keywordToken, variable);
+ _addReplaceEdit(range, 'var ');
+ }
+ String fieldName = getter.variable.displayName;
+ _addFix(DartFixKind.MAKE_FIELD_NOT_FINAL, [fieldName]);
+ }
+ }
+ }
+ }
+ }
+
void _addFix_nonBoolCondition_addNotNull() {
_addInsertEdit(error.offset + error.length, ' != null');
_addFix(DartFixKind.ADD_NE_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