Skip to content

Commit fd33d9e

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Use 'value' as the name of the formal parameter for a synthetic setter.
``` According to Gemini: There is a very strong and widely followed recommendation. The formal parameter for a setter in Dart should be named value. ``` So, it makes synthetic setters consistent with manually written setters. These names sometimes are show in UI, e.g. in hover. Change-Id: I4b53314aae63dce267906856d98a16ec22d38097 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441827 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent a207698 commit fd33d9e

28 files changed

+1528
-1535
lines changed

pkg/analysis_server/test/analysis/get_hover_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ void f(A a) {
890890
// Synthetic getters are now shown as getters to avoid confusing
891891
// users by hiding them.
892892
// https://github.com/dart-lang/sdk/issues/55956
893-
expect(hover.elementDescription, 'set fff(String _fff)');
893+
expect(hover.elementDescription, 'set fff(String value)');
894894
expect(hover.elementKind, 'setter');
895895
// types
896896
expect(hover.staticType, 'String');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ class B extends A {
960960
int get f => 0;
961961
962962
@override
963-
set f(int _f) {
963+
set f(int value) {
964964
// TODO: implement f
965965
}
966966
}

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6971,11 +6971,6 @@ class LocalVariableFragmentImpl extends NonParameterVariableFragmentImpl
69716971
@override
69726972
LocalVariableElementImpl get element => _element2;
69736973

6974-
@override
6975-
set enclosingFragment(FragmentImpl? value) {
6976-
super.enclosingFragment = value;
6977-
}
6978-
69796974
@override
69806975
LibraryFragmentImpl get libraryFragment => enclosingUnit;
69816976

pkg/analyzer/lib/src/summary2/element_builder.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,7 @@ class ElementBuilder {
335335
instanceFragment.addSetter(setterFragment);
336336

337337
var valueFragment = FormalParameterFragmentImpl(
338-
// TODO(scheglov): replace with null
339-
name: '_${fieldFragment.name ?? ''}',
338+
name: 'value',
340339
firstTokenOffset: null,
341340
nameOffset: null,
342341
parameterKind: ParameterKind.REQUIRED,
@@ -700,8 +699,7 @@ class ElementBuilder {
700699
libraryFragment.addSetter(setterFragment);
701700

702701
var valueFragment = FormalParameterFragmentImpl(
703-
// TODO(scheglov): replace with null
704-
name: '_${variableFragment.name ?? ''}',
702+
name: 'value',
705703
firstTokenOffset: null,
706704
nameOffset: null,
707705
parameterKind: ParameterKind.REQUIRED,

pkg/analyzer/test/src/dart/resolution/assignment_test.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ AssignmentExpression
378378
operator: =
379379
rightHandSide: IntegerLiteral
380380
literal: 0
381-
correspondingParameter: package:test/a.dart::@setter::v::@formalParameter::_v
381+
correspondingParameter: package:test/a.dart::@setter::v::@formalParameter::value
382382
staticType: int
383383
readElement2: <null>
384384
readType: null
@@ -2453,7 +2453,7 @@ AssignmentExpression
24532453
operator: =
24542454
rightHandSide: IntegerLiteral
24552455
literal: 1
2456-
correspondingParameter: <testLibrary>::@class::A::@setter::x::@formalParameter::_x
2456+
correspondingParameter: <testLibrary>::@class::A::@setter::x::@formalParameter::value
24572457
staticType: int
24582458
readElement2: <null>
24592459
readType: null
@@ -4066,7 +4066,7 @@ AssignmentExpression
40664066
operator: =
40674067
rightHandSide: IntegerLiteral
40684068
literal: 2
4069-
correspondingParameter: <testLibrary>::@class::C::@setter::x::@formalParameter::_x
4069+
correspondingParameter: <testLibrary>::@class::C::@setter::x::@formalParameter::value
40704070
staticType: int
40714071
readElement2: <null>
40724072
readType: null
@@ -4099,7 +4099,7 @@ AssignmentExpression
40994099
operator: =
41004100
rightHandSide: IntegerLiteral
41014101
literal: 2
4102-
correspondingParameter: <testLibrary>::@class::C::@setter::x::@formalParameter::_x
4102+
correspondingParameter: <testLibrary>::@class::C::@setter::x::@formalParameter::value
41034103
staticType: int
41044104
readElement2: <null>
41054105
readType: null
@@ -4882,7 +4882,7 @@ AssignmentExpression
48824882
operator: =
48834883
rightHandSide: IntegerLiteral
48844884
literal: 2
4885-
correspondingParameter: <testLibrary>::@class::A::@setter::x::@formalParameter::_x
4885+
correspondingParameter: <testLibrary>::@class::A::@setter::x::@formalParameter::value
48864886
staticType: int
48874887
readElement2: <null>
48884888
readType: null
@@ -5176,7 +5176,7 @@ AssignmentExpression
51765176
operator: =
51775177
rightHandSide: IntegerLiteral
51785178
literal: 2
5179-
correspondingParameter: <testLibrary>::@setter::x::@formalParameter::_x
5179+
correspondingParameter: <testLibrary>::@setter::x::@formalParameter::value
51805180
staticType: int
51815181
readElement2: <null>
51825182
readType: null
@@ -5210,7 +5210,7 @@ AssignmentExpression
52105210
operator: =
52115211
rightHandSide: BooleanLiteral
52125212
literal: true
5213-
correspondingParameter: <testLibrary>::@setter::x::@formalParameter::_x
5213+
correspondingParameter: <testLibrary>::@setter::x::@formalParameter::value
52145214
staticType: bool
52155215
readElement2: <null>
52165216
readType: null

pkg/analyzer/test/src/dart/resolution/ast_rewrite_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ ConstructorReference
16421642
element: <testLibrary>::@class::C::@constructor::new
16431643
staticType: null
16441644
element: <testLibrary>::@class::C::@constructor::new
1645-
correspondingParameter: <testLibrary>::@setter::f::@formalParameter::_f
1645+
correspondingParameter: <testLibrary>::@setter::f::@formalParameter::value
16461646
staticType: C Function()
16471647
''');
16481648
}

pkg/analyzer/test/src/dart/resolution/function_reference_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4151,7 +4151,7 @@ FunctionReference
41514151
operator: =
41524152
rightHandSide: SimpleIdentifier
41534153
token: f
4154-
correspondingParameter: <testLibrary>::@setter::g::@formalParameter::_g
4154+
correspondingParameter: <testLibrary>::@setter::g::@formalParameter::value
41554155
element: <testLibrary>::@function::foo::@formalParameter::f
41564156
staticType: void Function<T>(T)
41574157
readElement2: <null>

pkg/analyzer/test/src/dart/resolution/prefixed_identifier_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ AssignmentExpression
198198
operator: =
199199
rightHandSide: IntegerLiteral
200200
literal: 1
201-
correspondingParameter: <testLibrary>::@class::A::@setter::foo::@formalParameter::_foo
201+
correspondingParameter: <testLibrary>::@class::A::@setter::foo::@formalParameter::value
202202
staticType: int
203203
readElement2: <null>
204204
readType: null

pkg/analyzer/test/src/dart/resolution/property_access_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ AssignmentExpression
669669
operator: =
670670
rightHandSide: IntegerLiteral
671671
literal: 1
672-
correspondingParameter: <testLibrary>::@class::A::@setter::foo::@formalParameter::_foo
672+
correspondingParameter: <testLibrary>::@class::A::@setter::foo::@formalParameter::value
673673
staticType: int
674674
readElement2: <null>
675675
readType: null
@@ -2533,7 +2533,7 @@ AssignmentExpression
25332533
operator: =
25342534
rightHandSide: IntegerLiteral
25352535
literal: 1
2536-
correspondingParameter: <testLibrary>::@class::A::@setter::foo::@formalParameter::_foo
2536+
correspondingParameter: <testLibrary>::@class::A::@setter::foo::@formalParameter::value
25372537
staticType: int
25382538
readElement2: <null>
25392539
readType: null

pkg/analyzer/test/src/diagnostics/private_setter_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ AssignmentExpression
5050
operator: =
5151
rightHandSide: IntegerLiteral
5252
literal: 0
53-
correspondingParameter: package:test/a.dart::@class::A::@setter::_foo::@formalParameter::__foo
53+
correspondingParameter: package:test/a.dart::@class::A::@setter::_foo::@formalParameter::value
5454
staticType: int
5555
readElement2: <null>
5656
readType: null

0 commit comments

Comments
 (0)