Skip to content

Commit a477b7e

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Remove V1 VariableElement.
Change-Id: Ib326d8d1e22954bfb8b567917357e4687e488c13 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423069 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 3c5193f commit a477b7e

File tree

7 files changed

+67
-82
lines changed

7 files changed

+67
-82
lines changed

pkg/analyzer/api.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,7 +2952,6 @@ package:analyzer/dart/constant/value.dart:
29522952
hasKnownValue (getter: bool)
29532953
isNull (getter: bool)
29542954
type (getter: DartType?)
2955-
variable (getter: VariableElement?, deprecated)
29562955
variable2 (getter: VariableElement2?)
29572956
getField (method: DartObject? Function(String))
29582957
toBoolValue (method: bool? Function())
@@ -3180,17 +3179,6 @@ package:analyzer/dart/element/element.dart:
31803179
uri (getter: String?)
31813180
uriEnd (getter: int)
31823181
uriOffset (getter: int)
3183-
VariableElement (class extends Object implements Element, ConstantEvaluationTarget, deprecated):
3184-
new (constructor: VariableElement Function())
3185-
declaration (getter: VariableElement)
3186-
hasImplicitType (getter: bool)
3187-
isConst (getter: bool)
3188-
isFinal (getter: bool)
3189-
isLate (getter: bool)
3190-
isStatic (getter: bool)
3191-
name (getter: String)
3192-
type (getter: DartType)
3193-
computeConstantValue (method: DartObject? Function())
31943182
_ExistingElement (class extends Object implements Element, deprecated):
31953183
new (constructor: _ExistingElement Function())
31963184
declaration (getter: Element, deprecated)

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
/// [element model](../element/element.dart).
1313
library;
1414

