Ahmed Ashour has uploaded this change for review.
[analysis_server] remove `UseConst`
Use `AddConstant` or `RemoveConst` instead
Fixes #50803
Change-Id: Idf0b2f626558a8b2abb91eb0a4c4872f91e29632
---
D pkg/analysis_server/lib/src/services/correction/dart/use_const.dart
M pkg/analysis_server/lib/src/services/correction/fix.dart
M pkg/analysis_server/lib/src/services/correction/fix_internal.dart
M pkg/analysis_server/test/src/services/correction/fix/remove_const_test.dart
M pkg/analysis_server/test/src/services/correction/fix/test_all.dart
D pkg/analysis_server/test/src/services/correction/fix/use_const_test.dart
6 files changed, 27 insertions(+), 79 deletions(-)
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/use_const.dart b/pkg/analysis_server/lib/src/services/correction/dart/use_const.dart
deleted file mode 100644
index 17aeb6d..0000000
--- a/pkg/analysis_server/lib/src/services/correction/dart/use_const.dart
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
-import 'package:analysis_server/src/services/correction/fix.dart';
-import 'package:analyzer/dart/ast/ast.dart';
-import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
-import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
-import 'package:analyzer_plugin/utilities/range_factory.dart';
-
-class UseConst extends CorrectionProducer {
- @override
- FixKind get fixKind => DartFixKind.USE_CONST;
-
- @override
- Future<void> compute(ChangeBuilder builder) async {
- if (coveredNode is InstanceCreationExpression) {
- var instanceCreation = coveredNode as InstanceCreationExpression;
- await builder.addDartFileEdit(file, (builder) {
- var keyword = instanceCreation.keyword;
- if (keyword == null) {
- builder.addSimpleInsertion(
- instanceCreation.constructorName.offset, 'const');
- } else {
- builder.addSimpleReplacement(range.token(keyword), 'const');
- }
- });
- }
- }
-}
diff --git a/pkg/analysis_server/lib/src/services/correction/fix.dart b/pkg/analysis_server/lib/src/services/correction/fix.dart
index e9dd399..a8d71c5 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix.dart
@@ -1660,11 +1660,6 @@
DartFixKindPriority.DEFAULT,
'Update the SDK constraints',
);
- static const USE_CONST = FixKind(
- 'dart.fix.use.const',
- DartFixKindPriority.DEFAULT,
- 'Change to constant',
- );
static const USE_EFFECTIVE_INTEGER_DIVISION = FixKind(
'dart.fix.use.effectiveIntegerDivision',
DartFixKindPriority.DEFAULT,
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 4fcbac0..9daf235 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -200,7 +200,6 @@
import 'package:analysis_server/src/services/correction/dart/sort_constructor_first.dart';
import 'package:analysis_server/src/services/correction/dart/sort_unnamed_constructor_first.dart';
import 'package:analysis_server/src/services/correction/dart/update_sdk_constraints.dart';
-import 'package:analysis_server/src/services/correction/dart/use_const.dart';
import 'package:analysis_server/src/services/correction/dart/use_curly_braces.dart';
import 'package:analysis_server/src/services/correction/dart/use_effective_integer_division.dart';
import 'package:analysis_server/src/services/correction/dart/use_eq_eq_null.dart';
@@ -944,7 +943,7 @@
MakeClassAbstract.new,
],
CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE: [
- UseConst.new,
+ RemoveConst.new,
],
CompileTimeErrorCode.CONST_INSTANCE_FIELD: [
AddStatic.new,
@@ -1458,9 +1457,7 @@
HintCode.UNNECESSARY_NULL_COMPARISON_TRUE: [
RemoveComparison.new,
],
- HintCode.UNNECESSARY_QUESTION_MARK: [
- RemoveQuestionMark.new
- ],
+ HintCode.UNNECESSARY_QUESTION_MARK: [RemoveQuestionMark.new],
// HintCode.UNNECESSARY_TYPE_CHECK_FALSE: [
// TODO(brianwilkerson) Add a fix to remove the type check.
// ],
diff --git a/pkg/analysis_server/test/src/services/correction/fix/remove_const_test.dart b/pkg/analysis_server/test/src/services/correction/fix/remove_const_test.dart
index 3f347cc3..3d2a1c0 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/remove_const_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/remove_const_test.dart
@@ -20,6 +20,18 @@
@override
FixKind get kind => DartFixKind.REMOVE_CONST;
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49818')
+ Future<void> test_constInitializedWithNonConstantValue() async {
+ await resolveTestCode('''
+var x = 0;
+const y = x;
+''');
+ await assertHasFix('''
+var x = 0;
+final y = x;
+''');
+ }
+
Future<void> test_explicitConst() async {
await resolveTestCode('''
class A {
diff --git a/pkg/analysis_server/test/src/services/correction/fix/test_all.dart b/pkg/analysis_server/test/src/services/correction/fix/test_all.dart
index 7a67ea3..44efcc4 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/test_all.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/test_all.dart
@@ -243,7 +243,6 @@
import 'sort_unnamed_constructor_first_test.dart'
as sort_unnamed_constructor_first_test;
import 'update_sdk_constraints_test.dart' as update_sdk_constraints;
-import 'use_const_test.dart' as use_const;
import 'use_curly_braces_test.dart' as use_curly_braces;
import 'use_effective_integer_division_test.dart'
as use_effective_integer_division;
@@ -464,7 +463,6 @@
sort_combinators_test.main();
sort_unnamed_constructor_first_test.main();
update_sdk_constraints.main();
- use_const.main();
use_curly_braces.main();
use_effective_integer_division.main();
use_eq_eq_null.main();
diff --git a/pkg/analysis_server/test/src/services/correction/fix/use_const_test.dart b/pkg/analysis_server/test/src/services/correction/fix/use_const_test.dart
deleted file mode 100644
index 62e0701..0000000
--- a/pkg/analysis_server/test/src/services/correction/fix/use_const_test.dart
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-import 'package:analysis_server/src/services/correction/fix.dart';
-import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
-import 'package:test_reflective_loader/test_reflective_loader.dart';
-
-import 'fix_processor.dart';
-
-void main() {
- defineReflectiveSuite(() {
- defineReflectiveTests(UseConstTest);
- });
-}
-
-@reflectiveTest
-class UseConstTest extends FixProcessorTest {
- @override
- FixKind get kind => DartFixKind.USE_CONST;
-
- Future<void> test_explicitNew() async {
- await resolveTestCode('''
-class A {
- const A();
-}
-const a = new A();
-''');
- await assertHasFix('''
-class A {
- const A();
-}
-const a = const A();
-''');
- }
-}
To view, visit change 277120. To unsubscribe, or for help writing mail filters, visit settings.
Ahmed Ashour uploaded patch set #2 to this change.
[analysis_server] remove `UseConst`
Use `AddConstant` or `RemoveConst` instead
Fixes #50803
Change-Id: Idf0b2f626558a8b2abb91eb0a4c4872f91e29632
---
M pkg/analysis_server/lib/src/services/correction/dart/remove_unnecessary_new.dart
D pkg/analysis_server/lib/src/services/correction/dart/use_const.dart
M pkg/analysis_server/lib/src/services/correction/fix.dart
M pkg/analysis_server/lib/src/services/correction/fix_internal.dart
M pkg/analysis_server/test/src/services/correction/fix/remove_const_test.dart
M pkg/analysis_server/test/src/services/correction/fix/remove_unnecessary_new_test.dart
M pkg/analysis_server/test/src/services/correction/fix/test_all.dart
D pkg/analysis_server/test/src/services/correction/fix/use_const_test.dart
8 files changed, 63 insertions(+), 80 deletions(-)
To view, visit change 277120. To unsubscribe, or for help writing mail filters, visit settings.
Ahmed Ashour uploaded patch set #3 to this change.
[analysis_server] remove `UseConst`
Use `AddConstant` or `RemoveConst` instead
Fixes #50803
Change-Id: Idf0b2f626558a8b2abb91eb0a4c4872f91e29632
---
M pkg/analysis_server/lib/src/services/correction/dart/remove_unnecessary_new.dart
D pkg/analysis_server/lib/src/services/correction/dart/use_const.dart
M pkg/analysis_server/lib/src/services/correction/fix.dart
M pkg/analysis_server/lib/src/services/correction/fix_internal.dart
M pkg/analysis_server/test/src/services/correction/fix/remove_const_test.dart
M pkg/analysis_server/test/src/services/correction/fix/remove_unnecessary_new_test.dart
M pkg/analysis_server/test/src/services/correction/fix/test_all.dart
D pkg/analysis_server/test/src/services/correction/fix/use_const_test.dart
8 files changed, 62 insertions(+), 77 deletions(-)
To view, visit change 277120. To unsubscribe, or for help writing mail filters, visit settings.
go/dart-cbuild result: SUCCESS
Details: https://goto.google.com/dart-cbuild/find/e182c48dd5a7f96190c8056744f7ac71a5cad5e7
Attention is currently required from: Ahmed Ashour, Keerti Parthasarathy.
Patch set 4:Code-Review +1Commit-Queue +2
Commit Queue submitted this change.
[analysis_server] remove `UseConst`
Use `AddConstant` or `RemoveConst` instead
Fixes #50803
Change-Id: Idf0b2f626558a8b2abb91eb0a4c4872f91e29632
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/277120
Commit-Queue: Brian Wilkerson <brianwi...@google.com>
Reviewed-by: Brian Wilkerson <brianwi...@google.com>
---
M pkg/analysis_server/lib/src/services/correction/dart/remove_unnecessary_new.dart
D pkg/analysis_server/lib/src/services/correction/dart/use_const.dart
M pkg/analysis_server/lib/src/services/correction/fix.dart
M pkg/analysis_server/lib/src/services/correction/fix_internal.dart
M pkg/analysis_server/test/src/services/correction/fix/remove_const_test.dart
M pkg/analysis_server/test/src/services/correction/fix/remove_unnecessary_new_test.dart
M pkg/analysis_server/test/src/services/correction/fix/test_all.dart
D pkg/analysis_server/test/src/services/correction/fix/use_const_test.dart
8 files changed, 65 insertions(+), 77 deletions(-)
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/remove_unnecessary_new.dart b/pkg/analysis_server/lib/src/services/correction/dart/remove_unnecessary_new.dart
index c8f9b1d..1741f32 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/remove_unnecessary_new.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/remove_unnecessary_new.dart
@@ -9,7 +9,12 @@
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:analyzer_plugin/utilities/range_factory.dart';
-class RemoveUnnecessaryNew extends CorrectionProducer {
+class RemoveNew extends _RemoveNew {
+ @override
+ FixKind get fixKind => DartFixKind.REMOVE_NEW;
+}
+
+class RemoveUnnecessaryNew extends _RemoveNew {
@override
bool get canBeAppliedInBulk => true;
@@ -21,7 +26,9 @@
@override
FixKind get multiFixKind => DartFixKind.REMOVE_UNNECESSARY_NEW_MULTI;
+}
+class _RemoveNew extends CorrectionProducer {
@override
Future<void> compute(ChangeBuilder builder) async {
final creation = node;
index 2948fc1..86fe278 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix.dart
@@ -1108,6 +1108,11 @@
DartFixKindPriority.DEFAULT,
'{0}',
);
+ static const REMOVE_NEW = FixKind(
+ 'dart.fix.remove.new',
+ DartFixKindPriority.DEFAULT,
+ "Remove 'new' keyword",
+ );
static const REMOVE_NON_NULL_ASSERTION = FixKind(
'dart.fix.remove.nonNullAssertion',
DartFixKindPriority.DEFAULT,
@@ -1690,11 +1695,6 @@
DartFixKindPriority.DEFAULT,
'Update the SDK constraints',
);
- static const USE_CONST = FixKind(
- 'dart.fix.use.const',
- DartFixKindPriority.DEFAULT,
- 'Change to constant',
- );
static const USE_EFFECTIVE_INTEGER_DIVISION = FixKind(
'dart.fix.use.effectiveIntegerDivision',
DartFixKindPriority.DEFAULT,
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 03ec63b..1e78573 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -201,7 +201,6 @@
import 'package:analysis_server/src/services/correction/dart/sort_constructor_first.dart';
import 'package:analysis_server/src/services/correction/dart/sort_unnamed_constructor_first.dart';
import 'package:analysis_server/src/services/correction/dart/update_sdk_constraints.dart';
-import 'package:analysis_server/src/services/correction/dart/use_const.dart';
import 'package:analysis_server/src/services/correction/dart/use_curly_braces.dart';
import 'package:analysis_server/src/services/correction/dart/use_effective_integer_division.dart';
import 'package:analysis_server/src/services/correction/dart/use_eq_eq_null.dart';
@@ -950,7 +949,8 @@
MakeClassAbstract.new,
],
CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE: [
- UseConst.new,
+ RemoveConst.new,
+ RemoveNew.new,
],
CompileTimeErrorCode.CONST_INSTANCE_FIELD: [
AddStatic.new,
diff --git a/pkg/analysis_server/test/src/services/correction/fix/remove_const_test.dart b/pkg/analysis_server/test/src/services/correction/fix/remove_const_test.dart
index 3f347cc3..3d2a1c0 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/remove_const_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/remove_const_test.dart
@@ -20,6 +20,18 @@
@override
FixKind get kind => DartFixKind.REMOVE_CONST;
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49818')
+ Future<void> test_constInitializedWithNonConstantValue() async {
+ await resolveTestCode('''
+var x = 0;
+const y = x;
+''');
+ await assertHasFix('''
+var x = 0;
+final y = x;
+''');
+ }
+
Future<void> test_explicitConst() async {
await resolveTestCode('''
class A {
diff --git a/pkg/analysis_server/test/src/services/correction/fix/remove_unnecessary_new_test.dart b/pkg/analysis_server/test/src/services/correction/fix/remove_unnecessary_new_test.dart
index 5ad35bf..016ece1 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/remove_unnecessary_new_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/remove_unnecessary_new_test.dart
@@ -11,12 +11,34 @@
void main() {
defineReflectiveSuite(() {
+ defineReflectiveTests(RemoveNewTest);
defineReflectiveTests(RemoveUnnecessaryNewBulkTest);
defineReflectiveTests(RemoveUnnecessaryNewTest);
});
}
@reflectiveTest
+class RemoveNewTest extends FixProcessorTest {
+ @override
+ FixKind get kind => DartFixKind.REMOVE_NEW;
+
+ Future<void> test_explicitNew() async {
+ await resolveTestCode('''
+class A {
+ const A();
+}
+const a = new A();
+''');
+ await assertHasFix('''
+class A {
+ const A();
+}
+const a = A();
+''');
+ }
+}
+
+@reflectiveTest
class RemoveUnnecessaryNewBulkTest extends BulkFixProcessorTest {
@override
String get lintCode => LintNames.unnecessary_new;
diff --git a/pkg/analysis_server/test/src/services/correction/fix/test_all.dart b/pkg/analysis_server/test/src/services/correction/fix/test_all.dart
index 743f280..b38beb5 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/test_all.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/test_all.dart
@@ -245,7 +245,6 @@
import 'sort_unnamed_constructor_first_test.dart'
as sort_unnamed_constructor_first_test;
import 'update_sdk_constraints_test.dart' as update_sdk_constraints;
-import 'use_const_test.dart' as use_const;
import 'use_curly_braces_test.dart' as use_curly_braces;
import 'use_effective_integer_division_test.dart'
as use_effective_integer_division;
@@ -467,7 +466,6 @@
To view, visit change 277120. To unsubscribe, or for help writing mail filters, visit settings.
go/dart-cbuild result: SUCCESS
Details: https://goto.google.com/dart-cbuild/find/8e0b66b3c0f5a59a9ec6c6bd1feaee407021d628