Skip to content

Commit 44a1ebf

Browse files
fshcheglovCommit Queue
authored andcommitted
Deprecate getters from constant
Change-Id: Ib226fd68f80f0b186c914a80a7b45e4071fa9c24 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441991 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 7988665 commit 44a1ebf

File tree

7 files changed

+38
-10
lines changed

7 files changed

+38
-10
lines changed

pkg/analyzer/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* Deprecate `AnalysisSession.getParsedLibraryByElement2`, use `getParsedLibraryByElement` instead.
88
* Deprecate `AnalysisSession.getResolvedLibraryByElement2`, use `getResolvedLibraryByElement` instead.
99
* Deprecate `resolveFile2`, use `resolveFile` instead.
10+
* Deprecate `DartObject.variable2`, use `variable` instead.
11+
* Deprecate `DartObject.toFunctionValue2`, use `toFunctionValue` instead.
1012

1113
## 8.0.0
1214
* Remove deprecated element model V1.

pkg/analyzer/api.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3259,11 +3259,13 @@ package:analyzer/dart/constant/value.dart:
32593259
hasKnownValue (getter: bool)
32603260
isNull (getter: bool)
32613261
type (getter: DartType?)
3262-
variable2 (getter: VariableElement?)
3262+
variable (getter: VariableElement?)
3263+
variable2 (getter: VariableElement?, deprecated)
32633264
getField (method: DartObject? Function(String))
32643265
toBoolValue (method: bool? Function())
32653266
toDoubleValue (method: double? Function())
3266-
toFunctionValue2 (method: ExecutableElement? Function(), experimental)
3267+
toFunctionValue (method: ExecutableElement? Function(), experimental)
3268+
toFunctionValue2 (method: ExecutableElement? Function(), deprecated, experimental)
32673269
toIntValue (method: int? Function())
32683270
toListValue (method: List<DartObject>? Function())
32693271
toMapValue (method: Map<DartObject?, DartObject?>? Function())

pkg/analyzer/lib/dart/constant/value.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ abstract class DartObject {
8888
DartType? get type;
8989

9090
/// If this object is the value of a constant variable, the variable.
91+
VariableElement? get variable;
92+
93+
/// If this object is the value of a constant variable, the variable.
94+
@Deprecated('Use variable instead')
9195
VariableElement? get variable2;
9296

9397
/// Return a representation of the value of the field with the given [name].
@@ -122,6 +126,16 @@ abstract class DartObject {
122126
/// * the value of the object being represented is not known, or
123127
/// * the value of the object being represented is `null`.
124128
@experimental
129+
ExecutableElement? toFunctionValue();
130+
131+
/// Return an element corresponding to the value of the object being
132+
/// represented, or `null`
133+
/// if
134+
/// * this object is not of a function type,
135+
/// * the value of the object being represented is not known, or
136+
/// * the value of the object being represented is `null`.
137+
@Deprecated('Use toFunctionValue instead')
138+
@experimental
125139
ExecutableElement? toFunctionValue2();
126140

127141
/// Return an integer corresponding to the value of the object being

pkg/analyzer/lib/src/dart/constant/evaluation.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,7 +2138,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
21382138
FunctionReferenceImpl node,
21392139
DartObjectImpl value,
21402140
) {
2141-
var functionElement = value.toFunctionValue2();
2141+
var functionElement = value.toFunctionValue();
21422142
if (functionElement is! ExecutableElement2OrMember) {
21432143
return value;
21442144
}
@@ -2173,7 +2173,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
21732173
) {
21742174
// TODO(srawlins): When all code uses [FunctionReference]s generated via
21752175
// generic function instantiation, remove this method and all call sites.
2176-
var functionElement = value.toFunctionValue2();
2176+
var functionElement = value.toFunctionValue();
21772177
if (functionElement is! ExecutableElement2OrMember) {
21782178
return value;
21792179
}

pkg/analyzer/lib/src/dart/constant/value.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class DartObjectImpl implements DartObject, Constant {
173173
final InstanceState state;
174174

175175
@override
176-
final VariableElementImpl? variable2;
176+
final VariableElementImpl? variable;
177177

178178
/// Initialize a newly created object to have the given [type] and [state].
179179
factory DartObjectImpl(
@@ -183,7 +183,7 @@ class DartObjectImpl implements DartObject, Constant {
183183
VariableElementImpl? variable,
184184
}) {
185185
type = type.extensionTypeErasure;
186-
return DartObjectImpl._(typeSystem, type, state, variable2: variable);
186+
return DartObjectImpl._(typeSystem, type, state, variable: variable);
187187
}
188188

189189
/// Creates a duplicate instance of [other], tied to [variable].
@@ -238,7 +238,7 @@ class DartObjectImpl implements DartObject, Constant {
238238
}
239239

240240
/// Initialize a newly created object to have the given [type] and [state].
241-
DartObjectImpl._(this._typeSystem, this.type, this.state, {this.variable2}) {
241+
DartObjectImpl._(this._typeSystem, this.type, this.state, {this.variable}) {
242242
if (state case GenericState state) {
243243
state._object = this;
244244
}
@@ -284,6 +284,10 @@ class DartObjectImpl implements DartObject, Constant {
284284
@visibleForTesting
285285
List<DartType>? get typeArguments => (state as FunctionState).typeArguments;
286286

287+
@override
288+
@Deprecated('Use variable instead')
289+
VariableElement? get variable2 => variable;
290+
287291
@override
288292
bool operator ==(Object other) {
289293
if (other is DartObjectImpl) {
@@ -940,11 +944,17 @@ class DartObjectImpl implements DartObject, Constant {
940944
}
941945

942946
@override
943-
ExecutableElement2OrMember? toFunctionValue2() {
947+
ExecutableElement2OrMember? toFunctionValue() {
944948
var state = this.state;
945949
return state is FunctionState ? state.element : null;
946950
}
947951

952+
@override
953+
@Deprecated('Use toFunctionValue instead')
954+
ExecutableElement? toFunctionValue2() {
955+
return toFunctionValue();
956+
}
957+
948958
@override
949959
int? toIntValue() {
950960
var state = this.state;

pkg/analyzer/test/id_tests/constant_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class ConstantsDataExtractor extends AstDataExtractor<String> {
135135
}
136136
// TODO(paulberry): Support object constants.
137137
} else if (type is FunctionType) {
138-
var element = value.toFunctionValue2()!;
138+
var element = value.toFunctionValue()!;
139139
return 'Function(${element.name},type=${_stringifyType(value.type!)})';
140140
}
141141
throw UnimplementedError('_stringify for type $type');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class DartObjectPrinter {
249249
}
250250

251251
void _writeVariable(DartObjectImpl object) {
252-
var variable = object.variable2;
252+
var variable = object.variable;
253253
if (variable != null) {
254254
_sink.withIndent(() {
255255
_elementPrinter.writeNamedElement2('variable', variable);

0 commit comments

Comments
 (0)