15-
import 'package:analyzer/dart/element/element.dart';
1615
import 'package:analyzer/dart/element/element2.dart';
1716
import 'package:analyzer/dart/element/type.dart';
1817
import 'package:meta/meta.dart';
@@ -68,10 +67,6 @@ abstract class DartObject {
6867
/// would return `false` from [hasKnownValue].
6968
DartType? get type;
7069

71-
/// If this object is the value of a constant variable, the variable.
72-
@Deprecated('Use variable2 instead')
73-
VariableElement? get variable;
74-
7570
/// If this object is the value of a constant variable, the variable.
7671
VariableElement2? get variable2;
7772

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

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import 'package:analyzer/dart/analysis/session.dart';
4242
import 'package:analyzer/dart/constant/value.dart';
4343
import 'package:analyzer/dart/element/element2.dart';
4444
import 'package:analyzer/dart/element/nullability_suffix.dart';
45-
import 'package:analyzer/dart/element/type.dart';
4645
import 'package:analyzer/dart/element/type_provider.dart';
4746
import 'package:analyzer/dart/element/type_system.dart';
4847
import 'package:analyzer/error/error.dart';
@@ -913,58 +912,6 @@ abstract class UriReferencedElement implements _ExistingElement {
913912
int get uriOffset;
914913
}
915914

916-
/// A variable. There are more specific subclasses for more specific kinds of
917-
/// variables.
918-
///
919-
/// Clients may not extend, implement or mix-in this class.
920-
@Deprecated('Use VariableElement2 instead')
921-
abstract class VariableElement implements Element, ConstantEvaluationTarget {
922-
@override
923-
VariableElement get declaration;
924-
925-
/// Whether the variable element did not have an explicit type specified
926-
/// for it.
927-
bool get hasImplicitType;
928-
929-
/// Whether the variable was declared with the 'const' modifier.
930-
bool get isConst;
931-
932-
/// Whether the variable was declared with the 'final' modifier.
933-
///
934-
/// Variables that are declared with the 'const' modifier will return `false`
935-
/// even though they are implicitly final.
936-
bool get isFinal;
937-
938-
/// Whether the variable uses late evaluation semantics.
939-
///
940-
/// This will always return `false` unless the experiment 'non-nullable' is
941-
/// enabled.
942-
bool get isLate;
943-
944-
/// Whether the element is a static variable, as per section 8 of the Dart
945-
/// Language Specification:
946-
///
947-
/// > A static variable is a variable that is not associated with a particular
948-
/// > instance, but rather with an entire library or class. Static variables
949-
/// > include library variables and class variables. Class variables are
950-
/// > variables whose declaration is immediately nested inside a class
951-
/// > declaration and includes the modifier static. A library variable is
952-
/// > implicitly static.
953-
bool get isStatic;
954-
955-
@override
956-
String get name;
957-
958-
/// The declared type of this variable.
959-
DartType get type;
960-
961-
/// Returns a representation of the value of this variable, forcing the value
962-
/// to be computed if it had not previously been computed, or `null` if either
963-
/// this variable was not declared with the 'const' modifier or if the value
964-
/// of this variable could not be computed because of errors.
965-
DartObject? computeConstantValue();
966-
}
967-
968915
/// This class exists to provide non-nullable overrides for existing elements,
969916
/// as opposite to artificial "multiply defined" element.
970917
@Deprecated('Use Element2 instead')

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class DartObjectImpl implements DartObject, Constant {
180180
/// The state of the object.
181181
final InstanceState state;
182182

183-
@override
183+
/// If this object is the value of a constant variable, the variable.
184184
final VariableElementImpl? variable;
185185

186186
/// Initialize a newly created object to have the given [type] and [state].

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

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3373,6 +3373,12 @@ abstract class ElementOrMember {
33733373
/// The kind of element that this is.
33743374
ElementKind get kind;
33753375

3376+
/// All of the metadata associated with this element.
3377+
///
3378+
/// The array will be empty if the element does not have any metadata or if
3379+
/// the library containing this element has not yet been resolved.
3380+
List<ElementAnnotation> get metadata;
3381+
33763382
/// The name of this element, or `null` if this element does not have a name.
33773383
String? get name;
33783384

@@ -5572,9 +5578,7 @@ abstract class InstanceElementImpl2 extends ElementImpl2
55725578
@override
55735579
List<FieldElementImpl2> get fields2 {
55745580
_readMembers();
5575-
return firstFragment.fields
5576-
.map((e) => e.asElement2 as FieldElementImpl2)
5577-
.toList();
5581+
return firstFragment.fields.map((e) => e.asElement2).toList();
55785582
}
55795583

55805584
@override
@@ -11051,15 +11055,51 @@ abstract class VariableElementImpl2 extends ElementImpl2
1105111055
/// Common base class for all analyzer-internal classes that implement
1105211056
/// `VariableElement`.
1105311057
abstract class VariableElementOrMember
11054-
implements
11055-
ElementOrMember,
11056-
// ignore:deprecated_member_use_from_same_package,analyzer_use_new_elements
11057-
VariableElement {
11058+
implements ElementOrMember, ConstantEvaluationTarget {
1105811059
@override
1105911060
VariableElementImpl get declaration;
1106011061

11062+
/// Whether the variable element did not have an explicit type specified
11063+
/// for it.
11064+
bool get hasImplicitType;
11065+
11066+
/// Whether the variable was declared with the 'const' modifier.
11067+
bool get isConst;
11068+
11069+
/// Whether the variable was declared with the 'final' modifier.
11070+
///
11071+
/// Variables that are declared with the 'const' modifier will return `false`
11072+
/// even though they are implicitly final.
11073+
bool get isFinal;
11074+
11075+
/// Whether the variable uses late evaluation semantics.
11076+
///
11077+
/// This will always return `false` unless the experiment 'non-nullable' is
11078+
/// enabled.
11079+
bool get isLate;
11080+
11081+
/// Whether the element is a static variable, as per section 8 of the Dart
11082+
/// Language Specification:
11083+
///
11084+
/// > A static variable is a variable that is not associated with a particular
11085+
/// > instance, but rather with an entire library or class. Static variables
11086+
/// > include library variables and class variables. Class variables are
11087+
/// > variables whose declaration is immediately nested inside a class
11088+
/// > declaration and includes the modifier static. A library variable is
11089+
/// > implicitly static.
11090+
bool get isStatic;
11091+
1106111092
@override
11093+
String get name;
11094+
11095+
/// The declared type of this variable.
1106211096
TypeImpl get type;
11097+
11098+
/// Returns a representation of the value of this variable, forcing the value
11099+
/// to be computed if it had not previously been computed, or `null` if either
11100+
/// this variable was not declared with the 'const' modifier or if the value
11101+
/// of this variable could not be computed because of errors.
11102+
DartObject? computeConstantValue();
1106311103
}
1106411104

1106511105
mixin WrappedElementMixin implements ElementImpl2 {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,7 @@ class GetterMember extends PropertyAccessorMember
702702
}
703703

704704
@override
705-
PropertyInducingElement2OrMember? get variable3 =>
706-
variable2.asElement2 as PropertyInducingElement2OrMember?;
705+
PropertyInducingElement2OrMember? get variable3 => variable2?.asElement2;
707706

708707
@override
709708
GetterElementImpl get _element2 {
@@ -1441,8 +1440,7 @@ class SetterMember extends PropertyAccessorMember
14411440
}
14421441

14431442
@override
1444-
PropertyInducingElement2OrMember? get variable3 =>
1445-
variable2.asElement2 as PropertyInducingElement2OrMember?;
1443+
PropertyInducingElement2OrMember? get variable3 => variable2?.asElement2;
14461444

14471445
@override
14481446
SetterElementImpl get _element2 {

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,12 @@ extension FieldElementImpl2Extension on FieldElementImpl2 {
351351
}
352352
}
353353

354+
extension FieldElementImplExtension on FieldElementImpl {
355+
FieldElementImpl2 get asElement2 {
356+
return element;
357+
}
358+
}
359+
354360
extension FieldElementOrMemberExtension on FieldElementOrMember {
355361
FieldElement2OrMember get asElement2 {
356362
return switch (this) {
@@ -592,6 +598,17 @@ extension PropertyInducingElementExtension on PropertyInducingElement2 {
592598
}
593599
}
594600

601+
extension PropertyInducingElementOrMemberExtension
602+
on PropertyInducingElementOrMember {
603+
PropertyInducingElement2OrMember get asElement2 {
604+
return switch (this) {
605+
PropertyInducingElementImpl(:var element) => element,
606+
FieldMember member => member,
607+
_ => throw UnsupportedError('Unsupported type: $runtimeType'),
608+
};
609+
}
610+
}
611+
595612
extension SetterElementImplExtension on SetterElementImpl {
596613
PropertyAccessorElementImpl get asElement {
597614
return lastFragment;

0 commit comments

Comments
 (0)