Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the unneeded ModelFunctionAnonymous and related code #2084

Merged
merged 2 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 3 additions & 36 deletions lib/src/element_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,21 @@ abstract class ElementType extends Privacy {
if (f is FunctionType) {
assert(f is ParameterizedType);
if (isGenericTypeAlias) {
assert(element is! ModelFunctionAnonymous);
return CallableGenericTypeAliasElementType(
f, library, packageGraph, element, returnedFrom);
} else {
if (element is ModelFunctionAnonymous) {
return CallableAnonymousElementType(
f, library, packageGraph, element, returnedFrom);
} else {
assert(element is! ModelFunctionAnonymous);
return CallableElementType(
f, library, packageGraph, element, returnedFrom);
}
}
return CallableElementType(
f, library, packageGraph, element, returnedFrom);
} else if (isGenericTypeAlias) {
assert(f is TypeParameterType);
assert(element is! ModelFunctionAnonymous);
return GenericTypeAliasElementType(
f, library, packageGraph, element, returnedFrom);
}
if (f is TypeParameterType) {
assert(element is! ModelFunctionAnonymous);
return TypeParameterElementType(
f, library, packageGraph, element, returnedFrom);
}
assert(f is ParameterizedType);
assert(element is! ModelFunctionAnonymous);
return ParameterizedElementType(
f, library, packageGraph, element, returnedFrom);
}
Expand Down Expand Up @@ -329,10 +318,7 @@ abstract class CallableElementTypeMixin implements ParameterizedElementType {
dartTypeArguments = type.typeFormals.map(_legacyTypeParameterType);
}
} else {
DefinedElementType elementType = returnedFrom as DefinedElementType;
if (type.typeFormals.isEmpty &&
element is! ModelFunctionAnonymous &&
elementType?.element is! ModelFunctionAnonymous) {
if (type.typeFormals.isEmpty) {
dartTypeArguments = type.typeArguments;
} else if (returnedFrom != null &&
returnedFrom.type.element is GenericFunctionTypeElement) {
Expand Down Expand Up @@ -384,25 +370,6 @@ class CallableElementType extends ParameterizedElementType
String get superLinkedName => super.linkedName;
}

/// This is an anonymous function using the generic function syntax (declared
/// literally with "Function").
class CallableAnonymousElementType extends CallableElementType {
CallableAnonymousElementType(FunctionType t, Library library,
PackageGraph packageGraph, ModelElement element, ElementType returnedFrom)
: super(t, library, packageGraph, element, returnedFrom);
@override
String get name => 'Function';

@override
String get linkedName {
if (_linkedName == null) {
_linkedName =
CallableAnonymousElementTypeRendererHtml().renderLinkedName(this);
}
return _linkedName;
}
}

/// Types backed by a [GenericTypeAliasElement] that may or may not be callable.
abstract class GenericTypeAliasElementTypeMixin {}

Expand Down
19 changes: 3 additions & 16 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,9 @@ abstract class ModelElement extends Canonicalization
if (e is FunctionElement) {
newModelElement = ModelFunction(e, library, packageGraph);
} else if (e is GenericFunctionTypeElement) {
// TODO(scheglov) "e" cannot be both GenericFunctionTypeElement,
// and FunctionTypeAliasElement or GenericTypeAliasElement.
if (e is FunctionTypeAliasElement) {
assert(e.name != '');
newModelElement = ModelFunctionTypedef(e, library, packageGraph);
} else {
if (e.enclosingElement is GenericTypeAliasElement) {
assert(e.enclosingElement.name != '');
newModelElement = ModelFunctionTypedef(e, library, packageGraph);
} else {
// Allowing null here is allowed as a workaround for
// dart-lang/sdk#32005.
assert(e.name == '' || e.name == null);
newModelElement = ModelFunctionAnonymous(e, packageGraph);
}
}
assert(e.enclosingElement is GenericTypeAliasElement);
assert(e.enclosingElement.name != '');
newModelElement = ModelFunctionTypedef(e, library, packageGraph);
}
if (e is FunctionTypeAliasElement) {
newModelElement = Typedef(e, library, packageGraph);
Expand Down
40 changes: 1 addition & 39 deletions lib/src/model/model_function.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,6 @@ class ModelFunction extends ModelFunctionTyped with Categorization {
FunctionElement get _func => (element as FunctionElement);
}

/// A [ModelElement] for a [FunctionTypedElement] that is an
/// explicit typedef.
///
/// Distinct from ModelFunctionTypedef in that it doesn't
/// have a name, but we document it as "Function" to match how these are
/// written in declarations.
class ModelFunctionAnonymous extends ModelFunctionTyped {
ModelFunctionAnonymous(
FunctionTypedElement element, PackageGraph packageGraph)
: super(element, null, packageGraph);

@override
ModelElement get enclosingElement {
// These are not considered to be a part of libraries, so we can simply
// blindly instantiate a ModelElement for their enclosing element.
return ModelElement.fromElement(element.enclosingElement, packageGraph);
}

@override
String get name => 'Function';

@override
String get linkedName => 'Function';

@override
bool get isPublic => false;
}

/// A [ModelElement] for a [FunctionTypedElement] that is part of an
/// explicit typedef.
class ModelFunctionTypedef extends ModelFunctionTyped {
Expand All @@ -60,17 +32,7 @@ class ModelFunctionTypedef extends ModelFunctionTyped {
: super(element, library, packageGraph);

@override
String get name {
Element e = element;
while (e != null) {
if (e is FunctionTypeAliasElement || e is GenericTypeAliasElement) {
return e.name;
}
e = e.enclosingElement;
}
assert(false);
return super.name;
}
String get name => element.enclosingElement.name;
}

class ModelFunctionTyped extends ModelElement
Expand Down
16 changes: 0 additions & 16 deletions lib/src/render/element_type_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,3 @@ class CallableElementTypeRendererHtml
return buf.toString();
}
}

class CallableAnonymousElementTypeRendererHtml
extends ElementTypeRenderer<CallableAnonymousElementType> {
@override
String renderLinkedName(CallableAnonymousElementType elementType) {
StringBuffer buf = StringBuffer();
buf.write(elementType.returnType.linkedName);
buf.write(' ');
buf.write(elementType.superLinkedName);
buf.write('<span class="signature">(');
buf.write(ParameterRendererHtml()
.renderLinkedParams(elementType.element.parameters));
buf.write(')</span>');
return buf.toString();
}
}
1 change: 0 additions & 1 deletion lib/src/render/parameter_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ abstract class ParameterRenderer {
if (showNames) {
buf.write(' ${parameterName(param.name)}');
} else if (paramModelType.isTypedef ||
paramModelType is CallableAnonymousElementType ||
paramModelType.type is FunctionType) {
buf.write(' ${parameterName(paramModelType.name)}');
}
Expand Down