@@ -40,54 +40,14 @@ abstract class ElementType extends Privacy
40
40
41
41
factory ElementType ._from (
42
42
DartType f, Library library, PackageGraph packageGraph) {
43
- if (f is RecordType ) {
44
- return RecordElementType (f, library, packageGraph);
45
- }
46
43
var fElement = DartTypeExtension (f).element;
47
44
if (fElement == null ||
48
45
fElement.kind == ElementKind .DYNAMIC ||
49
46
fElement.kind == ElementKind .NEVER ) {
50
- // [UndefinedElementType]s.
51
- if (f is FunctionType ) {
52
- if (f.alias? .element != null ) {
53
- return AliasedFunctionTypeElementType (f, library, packageGraph);
54
- }
55
- return FunctionTypeElementType (f, library, packageGraph);
56
- }
57
- return UndefinedElementType (f, library, packageGraph);
58
- }
59
- // [DefinedElementType]s.
60
- var element = packageGraph.modelBuilder.fromElement (fElement);
61
- // `TypeAliasElement.alias.element` has different implications.
62
- // In that case it is an actual type alias of some kind (generic or
63
- // otherwise). Here however `alias.element` signals that this is a type
64
- // referring to an alias.
65
- if (f is ! TypeAliasElement && f.alias? .element != null ) {
66
- return AliasedElementType (
67
- f as ParameterizedType , library, packageGraph, element);
68
- }
69
- assert (f is ParameterizedType || f is TypeParameterType );
70
- // TODO(jcollins-g): strip out all the cruft that's accumulated
71
- // here for non-generic type aliases.
72
- var isGenericTypeAlias = f.alias? .element != null && f is ! InterfaceType ;
73
- if (f is FunctionType ) {
74
- assert (f is ParameterizedType );
75
- // And finally, delete this case and its associated class
76
- // after https://dart-review.googlesource.com/c/sdk/+/201520
77
- // is in all published versions of analyzer this version of dartdoc
78
- // is compatible with.
79
- return CallableElementType (f, library, packageGraph, element);
47
+ return UndefinedElementType ._from (f, library, packageGraph);
80
48
}
81
- if (isGenericTypeAlias) {
82
- return GenericTypeAliasElementType (
83
- f as TypeParameterType , library, packageGraph, element);
84
- }
85
- if (f is TypeParameterType ) {
86
- return TypeParameterElementType (f, library, packageGraph, element);
87
- }
88
- assert (f is ParameterizedType );
89
- return ParameterizedElementType (
90
- f as ParameterizedType , library, packageGraph, element);
49
+ var modelElement = packageGraph.modelBuilder.fromElement (fElement);
50
+ return DefinedElementType ._from (f, modelElement, library, packageGraph);
91
51
}
92
52
93
53
/// The element of [type] .
@@ -118,6 +78,24 @@ abstract class ElementType extends Privacy
118
78
class UndefinedElementType extends ElementType {
119
79
UndefinedElementType (super .f, super .library, super .packageGraph);
120
80
81
+ factory UndefinedElementType ._from (
82
+ DartType f, Library library, PackageGraph packageGraph) {
83
+ // [UndefinedElementType]s.
84
+ if (f.alias? .element != null ) {
85
+ if (f is FunctionType ) {
86
+ return AliasedUndefinedFunctionElementType (f, library, packageGraph);
87
+ }
88
+ return AliasedUndefinedElementType (f, library, packageGraph);
89
+ }
90
+ if (f is RecordType ) {
91
+ return RecordElementType (f, library, packageGraph);
92
+ }
93
+ if (f is FunctionType ) {
94
+ return FunctionTypeElementType (f, library, packageGraph);
95
+ }
96
+ return UndefinedElementType (f, library, packageGraph);
97
+ }
98
+
121
99
@override
122
100
bool get isPublic => true ;
123
101
@@ -196,16 +174,22 @@ class RecordElementType extends UndefinedElementType with Rendered {
196
174
RecordType get type => super .type as RecordType ;
197
175
}
198
176
199
- class AliasedFunctionTypeElementType extends FunctionTypeElementType
200
- with Aliased {
201
- AliasedFunctionTypeElementType (super .f, super .library, super .packageGraph) {
177
+ class AliasedUndefinedFunctionElementType extends AliasedUndefinedElementType
178
+ with Callable {
179
+ AliasedUndefinedFunctionElementType (
180
+ super .f, super .library, super .packageGraph);
181
+ }
182
+
183
+ class AliasedUndefinedElementType extends UndefinedElementType
184
+ with Aliased , Rendered {
185
+ AliasedUndefinedElementType (super .f, super .library, super .packageGraph) {
202
186
assert (type.alias? .element != null );
203
187
assert (type.alias? .typeArguments != null );
204
188
}
205
189
206
190
@override
207
- ElementTypeRenderer < AliasedFunctionTypeElementType > get _renderer =>
208
- packageGraph.rendererFactory.aliasedFunctionTypeElementTypeRenderer ;
191
+ ElementTypeRenderer get _renderer =>
192
+ packageGraph.rendererFactory.aliasedUndefinedElementTypeRenderer ;
209
193
}
210
194
211
195
class ParameterizedElementType extends DefinedElementType with Rendered {
@@ -284,6 +268,35 @@ abstract class DefinedElementType extends ElementType {
284
268
DefinedElementType (
285
269
super .type, super .library, super .packageGraph, this .modelElement);
286
270
271
+ factory DefinedElementType ._from (DartType f, ModelElement modelElement,
272
+ Library library, PackageGraph packageGraph) {
273
+ // `TypeAliasElement.alias.element` has different implications.
274
+ // In that case it is an actual type alias of some kind (generic or
275
+ // otherwise). Here however `alias.element` signals that this is a type
276
+ // referring to an alias.
277
+ if (f is ! TypeAliasElement && f.alias? .element != null ) {
278
+ return AliasedElementType (
279
+ f as ParameterizedType , library, packageGraph, modelElement);
280
+ }
281
+ assert (f is ParameterizedType || f is TypeParameterType );
282
+ assert (f is ! FunctionType ,
283
+ 'detected DefinedElementType for FunctionType: analyzer version too old?' );
284
+ // TODO(jcollins-g): strip out all the cruft that's accumulated
285
+ // here for non-generic type aliases.
286
+ var isGenericTypeAlias = f.alias? .element != null && f is ! InterfaceType ;
287
+ if (isGenericTypeAlias) {
288
+ assert (false );
289
+ return GenericTypeAliasElementType (
290
+ f as TypeParameterType , library, packageGraph, modelElement);
291
+ }
292
+ if (f is TypeParameterType ) {
293
+ return TypeParameterElementType (f, library, packageGraph, modelElement);
294
+ }
295
+ assert (f is ParameterizedType );
296
+ return ParameterizedElementType (
297
+ f as ParameterizedType , library, packageGraph, modelElement);
298
+ }
299
+
287
300
Element get element => modelElement.element;
288
301
289
302
@override
0 commit comments