Skip to content

Cosmetic cleanups for type parameters #1558

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 3 commits into from
Dec 6, 2017
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
29 changes: 29 additions & 0 deletions lib/src/element_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,52 @@ class ElementType extends Privacy {
if (isParameterizedType) {
if (!typeArguments.every((t) => t.linkedName == 'dynamic') &&
typeArguments.isNotEmpty) {
buf.write('<span class="signature">');
buf.write('&lt;');
buf.writeAll(typeArguments.map((t) => t.linkedName), ', ');
buf.write('&gt;');
buf.write('</span>');
}
// Hide parameters if there's a an explicit typedef behind this
// element, but if there is no typedef, be explicit.
if (element is ModelFunctionAnonymous) {
buf.write('<span class="signature">');
buf.write('(');
buf.write(element.linkedParams());
buf.write(')');
buf.write('</span>');
}
}
_linkedName = buf.toString();
}
return _linkedName;
}

String _nameWithGenerics;
String get nameWithGenerics {
if (_nameWithGenerics == null) {
StringBuffer buf = new StringBuffer();

if (isParameterType) {
buf.write(name);
} else {
buf.write(element.name);
}

// not TypeParameterType or Void or Union type
if (isParameterizedType) {
if (!typeArguments.every((t) => t.linkedName == 'dynamic') &&
typeArguments.isNotEmpty) {
buf.write('&lt;');
buf.writeAll(typeArguments.map((t) => t.nameWithGenerics), ', ');
buf.write('&gt;');
}
}
_nameWithGenerics = buf.toString();
}
return _nameWithGenerics;
}

String get name => _type.name ?? _type.element.name;

