File tree Expand file tree Collapse file tree
analysis_server/lib/src/services/correction/dart
analyzer_plugin/test/utilities Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import 'package:analyzer_plugin/utilities/assist/assist.dart';
1212import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart' ;
1313import 'package:analyzer_plugin/utilities/change_builder/change_builder_dart.dart' ;
1414import 'package:analyzer_plugin/utilities/fixes/fixes.dart' ;
15+ import 'package:collection/collection.dart' ;
1516
1617class AddDiagnosticPropertyReference extends CorrectionProducer {
1718 @override
@@ -113,8 +114,10 @@ class AddDiagnosticPropertyReference extends CorrectionProducer {
113114 builder.writeln ("$constructorName ('${node .name }', ${node .name }));" );
114115 }
115116
116- final debugFillProperties =
117- classDeclaration.getMethod ('debugFillProperties' );
117+ final debugFillProperties = classDeclaration.members
118+ .whereType <MethodDeclaration >()
119+ .where ((e) => e.name.name == 'debugFillProperties' )
120+ .singleOrNull;
118121 if (debugFillProperties == null ) {
119122 var location = utils.prepareNewMethodLocation (classDeclaration);
120123 if (location == null ) {
Original file line number Diff line number Diff line change 11## 4.4.0-dev
22* Deprecated ` ClassDeclaration.isAbstract ` , use ` abstractKeyword ` instead.
33* Deprecated ` ClassTypeAlias.isAbstract ` , use ` abstractKeyword ` instead.
4+ * Deprecated ` ClassOrMixinDeclaration.getField ` , filter ` members ` instead.
5+ * Deprecated ` ClassOrMixinDeclaration.getMethod ` , filter ` members ` instead.
6+ * Deprecated ` ClassDeclaration.getConstructor ` , filter ` members ` instead.
47
58## 4.3.1
69* Fix ` identifier ` for ` LibraryExportElement ` and ` LibraryImportElement ` .
Original file line number Diff line number Diff line change @@ -860,6 +860,7 @@ abstract class ClassDeclaration implements ClassOrMixinDeclaration {
860860 ///
861861 /// If the [name] is `null` then the default constructor will be searched
862862 /// for.
863+ @Deprecated ('Filter members instead' )
863864 ConstructorDeclaration ? getConstructor (String ? name);
864865}
865866
@@ -900,10 +901,12 @@ abstract class ClassOrMixinDeclaration implements NamedCompilationUnitMember {
900901
901902 /// Returns the field declared in the class/mixin with the given [name] , or
902903 /// `null` if there is no such field.
904+ @Deprecated ('Filter members instead' )
903905 VariableDeclaration ? getField (String name);
904906
905907 /// Returns the method declared in the class/mixin with the given [name] , or
906908 /// `null` if there is no such method.
909+ @Deprecated ('Filter members instead' )
907910 MethodDeclaration ? getMethod (String name);
908911}
909912
Original file line number Diff line number Diff line change @@ -1699,6 +1699,7 @@ class ClassDeclarationImpl extends ClassOrMixinDeclarationImpl
16991699 @override
17001700 E ? accept <E >(AstVisitor <E > visitor) => visitor.visitClassDeclaration (this );
17011701
1702+ @Deprecated ('Filter members instead' )
17021703 @override
17031704 ConstructorDeclaration ? getConstructor (String ? name) {
17041705 int length = _members.length;
@@ -1795,6 +1796,7 @@ abstract class ClassOrMixinDeclarationImpl
17951796 _typeParameters = _becomeParentOf (typeParameters as TypeParameterListImpl ? );
17961797 }
17971798
1799+ @Deprecated ('Filter members instead' )
17981800 @override
17991801 VariableDeclaration ? getField (String name) {
18001802 int memberLength = _members.length;
@@ -1816,6 +1818,7 @@ abstract class ClassOrMixinDeclarationImpl
18161818 return null ;
18171819 }
18181820
1821+ @Deprecated ('Filter members instead' )
18191822 @override
18201823 MethodDeclaration ? getMethod (String name) {
18211824 int length = _members.length;
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ main() {
4242
4343@reflectiveTest
4444class ClassDeclarationTest extends ParserTestCase {
45+ @Deprecated ('Filter members instead' )
4546 void test_getConstructor () {
4647 List <ConstructorInitializer > initializers = < ConstructorInitializer > [];
4748 ConstructorDeclaration defaultConstructor =
@@ -69,6 +70,7 @@ class ClassDeclarationTest extends ParserTestCase {
6970 expect (clazz.getConstructor ("noSuchConstructor" ), isNull);
7071 }
7172
73+ @Deprecated ('Filter members instead' )
7274 void test_getField () {
7375 VariableDeclaration aVar = AstTestFactory .variableDeclaration ("a" );
7476 VariableDeclaration bVar = AstTestFactory .variableDeclaration ("b" );
@@ -85,6 +87,7 @@ class ClassDeclarationTest extends ParserTestCase {
8587 expect (clazz.getField ("noSuchField" ), isNull);
8688 }
8789
90+ @Deprecated ('Filter members instead' )
8891 void test_getMethod () {
8992 MethodDeclaration aMethod = AstTestFactory .methodDeclaration (
9093 null ,
Original file line number Diff line number Diff line change @@ -390,7 +390,7 @@ class Foo {
390390''' );
391391 var classDeclaration = unit.declarations.first as ClassDeclaration ;
392392 var constructor =
393- classDeclaration.getConstructor ( null ) as ConstructorDeclaration ;
393+ classDeclaration.members. whereType < ConstructorDeclaration >().single ;
394394
395395 // Object? o
396396 var parameter =
@@ -436,7 +436,7 @@ class Foo {
436436''' );
437437 var classDeclaration = unit.declarations.first as ClassDeclaration ;
438438 var constructor =
439- classDeclaration.getConstructor ( null ) as ConstructorDeclaration ;
439+ classDeclaration.members. whereType < ConstructorDeclaration >().single ;
440440
441441 // Object? o
442442 var parameter =
@@ -489,7 +489,7 @@ class Foo {
489489''' );
490490 var classDeclaration = unit.declarations.first as ClassDeclaration ;
491491 var constructor =
492- classDeclaration.getConstructor ( null ) as ConstructorDeclaration ;
492+ classDeclaration.members. whereType < ConstructorDeclaration >().single ;
493493
494494 // Object? o
495495 var parameter =
Original file line number Diff line number Diff line change @@ -198,7 +198,7 @@ class RangeFactory_NodeInListTest extends AbstractSingleUnitTest {
198198 /// return the list of initializers in that constructor.
199199 NodeList <ConstructorInitializer > get _constructorInitializers {
200200 var c = testUnit.declarations[0 ] as ClassDeclaration ;
201- var constructor = c.getConstructor ( null ) as ConstructorDeclaration ;
201+ var constructor = c.members. whereType < ConstructorDeclaration >().single ;
202202 return constructor.initializers;
203203 }
204204
Original file line number Diff line number Diff line change @@ -27,5 +27,5 @@ CHANNEL dev
2727MAJOR 2
2828MINOR 19
2929PATCH 0
30- PRERELEASE 35
30+ PRERELEASE 36
3131PRERELEASE_PATCH 0
You can’t perform that action at this time.
0 commit comments