Skip to content

Commit 76606ca

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Restore InstanceElement.augmented
This API was removed in 7.4.0 under the assumption that its removal would not be a breaking change, because it was marked as `@experimental`. But it turns out that some clients had been published to pub that relied on it (for example `drift_dev`). To avoid breakages in those packages, the API has been restored (by pulling `AugmentedXyz` APIs from the published version `7.3.0`, and re-implementing on top of new `XyzElement2`). However the restored API is still slated for removal in analyzer 8.0.0, so it's been marked as `@deprecated`. Clients relying on this API should migrate away from it as soon as possible. Bug: #60545 Bug: #60553 Change-Id: If12c1fa37cafa63d0eef121a39350ce6d41ab68f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422846 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 6e88d87 commit 76606ca

File tree

6 files changed

+491
-3
lines changed

6 files changed

+491
-3
lines changed

pkg/analyzer/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 7.4.1
2+
* Restore `InstanceElement.augmented` getter.
3+
This API was removed in 7.4.0 under the assumption that its removal would
4+
not be a breaking change, because it was marked as `@experimental`.
5+
But it turns out that some clients had been published to pub that relied
6+
on it. So, these APIs were restored, and implemented on top of `Element2`.
7+
18
## 7.4.0
29
* Updated SDK constraint to `^3.5.0`.
310
* Deprecated element model V1.

