Skip to content

Add support for GenericFunctionTypeElementImpl #1497

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 8 commits into from
Sep 8, 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
71 changes: 49 additions & 22 deletions lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1394,16 +1394,26 @@ abstract class GetterSetterCombo implements ModelElement {

if (hasGetter && !getter.element.isSynthetic) {
assert(getter.documentationFrom.length == 1);
String docs = getter.documentationFrom.first.computeDocumentationComment;
if (docs != null) buffer.write(docs);
// We have to check against dropTextFrom here since documentationFrom
// doesn't yield the real elements for GetterSetterCombos.
if (!config.dropTextFrom
.contains(getter.documentationFrom.first.element.library.name)) {
String docs =
getter.documentationFrom.first.computeDocumentationComment;
if (docs != null) buffer.write(docs);
}
}

if (hasSetter && !setter.element.isSynthetic) {
assert(setter.documentationFrom.length == 1);
String docs = setter.documentationFrom.first.computeDocumentationComment;
if (docs != null) {
if (buffer.isNotEmpty) buffer.write('\n\n');
buffer.write(docs);
if (!config.dropTextFrom
.contains(setter.documentationFrom.first.element.library.name)) {
String docs =
setter.documentationFrom.first.computeDocumentationComment;
if (docs != null) {
if (buffer.isNotEmpty) buffer.write('\n\n');
buffer.write(docs);
}
}
}
return buffer.toString();
Expand Down Expand Up @@ -2225,6 +2235,10 @@ abstract class ModelElement extends Nameable
newModelElement = new Parameter(e, library);
}
}
// TODO(jcollins-g): Consider subclass for ModelFunctionTyped.
if (e is GenericFunctionTypeElement) {
newModelElement = new ModelFunctionTyped(e, library);
}
if (newModelElement == null) throw "Unknown type ${e.runtimeType}";
if (enclosingClass != null) assert(newModelElement is Inheritable);
if (library != null) {
Expand Down Expand Up @@ -2333,7 +2347,8 @@ abstract class ModelElement extends Nameable
return md.map((dynamic a) {
String annotation = (const HtmlEscape()).convert(a.toSource());
// a.element can be null if the element can't be resolved.
var me = package.findCanonicalModelElementFor(a.element?.enclosingElement);
var me =
package.findCanonicalModelElementFor(a.element?.enclosingElement);
if (me != null)
annotation = annotation.replaceFirst(me.name, me.linkedName);
return annotation;
Expand Down Expand Up @@ -2363,7 +2378,7 @@ abstract class ModelElement extends Nameable
}

bool get canHaveParameters =>
element is ExecutableElement || element is FunctionTypeAliasElement;
element is ExecutableElement || element is FunctionTypedElement;

List<ModelElement> _documentationFrom;
// TODO(jcollins-g): untangle when mixins can call super
Expand Down Expand Up @@ -2762,13 +2777,8 @@ abstract class ModelElement extends Nameable

List<ParameterElement> params;

if (element is ExecutableElement) {
// the as check silences the warning
params = (element as ExecutableElement).parameters;
}

if (element is FunctionTypeAliasElement) {
params = (element as FunctionTypeAliasElement).parameters;
if (element is FunctionTypedElement) {
params = (element as FunctionTypedElement).parameters;
}

_parameters = new UnmodifiableListView<Parameter>(params
Expand Down Expand Up @@ -3127,12 +3137,25 @@ abstract class ModelElement extends Nameable
}
}

class ModelFunction extends ModelElement
class ModelFunction extends ModelFunctionTyped {
ModelFunction(FunctionElement element, Library library)
: super(element, library);

@override
bool get isStatic {
return _func.isStatic;
}

@override
FunctionElement get _func => (element as FunctionElement);
}

class ModelFunctionTyped extends ModelElement
with SourceCodeMixin
implements EnclosedElement {
List<TypeParameter> typeParameters = [];

ModelFunction(FunctionElement element, Library library)
ModelFunctionTyped(FunctionTypedElement element, Library library)
: super(element, library) {
_modelType = new ElementType(_func.type, this);
_calcTypeParameters();
Expand Down Expand Up @@ -3162,9 +3185,6 @@ class ModelFunction extends ModelElement
return '${canonicalLibrary.dirName}/$fileName';
}

@override
bool get isStatic => _func.isStatic;

@override
String get kind => 'function';

Expand All @@ -3182,7 +3202,7 @@ class ModelFunction extends ModelElement
return '&lt;${typeParameters.map((t) => t.name).join(', ')}&gt;';
}

FunctionElement get _func => (element as FunctionElement);
FunctionTypedElement get _func => (element as FunctionTypedElement);
}

/// Something that has a name.
Expand Down Expand Up @@ -4229,7 +4249,14 @@ class Parameter extends ModelElement implements EnclosedElement {
}

@override
String get htmlId => '${_parameter.enclosingElement.name}-param-${name}';
String get htmlId {
String enclosingName = _parameter.enclosingElement.name;
if (_parameter.enclosingElement is GenericFunctionTypeElement) {
// TODO(jcollins-g): Drop when GenericFunctionTypeElement populates name.
enclosingName = _parameter.enclosingElement.enclosingElement.name;
}
return '${enclosingName}-param-${name}';
}

bool get isOptional => _parameter.parameterKind.isOptional;

Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,4 @@ packages:
source: hosted
version: "2.1.12"
sdks:
dart: ">=1.23.0-dev.11.5 <2.0.0"
dart: ">=1.23.0-dev.11.5 <2.0.0-dev.infinity"
9 changes: 9 additions & 0 deletions test/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
Field sFromApple, mFromApple, mInB, autoCompress;
Field isEmpty;
Field implicitGetterExplicitSetter, explicitGetterImplicitSetter;
Field ExtraSpecialListLength;

setUp(() {
c = exLibrary.classes.firstWhere((c) => c.name == 'Apple');
Expand Down Expand Up @@ -1252,8 +1253,16 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
.firstWhere((c) => c.name == 'B')
.allInstanceProperties
.firstWhere((p) => p.name == 'autoCompress');
ExtraSpecialListLength =
fakeLibrary.classes.firstWhere((c) => c.name == 'SpecialList').allInstanceProperties.firstWhere((f) => f.name == 'length');
});

test('inheritance of docs from SDK works for getter/setter combos', () {
expect(ExtraSpecialListLength.getter.documentationFrom.first.element.library.name == 'dart.core', isTrue);
expect(ExtraSpecialListLength.oneLineDoc == '', isFalse);
}, skip:
'Passes on Analyzer 0.31.0+');

test('split inheritance with explicit setter works', () {
expect(implicitGetterExplicitSetter.getter.isInherited, isTrue);
expect(implicitGetterExplicitSetter.setter.isInherited, isFalse);
Expand Down
2 changes: 1 addition & 1 deletion testing/test_package_docs/fake/NewGenericTypedef.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ <h5>library fake</h5>

<section class="multi-line-signature">
<span class="returntype">List&lt;S&gt;</span>
<span class="name ">NewGenericTypedef</span>&lt;S&gt;(<wbr><span class="parameter" id="-param-"><span class="type-annotation">T</span></span> <span class="parameter" id="-param-"><span class="type-annotation">T</span></span> <span class="parameter" id="-param-"><span class="type-annotation">T</span></span>)
<span class="name ">NewGenericTypedef</span>&lt;S&gt;(<wbr><span class="parameter" id="NewGenericTypedef-param-"><span class="type-annotation">T</span></span> <span class="parameter" id="NewGenericTypedef-param-"><span class="type-annotation">T</span></span> <span class="parameter" id="NewGenericTypedef-param-"><span class="type-annotation">T</span></span>)
</section>

<section class="desc markdown">
Expand Down
2 changes: 1 addition & 1 deletion testing/test_package_docs/fake/fake-library.html
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ <h2>Typedefs</h2>

</dd>
<dt id="NewGenericTypedef" class="callable">
<span class="name"><a href="fake/NewGenericTypedef.html">NewGenericTypedef</a></span><span class="signature">&lt;S&gt;(<wbr><span class="parameter" id="-param-"><span class="type-annotation">T</span></span> <span class="parameter" id="-param-"><span class="type-annotation">T</span></span> <span class="parameter" id="-param-"><span class="type-annotation">T</span></span>)
<span class="name"><a href="fake/NewGenericTypedef.html">NewGenericTypedef</a></span><span class="signature">&lt;S&gt;(<wbr><span class="parameter" id="NewGenericTypedef-param-"><span class="type-annotation">T</span></span> <span class="parameter" id="NewGenericTypedef-param-"><span class="type-annotation">T</span></span> <span class="parameter" id="NewGenericTypedef-param-"><span class="type-annotation">T</span></span>)
<span class="returntype parameter">&#8594; List&lt;S&gt;</span>
</span>
</dt>
Expand Down