ModelElement get returnElement {
Expand Down
1 change: 0 additions & 1 deletion lib/src/html/html_generator_instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class HtmlGeneratorInstance {
generatePackage();

for (var lib in filterNonDocumented(_package.libraries)) {
// if (lib.name != 'extract_messages') continue;
generateLibrary(_package, lib);

for (var clazz in filterNonDocumented(lib.allClasses)) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/html/template_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ class ClassTemplateData extends TemplateData<Class> {
'${library.name} library, for the Dart programming language.';

@override
String get layoutTitle =>
_layoutTitle(clazz.nameWithGenerics, clazz.fullkind, clazz.isDeprecated);
String get layoutTitle => _layoutTitle(
clazz.nameWithLinkedGenerics, clazz.fullkind, clazz.isDeprecated);
@override
List get navLinks => [package, library];
@override
Expand Down
31 changes: 28 additions & 3 deletions lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ class Class extends ModelElement
..addAll([]
..addAll(inheritedProperties)
..sort(byName));

return _allInstanceProperties;
}

Expand Down Expand Up @@ -4711,11 +4710,20 @@ abstract class SourceCodeMixin {
abstract class TypeParameters implements Nameable {
String get nameWithGenerics => '$name$genericParameters';

String get nameWithLinkedGenerics => '$name$linkedGenericParameters';

bool get hasGenericParameters => typeParameters.isNotEmpty;

String get genericParameters {
if (typeParameters.isEmpty) return '';
return '&lt;${typeParameters.map((t) => t.name).join(', ')}&gt;';
}

String get linkedGenericParameters {
if (typeParameters.isEmpty) return '';
return '<span class="signature">&lt;${typeParameters.map((t) => t.linkedName).join(', ')}&gt;</span>';
}

List<TypeParameter> get typeParameters;
}

Expand Down Expand Up @@ -4862,11 +4870,28 @@ class TypeParameter extends ModelElement {
@override
String get kind => 'type parameter';

ElementType get boundType {
var bound = _typeParameter.bound;
if (bound != null) {
ModelElement boundClass =
new ModelElement.fromElement(bound.element, package);
return new ElementType(bound, boundClass);
}
return null;
}

@override
String get name {
var bound = _typeParameter.bound;
return bound != null
? '${_typeParameter.name} extends ${bound.name}'
return _typeParameter.bound != null
? '${_typeParameter.name} extends ${boundType.nameWithGenerics}'
: _typeParameter.name;
}

@override
String get linkedName {
return _typeParameter.bound != null
? '${_typeParameter.name} extends ${boundType.linkedName}'
: _typeParameter.name;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/templates/_callable.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<dt id="{{htmlId}}" class="callable{{ #isInherited }} inherited{{ /isInherited}}">
<span class="name{{#isDeprecated}} deprecated{{/isDeprecated}}">{{{linkedName}}}</span><span class="signature">{{{genericParameters}}}(<wbr>{{{ linkedParamsNoMetadata }}})
<span class="name{{#isDeprecated}} deprecated{{/isDeprecated}}">{{{linkedName}}}</span>{{{linkedGenericParameters}}}<span class="signature">(<wbr>{{{ linkedParamsNoMetadata }}})
<span class="returntype parameter">&#8594; {{{ linkedReturnType }}}</span>
</span>
</dt>
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/_head.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<li><a href="{{href}}">{{name}}</a></li>
{{/navLinks}}
{{#navLinksWithGenerics}}
<li><a href="{{href}}">{{name}}{{{genericParameters}}}</a></li>
<li><a href="{{href}}">{{name}}{{#hasGenericParameters}}<span class="signature">{{{genericParameters}}}</span>{{/hasGenericParameters}}</a></li>
{{/navLinksWithGenerics}}
{{^hasHomepage}}
<li class="self-crumb">{{{ layoutTitle }}}</li>
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/library.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h2>Classes</h2>
<dl>
{{#library.publicClasses}}
<dt id="{{htmlId}}">
<span class="name {{#isDeprecated}}deprecated{{/isDeprecated}}">{{{linkedName}}}</span>
<span class="name {{#isDeprecated}}deprecated{{/isDeprecated}}">{{{linkedName}}}{{{linkedGenericParameters}}}</span>
</dt>
<dd>
{{{ oneLineDoc }}}
Expand Down
38 changes: 19 additions & 19 deletions test/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1116,21 +1116,21 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
// TODO(jcollins-g): really, these shouldn't be called "parameters" in
// the span class.
expect(explicitSetter.linkedReturnType,
'<span class="parameter" id="explicitSetter=-param-f"><span class="type-annotation">dynamic</span> <span class="parameter-name">Function</span>(<span class="parameter" id="f-param-bar"><span class="type-annotation">int</span>, </span> <span class="parameter" id="f-param-baz"><span class="type-annotation"><a href="fake/Cool-class.html">Cool</a></span>, </span> <span class="parameter" id="f-param-macTruck"><span class="type-annotation">List&lt;int&gt;</span></span>)</span>');
'<span class="parameter" id="explicitSetter=-param-f"><span class="type-annotation">dynamic</span> <span class="parameter-name">Function</span>(<span class="parameter" id="f-param-bar"><span class="type-annotation">int</span>, </span> <span class="parameter" id="f-param-baz"><span class="type-annotation"><a href="fake/Cool-class.html">Cool</a></span>, </span> <span class="parameter" id="f-param-macTruck"><span class="type-annotation">List<span class="signature">&lt;int&gt;</span></span></span>)</span>');
});

test('parameterized type from field is correctly displayed', () {
Field aField = TemplatedInterface.instanceProperties
.singleWhere((f) => f.name == 'aField');
expect(aField.linkedReturnType,
'<a href=\"ex/AnotherParameterizedClass-class.html\">AnotherParameterizedClass</a>&lt;Stream&lt;List&lt;int&gt;&gt;&gt;');
'<a href=\"ex/AnotherParameterizedClass-class.html\">AnotherParameterizedClass</a><span class="signature">&lt;Stream<span class="signature">&lt;List<span class="signature">&lt;int&gt;</span>&gt;</span>&gt;</span>');
});

test('parameterized type from inherited field is correctly displayed', () {
Field aInheritedField = TemplatedInterface.inheritedProperties
.singleWhere((f) => f.name == 'aInheritedField');
expect(aInheritedField.linkedReturnType,
'<a href="ex/AnotherParameterizedClass-class.html">AnotherParameterizedClass</a>&lt;List&lt;int&gt;&gt;');
'<a href="ex/AnotherParameterizedClass-class.html">AnotherParameterizedClass</a><span class="signature">&lt;List<span class="signature">&lt;int&gt;</span>&gt;</span>');
});

test(
Expand All @@ -1140,7 +1140,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
.singleWhere((f) => f.name == 'aGetter')
.getter;
expect(aGetter.linkedReturnType,
'<a href=\"ex/AnotherParameterizedClass-class.html\">AnotherParameterizedClass</a>&lt;Map&lt;A, List&lt;String&gt;&gt;&gt;');
'<a href=\"ex/AnotherParameterizedClass-class.html\">AnotherParameterizedClass</a><span class="signature">&lt;Map<span class="signature">&lt;A, List<span class="signature">&lt;String&gt;</span>&gt;</span>&gt;</span>');
});

test(
Expand All @@ -1150,7 +1150,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
.singleWhere((f) => f.name == 'aInheritedGetter')
.getter;
expect(aInheritedGetter.linkedReturnType,
'<a href="ex/AnotherParameterizedClass-class.html">AnotherParameterizedClass</a>&lt;List&lt;int&gt;&gt;');
'<a href="ex/AnotherParameterizedClass-class.html">AnotherParameterizedClass</a><span class="signature">&lt;List<span class="signature">&lt;int&gt;</span>&gt;</span>');
});

test(
Expand All @@ -1160,11 +1160,11 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
.singleWhere((f) => f.name == 'aInheritedSetter')
.setter;
expect(aInheritedSetter.allParameters.first.modelType.linkedName,
'<a href="ex/AnotherParameterizedClass-class.html">AnotherParameterizedClass</a>&lt;List&lt;int&gt;&gt;');
'<a href="ex/AnotherParameterizedClass-class.html">AnotherParameterizedClass</a><span class="signature">&lt;List<span class="signature">&lt;int&gt;</span>&gt;</span>');
// TODO(jcollins-g): really, these shouldn't be called "parameters" in
// the span class.
expect(aInheritedSetter.enclosingCombo.linkedReturnType,
'<span class="parameter" id="aInheritedSetter=-param-thingToSet"><span class="type-annotation"><a href="ex/AnotherParameterizedClass-class.html">AnotherParameterizedClass</a>&lt;List&lt;int&gt;&gt;</span></span>');
'<span class="parameter" id="aInheritedSetter=-param-thingToSet"><span class="type-annotation"><a href="ex/AnotherParameterizedClass-class.html">AnotherParameterizedClass</a><span class="signature">&lt;List<span class="signature">&lt;int&gt;</span>&gt;</span></span></span>');
});