pkg/analyzer/api.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3014,10 +3014,54 @@ package:analyzer/dart/constant/value.dart:
30143014
toSymbolValue (method: String? Function())
30153015
toTypeValue (method: DartType? Function())
30163016
package:analyzer/dart/element/element.dart:
3017+
AugmentedClassElement (class extends Object implements AugmentedInterfaceElement, deprecated):
3018+
new (constructor: AugmentedClassElement Function())
3019+
firstFragment (getter: ClassElement)
3020+
AugmentedEnumElement (class extends Object implements AugmentedInterfaceElement, deprecated):
3021+
new (constructor: AugmentedEnumElement Function())
3022+
constants (getter: List<FieldElement>)
3023+
firstFragment (getter: EnumElement)
3024+
AugmentedExtensionElement (class extends Object implements AugmentedInstanceElement, deprecated):
3025+
new (constructor: AugmentedExtensionElement Function())
3026+
extendedType (getter: DartType)
3027+
AugmentedExtensionTypeElement (class extends Object implements AugmentedInterfaceElement, deprecated):
3028+
new (constructor: AugmentedExtensionTypeElement Function())
3029+
firstFragment (getter: ExtensionTypeElement)
3030+
primaryConstructor (getter: ConstructorElement)
3031+
representation (getter: FieldElement)
3032+
typeErasure (getter: DartType)
3033+
AugmentedInstanceElement (class extends Object, deprecated):
3034+
new (constructor: AugmentedInstanceElement Function())
3035+
accessors (getter: List<PropertyAccessorElement>)
3036+
fields (getter: List<FieldElement>)
3037+
firstFragment (getter: InstanceElement)
3038+
metadata (getter: List<ElementAnnotation>)
3039+
methods (getter: List<MethodElement>)
3040+
thisType (getter: DartType)
3041+
getField (method: FieldElement? Function(String))
3042+
getGetter (method: PropertyAccessorElement? Function(String))
3043+
getMethod (method: MethodElement? Function(String))
3044+
getSetter (method: PropertyAccessorElement? Function(String))
3045+
lookUpGetter (method: PropertyAccessorElement? Function({required LibraryElement library, required String name}))
3046+
lookUpMethod (method: MethodElement? Function({required LibraryElement library, required String name}))
3047+
lookUpSetter (method: PropertyAccessorElement? Function({required LibraryElement library, required String name}))
3048+
AugmentedInterfaceElement (class extends Object implements AugmentedInstanceElement, deprecated):
3049+
new (constructor: AugmentedInterfaceElement Function())
3050+
constructors (getter: List<ConstructorElement>)
3051+
firstFragment (getter: InterfaceElement)
3052+
interfaces (getter: List<InterfaceType>)
3053+
mixins (getter: List<InterfaceType>)
3054+
thisType (getter: InterfaceType)
3055+
unnamedConstructor (getter: ConstructorElement?)
3056+
getNamedConstructor (method: ConstructorElement? Function(String))
3057+
AugmentedMixinElement (class extends AugmentedInterfaceElement, deprecated):
3058+
new (constructor: AugmentedMixinElement Function())
3059+
superclassConstraints (getter: List<InterfaceType>)
30173060
BindPatternVariableElement (class extends Object implements PatternVariableElement, deprecated):
30183061
new (constructor: BindPatternVariableElement Function())
30193062
ClassElement (class extends Object implements InterfaceElement, deprecated):
30203063
new (constructor: ClassElement Function())
3064+
augmented (getter: AugmentedClassElement, deprecated)
30213065
hasNonFinalField (getter: bool)
30223066
isAbstract (getter: bool)
30233067
isBase (getter: bool)
@@ -3268,6 +3312,7 @@ package:analyzer/dart/element/element.dart:
32683312
visitTypeParameterElement (method: R? Function(TypeParameterElement))
32693313
EnumElement (class extends Object implements InterfaceElement, deprecated):
32703314
new (constructor: EnumElement Function())
3315+
augmented (getter: AugmentedEnumElement, deprecated)
32713316
ExecutableElement (class extends Object implements FunctionTypedElement, deprecated):
32723317
new (constructor: ExecutableElement Function())
32733318
declaration (getter: ExecutableElement)
@@ -3286,13 +3331,15 @@ package:analyzer/dart/element/element.dart:
32863331
name (getter: String)
32873332
ExtensionElement (class extends Object implements InstanceElement, deprecated):
32883333
new (constructor: ExtensionElement Function())
3334+
augmented (getter: AugmentedExtensionElement, deprecated)
32893335
extendedType (getter: DartType)
32903336
getField (method: FieldElement? Function(String))
32913337
getGetter (method: PropertyAccessorElement? Function(String))
32923338
getMethod (method: MethodElement? Function(String))
32933339
getSetter (method: PropertyAccessorElement? Function(String))
32943340
ExtensionTypeElement (class extends Object implements InterfaceElement, deprecated):
32953341
new (constructor: ExtensionTypeElement Function())
3342+
augmented (getter: AugmentedExtensionTypeElement, deprecated)
32963343
primaryConstructor (getter: ConstructorElement, deprecated)
32973344
representation (getter: FieldElement)
32983345
typeErasure (getter: DartType)
@@ -3332,6 +3379,7 @@ package:analyzer/dart/element/element.dart:
33323379
InstanceElement (class extends Object implements TypeDefiningElement, TypeParameterizedElement, deprecated):
33333380
new (constructor: InstanceElement Function())
33343381
accessors (getter: List<PropertyAccessorElement>)
3382+
augmented (getter: AugmentedInstanceElement, deprecated)
33353383
enclosingElement3 (getter: CompilationUnitElement, deprecated)
33363384
fields (getter: List<FieldElement>)
33373385
isAugmentation (getter: bool)
@@ -3340,6 +3388,7 @@ package:analyzer/dart/element/element.dart:
33403388
InterfaceElement (class extends Object implements InstanceElement, deprecated):
33413389
new (constructor: InterfaceElement Function())
33423390
allSupertypes (getter: List<InterfaceType>)
3391+
augmented (getter: AugmentedInterfaceElement, deprecated)
33433392
constructors (getter: List<ConstructorElement>, deprecated)
33443393
interfaces (getter: List<InterfaceType>)
33453394
mixins (getter: List<InterfaceType>, deprecated)
@@ -3425,6 +3474,7 @@ package:analyzer/dart/element/element.dart:
34253474
declaration (getter: MethodElement)
34263475
MixinElement (class extends Object implements InterfaceElement, deprecated):
34273476
new (constructor: MixinElement Function())
3477+
augmented (getter: AugmentedMixinElement, deprecated)
34283478
isBase (getter: bool)
34293479
superclassConstraints (getter: List<InterfaceType>)
34303480
isImplementableIn (method: bool Function(LibraryElement))

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

