Skip to content

Commit e1be04c

Browse files
bwilkersonCommit Queue
authored andcommitted
Implement element and fragment for generic function types
Change-Id: I75fcdcb8d102cd7cd8a861d2bfb8a2c44f0fd692 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401341 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent a9c3991 commit e1be04c

File tree

1 file changed

+72
-8
lines changed

1 file changed

+72
-8
lines changed

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

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5148,7 +5148,10 @@ abstract class FunctionTypedElementImpl2 extends TypeParameterizedElementImpl2
51485148
/// Clients may not extend, implement or mix-in this class.
51495149
class GenericFunctionTypeElementImpl extends _ExistingElementImpl
51505150
with TypeParameterizedElementMixin
5151-
implements GenericFunctionTypeElement, FunctionTypedElementImpl {
5151+
implements
5152+
GenericFunctionTypeElement,
5153+
FunctionTypedElementImpl,
5154+
GenericFunctionTypeFragment {
51525155
/// The declared return type of the function.
51535156
DartType? _returnType;
51545157

@@ -5161,6 +5164,9 @@ class GenericFunctionTypeElementImpl extends _ExistingElementImpl
51615164
/// The type defined by this element.
51625165
FunctionType? _type;
51635166

5167+
late final GenericFunctionTypeElementImpl2 _element2 =
5168+
GenericFunctionTypeElementImpl2(this);
5169+
51645170
/// Initialize a newly created function element to have no name and the given
51655171
/// [nameOffset]. This is used for function expressions, that have no name.
51665172
GenericFunctionTypeElementImpl.forOffset(int nameOffset)
@@ -5180,12 +5186,15 @@ class GenericFunctionTypeElementImpl extends _ExistingElementImpl
51805186
}
51815187

51825188
@override
5183-
GenericFunctionTypeElement2 get element =>
5184-
throw UnsupportedError('This is not a fragment');
5189+
GenericFunctionTypeElement2 get element => _element2;
51855190

51865191
@override
51875192
LibraryFragment? get enclosingFragment =>
5188-
throw UnsupportedError('This is not a fragment');
5193+
enclosingElement3 as LibraryFragment;
5194+
5195+
@override
5196+
List<FormalParameterFragment> get formalParameters =>
5197+
parameters.cast<FormalParameterFragment>();
51895198

51905199
@override
51915200
String get identifier => '-';
@@ -5203,8 +5212,7 @@ class GenericFunctionTypeElementImpl extends _ExistingElementImpl
52035212
int? get nameOffset2 => null;
52045213

52055214
@override
5206-
GenericFunctionTypeFragment? get nextFragment =>
5207-
throw UnsupportedError('This is not a fragment');
5215+
GenericFunctionTypeFragment? get nextFragment => null;
52085216

52095217
@override
52105218
List<ParameterElement> get parameters {
@@ -5221,8 +5229,7 @@ class GenericFunctionTypeElementImpl extends _ExistingElementImpl
52215229
}
52225230

52235231
@override
5224-
GenericFunctionTypeFragment? get previousFragment =>
5225-
throw UnsupportedError('This is not a fragment');
5232+
GenericFunctionTypeFragment? get previousFragment => null;
52265233

52275234
@override
52285235
DartType get returnType {
@@ -5266,6 +5273,63 @@ class GenericFunctionTypeElementImpl extends _ExistingElementImpl
52665273
}
52675274
}
52685275

5276+
/// The element used for a generic function type.
5277+
///
5278+
/// Clients may not extend, implement or mix-in this class.
5279+
class GenericFunctionTypeElementImpl2 extends FunctionTypedElementImpl2
5280+
implements GenericFunctionTypeElement2 {
5281+
final GenericFunctionTypeElementImpl _wrappedElement;
5282+
5283+
GenericFunctionTypeElementImpl2(this._wrappedElement);
5284+
5285+
@override
5286+
String? get documentationComment => _wrappedElement.documentationComment;
5287+
5288+
@override
5289+
GenericFunctionTypeFragment get firstFragment => _wrappedElement;
5290+
5291+
@override
5292+
List<FormalParameterElement> get formalParameters =>
5293+
_wrappedElement.formalParameters
5294+
.map((fragment) => fragment.element)
5295+
.toList();
5296+
5297+
@override
5298+
bool get isSimplyBounded => _wrappedElement.isSimplyBounded;
5299+
5300+
@override
5301+
bool get isSynthetic => _wrappedElement.isSynthetic;
5302+
5303+
@override
5304+
ElementKind get kind => _wrappedElement.kind;
5305+
5306+
@override
5307+
LibraryElement2 get library2 => _wrappedElement.library2!;
5308+
5309+
@override
5310+
Metadata get metadata2 => _wrappedElement.metadata2;
5311+
5312+
@override
5313+
String? get name3 => _wrappedElement.name3;
5314+
5315+
@override
5316+
DartType get returnType => _wrappedElement.returnType;
5317+
5318+
@override
5319+
FunctionType get type => _wrappedElement.type;
5320+
5321+
@override
5322+
List<TypeParameterElement2> get typeParameters2 =>
5323+
_wrappedElement.typeParameters2
5324+
.map((fragment) => fragment.element)
5325+
.toList();
5326+
5327+
@override
5328+
T? accept2<T>(ElementVisitor2<T> visitor) {
5329+
return visitor.visitGenericFunctionTypeElement(this);
5330+
}
5331+
}
5332+
52695333
class GetterElementImpl extends PropertyAccessorElementImpl2
52705334
with
52715335
FragmentedExecutableElementMixin<GetterFragment>,

0 commit comments

Comments
 (0)