@@ -30,39 +30,44 @@ String getParameterDocumentation(ParameterElement parameter) {
3030}
3131
3232class PropertyDescription {
33- final PropertyDescription _parent;
33+ static int _nextPropertyId = 0 ;
34+
35+ final PropertyDescription parent;
3436
3537 /// The resolved unit, where the property value is.
36- final ResolvedUnitResult _resolvedUnit;
38+ final ResolvedUnitResult resolvedUnit;
39+
40+ /// The instance of [Flutter] support for the [resolvedUnit] .
41+ final Flutter flutter;
3742
3843 /// If the object that has this property is not materialized yet, so the
39- /// [_instanceCreation ] is `null` , the description of the object to
44+ /// [instanceCreation ] is `null` , the description of the object to
4045 /// materialize.
41- final ClassDescription _classDescription ;
46+ final ClassDescription classDescription ;
4247
4348 /// The instance creation of the object that has this property. Or `null`
44- /// if the object is not materialized yet, in this case [_classDescription ]
49+ /// if the object is not materialized yet, in this case [classDescription ]
4550 /// is set.
46- final InstanceCreationExpression _instanceCreation ;
51+ final InstanceCreationExpression instanceCreation ;
4752
4853 /// Information about the `Container` property, which is not based on an
49- /// actual [_instanceCreation ] of the `Container` widget, i.e. is not
54+ /// actual [instanceCreation ] of the `Container` widget, i.e. is not
5055 /// materialized.
5156 final VirtualContainerProperty virtualContainer;
5257
5358 /// If the property is set, the full argument expression, might be a
5459 /// [NamedExpression] .
55- final Expression _argumentExpression ;
60+ final Expression argumentExpression ;
5661
5762 /// If the property is set, the value part of the argument expression,
58- /// the same as [_argumentExpression ] if a positional argument, or the
63+ /// the same as [argumentExpression ] if a positional argument, or the
5964 /// expression part of the [NamedExpression] .
60- final Expression _valueExpression ;
65+ final Expression valueExpression ;
6166
6267 /// The parameter element in the object constructor that is actually
63- /// invoked by [_instanceCreation ] , or will be invoked when
64- /// [_classDescription ] is materialized.
65- final ParameterElement _parameterElement ;
68+ /// invoked by [instanceCreation ] , or will be invoked when
69+ /// [classDescription ] is materialized.
70+ final ParameterElement parameterElement ;
6671
6772 /// Optional nested properties.
6873 final List <PropertyDescription > children = [];
@@ -73,54 +78,46 @@ class PropertyDescription {
7378 /// Otherwise `null` .
7479 _EdgeInsetsProperty _edgeInsetsProperty;
7580
76- PropertyDescription (
77- this ._parent,
78- this ._resolvedUnit,
79- this ._classDescription,
80- this ._instanceCreation,
81- this ._argumentExpression,
82- this ._valueExpression,
83- this ._parameterElement,
84- this .protocolProperty, {
81+ PropertyDescription ({
82+ this .parent,
83+ this .resolvedUnit,
84+ this .flutter,
85+ this .classDescription,
86+ this .instanceCreation,
87+ this .argumentExpression,
88+ this .valueExpression,
89+ this .parameterElement,
90+ this .protocolProperty,
8591 this .virtualContainer,
8692 });
8793
8894 String get name => protocolProperty.name;
8995
9096 /// This property has type `EdgeInsets` , add its nested properties.
91- int addEdgeInsetsNestedProperties (
92- int nextPropertyId,
93- Flutter flutter,
94- ClassElement classEdgeInsets,
95- ) {
96- _edgeInsetsProperty = _EdgeInsetsProperty (
97- flutter,
98- classEdgeInsets,
99- this ,
100- nextPropertyId,
101- );
102- return _edgeInsetsProperty.addNested ();
97+ void addEdgeInsetsNestedProperties (ClassElement classEdgeInsets) {
98+ _edgeInsetsProperty = _EdgeInsetsProperty (classEdgeInsets, this );
99+ _edgeInsetsProperty.addNested ();
103100 }
104101
105102 Future <protocol.SourceChange > changeValue (
106103 protocol.FlutterWidgetPropertyValue value) async {
107- if (_parent ? ._edgeInsetsProperty != null ) {
108- return _parent ._edgeInsetsProperty.changeValue (this , value);
104+ if (parent ? ._edgeInsetsProperty != null ) {
105+ return parent ._edgeInsetsProperty.changeValue (this , value);
109106 }
110107
111- var changeBuilder = DartChangeBuilder (_resolvedUnit .session);
108+ var changeBuilder = DartChangeBuilder (resolvedUnit .session);
112109
113110 ClassElement enumClassElement;
114111 var enumValue = value.enumValue;
115112 if (enumValue != null ) {
116- var helper = AnalysisSessionHelper (_resolvedUnit .session);
113+ var helper = AnalysisSessionHelper (resolvedUnit .session);
117114 enumClassElement = await helper.getClass (
118115 enumValue.libraryUri,
119116 enumValue.className,
120117 );
121118 }
122119
123- await changeBuilder.addFileEdit (_resolvedUnit .path, (builder) {
120+ await changeBuilder.addFileEdit (resolvedUnit .path, (builder) {
124121 _changeCode (builder, (builder) {
125122 if (enumClassElement != null ) {
126123 builder.writeReference (enumClassElement);
@@ -138,21 +135,21 @@ class PropertyDescription {
138135 }
139136
140137 Future <protocol.SourceChange > removeValue () async {
141- var changeBuilder = DartChangeBuilder (_resolvedUnit .session);
138+ var changeBuilder = DartChangeBuilder (resolvedUnit .session);
142139
143- if (_argumentExpression != null ) {
140+ if (argumentExpression != null ) {
144141 int endOffset;
145- var argumentList = _instanceCreation .argumentList;
142+ var argumentList = instanceCreation .argumentList;
146143 var arguments = argumentList.arguments;
147- var argumentIndex = arguments.indexOf (_argumentExpression );
144+ var argumentIndex = arguments.indexOf (argumentExpression );
148145 if (argumentIndex < arguments.length - 1 ) {
149146 endOffset = arguments[argumentIndex + 1 ].offset;
150147 } else {
151148 endOffset = argumentList.rightParenthesis.offset;
152149 }
153150
154- var beginOffset = _argumentExpression .offset;
155- await changeBuilder.addFileEdit (_resolvedUnit .path, (builder) {
151+ var beginOffset = argumentExpression .offset;
152+ await changeBuilder.addFileEdit (resolvedUnit .path, (builder) {
156153 builder.addDeletion (
157154 SourceRange (beginOffset, endOffset - beginOffset),
158155 );
@@ -163,7 +160,7 @@ class PropertyDescription {
163160 }
164161
165162 void replaceChild (String name, PropertyDescription newChild) {
166- assert (newChild._parent == this );
163+ assert (newChild.parent == this );
167164 for (var i = 0 ; i < children.length; i++ ) {
168165 if (children[i].name == name) {
169166 children[i] = newChild;
@@ -176,12 +173,12 @@ class PropertyDescription {
176173 DartFileEditBuilder builder,
177174 void buildCode (DartEditBuilder builder),
178175 ) {
179- if (_valueExpression != null ) {
180- builder.addReplacement (range.node (_valueExpression ), buildCode);
176+ if (valueExpression != null ) {
177+ builder.addReplacement (range.node (valueExpression ), buildCode);
181178 } else {
182- var parameterName = _parameterElement .name;
183- if (_instanceCreation != null ) {
184- var argumentList = _instanceCreation .argumentList;
179+ var parameterName = parameterElement .name;
180+ if (instanceCreation != null ) {
181+ var argumentList = instanceCreation .argumentList;
185182
186183 var insertOffset = 0 ;
187184 for (var argument in argumentList.arguments) {
@@ -219,12 +216,11 @@ class PropertyDescription {
219216 builder.write (', ' );
220217 });
221218 } else {
222- if (_parent.virtualContainer != null ) {
223- _parent._changeCodeVirtualContainer (
224- builder, parameterName, buildCode);
219+ if (parent.virtualContainer != null ) {
220+ parent._changeCodeVirtualContainer (builder, parameterName, buildCode);
225221 } else {
226- _parent ._changeCode (builder, (builder) {
227- builder.writeReference (_classDescription .element);
222+ parent ._changeCode (builder, (builder) {
223+ builder.writeReference (classDescription .element);
228224 // TODO(scheglov) constructor name
229225 builder.write ('(' );
230226 builder.write (parameterName);
@@ -311,10 +307,10 @@ class PropertyDescription {
311307 }
312308
313309 FunctionBody _enclosingFunctionBody () {
314- if (_parent != null ) {
315- return _parent ._enclosingFunctionBody ();
310+ if (parent != null ) {
311+ return parent ._enclosingFunctionBody ();
316312 }
317- var anchorExpr = virtualContainer? .widgetCreation ?? _instanceCreation ;
313+ var anchorExpr = virtualContainer? .widgetCreation ?? instanceCreation ;
318314 return anchorExpr.thisOrAncestorOfType <FunctionBody >();
319315 }
320316
@@ -350,6 +346,8 @@ class PropertyDescription {
350346
351347 throw StateError ('Not a primitive value: $value ' );
352348 }
349+
350+ static int nextId () => _nextPropertyId++ ;
353351}
354352
355353/// Every widget has the `Container` property, either based of an actual
@@ -390,14 +388,11 @@ class VirtualContainerProperty {
390388///
391389/// We try to generate nice looking code for `EdgeInsets` instances.
392390class _EdgeInsetsProperty {
393- final Flutter flutter;
394391 final ClassElement classEdgeInsets;
395392
396393 /// The property that has type `EdgeInsets` .
397394 final PropertyDescription property;
398395
399- int nextPropertyId;
400-
401396 /// The constructor `EdgeInsets.only` .
402397 ConstructorElement onlyConstructor;
403398
@@ -411,19 +406,16 @@ class _EdgeInsetsProperty {
411406 PropertyDescription rightProperty;
412407 PropertyDescription bottomProperty;
413408
414- _EdgeInsetsProperty (
415- this .flutter,
416- this .classEdgeInsets,
417- this .property,
418- this .nextPropertyId,
419- );
409+ _EdgeInsetsProperty (this .classEdgeInsets, this .property);
410+
411+ Flutter get flutter => property.flutter;
420412
421- int addNested () {
413+ void addNested () {
422414 Expression leftExpression;
423415 Expression topExpression;
424416 Expression rightExpression;
425417 Expression bottomExpression;
426- var propertyExpression = property._valueExpression ;
418+ var propertyExpression = property.valueExpression ;
427419 if (propertyExpression is InstanceCreationExpression ) {
428420 var constructor = propertyExpression.staticElement;
429421 if (constructor? .enclosingElement == classEdgeInsets) {
@@ -486,8 +478,6 @@ class _EdgeInsetsProperty {
486478 expression: bottomExpression,
487479 value: bottomValue,
488480 );
489-
490- return nextPropertyId;
491481 }
492482
493483 /// The value of the [nested] property is changed, make changes to the
@@ -521,9 +511,9 @@ class _EdgeInsetsProperty {
521511 return property.removeValue ();
522512 }
523513
524- var changeBuilder = DartChangeBuilder (property._resolvedUnit .session);
514+ var changeBuilder = DartChangeBuilder (property.resolvedUnit .session);
525515
526- await changeBuilder.addFileEdit (property._resolvedUnit .path, (builder) {
516+ await changeBuilder.addFileEdit (property.resolvedUnit .path, (builder) {
527517 property._changeCode (builder, (builder) {
528518 if (leftCode == rightCode && topCode == bottomCode) {
529519 builder.writeReference (classEdgeInsets);
@@ -600,15 +590,12 @@ class _EdgeInsetsProperty {
600590 );
601591 var parameterDocumentation = getParameterDocumentation (parameter);
602592 var nested = PropertyDescription (
603- property,
604- property._resolvedUnit,
605- null ,
606- null ,
607- null ,
608- expression,
609- parameter,
610- protocol.FlutterWidgetProperty (
611- nextPropertyId++ ,
593+ parent: property,
594+ resolvedUnit: property.resolvedUnit,
595+ valueExpression: expression,
596+ parameterElement: parameter,
597+ protocolProperty: protocol.FlutterWidgetProperty (
598+ PropertyDescription .nextId (),
612599 true ,
613600 true ,
614601 name,
@@ -626,7 +613,7 @@ class _EdgeInsetsProperty {
626613
627614 String _expressionCode (Expression expression) {
628615 if (expression != null ) {
629- var content = property._resolvedUnit .content;
616+ var content = property.resolvedUnit .content;
630617 return content.substring (expression.offset, expression.end);
631618 }
632619 return null ;
0 commit comments