-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '7605a36ab3e1601ee561758fc6936c707c0f90c0' into 'dev'
- Loading branch information
Showing
57 changed files
with
7,445 additions
and
7,298 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
pkg/analysis_server/lib/src/services/correction/dart/sort_constructor_first.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,49 @@ | ||
// Copyright (c) 2022, 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 SortConstructorFirst extends CorrectionProducer { | ||
@override | ||
bool get canBeAppliedInBulk => true; | ||
|
||
@override | ||
bool get canBeAppliedToFile => true; | ||
|
||
@override | ||
FixKind get fixKind => DartFixKind.SORT_CONSTRUCTOR_FIRST; | ||
|
||
@override | ||
FixKind get multiFixKind => DartFixKind.SORT_CONSTRUCTOR_FIRST_MULTI; | ||
|
||
@override | ||
Future<void> compute(ChangeBuilder builder) async { | ||
var constructor = coveredNode?.parent; | ||
var clazz = constructor?.parent; | ||
if (clazz is! ClassDeclaration || constructor is! ConstructorDeclaration) { | ||
return; | ||
} | ||
|
||
await builder.addDartFileEdit(file, (builder) { | ||
var deletionRange = range.endEnd( | ||
constructor.beginToken.previous!, | ||
constructor.endToken, | ||
); | ||
|
||
builder.addDeletion(deletionRange); | ||
builder.addSimpleInsertion( | ||
clazz.leftBracket.end, | ||
utils.getRangeText(deletionRange), | ||
); | ||
}); | ||
} | ||
|
||
/// Return an instance of this class. Used as a tear-off in `FixProcessor`. | ||
static SortConstructorFirst newInstance() => SortConstructorFirst(); | ||
} |
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
97 changes: 97 additions & 0 deletions
97
pkg/analysis_server/test/src/services/correction/fix/sort_constructor_first_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,97 @@ | ||
// Copyright (c) 2022, 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:analysis_server/src/services/linter/lint_names.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(SortConstructorFirstBulkTest); | ||
defineReflectiveTests(SortConstructorFirstTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class SortConstructorFirstBulkTest extends BulkFixProcessorTest { | ||
@override | ||
String get lintCode => LintNames.sort_constructors_first; | ||
|
||
Future<void> test_multiple_classes() async { | ||
await resolveTestCode(''' | ||
class A { | ||
X() {} | ||
A(); | ||
} | ||
class B { | ||
Y() {} | ||
B(); | ||
} | ||
'''); | ||
await assertHasFix(''' | ||
class A { | ||
A(); | ||
X() {} | ||
} | ||
class B { | ||
B(); | ||
Y() {} | ||
} | ||
'''); | ||
} | ||
|
||
Future<void> test_single_class() async { | ||
await resolveTestCode(''' | ||
class A { | ||
X() {} | ||
A(); | ||
Y() {} | ||
A._(); | ||
} | ||
'''); | ||
await assertHasFix(''' | ||
class A { | ||
A(); | ||
A._(); | ||
X() {} | ||
Y() {} | ||
} | ||
'''); | ||
} | ||
} | ||
|
||
@reflectiveTest | ||
class SortConstructorFirstTest extends FixProcessorLintTest { | ||
@override | ||
FixKind get kind => DartFixKind.SORT_CONSTRUCTOR_FIRST; | ||
|
||
@override | ||
String get lintCode => LintNames.sort_constructors_first; | ||
|
||
Future<void> test_one_fix() async { | ||
await resolveTestCode(''' | ||
class A { | ||
X() {} | ||
A(); | ||
} | ||
'''); | ||
await assertHasFix(''' | ||
class A { | ||
A(); | ||
X() {} | ||
} | ||
'''); | ||
} | ||
} |
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
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
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
Oops, something went wrong.