Skip to content

Fix several problems with anonymous functions and type parameters #1651

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

Merged
merged 10 commits into from
Mar 29, 2018
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 9 additions & 0 deletions lib/resources/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,15 @@ dl dt.callable .name {
white-space: nowrap;
}

.type-parameter {
white-space: nowrap;
}

.multi-line-signature .type-parameter .parameter {
margin-left: 0px;
display: unset;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

.signature {
color: #727272;
}
Expand Down
28 changes: 16 additions & 12 deletions lib/src/element_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,14 @@ abstract class ElementType extends Privacy {
assert(f is ParameterizedType || f is TypeParameterType);
bool isGenericTypeAlias =
f.element.enclosingElement is GenericTypeAliasElement;
// can happen if element is dynamic
assert(f.element.library != null);
if (f is FunctionType) {
assert(f is ParameterizedType);
if (isGenericTypeAlias) {
assert(element is! ModelFunctionAnonymous);
return new CallableGenericTypeAliasElementType(
f, packageGraph, element, returnedFrom);
} else {
if ((f.name ?? f.element.name) == '' ||
(f.name ?? f.element.name) == null) {
assert(element is ModelFunctionAnonymous);
if (element is ModelFunctionAnonymous) {
return new CallableAnonymousElementType(
f, packageGraph, element, returnedFrom);
} else {
Expand Down Expand Up @@ -129,9 +125,10 @@ class ParameterizedElementType extends DefinedElementType {
if (!typeArguments.every((t) => t.name == 'dynamic') &&
typeArguments.isNotEmpty) {
buf.write('<span class="signature">');
buf.write('&lt;');
buf.writeAll(typeArguments.map((t) => t.linkedName), ', ');
buf.write('&gt;');
buf.write('&lt;<wbr><span class="type-parameter">');
buf.writeAll(typeArguments.map((t) => t.linkedName),
'</span>, <span class="type-parameter">');
buf.write('</span>&gt;');
buf.write('</span>');
}

Expand All @@ -150,9 +147,10 @@ class ParameterizedElementType extends DefinedElementType {

if (!typeArguments.every((t) => t.name == 'dynamic') &&
typeArguments.isNotEmpty) {
buf.write('&lt;');
buf.writeAll(typeArguments.map((t) => t.nameWithGenerics), ', ');
buf.write('&gt;');
buf.write('&lt;<wbr><span class="type-parameter">');
buf.writeAll(typeArguments.map((t) => t.nameWithGenerics),
'</span>, <span class="type-parameter">');
buf.write('</span>&gt;');
}
_nameWithGenerics = buf.toString();
}
Expand Down Expand Up @@ -286,6 +284,12 @@ class CallableElementType extends ParameterizedElementType
CallableElementType(FunctionType t, PackageGraph packageGraph,
ModelElement element, ElementType returnedFrom)
: super(t, packageGraph, element, returnedFrom);

@override
String get linkedName {
if (name != null && name.isNotEmpty) return super.linkedName;
return '${nameWithGenerics}(${element.linkedParams(showNames: false).trim()}) → ${returnType.linkedName}';
}
}

/// This is an anonymous function using the generic function syntax (declared
Expand All @@ -301,7 +305,7 @@ class CallableAnonymousElementType extends CallableElementType {
String get linkedName {
if (_linkedName == null) {
_linkedName =
'${super.linkedName}<span class="signature">(${element.linkedParams()})</span>';
'${returnType.linkedName} ${super.linkedName}<span class="signature">(${element.linkedParams()})</span>';
}
return _linkedName;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/markdown_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@ ModelElement _findRefElementInLibrary(String codeRef, Warnable element,
}

if (results.length > 1) {
if (results.any((r) => r.library.packageName == library.packageName)) {
results.removeWhere((r) => r.library.packageName != library.packageName);
if (results.any((r) => r.library?.packageName == library.packageName)) {
results.removeWhere((r) => r.library?.packageName != library.packageName);
}
}

Expand Down
Loading