test(
Expand All @@ -1173,7 +1173,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
Method aMethodInterface = TemplatedInterface.allInstanceMethods
.singleWhere((m) => m.name == 'aMethodInterface');
expect(aMethodInterface.linkedReturnType,
'<a href=\"ex/AnotherParameterizedClass-class.html\">AnotherParameterizedClass</a>&lt;List&lt;int&gt;&gt;');
'<a href=\"ex/AnotherParameterizedClass-class.html\">AnotherParameterizedClass</a><span class="signature">&lt;List<span class="signature">&lt;int&gt;</span>&gt;</span>');
});

test(
Expand All @@ -1182,7 +1182,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
Method aInheritedMethod = TemplatedInterface.allInstanceMethods
.singleWhere((m) => m.name == 'aInheritedMethod');
expect(aInheritedMethod.linkedReturnType,
'<a href=\"ex/AnotherParameterizedClass-class.html\">AnotherParameterizedClass</a>&lt;List&lt;int&gt;&gt;');
'<a href=\"ex/AnotherParameterizedClass-class.html\">AnotherParameterizedClass</a><span class="signature">&lt;List<span class="signature">&lt;int&gt;</span>&gt;</span>');
});

test(
Expand All @@ -1192,7 +1192,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
.allInstanceMethods
.singleWhere((m) => m.name == 'aTypedefReturningMethodInterface');
expect(aTypedefReturningMethodInterface.linkedReturnType,
'<a href=\"ex/ParameterizedTypedef.html\">ParameterizedTypedef</a>&lt;List&lt;String&gt;&gt;');
'<a href=\"ex/ParameterizedTypedef.html\">ParameterizedTypedef</a><span class="signature">&lt;List<span class="signature">&lt;String&gt;</span>&gt;</span>');
});

