Skip to content

Commit 3cf0093

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer] Stop implementing some shared types in public API.
The following adjustements are made to the analyzer class hierarchy: - `SharedNamedFunctionParameterStructure` is moved from the `implements` clause of `ParameterElement` to the implements clause of `ParameterElementMixin`, a mixin that is used by all concrete subtypes of `ParameterElement`, but which is not part of the analyzer's public API. - `SharedNamedTypeStructure` is moved from the `implements` clause of `RecordTypeNamedField` to the implements clause of `RecordTypeNamedFieldImpl`, the sole concrete subtype of `RecordTypeNamedField`, which is not part of the analyzer's public API. To account for these changes, the analyzer's use of the shared types `FunctionTypeImpl`, `TypeConstraintGenerator`, and `TypeConstraintGeneratorMixin` needed to be adjusted so `ParameterElementMixin` is supplied as a type parameter instead of `ParameterElement`. This required adding a cast to the `FunctionTypeImpl` constructor, which I intend to remove in a future CL. This is part of a larger arc of work to change the analyzer's use of the shared code so that the type parameters it supplies are not part of the analyzer public API. See #59763. Change-Id: I889b9f87d7d077d10935c4506c454507a480afcd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402380 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 70c0a2e commit 3cf0093

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2142,10 +2142,7 @@ sealed class NamespaceCombinator {}
21422142
///
21432143
/// Clients may not extend, implement or mix-in this class.
21442144
abstract class ParameterElement
2145-
implements
2146-
PromotableElement,
2147-
ConstantEvaluationTarget,
2148-
SharedNamedFunctionParameterStructure<DartType> {
2145+
implements PromotableElement, ConstantEvaluationTarget {
21492146
@override
21502147
ParameterElement get declaration;
21512148

@@ -2202,7 +2199,6 @@ abstract class ParameterElement
22022199
/// change the meaning of this getter. The parameter `{@required int x}`
22032200
/// will return `false` and the parameter `{@required required int x}`
22042201
/// will return `true`.
2205-
@override
22062202
bool get isRequired;
22072203

22082204
/// Whether the parameter is both a required and named parameter.

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,8 @@ abstract class RecordTypeField {
604604
/// A named field in a [RecordType].
605605
///
606606
/// Clients may not extend, implement or mix-in this class.
607-
abstract class RecordTypeNamedField
608-
implements RecordTypeField, SharedNamedTypeStructure<DartType> {
607+
abstract class RecordTypeNamedField implements RecordTypeField {
609608
/// The name of the field.
610-
@override
611609
String get name;
612610
}
613611

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:_fe_analyzer_shared/src/type_inference/type_analyzer.dart'
1010
as shared;
1111
import 'package:_fe_analyzer_shared/src/type_inference/type_analyzer_operations.dart'
1212
as shared;
13+
import 'package:_fe_analyzer_shared/src/types/shared_type.dart';
1314
import 'package:analyzer/dart/analysis/features.dart';
1415
import 'package:analyzer/dart/analysis/session.dart';
1516
import 'package:analyzer/dart/ast/token.dart';
@@ -9188,7 +9189,10 @@ class ParameterElementImpl_ofImplicitSetter extends ParameterElementImpl {
91889189

91899190
/// A mixin that provides a common implementation for methods defined in
91909191
/// [ParameterElement].
9191-
mixin ParameterElementMixin implements ParameterElement {
9192+
mixin ParameterElementMixin
9193+
implements
9194+
ParameterElement,
9195+
SharedNamedFunctionParameterStructure<DartType> {
91929196
@override
91939197
bool get isNamed => parameterKind.isNamed;
91949198

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class FunctionTypeImpl extends TypeImpl
9090
implements
9191
FunctionType,
9292
SharedFunctionTypeStructure<DartType, TypeParameterElement,
93-
ParameterElement> {
93+
ParameterElementMixin> {
9494
@override
9595
late int hashCode = _computeHashCode();
9696

@@ -113,7 +113,7 @@ class FunctionTypeImpl extends TypeImpl
113113
final int requiredPositionalParameterCount;
114114

115115
@override
116-
final List<ParameterElement> sortedNamedParameters;
116+
final List<ParameterElementMixin> sortedNamedParameters;
117117

118118
factory FunctionTypeImpl({
119119
required List<TypeParameterElement> typeFormals,
@@ -166,7 +166,9 @@ class FunctionTypeImpl extends TypeImpl
166166
nullabilitySuffix: nullabilitySuffix,
167167
positionalParameterTypes: positionalParameterTypes,
168168
requiredPositionalParameterCount: requiredPositionalParameterCount,
169-
sortedNamedParameters: sortedNamedParameters,
169+
// TODO(paulberry): avoid the cast by changing the type of
170+
// `sortedNamedParameters`.
171+
sortedNamedParameters: sortedNamedParameters.cast(),
170172
alias: alias);
171173
}
172174

@@ -1453,7 +1455,7 @@ class RecordTypeImpl extends TypeImpl implements RecordType {
14531455
}
14541456

14551457
class RecordTypeNamedFieldImpl extends RecordTypeFieldImpl
1456-
implements RecordTypeNamedField {
1458+
implements RecordTypeNamedField, SharedNamedTypeStructure<DartType> {
14571459
@override
14581460
final String name;
14591461

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ typedef UnknownTypeConstraintOrigin = shared.UnknownTypeConstraintOrigin<
9595
/// attempt to make one type schema a subtype of another.
9696
class TypeConstraintGatherer extends shared.TypeConstraintGenerator<
9797
DartType,
98-
ParameterElement,
98+
ParameterElementMixin,
9999
PromotableElementImpl2,
100100
TypeParameterElement,
101101
InterfaceType,
@@ -104,7 +104,7 @@ class TypeConstraintGatherer extends shared.TypeConstraintGenerator<
104104
with
105105
shared.TypeConstraintGeneratorMixin<
106106
DartType,
107-
ParameterElement,
107+
ParameterElementMixin,
108108
PromotableElementImpl2,
109109
TypeParameterElement,
110110
InterfaceType,

0 commit comments

Comments
 (0)