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

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

Issue 1764853002: Quick fix to ignore a specific error (#25915). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: fixes Created 4 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
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 3fdd5f9a3db8a3b7a43e2afc1012365455acbf5e..dada281823dbb821c776c84e5badb4865106410a 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -32,6 +32,7 @@ import 'package:analyzer/src/dart/ast/token.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/element/member.dart';
import 'package:analyzer/src/dart/element/type.dart';
+import 'package:analyzer/src/dart/scanner/scanner.dart';
scheglov 2016/03/04 18:55:20 Do we need this import?
pquitslund 2016/03/04 19:09:39 We don't! That was dead. Removed.
import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/error.dart';
@@ -143,6 +144,15 @@ class FixProcessor {
new NodeLocator2(errorOffset, errorEnd - 1).searchWithin(unit);
// analyze ErrorCode
ErrorCode errorCode = error.errorCode;
+ // add ignore fix for ignorable errors.
+ // note that this fix needs to be added before fixes that side-effect
+ // the utils instance.
+ if (errorCode is StaticWarningCode ||
+ errorCode is StaticTypeWarningCode ||
+ errorCode is HintCode ||
+ errorCode is LintCode) {
+ _addFix_ignore(errorCode);
+ }
if (errorCode == StaticWarningCode.UNDEFINED_CLASS_BOOLEAN) {
_addFix_boolInsteadOfBoolean();
}
@@ -1383,6 +1393,18 @@ class FixProcessor {
}
}
+ void _addFix_ignore(ErrorCode errorCode) {
+ int offset = node.offset;
+ int lineOffset = utils.getLineThis(offset);
+
+ exitPosition = new Position(file, lineOffset - 1);
+ String indent = utils.getLinePrefix(offset);
+ String errorCodeName = errorCode.name.toLowerCase();
+ String content = '$indent//ignore: $errorCodeName$eol';
+ _addReplaceEdit(rf.rangeStartLength(lineOffset, 0), content);
+ _addFix(DartFixKind.IGNORE_ERROR, [errorCodeName]);
+ }
+
void _addFix_illegalAsyncReturnType() {
// prepare the existing type
TypeName typeName = node.getAncestor((n) => n is TypeName);

Powered by Google App Engine
This is Rietveld 408576698