Skip to content

Commit 77986bd

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate TypeParameterTypeImpl.
Change-Id: Ib2130458b45a7bd49d2521190894790a7afad294 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415681 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent c892080 commit 77986bd

19 files changed

+81
-90
lines changed

pkg/analyzer/api.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4397,7 +4397,7 @@ package:analyzer/dart/element/type.dart:
43974397
TypeParameterType (class extends Object implements DartType):
43984398
new (constructor: TypeParameterType Function())
43994399
bound (getter: DartType)
4400-
definition (getter: ElementLocation)
4400+
definition (getter: ElementLocation, deprecated)
44014401
element (getter: TypeParameterElement, deprecated)
44024402
element3 (getter: TypeParameterElement2, experimental)
44034403
VoidType (class extends Object implements DartType):

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ abstract class TypeParameterType implements DartType {
685685
/// Depending on the use, [bound] may also need to be taken into account.
686686
/// A given type parameter, it may have different bounds in different scopes.
687687
/// Always consult the bound if that could be relevant.
688+
@Deprecated('Elements are equal when they are identical')
688689
ElementLocation get definition;
689690

690691
@Deprecated('Use element3 instead')

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,14 +392,14 @@ class ElementDisplayStringBuilder {
392392
if (hasSuffix) {
393393
_write('(');
394394
}
395-
_write(type.element.displayName);
395+
_write(type.element3.displayName);
396396
_write(' & ');
397397
_writeType(promotedBound);
398398
if (hasSuffix) {
399399
_write(')');
400400
}
401401
} else {
402-
_write(type.element.displayName);
402+
_write(type.element3.displayName);
403403
}
404404
_writeNullability(type.nullabilitySuffix);
405405
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11369,7 +11369,7 @@ class TypeAliasElementImpl2 extends TypeDefiningElementImpl2
1136911369
);
1137011370
} else if (type is TypeParameterTypeImpl) {
1137111371
return TypeParameterTypeImpl(
11372-
element: type.element,
11372+
element3: type.element3,
1137311373
nullabilitySuffix: resultNullability,
1137411374
alias: InstantiatedTypeAliasElementImpl(
1137511375
element2: this,
@@ -11531,7 +11531,7 @@ class TypeParameterElementImpl extends ElementImpl
1153111531
/// Computes the variance of the type parameters in the [type].
1153211532
shared.Variance computeVarianceInType(DartType type) {
1153311533
if (type is TypeParameterTypeImpl) {
11534-
if (type.element == this) {
11534+
if (type.element3 == element) {
1153511535
return shared.Variance.covariant;
1153611536
} else {
1153711537
return shared.Variance.unrelated;
@@ -11577,8 +11577,7 @@ class TypeParameterElementImpl extends ElementImpl
1157711577
TypeParameterTypeImpl instantiate({
1157811578
required NullabilitySuffix nullabilitySuffix,
1157911579
}) {
11580-
return TypeParameterTypeImpl(
11581-
element: this,
11580+
return element.instantiate(
1158211581
nullabilitySuffix: nullabilitySuffix,
1158311582
);
1158411583
}
@@ -11666,8 +11665,8 @@ class TypeParameterElementImpl2 extends TypeDefiningElementImpl2
1166611665
TypeParameterTypeImpl instantiate({
1166711666
required NullabilitySuffix nullabilitySuffix,
1166811667
}) {
11669-
return TypeParameterTypeImpl.v2(
11670-
element: this,
11668+
return TypeParameterTypeImpl(
11669+
element3: this,
1167111670
nullabilitySuffix: nullabilitySuffix,
1167211671
);
1167311672
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ class NormalizeHelper {
274274
}
275275

276276
// * else X & S
277-
return TypeParameterTypeImpl.v2(
278-
element: X,
277+
return TypeParameterTypeImpl(
278+
element3: X,
279279
nullabilitySuffix: NullabilitySuffix.none,
280280
promotedBound: S,
281281
);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ class ReplacementVisitor
133133
}
134134

135135
var promotedBound = (type as TypeParameterTypeImpl).promotedBound;
136-
return TypeParameterTypeImpl.v2(
137-
element: type.element3,
136+
return TypeParameterTypeImpl(
137+
element3: type.element3,
138138
nullabilitySuffix: newNullability ?? type.nullabilitySuffix,
139139
promotedBound: newPromotedBound ?? promotedBound,
140140
alias: type.alias,
@@ -149,8 +149,8 @@ class ReplacementVisitor
149149
return null;
150150
}
151151

152-
return TypeParameterTypeImpl.v2(
153-
element: type.element3,
152+
return TypeParameterTypeImpl(
153+
element3: type.element3,
154154
nullabilitySuffix: newNullability,
155155
alias: type.alias,
156156
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ class SubtypeHelper {
182182
if (T1 is TypeParameterTypeImpl) {
183183
var T1_promotedBound = T1.promotedBound;
184184
if (T1_promotedBound != null) {
185-
var X1 = TypeParameterTypeImpl.v2(
186-
element: T1.element3,
185+
var X1 = TypeParameterTypeImpl(
186+
element3: T1.element3,
187187
nullabilitySuffix: T1.nullabilitySuffix,
188188
);
189189
return isSubtypeOf(T0, X1) && isSubtypeOf(T0, T1_promotedBound);

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

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ class FunctionTypeImpl extends TypeImpl
316316
);
317317
}
318318

319+
@Deprecated('Use referencesAny2() instead')
319320
@override
320321
bool referencesAny(Set<TypeParameterElementImpl> parameters) {
321322
if (typeFormals.any((element) {
@@ -396,8 +397,9 @@ class FunctionTypeImpl extends TypeImpl
396397
return instantiate([
397398
for (var i = 0; i < typeFormals.length; i++)
398399
TypeParameterTypeImpl(
399-
element: TypeParameterElementImpl.synthetic('T$i'),
400-
nullabilitySuffix: NullabilitySuffix.none)
400+
element3: TypeParameterElementImpl.synthetic('T$i').element,
401+
nullabilitySuffix: NullabilitySuffix.none,
402+
)
401403
]).hashCode;
402404
}
403405

@@ -1138,6 +1140,7 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
11381140
return null;
11391141
}
11401142

1143+
@Deprecated('Use referencesAny2() instead')
11411144
@override
11421145
bool referencesAny(Set<TypeParameterElementImpl> parameters) {
11431146
return typeArguments.any((argument) => argument.referencesAny(parameters));
@@ -1629,6 +1632,7 @@ abstract class TypeImpl implements DartType, SharedType {
16291632
bool isStructurallyEqualTo(Object other) => this == other;
16301633

16311634
/// Returns true if this type references any of the [parameters].
1635+
@Deprecated('Use referencesAny2() instead')
16321636
bool referencesAny(Set<TypeParameterElementImpl> parameters) {
16331637
return false;
16341638
}
@@ -1672,60 +1676,42 @@ abstract class TypeImpl implements DartType, SharedType {
16721676
/// A concrete implementation of a [TypeParameterType].
16731677
class TypeParameterTypeImpl extends TypeImpl implements TypeParameterType {
16741678
@override
1675-
final TypeParameterElementImpl element;
1679+
final TypeParameterElementImpl2 element3;
16761680

16771681
@override
16781682
final NullabilitySuffix nullabilitySuffix;
16791683

16801684
/// An optional promoted bound on the type parameter.
16811685
///
16821686
/// 'null' indicates that the type parameter's bound has not been promoted and
1683-
/// is therefore the same as the bound of [element].
1687+
/// is therefore the same as the bound of [element3].
16841688
final TypeImpl? promotedBound;
16851689

16861690
/// Initialize a newly created type parameter type to be declared by the given
1687-
/// [element] and to have the given name.
1691+
/// [element3] and to have the given name.
16881692
TypeParameterTypeImpl({
1689-
required TypeParameterElement element,
1693+
required this.element3,
16901694
required this.nullabilitySuffix,
16911695
DartType? promotedBound,
16921696
super.alias,
1693-
}) :
1694-
// TODO(paulberry): change the type of the parameter `element` so
1695-
// that this cast isn't needed.
1696-
element = element as TypeParameterElementImpl,
1697-
// TODO(paulberry): change the type of the parameter `promotedBound` so
1697+
}) : // TODO(paulberry): change the type of the parameter `promotedBound` so
16981698
// that this cast isn't needed.
16991699
promotedBound = promotedBound as TypeImpl?;
17001700

1701-
/// Initialize a newly created type parameter type to be declared by the given
1702-
/// [element] and to have the given name.
1703-
factory TypeParameterTypeImpl.v2({
1704-
required TypeParameterElement2 element,
1705-
required NullabilitySuffix nullabilitySuffix,
1706-
DartType? promotedBound,
1707-
InstantiatedTypeAliasElementImpl? alias,
1708-
}) {
1709-
return TypeParameterTypeImpl(
1710-
element: element.asElement,
1711-
nullabilitySuffix: nullabilitySuffix,
1712-
promotedBound: promotedBound,
1713-
alias: alias,
1714-
);
1715-
}
1716-
17171701
@override
17181702
TypeImpl get bound =>
1719-
promotedBound ?? element.bound ?? DynamicTypeImpl.instance;
1703+
promotedBound ?? element3.bound ?? DynamicTypeImpl.instance;
17201704

1705+
@Deprecated('Elements are equal when they are identical')
17211706
@override
17221707
ElementLocation get definition => element.location;
17231708

1709+
@Deprecated('Use element3 instead')
17241710
@override
1725-
TypeParameterElementImpl2 get element3 => element.element;
1711+
TypeParameterElementImpl get element => element3.asElement;
17261712

17271713
@override
1728-
int get hashCode => element.hashCode;
1714+
int get hashCode => element3.hashCode;
17291715

17301716
@override
17311717
bool get isBottom {
@@ -1755,7 +1741,7 @@ class TypeParameterTypeImpl extends TypeImpl implements TypeParameterType {
17551741

17561742
TypeParameterTypeImpl get withoutPromotedBound {
17571743
return TypeParameterTypeImpl(
1758-
element: element,
1744+
element3: element3,
17591745
nullabilitySuffix: nullabilitySuffix,
17601746
);
17611747
}
@@ -1766,7 +1752,7 @@ class TypeParameterTypeImpl extends TypeImpl implements TypeParameterType {
17661752
return true;
17671753
}
17681754

1769-
if (other is TypeParameterTypeImpl && other.element == element) {
1755+
if (other is TypeParameterTypeImpl && other.element3 == element3) {
17701756
if (other.nullabilitySuffix != nullabilitySuffix) {
17711757
return false;
17721758
}
@@ -1804,6 +1790,7 @@ class TypeParameterTypeImpl extends TypeImpl implements TypeParameterType {
18041790
return bound.asInstanceOf2(targetElement);
18051791
}
18061792

1793+
@Deprecated('Use referencesAny2() instead')
18071794
@override
18081795
bool referencesAny(Set<TypeParameterElement> parameters) {
18091796
return parameters.contains(element);
@@ -1818,7 +1805,7 @@ class TypeParameterTypeImpl extends TypeImpl implements TypeParameterType {
18181805
TypeImpl withNullability(NullabilitySuffix nullabilitySuffix) {
18191806
if (this.nullabilitySuffix == nullabilitySuffix) return this;
18201807
return TypeParameterTypeImpl(
1821-
element: element,
1808+
element3: element3,
18221809
nullabilitySuffix: nullabilitySuffix,
18231810
promotedBound: promotedBound,
18241811
);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ FreshTypeParameters getFreshTypeParameters2(
3232

3333
var map = <TypeParameterElement2, DartType>{};
3434
for (int i = 0; i < typeParameters.length; ++i) {
35-
map[typeParameters[i]] = TypeParameterTypeImpl.v2(
36-
element: freshParameters[i],
35+
map[typeParameters[i]] = TypeParameterTypeImpl(
36+
element3: freshParameters[i],
3737
nullabilitySuffix: NullabilitySuffix.none,
3838
);
3939
}
@@ -307,8 +307,8 @@ class _NullSubstitution extends MapSubstitution {
307307

308308
@override
309309
DartType getSubstitute(TypeParameterElement2 parameter, bool upperBound) {
310-
return TypeParameterTypeImpl.v2(
311-
element: parameter,
310+
return TypeParameterTypeImpl(
311+
element3: parameter as TypeParameterElementImpl2,
312312
nullabilitySuffix: NullabilitySuffix.none,
313313
);
314314
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class DemotionVisitor extends ReplacementVisitor {
2020
return null;
2121
}
2222

23-
return TypeParameterTypeImpl.v2(
24-
element: type.element3,
23+
return TypeParameterTypeImpl(
24+
element3: type.element3,
2525
nullabilitySuffix: type.nullabilitySuffix,
2626
alias: type.alias,
2727
);

0 commit comments

Comments
 (0)