[M] Change in dart/sdk[main]: [analysis_server] remove `UseConst`

1 view
Skip to first unread message

Ahmed Ashour (Gerrit)

unread,
Dec 22, 2022, 5:51:46 AM12/22/22
to rev...@dartlang.org

Ahmed Ashour has uploaded this change for review.

View Change

[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.

Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: Idf0b2f626558a8b2abb91eb0a4c4872f91e29632
Gerrit-Change-Number: 277120
Gerrit-PatchSet: 1
Gerrit-Owner: Ahmed Ashour <asas...@yahoo.com>
Gerrit-MessageType: newchange

Ahmed Ashour (Gerrit)

unread,
Dec 22, 2022, 6:33:21 AM12/22/22
to rev...@dartlang.org

Ahmed Ashour uploaded patch set #2 to this change.

View 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.

Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: Idf0b2f626558a8b2abb91eb0a4c4872f91e29632
Gerrit-Change-Number: 277120
Gerrit-PatchSet: 2
Gerrit-Owner: Ahmed Ashour <asas...@yahoo.com>
Gerrit-MessageType: newpatchset

Ahmed Ashour (Gerrit)

unread,
Jan 4, 2023, 4:26:49 AM1/4/23
to rev...@dartlang.org

Ahmed Ashour uploaded patch set #3 to this change.

View 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.

Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: Idf0b2f626558a8b2abb91eb0a4c4872f91e29632
Gerrit-Change-Number: 277120
Gerrit-PatchSet: 3

CBuild (Gerrit)

unread,
Jan 19, 2023, 2:12:10 PM1/19/23
to Keerti Parthasarathy, Ahmed Ashour, rev...@dartlang.org, Commit Queue

go/dart-cbuild result: SUCCESS

Details: https://goto.google.com/dart-cbuild/find/e182c48dd5a7f96190c8056744f7ac71a5cad5e7

View Change

    To view, visit change 277120. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: Idf0b2f626558a8b2abb91eb0a4c4872f91e29632
    Gerrit-Change-Number: 277120
    Gerrit-PatchSet: 4
    Gerrit-Owner: Ahmed Ashour <asas...@yahoo.com>
    Gerrit-Reviewer: Keerti Parthasarathy <kee...@google.com>
    Gerrit-Comment-Date: Thu, 19 Jan 2023 19:12:05 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Brian Wilkerson (Gerrit)

    unread,
    Feb 7, 2023, 2:31:22 PM2/7/23
    to Keerti Parthasarathy, Ahmed Ashour, rev...@dartlang.org, Brian Wilkerson, CBuild, Commit Queue

    Attention is currently required from: Ahmed Ashour, Keerti Parthasarathy.

    Patch set 4:Code-Review +1Commit-Queue +2

    View Change

      To view, visit change 277120. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: sdk
      Gerrit-Branch: main
      Gerrit-Change-Id: Idf0b2f626558a8b2abb91eb0a4c4872f91e29632
      Gerrit-Change-Number: 277120
      Gerrit-PatchSet: 4
      Gerrit-Owner: Ahmed Ashour <asas...@yahoo.com>
      Gerrit-Reviewer: Brian Wilkerson <brianwi...@google.com>
      Gerrit-Reviewer: Keerti Parthasarathy <kee...@google.com>
      Gerrit-Attention: Keerti Parthasarathy <kee...@google.com>
      Gerrit-Attention: Ahmed Ashour <asas...@yahoo.com>
      Gerrit-Comment-Date: Tue, 07 Feb 2023 19:31:17 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      Gerrit-MessageType: comment

      Commit Queue (Gerrit)

      unread,
      Feb 7, 2023, 3:27:07 PM2/7/23
      to Ahmed Ashour, rev...@dartlang.org, Brian Wilkerson, CBuild, Keerti Parthasarathy

      Commit Queue submitted this change.

      View Change

      Approvals: Brian Wilkerson: Looks good to me, approved; Commit
      [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.

      Gerrit-Project: sdk
      Gerrit-Branch: main
      Gerrit-Change-Id: Idf0b2f626558a8b2abb91eb0a4c4872f91e29632
      Gerrit-Change-Number: 277120
      Gerrit-PatchSet: 5
      Gerrit-Owner: Ahmed Ashour <asas...@yahoo.com>
      Gerrit-Reviewer: Brian Wilkerson <brianwi...@google.com>
      Gerrit-Reviewer: Keerti Parthasarathy <kee...@google.com>
      Gerrit-MessageType: merged

      CBuild (Gerrit)

      unread,
      Feb 7, 2023, 3:56:37 PM2/7/23
      to Commit Queue, Ahmed Ashour, rev...@dartlang.org, Brian Wilkerson, Keerti Parthasarathy

      go/dart-cbuild result: SUCCESS

      Details: https://goto.google.com/dart-cbuild/find/8e0b66b3c0f5a59a9ec6c6bd1feaee407021d628

      View Change

        To view, visit change 277120. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: sdk
        Gerrit-Branch: main
        Gerrit-Change-Id: Idf0b2f626558a8b2abb91eb0a4c4872f91e29632
        Gerrit-Change-Number: 277120
        Gerrit-PatchSet: 5
        Gerrit-Owner: Ahmed Ashour <asas...@yahoo.com>
        Gerrit-Reviewer: Brian Wilkerson <brianwi...@google.com>
        Gerrit-Reviewer: Keerti Parthasarathy <kee...@google.com>
        Gerrit-Comment-Date: Tue, 07 Feb 2023 20:56:33 +0000
        Reply all
        Reply to author
        Forward
        0 new messages