@@ -7,23 +7,24 @@ import 'package:analysis_server/src/services/flutter/class_description.dart';
77import 'package:analyzer/dart/analysis/results.dart' ;
88import 'package:analyzer/dart/ast/ast.dart' ;
99import 'package:analyzer/dart/ast/token.dart' ;
10- import 'package:analyzer/dart/element/element .dart' ;
10+ import 'package:analyzer/dart/element/element2 .dart' ;
1111import 'package:analyzer/source/source_range.dart' ;
1212import 'package:analyzer/src/dart/analysis/session_helper.dart' ;
1313import 'package:analyzer/src/dart/ast/extensions.dart' ;
1414import 'package:analyzer/src/util/comment.dart' ;
1515import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart' ;
1616import 'package:analyzer_plugin/utilities/change_builder/change_builder_dart.dart' ;
1717import 'package:analyzer_plugin/utilities/range_factory.dart' ;
18+ import 'package:collection/collection.dart' ;
1819
19- String ? getFieldDocumentation (FieldElement field) {
20+ String ? getFieldDocumentation (FieldElement2 field) {
2021 var rawComment = field.documentationComment;
2122 return getDartDocPlainText (rawComment);
2223}
2324
24- String ? getParameterDocumentation (ParameterElement ? parameter) {
25- if (parameter is FieldFormalParameterElement ) {
26- var rawComment = parameter.field ? .documentationComment;
25+ String ? getParameterDocumentation (FormalParameterElement ? parameter) {
26+ if (parameter is FieldFormalParameterElement2 ) {
27+ var rawComment = parameter.field2 ? .documentationComment;
2728 return getDartDocPlainText (rawComment);
2829 }
2930 return null ;
@@ -64,7 +65,7 @@ class PropertyDescription {
6465 /// The parameter element in the object constructor that is actually
6566 /// invoked by [instanceCreation] , or will be invoked when
6667 /// [classDescription] is materialized.
67- final ParameterElement ? parameterElement;
68+ final FormalParameterElement ? parameterElement;
6869
6970 /// Optional nested properties.
7071 final List <PropertyDescription > children = [];
@@ -90,7 +91,7 @@ class PropertyDescription {
9091 String get name => protocolProperty.name;
9192
9293 /// This property has type `EdgeInsets` , add its nested properties.
93- void addEdgeInsetsNestedProperties (ClassElement classEdgeInsets) {
94+ void addEdgeInsetsNestedProperties (ClassElement2 classEdgeInsets) {
9495 _edgeInsetsProperty = _EdgeInsetsProperty (classEdgeInsets, this )
9596 ..addNested ();
9697 }
@@ -105,15 +106,15 @@ class PropertyDescription {
105106
106107 var builder = ChangeBuilder (session: resolvedUnit.session);
107108
108- InterfaceElement ? enumElement;
109+ InterfaceElement2 ? enumElement;
109110 var enumValue = value.enumValue;
110111 if (enumValue != null ) {
111112 var helper = AnalysisSessionHelper (resolvedUnit.session);
112- enumElement = await helper.getClass (
113+ enumElement = await helper.getClass2 (
113114 enumValue.libraryUri,
114115 enumValue.className,
115116 );
116- enumElement ?? = await helper.getEnum (
117+ enumElement ?? = await helper.getEnum2 (
117118 enumValue.libraryUri,
118119 enumValue.className,
119120 );
@@ -125,7 +126,7 @@ class PropertyDescription {
125126 if (expression != null ) {
126127 builder.write (expression);
127128 } else if (enumElement != null && enumValue != null ) {
128- builder.writeReference (enumElement);
129+ builder.writeReference2 (enumElement);
129130 builder.write ('.' );
130131 builder.write (enumValue.name);
131132 } else {
@@ -186,7 +187,7 @@ class PropertyDescription {
186187 if (parameterElement == null ) {
187188 return ;
188189 }
189- var parameterName = parameterElement.name ;
190+ var parameterName = parameterElement.name3 ! ;
190191 var instanceCreation = this .instanceCreation;
191192 if (instanceCreation != null ) {
192193 var argumentList = instanceCreation.argumentList;
@@ -240,7 +241,7 @@ class PropertyDescription {
240241 return ;
241242 }
242243 parent._changeCode (builder, (builder) {
243- builder.writeReference (classDescription.element);
244+ builder.writeReference2 (classDescription.element);
244245 // TODO(scheglov): constructor name
245246 builder.write ('(' );
246247 builder.write (parameterName);
@@ -269,7 +270,7 @@ class PropertyDescription {
269270 builder.addReplacement (
270271 range.startEnd (parentCreation, parentCreation.constructorName),
271272 (builder) {
272- builder.writeReference (virtualContainer.containerElement);
273+ builder.writeReference2 (virtualContainer.containerElement);
273274 },
274275 );
275276
@@ -311,7 +312,7 @@ class PropertyDescription {
311312 });
312313 } else {
313314 builder.addInsertion (virtualContainer.widgetCreation.offset, (builder) {
314- builder.writeReference (virtualContainer.containerElement);
315+ builder.writeReference2 (virtualContainer.containerElement);
315316 builder.write ('(' );
316317
317318 builder.write (parameterName);
@@ -388,7 +389,7 @@ class PropertyDescription {
388389///
389390/// This class provides information necessary for such materialization.
390391class VirtualContainerProperty {
391- final ClassElement containerElement;
392+ final ClassElement2 containerElement;
392393 final InstanceCreationExpression widgetCreation;
393394
394395 /// The existing wrapper around the widget, with semantic that is a subset
@@ -417,13 +418,13 @@ class VirtualContainerProperty {
417418///
418419/// We try to generate nice looking code for `EdgeInsets` instances.
419420class _EdgeInsetsProperty {
420- final ClassElement classEdgeInsets;
421+ final ClassElement2 classEdgeInsets;
421422
422423 /// The property that has type `EdgeInsets` .
423424 final PropertyDescription property;
424425
425426 /// The constructor `EdgeInsets.only` .
426- ConstructorElement ? onlyConstructor;
427+ ConstructorElement2 ? onlyConstructor;
427428
428429 double ? leftValue;
429430 double ? topValue;
@@ -444,11 +445,11 @@ class _EdgeInsetsProperty {
444445 Expression ? bottomExpression;
445446 var propertyExpression = property.valueExpression;
446447 if (propertyExpression is InstanceCreationExpression ) {
447- var constructor = propertyExpression.constructorName.staticElement ;
448+ var constructor = propertyExpression.constructorName.element ;
448449 if (constructor != null &&
449- constructor.enclosingElement3 == classEdgeInsets) {
450+ constructor.enclosingElement2 == classEdgeInsets) {
450451 var arguments = propertyExpression.argumentList;
451- var constructorName = constructor.name ;
452+ var constructorName = constructor.name3 ;
452453 if (constructorName == 'all' ) {
453454 var expression = arguments.elementAtOrNull (0 );
454455 leftExpression = expression;
@@ -485,7 +486,9 @@ class _EdgeInsetsProperty {
485486 }
486487 }
487488
488- onlyConstructor = classEdgeInsets.getNamedConstructor ('only' );
489+ onlyConstructor = classEdgeInsets.constructors2.firstWhereOrNull (
490+ (e) => e.name3 == 'only' ,
491+ );
489492
490493 leftProperty = _addNestedProperty (
491494 name: 'left' ,
@@ -545,7 +548,7 @@ class _EdgeInsetsProperty {
545548 await builder.addDartFileEdit (property.resolvedUnit.path, (builder) {
546549 property._changeCode (builder, (builder) {
547550 if (leftCode == rightCode && topCode == bottomCode) {
548- builder.writeReference (classEdgeInsets);
551+ builder.writeReference2 (classEdgeInsets);
549552 if (leftCode == topCode) {
550553 builder.write ('.all(' );
551554 builder.write (leftCode);
@@ -568,7 +571,7 @@ class _EdgeInsetsProperty {
568571 builder.write (')' );
569572 }
570573 } else {
571- builder.writeReference (classEdgeInsets);
574+ builder.writeReference2 (classEdgeInsets);
572575 builder.write ('.only(' );
573576 var needsComma = false ;
574577 if (leftCode != '0' ) {
@@ -614,8 +617,8 @@ class _EdgeInsetsProperty {
614617 required Expression ? expression,
615618 required double ? value,
616619 }) {
617- var parameter = onlyConstructor? .parameters .singleWhere (
618- (p) => p.name == name,
620+ var parameter = onlyConstructor? .formalParameters .singleWhere (
621+ (p) => p.name3 == name,
619622 );
620623 var parameterDocumentation = getParameterDocumentation (parameter);
621624 var nested = PropertyDescription (
0 commit comments