-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge aa28753 into dev
- Loading branch information
Showing
7 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
pkg/analysis_server/lib/src/services/correction/dart/add_class_modifier.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,41 @@ | ||
// 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'; | ||
|
||
class AddClassModifier extends ResolvedCorrectionProducer { | ||
final String _modifier; | ||
|
||
AddClassModifier.base() : this._('base'); | ||
|
||
AddClassModifier._(this._modifier); | ||
|
||
@override | ||
CorrectionApplicability get applicability => | ||
CorrectionApplicability.acrossSingleFile; | ||
|
||
@override | ||
List<String> get fixArguments => [_modifier]; | ||
|
||
@override | ||
FixKind get fixKind => DartFixKind.ADD_CLASS_MODIFIER; | ||
|
||
@override | ||
FixKind get multiFixKind => DartFixKind.ADD_CLASS_MODIFIER_MULTI; | ||
|
||
@override | ||
Future<void> compute(ChangeBuilder builder) async { | ||
var node = this.node; | ||
if (node is! NamedCompilationUnitMember) return; | ||
|
||
await builder.addDartFileEdit(file, (builder) { | ||
builder.addSimpleInsertion( | ||
node.firstTokenAfterCommentAndMetadata.offset, '$_modifier '); | ||
}); | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
pkg/analysis_server/test/src/services/correction/fix/add_class_modifier_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,45 @@ | ||
// 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_plugin/utilities/fixes/fixes.dart'; | ||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import 'fix_processor.dart'; | ||
|
||
void main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(AddClassModifierTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class AddClassModifierTest extends FixProcessorTest { | ||
@override | ||
FixKind get kind => DartFixKind.ADD_CLASS_MODIFIER; | ||
|
||
Future<void> test_mixinSubtypeOfBaseIsNotBase() async { | ||
await resolveTestCode(''' | ||
base class A {} | ||
mixin B implements A {} | ||
'''); | ||
await assertHasFix(''' | ||
base class A {} | ||
base mixin B implements A {} | ||
'''); | ||
} | ||
|
||
Future<void> test_mixinSubtypeOfBaseIsNotBase_withDoc() async { | ||
await resolveTestCode(''' | ||
base class A {} | ||
// Doc. | ||
mixin B implements A {} | ||
'''); | ||
await assertHasFix(''' | ||
base class A {} | ||
// Doc. | ||
base mixin B implements A {} | ||
'''); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,5 @@ CHANNEL dev | |
MAJOR 3 | ||
MINOR 5 | ||
PATCH 0 | ||
PRERELEASE 192 | ||
PRERELEASE 193 | ||
PRERELEASE_PATCH 0 |