test(
Expand All @@ -1202,7 +1202,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
.allInstanceMethods
.singleWhere((m) => m.name == 'aInheritedTypedefReturningMethod');
expect(aInheritedTypedefReturningMethod.linkedReturnType,
'<a href=\"ex/ParameterizedTypedef.html\">ParameterizedTypedef</a>&lt;List&lt;int&gt;&gt;');
'<a href=\"ex/ParameterizedTypedef.html\">ParameterizedTypedef</a><span class="signature">&lt;List<span class="signature">&lt;int&gt;</span>&gt;</span>');
});

test('parameterized types for inherited operator is correctly displayed',
Expand All @@ -1211,9 +1211,9 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
.inheritedOperators
.singleWhere((m) => m.name == 'operator +');
expect(aInheritedAdditionOperator.linkedReturnType,
'<a href=\"ex/ParameterizedClass-class.html\">ParameterizedClass</a>&lt;List&lt;int&gt;&gt;');
'<a href=\"ex/ParameterizedClass-class.html\">ParameterizedClass</a><span class="signature">&lt;List<span class="signature">&lt;int&gt;</span>&gt;</span>');
expect(aInheritedAdditionOperator.linkedParams(),
'<span class="parameter" id="+-param-other"><span class="type-annotation"><a href="ex/ParameterizedClass-class.html">ParameterizedClass</a>&lt;List&lt;int&gt;&gt;</span> <span class="parameter-name">other</span></span>');
'<span class="parameter" id="+-param-other"><span class="type-annotation"><a href="ex/ParameterizedClass-class.html">ParameterizedClass</a><span class="signature">&lt;List<span class="signature">&lt;int&gt;</span>&gt;</span></span> <span class="parameter-name">other</span></span>');
});

test('', () {});
Expand Down Expand Up @@ -1279,7 +1279,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
expect(
getAFunctionReturningVoid.linkedReturnType,
equals(
'Function(<span class="parameter" id="getAFunctionReturningVoid-param-"><span class="type-annotation">T1</span>, </span> <span class="parameter" id="getAFunctionReturningVoid-param-"><span class="type-annotation">T2</span></span>)'));
'Function<span class="signature">(<span class="parameter" id="getAFunctionReturningVoid-param-"><span class="type-annotation">T1</span>, </span> <span class="parameter" id="getAFunctionReturningVoid-param-"><span class="type-annotation">T2</span></span>)</span>'));
});

test(
Expand All @@ -1288,7 +1288,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
expect(
getAFunctionReturningBool.linkedReturnType,
equals(
'Function&lt;T4&gt;(<span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">String</span>, </span> <span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">T1</span>, </span> <span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">T4</span></span>)'));
'Function<span class="signature">&lt;T4&gt;</span><span class="signature">(<span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">String</span>, </span> <span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">T1</span>, </span> <span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">T4</span></span>)</span>'));
});

test('has a fully qualified name', () {
Expand Down Expand Up @@ -1362,7 +1362,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,

test('parameter has generics in signature', () {
expect(testGeneric.parameters[0].modelType.linkedName,
'Map&lt;String, dynamic&gt;');
'Map<span class="signature">&lt;String, dynamic&gt;</span>');
});

test('parameter is a function', () {
Expand Down Expand Up @@ -1768,7 +1768,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
expect(
fieldWithTypedef.linkedReturnType,
equals(
'<a href="ex/ParameterizedTypedef.html">ParameterizedTypedef</a>&lt;bool&gt;'));
'<a href="ex/ParameterizedTypedef.html">ParameterizedTypedef</a><span class="signature">&lt;bool&gt;</span>'));
});
});