Lines changed: 212 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,186 @@ import 'package:analyzer/src/task/api/model.dart' show AnalysisTarget;
6060
import 'package:meta/meta.dart';
6161
import 'package:pub_semver/pub_semver.dart';
6262

63+
/// The result of applying augmentations to a [ClassElement].
64+
///
65+
/// Clients may not extend, implement or mix-in this class.
66+
@Deprecated(elementModelDeprecationMsg)
67+
abstract class AugmentedClassElement implements AugmentedInterfaceElement {
68+
@override
69+
ClassElement get firstFragment;
70+
}
71+
72+
/// The result of applying augmentations to an [EnumElement].
73+
///
74+
/// Clients may not extend, implement or mix-in this class.
75+
@Deprecated(elementModelDeprecationMsg)
76+
abstract class AugmentedEnumElement implements AugmentedInterfaceElement {
77+
/// The enum constants declared in this element.
78+
List<FieldElement> get constants;
79+
80+
@override
81+
EnumElement get firstFragment;
82+
}
83+
84+
/// The result of applying augmentations to an [ExtensionElement].
85+
///
86+
/// Clients may not extend, implement or mix-in this class.
87+
@Deprecated(elementModelDeprecationMsg)
88+
abstract class AugmentedExtensionElement implements AugmentedInstanceElement {
89+
/// The type that is extended by this extension.
90+
DartType get extendedType;
91+
}
92+
93+
/// The result of applying augmentations to an [ExtensionTypeElement].
94+
///
95+
/// Clients may not extend, implement or mix-in this class.
96+
@Deprecated(elementModelDeprecationMsg)
97+
abstract class AugmentedExtensionTypeElement
98+
implements AugmentedInterfaceElement {
99+
@override
100+
ExtensionTypeElement get firstFragment;
101+
102+
/// The primary constructor of this extension.
103+
ConstructorElement get primaryConstructor;
104+
105+
/// The representation of this extension.
106+
FieldElement get representation;
107+
108+
/// The extension type erasure, obtained by recursively replacing every
109+
/// subterm which is an extension type by the corresponding representation
110+
/// type.
111+
DartType get typeErasure;
112+
}
113+
114+
/// The result of applying augmentations to a [InstanceElement].
115+
///
116+
/// Clients may not extend, implement or mix-in this class.
117+
@Deprecated(elementModelDeprecationMsg)
118+
abstract class AugmentedInstanceElement {
119+
/// The accessors (getters and setters) declared in this element.
120+
///
121+
/// [PropertyAccessorElement]s replace corresponding elements,
122+
/// other [PropertyAccessorElement]s are appended.
123+
List<PropertyAccessorElement> get accessors;
124+
125+
/// The fields declared in this element.
126+
///
127+
/// `FieldAugmentationElement`s replace corresponding elements, other
128+
/// [FieldElement]s are appended.
129+
List<FieldElement> get fields;
130+
131+
/// The declaration (not augmentation) that owns this result.
132+
InstanceElement get firstFragment;
133+
134+
/// The metadata associated with this element.
135+
///
136+
/// This is a union of annotations associated with the class declaration and
137+
/// all its augmentations.
138+
List<ElementAnnotation> get metadata;
139+
140+
/// The methods declared in this element.
141+
///
142+
/// `MethodAugmentationElement`s replace corresponding elements, other
143+
/// [MethodElement]s are appended.
144+
List<MethodElement> get methods;
145+
146+
/// The type of `this` expression.
147+
DartType get thisType;
148+
149+
/// Returns the field from [fields] that has the given [name].
150+
FieldElement? getField(String name);
151+
152+
/// Returns the getter from [accessors] that has the given [name].
153+
PropertyAccessorElement? getGetter(String name);
154+
155+
/// Returns the method from [methods] that has the given [name].
156+
MethodElement? getMethod(String name);
157+
158+
/// Returns the setter from [accessors] that has the given [name].
159+
PropertyAccessorElement? getSetter(String name);
160+
161+
/// Returns the element representing the getter that results from looking up
162+
/// the given [name] in this class with respect to the given [library],
163+
/// or `null` if the look up fails.
164+
///
165+
/// The behavior of this method is defined by the Dart Language Specification
166+
/// in section 17.18 Lookup.
167+
PropertyAccessorElement? lookUpGetter({
168+
required String name,
169+
required LibraryElement library,
170+
});
171+
172+
/// Returns the element representing the method that results from looking up
173+
/// the given [name] in this class with respect to the given [library],
174+
/// or `null` if the look up fails.
175+
///
176+
/// The behavior of this method is defined by the Dart Language Specification
177+
/// in section 17.18 Lookup.
178+
MethodElement? lookUpMethod({
179+
required String name,
180+
required LibraryElement library,
181+
});
182+
183+
/// Returns the element representing the setter that results from looking up
184+
/// the given [name] in this class with respect to the given [library],
185+
/// or `null` if the look up fails.
186+
///
187+
/// The behavior of this method is defined by the Dart Language Specification
188+
/// in section 17.18 Lookup.
189+
PropertyAccessorElement? lookUpSetter({
190+
required String name,
191+
required LibraryElement library,
192+
});
193+
}
194+
195+
/// The result of applying augmentations to a [InterfaceElement].
196+
///
197+
/// Clients may not extend, implement or mix-in this class.
198+
@Deprecated(elementModelDeprecationMsg)
199+
abstract class AugmentedInterfaceElement implements AugmentedInstanceElement {
200+
/// The constructors declared in this element.
201+
///
202+
/// `ConstructorAugmentationElement`s replace corresponding elements,
203+
/// other [ConstructorElement]s are appended.
204+
List<ConstructorElement> get constructors;
205+
206+
@override
207+
InterfaceElement get firstFragment;
208+
209+
/// The interfaces implemented by this element.
210+
///
211+
/// This is a union of interfaces declared by the class declaration and
212+
/// all its augmentations.
213+
List<InterfaceType> get interfaces;
214+
215+
/// The mixins applied by this class or in its augmentations.
216+
///
217+
/// This is a union of mixins applied by the class declaration and all its
218+
/// augmentations.
219+
List<InterfaceType> get mixins;
220+
221+
@override
222+
InterfaceType get thisType;
223+
224+
/// The unnamed constructor from [constructors].
225+
ConstructorElement? get unnamedConstructor;
226+
227+
/// Returns the constructor from [constructors] that has the given [name].
228+
ConstructorElement? getNamedConstructor(String name);
229+
}
230+
231+
/// The result of applying augmentations to a [MixinElement].
232+
///
233+
/// Clients may not extend, implement or mix-in this class.
234+
@Deprecated(elementModelDeprecationMsg)
235+
abstract class AugmentedMixinElement extends AugmentedInterfaceElement {
236+
/// The superclass constraints of this element.
237+
///
238+
/// This is a union of constraints declared by the class declaration and
239+
/// all its augmentations.
240+
List<InterfaceType> get superclassConstraints;
241+
}
242+
63243
/// A pattern variable that is explicitly declared.
64244
///
65245
/// Clients may not extend, implement or mix-in this class.
@@ -74,6 +254,10 @@ abstract class BindPatternVariableElement implements PatternVariableElement {}
74254
/// Clients may not extend, implement or mix-in this class.
75255
@Deprecated('Use ClassElement2 instead')
76256
abstract class ClassElement implements InterfaceElement {
257+
@Deprecated(elementModelDeprecationMsg)
258+
@override
259+
AugmentedClassElement get augmented;
260+
77261
/// Whether the class or its superclass declares a non-final instance field.
78262
bool get hasNonFinalField;
79263

@@ -1079,7 +1263,11 @@ abstract class ElementVisitor<R> {
10791263
///
10801264
/// Clients may not extend, implement or mix-in this class.
10811265
@Deprecated('Use EnumElement2 instead')
1082-
abstract class EnumElement implements InterfaceElement {}
1266+
abstract class EnumElement implements InterfaceElement {
1267+
@Deprecated(elementModelDeprecationMsg)
1268+
@override
1269+
AugmentedEnumElement get augmented;
1270+
}
10831271

10841272
/// An element representing an executable object, including functions, methods,
10851273
/// constructors, getters, and setters.
@@ -1150,6 +1338,10 @@ abstract class ExecutableElement implements FunctionTypedElement {
11501338
/// Clients may not extend, implement or mix-in this class.
11511339
@Deprecated('Use ExtensionElement2 instead')
11521340
abstract class ExtensionElement implements InstanceElement {
1341+
@Deprecated(elementModelDeprecationMsg)
1342+
@override
1343+
AugmentedExtensionElement get augmented;
1344+
11531345
/// The type that is extended by this extension.
11541346
DartType get extendedType;
11551347

@@ -1179,6 +1371,10 @@ abstract class ExtensionElement implements InstanceElement {
11791371
/// Clients may not extend, implement or mix-in this class.
11801372
@Deprecated('Use ExtensionTypeElement2 instead')
11811373
abstract class ExtensionTypeElement implements InterfaceElement {
1374+
@Deprecated(elementModelDeprecationMsg)
1375+
@override
1376+
AugmentedExtensionTypeElement get augmented;
1377+
11821378
/// The primary constructor of this extension.
11831379
@Deprecated(elementModelDeprecationMsg)
11841380
ConstructorElement get primaryConstructor;
@@ -1320,6 +1516,13 @@ abstract class InstanceElement
13201516
/// The declared accessors (getters and setters).
13211517
List<PropertyAccessorElement> get accessors;
13221518

1519+
/// The result of merging augmentations.
1520+
///
1521+
/// It includes the members of the base element and its augmentations as
1522+
/// specified by the merge operations.
1523+
@Deprecated(elementModelDeprecationMsg)
1524+
AugmentedInstanceElement get augmented;
1525+
13231526
@Deprecated(elementModelDeprecationMsg)
13241527
@override
13251528
CompilationUnitElement get enclosingElement3;
@@ -1351,6 +1554,10 @@ abstract class InterfaceElement implements InstanceElement {
13511554
/// This includes superclasses, mixins, interfaces, and superclass constraints.
13521555
List<InterfaceType> get allSupertypes;
13531556

1557+
@Deprecated(elementModelDeprecationMsg)
1558+
@override
1559+
AugmentedInterfaceElement get augmented;
1560+
13541561
/// The declared constructors.
13551562
///
13561563
/// The list is empty for [MixinElement].
@@ -1838,6 +2045,10 @@ abstract class MethodElement implements ClassMemberElement, ExecutableElement {
18382045
/// Clients may not extend, implement or mix-in this class.
18392046
@Deprecated('Use MixinElement2 instead')
18402047
abstract class MixinElement implements InterfaceElement {
2048+
@Deprecated(elementModelDeprecationMsg)
2049+
@override
2050+
AugmentedMixinElement get augmented;
2051+
18412052
/// Whether the mixin is a base mixin.
18422053
///
18432054
/// A mixin is a base mixin if it has an explicit `base` modifier.

0 commit comments

Comments
 (0)