-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[macros] quick fix for
EXTENSION_AUGMENTATION_HAS_ON_CLAUSE
Change-Id: I4521f742bfb60d7ff03dc76fe3ac6ea2810bb84f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366400 Commit-Queue: Phil Quitslund <pquitslund@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
- Loading branch information
Showing
6 changed files
with
125 additions
and
3 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
pkg/analysis_server/lib/src/services/correction/dart/remove_on_clause.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2024, 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 RemoveOnClause extends ResolvedCorrectionProducer { | ||
@override | ||
bool get canBeAppliedInBulk => true; | ||
|
||
@override | ||
bool get canBeAppliedToFile => true; | ||
|
||
@override | ||
FixKind get fixKind => DartFixKind.REMOVE_ON_CLAUSE; | ||
|
||
@override | ||
FixKind get multiFixKind => DartFixKind.REMOVE_ON_CLAUSE_MULTI; | ||
|
||
@override | ||
Future<void> compute(ChangeBuilder builder) async { | ||
var extensionDeclaration = | ||
node.thisOrAncestorOfType<ExtensionDeclaration>(); | ||
if (extensionDeclaration == null) return; | ||
|
||
await builder.addDartFileEdit(file, (builder) { | ||
builder.addDeletion(range.startStart( | ||
extensionDeclaration.onClause!, extensionDeclaration.leftBracket)); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
pkg/analysis_server/test/src/services/correction/fix/remove_on_clause_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) 2024, 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/src/generated/parser.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(RemoveOnClauseMultiTest); | ||
defineReflectiveTests(RemoveOnClauseTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class RemoveOnClauseMultiTest extends FixProcessorTest { | ||
@override | ||
FixKind get kind => DartFixKind.REMOVE_ON_CLAUSE_MULTI; | ||
|
||
Future<void> test_singleFile() async { | ||
newFile('$testPackageLibPath/a.dart', ''' | ||
import augment 'test.dart'; | ||
extension E on int { } | ||
'''); | ||
|
||
await resolveTestCode(''' | ||
augment library 'a.dart'; | ||
augment extension E on int { } | ||
augment extension E on num { } | ||
'''); | ||
await assertHasFixAllFix( | ||
ParserErrorCode.EXTENSION_AUGMENTATION_HAS_ON_CLAUSE, ''' | ||
augment library 'a.dart'; | ||
augment extension E { } | ||
augment extension E { } | ||
'''); | ||
} | ||
} | ||
|
||
@reflectiveTest | ||
class RemoveOnClauseTest extends FixProcessorTest { | ||
@override | ||
FixKind get kind => DartFixKind.REMOVE_ON_CLAUSE; | ||
|
||
Future<void> test_it() async { | ||
newFile('$testPackageLibPath/a.dart', ''' | ||
import augment 'test.dart'; | ||
extension E on int { } | ||
'''); | ||
|
||
await resolveTestCode(''' | ||
augment library 'a.dart'; | ||
augment extension E on int { } | ||
'''); | ||
await assertHasFix(''' | ||
augment library 'a.dart'; | ||
augment extension E { } | ||
'''); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters