diff --git a/lib/src/model.dart b/lib/src/model.dart index f074bde57d..5171251a71 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -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(); @@ -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) { @@ -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; @@ -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 _documentationFrom; // TODO(jcollins-g): untangle when mixins can call super @@ -2762,13 +2777,8 @@ abstract class ModelElement extends Nameable List 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(params @@ -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 typeParameters = []; - ModelFunction(FunctionElement element, Library library) + ModelFunctionTyped(FunctionTypedElement element, Library library) : super(element, library) { _modelType = new ElementType(_func.type, this); _calcTypeParameters(); @@ -3162,9 +3185,6 @@ class ModelFunction extends ModelElement return '${canonicalLibrary.dirName}/$fileName'; } - @override - bool get isStatic => _func.isStatic; - @override String get kind => 'function'; @@ -3182,7 +3202,7 @@ class ModelFunction extends ModelElement return '<${typeParameters.map((t) => t.name).join(', ')}>'; } - FunctionElement get _func => (element as FunctionElement); + FunctionTypedElement get _func => (element as FunctionTypedElement); } /// Something that has a name. @@ -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; diff --git a/pubspec.lock b/pubspec.lock index e929856c90..ce8484b9db 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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" diff --git a/test/model_test.dart b/test/model_test.dart index 506d5a7245..9cb8f5d6ed 100644 --- a/test/model_test.dart +++ b/test/model_test.dart @@ -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'); @@ -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); diff --git a/testing/test_package_docs/fake/NewGenericTypedef.html b/testing/test_package_docs/fake/NewGenericTypedef.html index c53e3990e8..35c681ef7e 100644 --- a/testing/test_package_docs/fake/NewGenericTypedef.html +++ b/testing/test_package_docs/fake/NewGenericTypedef.html @@ -120,7 +120,7 @@
library fake
List<S> - NewGenericTypedef<S>(T T T) + NewGenericTypedef<S>(T T T)
diff --git a/testing/test_package_docs/fake/fake-library.html b/testing/test_package_docs/fake/fake-library.html index 2662c0c910..302c93f087 100644 --- a/testing/test_package_docs/fake/fake-library.html +++ b/testing/test_package_docs/fake/fake-library.html @@ -602,7 +602,7 @@

Typedefs

- NewGenericTypedef<S>(T T T) + NewGenericTypedef<S>(T T T) → List<S>