Skip to content

Commit 4e719de

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Adds quick-fix for extension name
[email protected] Fixes: #59723 Change-Id: I3679146ac70dd6bcb936c151cb93dacf8273d4b9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401040 Auto-Submit: Felipe Morschel <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent 302315c commit 4e719de

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

pkg/analysis_server/lib/src/services/correction/fix_internal.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,10 @@ import 'package:analyzer/src/generated/parser.dart';
252252
import 'package:linter/src/lint_codes.dart';
253253

254254
final _builtInLintMultiProducers = {
255-
LinterLintCode.comment_references: [ImportLibrary.forType],
255+
LinterLintCode.comment_references: [
256+
ImportLibrary.forType,
257+
ImportLibrary.forExtension,
258+
],
256259
LinterLintCode.deprecated_member_use_from_same_package_without_message: [
257260
DataDriven.new,
258261
],
@@ -1094,8 +1097,8 @@ final _builtInNonLintProducers = <ErrorCode, List<ProducerGenerator>>{
10941097
// updated so that only the appropriate subset is generated.
10951098
QualifyReference.new,
10961099
],
1097-
CompileTimeErrorCode.UNQUALIFIED_REFERENCE_TO_STATIC_MEMBER_OF_EXTENDED_TYPE:
1098-
[
1100+
CompileTimeErrorCode
1101+
.UNQUALIFIED_REFERENCE_TO_STATIC_MEMBER_OF_EXTENDED_TYPE: [
10991102
// TODO(brianwilkerson): Consider adding fixes to create a field, getter,
11001103
// method or setter. The existing producers would need to be updated so
11011104
// that only the appropriate subset is generated.

pkg/analysis_server/test/src/services/correction/fix/import_library_project_test.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,23 @@ void f() {
314314
await assertNoFix();
315315
}
316316

317+
Future<void> test_extension_name() async {
318+
createAnalysisOptionsFile(lints: [LintNames.comment_references]);
319+
newFile('$testPackageLibPath/lib.dart', '''
320+
extension Ext on int {}
321+
''');
322+
await resolveTestCode('''
323+
/// This should import [Ext].
324+
void f() {}
325+
''');
326+
await assertHasFix('''
327+
import 'package:test/lib.dart';
328+
329+
/// This should import [Ext].
330+
void f() {}
331+
''');
332+
}
333+
317334
Future<void> test_extension_notImported_binaryOperator() async {
318335
newFile('$testPackageLibPath/lib.dart', '''
319336
extension E on String {
@@ -2164,6 +2181,25 @@ class ImportLibraryProject2Test extends FixProcessorTest {
21642181
@override
21652182
FixKind get kind => DartFixKind.IMPORT_LIBRARY_PROJECT2;
21662183

2184+
Future<void> test_extension_name() async {
2185+
createAnalysisOptionsFile(lints: [LintNames.comment_references]);
2186+
newFile('$testPackageLibPath/lib1.dart', '''
2187+
extension Ext on int {}
2188+
''');
2189+
newFile('$testPackageLibPath/lib2.dart', '''
2190+
export 'package:test/lib1.dart';''');
2191+
await resolveTestCode('''
2192+
/// This should import [Ext].
2193+
void f() {}
2194+
''');
2195+
await assertHasFix('''
2196+
import 'package:test/lib2.dart';
2197+
2198+
/// This should import [Ext].
2199+
void f() {}
2200+
''');
2201+
}
2202+
21672203
Future<void> test_lib() async {
21682204
newFile('$packagesRootPath/my_pkg/lib/a.dart', '''
21692205
export 'b.dart';
@@ -2540,6 +2576,23 @@ class ImportLibraryProject3Test extends FixProcessorTest {
25402576
@override
25412577
FixKind get kind => DartFixKind.IMPORT_LIBRARY_PROJECT3;
25422578

2579+
Future<void> test_extension_name() async {
2580+
createAnalysisOptionsFile(lints: [LintNames.comment_references]);
2581+
newFile('$testPackageLibPath/src/lib1.dart', '''
2582+
extension Ext on int {}
2583+
''');
2584+
await resolveTestCode('''
2585+
/// This should import [Ext].
2586+
void f() {}
2587+
''');
2588+
await assertHasFix('''
2589+
import 'package:test/src/lib1.dart';
2590+
2591+
/// This should import [Ext].
2592+
void f() {}
2593+
''');
2594+
}
2595+
25432596
Future<void> test_inLibSrc_thisContextRoot_extension() async {
25442597
newFile('$testPackageLibPath/src/lib.dart', '''
25452598
extension E on int {

0 commit comments

Comments
 (0)