Skip to content

Commit f8d33bc

Browse files
authored
Remove the unneeded ModelFunctionAnonymous and related code (#2084)
* Strip anonymous construction? * Remove unneeded 'anonymous' model and type
1 parent 7b87236 commit f8d33bc

File tree

5 files changed

+7
-108
lines changed

5 files changed

+7
-108
lines changed

lib/src/element_type.dart

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,21 @@ abstract class ElementType extends Privacy {
3939
if (f is FunctionType) {
4040
assert(f is ParameterizedType);
4141
if (isGenericTypeAlias) {
42-
assert(element is! ModelFunctionAnonymous);
4342
return CallableGenericTypeAliasElementType(
4443
f, library, packageGraph, element, returnedFrom);
45-
} else {
46-
if (element is ModelFunctionAnonymous) {
47-
return CallableAnonymousElementType(
48-
f, library, packageGraph, element, returnedFrom);
49-
} else {
50-
assert(element is! ModelFunctionAnonymous);
51-
return CallableElementType(
52-
f, library, packageGraph, element, returnedFrom);
53-
}
5444
}
45+
return CallableElementType(
46+
f, library, packageGraph, element, returnedFrom);
5547
} else if (isGenericTypeAlias) {
5648
assert(f is TypeParameterType);
57-
assert(element is! ModelFunctionAnonymous);
5849
return GenericTypeAliasElementType(
5950
f, library, packageGraph, element, returnedFrom);
6051
}
6152
if (f is TypeParameterType) {
62-
assert(element is! ModelFunctionAnonymous);
6353
return TypeParameterElementType(
6454
f, library, packageGraph, element, returnedFrom);
6555
}
6656
assert(f is ParameterizedType);
67-
assert(element is! ModelFunctionAnonymous);
6857
return ParameterizedElementType(
6958
f, library, packageGraph, element, returnedFrom);
7059
}
@@ -329,10 +318,7 @@ abstract class CallableElementTypeMixin implements ParameterizedElementType {
329318
dartTypeArguments = type.typeFormals.map(_legacyTypeParameterType);
330319
}
331320
} else {
332-
DefinedElementType elementType = returnedFrom as DefinedElementType;
333-
if (type.typeFormals.isEmpty &&
334-
element is! ModelFunctionAnonymous &&
335-
elementType?.element is! ModelFunctionAnonymous) {
321+
if (type.typeFormals.isEmpty) {
336322
dartTypeArguments = type.typeArguments;
337323
} else if (returnedFrom != null &&
338324
returnedFrom.type.element is GenericFunctionTypeElement) {
@@ -384,25 +370,6 @@ class CallableElementType extends ParameterizedElementType
384370
String get superLinkedName => super.linkedName;
385371
}
386372

387-
/// This is an anonymous function using the generic function syntax (declared
388-
/// literally with "Function").
389-
class CallableAnonymousElementType extends CallableElementType {
390-
CallableAnonymousElementType(FunctionType t, Library library,
391-
PackageGraph packageGraph, ModelElement element, ElementType returnedFrom)
392-
: super(t, library, packageGraph, element, returnedFrom);
393-
@override
394-
String get name => 'Function';
395-
396-
@override
397-
String get linkedName {
398-
if (_linkedName == null) {
399-
_linkedName =
400-
CallableAnonymousElementTypeRendererHtml().renderLinkedName(this);
401-
}
402-
return _linkedName;
403-
}
404-
}
405-
406373
/// Types backed by a [GenericTypeAliasElement] that may or may not be callable.
407374
abstract class GenericTypeAliasElementTypeMixin {}
408375

lib/src/model/model_element.dart

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -246,22 +246,9 @@ abstract class ModelElement extends Canonicalization
246246
if (e is FunctionElement) {
247247
newModelElement = ModelFunction(e, library, packageGraph);
248248
} else if (e is GenericFunctionTypeElement) {
249-
// TODO(scheglov) "e" cannot be both GenericFunctionTypeElement,
250-
// and FunctionTypeAliasElement or GenericTypeAliasElement.
251-
if (e is FunctionTypeAliasElement) {
252-
assert(e.name != '');
253-
newModelElement = ModelFunctionTypedef(e, library, packageGraph);
254-
} else {
255-
if (e.enclosingElement is GenericTypeAliasElement) {
256-
assert(e.enclosingElement.name != '');
257-
newModelElement = ModelFunctionTypedef(e, library, packageGraph);
258-
} else {
259-
// Allowing null here is allowed as a workaround for
260-
// dart-lang/sdk#32005.
261-
assert(e.name == '' || e.name == null);
262-
newModelElement = ModelFunctionAnonymous(e, packageGraph);
263-
}
264-
}
249+
assert(e.enclosingElement is GenericTypeAliasElement);
250+
assert(e.enclosingElement.name != '');
251+
newModelElement = ModelFunctionTypedef(e, library, packageGraph);
265252
}
266253
if (e is FunctionTypeAliasElement) {
267254
newModelElement = Typedef(e, library, packageGraph);

lib/src/model/model_function.dart

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,6 @@ class ModelFunction extends ModelFunctionTyped with Categorization {
2424
FunctionElement get _func => (element as FunctionElement);
2525
}
2626

27-
/// A [ModelElement] for a [FunctionTypedElement] that is an
28-
/// explicit typedef.
29-
///
30-
/// Distinct from ModelFunctionTypedef in that it doesn't
31-
/// have a name, but we document it as "Function" to match how these are
32-
/// written in declarations.
33-
class ModelFunctionAnonymous extends ModelFunctionTyped {
34-
ModelFunctionAnonymous(
35-
FunctionTypedElement element, PackageGraph packageGraph)
36-
: super(element, null, packageGraph);
37-
38-
@override
39-
ModelElement get enclosingElement {
40-
// These are not considered to be a part of libraries, so we can simply
41-
// blindly instantiate a ModelElement for their enclosing element.
42-
return ModelElement.fromElement(element.enclosingElement, packageGraph);
43-
}
44-
45-
@override
46-
String get name => 'Function';
47-
48-
@override
49-
String get linkedName => 'Function';
50-
51-
@override
52-
bool get isPublic => false;
53-
}
54-
5527
/// A [ModelElement] for a [FunctionTypedElement] that is part of an
5628
/// explicit typedef.
5729
class ModelFunctionTypedef extends ModelFunctionTyped {
@@ -60,17 +32,7 @@ class ModelFunctionTypedef extends ModelFunctionTyped {
6032
: super(element, library, packageGraph);
6133

6234
@override
63-
String get name {
64-
Element e = element;
65-
while (e != null) {
66-
if (e is FunctionTypeAliasElement || e is GenericTypeAliasElement) {
67-
return e.name;
68-
}
69-
e = e.enclosingElement;
70-
}
71-
assert(false);
72-
return super.name;
73-
}
35+
String get name => element.enclosingElement.name;
7436
}
7537

7638
class ModelFunctionTyped extends ModelElement

lib/src/render/element_type_renderer.dart

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,3 @@ class CallableElementTypeRendererHtml
9393
return buf.toString();
9494
}
9595
}
96-
97-
class CallableAnonymousElementTypeRendererHtml
98-
extends ElementTypeRenderer<CallableAnonymousElementType> {
99-
@override
100-
String renderLinkedName(CallableAnonymousElementType elementType) {
101-
StringBuffer buf = StringBuffer();
102-
buf.write(elementType.returnType.linkedName);
103-
buf.write(' ');
104-
buf.write(elementType.superLinkedName);
105-
buf.write('<span class="signature">(');
106-
buf.write(ParameterRendererHtml()
107-
.renderLinkedParams(elementType.element.parameters));
108-
buf.write(')</span>');
109-
return buf.toString();
110-
}
111-
}

lib/src/render/parameter_renderer.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ abstract class ParameterRenderer {
135135
if (showNames) {
136136
buf.write(' ${parameterName(param.name)}');
137137
} else if (paramModelType.isTypedef ||
138-
paramModelType is CallableAnonymousElementType ||
139138
paramModelType.type is FunctionType) {
140139
buf.write(' ${parameterName(paramModelType.name)}');
141140
}

0 commit comments

Comments
 (0)