Expand Down Expand Up @@ -2040,7 +2040,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
expect(
aComplexTypedef.linkedReturnType,
equals(
'Function(<span class="parameter" id="-param-"><span class="type-annotation">A1</span>, </span> <span class="parameter" id="-param-"><span class="type-annotation">A2</span>, </span> <span class="parameter" id="-param-"><span class="type-annotation">A3</span></span>)'));
'Function<span class="signature">(<span class="parameter" id="-param-"><span class="type-annotation">A1</span>, </span> <span class="parameter" id="-param-"><span class="type-annotation">A2</span>, </span> <span class="parameter" id="-param-"><span class="type-annotation">A3</span></span>)</span>'));
expect(
aComplexTypedef.linkedParamsLines,
equals(
Expand All @@ -2065,7 +2065,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,

test('linked return type', () {
expect(t.linkedReturnType, equals('String'));
expect(generic.linkedReturnType, equals('List&lt;S&gt;'));
expect(generic.linkedReturnType, equals('List<span class="signature">&lt;S&gt;</span>'));
});

test("name with generics", () {
Expand Down
2 changes: 1 addition & 1 deletion testing/test_package_docs/ex/Animal-class.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ <h2>Constants</h2>
</dd>
<dt id="values" class="constant">
<span class="name ">values</span>
<span class="signature">&#8594; List&lt;<a href="ex/Animal-class.html">Animal</a>&gt;</span>
<span class="signature">&#8594; List<span class="signature">&lt;<a href="ex/Animal-class.html">Animal</a>&gt;</span></span>
</dt>
<dd>
<p>A constant List of the values in this enum, in order of their declaration.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<ol class="breadcrumbs gt-separated dark hidden-xs">
<li><a href="index.html">test_package</a></li>
<li><a href="ex/ex-library.html">ex</a></li>
<li class="self-crumb">class AnotherParameterizedClass&lt;B&gt;</li>
<li class="self-crumb">class AnotherParameterizedClass<span class="signature">&lt;B&gt;</span></li>
</ol>
<div class="self-name">AnotherParameterizedClass</div>
<form class="search navbar-right" role="search">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<ol class="breadcrumbs gt-separated dark hidden-xs">
<li><a href="index.html">test_package</a></li>
<li><a href="ex/ex-library.html">ex</a></li>
<li><a href="ex/AnotherParameterizedClass-class.html">AnotherParameterizedClass&lt;B&gt;</a></li>
<li><a href="ex/AnotherParameterizedClass-class.html">AnotherParameterizedClass<span class="signature">&lt;B&gt;</span></a></li>
<li class="self-crumb">constructor AnotherParameterizedClass</li>
</ol>
<div class="self-name">AnotherParameterizedClass</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<ol class="breadcrumbs gt-separated dark hidden-xs">
<li><a href="index.html">test_package</a></li>
<li><a href="ex/ex-library.html">ex</a></li>
<li><a href="ex/AnotherParameterizedClass-class.html">AnotherParameterizedClass&lt;B&gt;</a></li>
<li><a href="ex/AnotherParameterizedClass-class.html">AnotherParameterizedClass<span class="signature">&lt;B&gt;</span></a></li>
<li class="self-crumb">property hashCode</li>
</ol>
<div class="self-name">hashCode</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<ol class="breadcrumbs gt-separated dark hidden-xs">
<li><a href="index.html">test_package</a></li>
<li><a href="ex/ex-library.html">ex</a></li>
<li><a href="ex/AnotherParameterizedClass-class.html">AnotherParameterizedClass&lt;B&gt;</a></li>
<li><a href="ex/AnotherParameterizedClass-class.html">AnotherParameterizedClass<span class="signature">&lt;B&gt;</span></a></li>
<li class="self-crumb">method noSuchMethod</li>
</ol>
<div class="self-name">noSuchMethod</div>
Expand Down
Loading