diff --git a/lib/src/element_type.dart b/lib/src/element_type.dart index 553c55161c..3bb9529bb5 100644 --- a/lib/src/element_type.dart +++ b/lib/src/element_type.dart @@ -62,10 +62,6 @@ abstract class ElementType extends Privacy { bool get canHaveParameters => false; - // TODO(jcollins-g): change clients of ElementType to use subtypes more consistently - // and eliminate createLinkedReturnTypeName (instead, using returnType.linkedName); - String createLinkedReturnTypeName() => linkedName; - bool get isTypedef => false; String get linkedName; @@ -90,7 +86,7 @@ abstract class ElementType extends Privacy { } /// An unmodifiable list of this element type's parameters. - List get parameters => const []; + List get parameters; DartType get instantiatedType; @@ -149,22 +145,25 @@ class UndefinedElementType extends ElementType { @override String get linkedName => name; + + @override + // TODO(jcollins-g): remove the need for an empty list here. + List get parameters => []; } /// A FunctionType that does not have an underpinning Element. -class FunctionTypeElementType extends UndefinedElementType { +class FunctionTypeElementType extends UndefinedElementType + with CallableElementTypeMixin { FunctionTypeElementType(DartType f, Library library, PackageGraph packageGraph, ElementType returnedFrom) : super(f, library, packageGraph, returnedFrom); - @override - FunctionType get type => super.type; - @override List get parameters => type.parameters .map((p) => ModelElement.from(p, library, packageGraph) as Parameter) .toList(growable: false); + @override ElementType get returnType => ElementType.from(type.returnType, library, packageGraph, this); @@ -174,11 +173,7 @@ class FunctionTypeElementType extends UndefinedElementType { return _linkedName; } - @override - String createLinkedReturnTypeName() => returnType.linkedName; - String _nameWithGenerics; - @override String get nameWithGenerics { _nameWithGenerics ??= _renderer.renderNameWithGenerics(this); @@ -216,7 +211,7 @@ class ParameterizedElementType extends DefinedElementType { return _nameWithGenerics; } - ElementTypeRenderer get _renderer => + ElementTypeRenderer get _renderer => packageGraph.rendererFactory.parameterizedElementTypeRenderer; } @@ -281,9 +276,6 @@ abstract class DefinedElementType extends ElementType { return _returnType; } - @override - String createLinkedReturnTypeName() => returnType.linkedName; - Iterable _typeArguments; /// An unmodifiable list of this element type's parameters. @@ -341,13 +333,14 @@ abstract class DefinedElementType extends ElementType { } /// Any callable ElementType will mix-in this class, whether anonymous or not. -abstract class CallableElementTypeMixin implements ParameterizedElementType { - @override +abstract class CallableElementTypeMixin implements ElementType { + Iterable _typeArguments; + ModelElement get returnElement => returnType is DefinedElementType ? (returnType as DefinedElementType).element : null; - @override + ElementType _returnType; ElementType get returnType { _returnType ??= ElementType.from(type.returnType, library, packageGraph, this); @@ -357,7 +350,6 @@ abstract class CallableElementTypeMixin implements ParameterizedElementType { @override FunctionType get type => _type; - @override // TODO(jcollins-g): Rewrite this and improve object model so this doesn't // require type checking everywhere. Iterable get typeArguments { @@ -414,12 +406,16 @@ class CallableElementType extends ParameterizedElementType @override String get linkedName { - _linkedName ??= _renderer.renderLinkedName(this); + if (_linkedName == null) { + if (name != null && name.isNotEmpty) { + _linkedName = super.linkedName; + } else { + _linkedName = _renderer.renderLinkedName(this); + } + } return _linkedName; } - String get superLinkedName => super.linkedName; - @override ElementTypeRenderer get _renderer => packageGraph.rendererFactory.callableElementTypeRenderer; diff --git a/lib/src/model/accessor.dart b/lib/src/model/accessor.dart index ff84496267..831b93ca16 100644 --- a/lib/src/model/accessor.dart +++ b/lib/src/model/accessor.dart @@ -4,6 +4,7 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/src/dart/element/member.dart' show Member; +import 'package:dartdoc/src/element_type.dart'; import 'package:dartdoc/src/model/model.dart'; import 'package:dartdoc/src/render/source_code_renderer.dart'; import 'package:dartdoc/src/utils.dart'; @@ -18,10 +19,8 @@ class Accessor extends ModelElement implements EnclosedElement { [Member /*?*/ originalMember]) : super(element, library, packageGraph, originalMember); - String get linkedReturnType { - assert(isGetter); - return modelType.createLinkedReturnTypeName(); - } + @override + CallableElementTypeMixin get modelType => super.modelType; bool get isSynthetic => element.isSynthetic; diff --git a/lib/src/model/field.dart b/lib/src/model/field.dart index dcf4570f56..0b464dc03e 100644 --- a/lib/src/model/field.dart +++ b/lib/src/model/field.dart @@ -4,7 +4,6 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/src/dart/element/element.dart'; -import 'package:dartdoc/src/element_type.dart'; import 'package:dartdoc/src/model/model.dart'; import 'package:dartdoc/src/render/source_code_renderer.dart'; @@ -199,9 +198,6 @@ class Field extends ModelElement } } - @override - CallableElementType get modelType => super.modelType; - @override Inheritable get overriddenElement => null; } diff --git a/lib/src/model/getter_setter_combo.dart b/lib/src/model/getter_setter_combo.dart index 7b17289bb2..f9c8006cd5 100644 --- a/lib/src/model/getter_setter_combo.dart +++ b/lib/src/model/getter_setter_combo.dart @@ -8,6 +8,7 @@ import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/source/line_info.dart'; import 'package:analyzer/src/dart/element/element.dart'; +import 'package:dartdoc/src/element_type.dart'; import 'package:dartdoc/src/model/model.dart'; import 'package:dartdoc/src/utils.dart'; import 'package:dartdoc/src/warnings.dart'; @@ -179,14 +180,10 @@ mixin GetterSetterCombo on ModelElement { return buffer.toString(); } - String get linkedReturnType { - if (hasGetter) { - return getter.linkedReturnType; - } else { - // TODO(jcollins-g): this results in the wrong span class for the return - // type. - return setter.linkedParamsNoMetadataOrNames; - } + @override + ElementType get modelType { + if (hasGetter) return getter.modelType.returnType; + return setter.parameters.first.modelType; } @override diff --git a/lib/src/model/method.dart b/lib/src/model/method.dart index 496cb1d494..8583a440eb 100644 --- a/lib/src/model/method.dart +++ b/lib/src/model/method.dart @@ -5,6 +5,7 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/source/line_info.dart'; import 'package:analyzer/src/dart/element/member.dart' show Member; +import 'package:dartdoc/src/element_type.dart'; import 'package:dartdoc/src/model/model.dart'; class Method extends ModelElement @@ -92,7 +93,8 @@ class Method extends ModelElement @override String get kind => 'method'; - String get linkedReturnType => modelType.createLinkedReturnTypeName(); + @override + CallableElementTypeMixin get modelType => super.modelType; @override Method get overriddenElement { diff --git a/lib/src/model/model_function.dart b/lib/src/model/model_function.dart index e5db7fab74..bb6c4ccca7 100644 --- a/lib/src/model/model_function.dart +++ b/lib/src/model/model_function.dart @@ -66,8 +66,6 @@ class ModelFunctionTyped extends ModelElement @override String get kind => 'function'; - String get linkedReturnType => modelType.createLinkedReturnTypeName(); - // Food for mustache. TODO(jcollins-g): what about enclosing elements? bool get isInherited => false; diff --git a/lib/src/model/top_level_variable.dart b/lib/src/model/top_level_variable.dart index 0128736ab5..bf0c2fc317 100644 --- a/lib/src/model/top_level_variable.dart +++ b/lib/src/model/top_level_variable.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/element.dart'; -import 'package:dartdoc/src/element_type.dart'; import 'package:dartdoc/src/model/model.dart'; /// Top-level variables. But also picks up getters and setters? @@ -86,8 +85,5 @@ class TopLevelVariable extends ModelElement @override String get fileName => '${isConst ? '$name-constant' : name}.$fileType'; - @override - DefinedElementType get modelType => super.modelType; - TopLevelVariableElement get _variable => (element as TopLevelVariableElement); } diff --git a/lib/src/model/typedef.dart b/lib/src/model/typedef.dart index 07f10bfd2f..1401da1c7f 100644 --- a/lib/src/model/typedef.dart +++ b/lib/src/model/typedef.dart @@ -4,6 +4,7 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; +import 'package:dartdoc/src/element_type.dart'; import 'package:dartdoc/src/model/model.dart'; import 'package:dartdoc/src/render/typedef_renderer.dart'; @@ -49,8 +50,6 @@ class Typedef extends ModelElement @override String get kind => 'typedef'; - String get linkedReturnType => modelType.createLinkedReturnTypeName(); - @override List get typeParameters => element.typeParameters.map((f) { return ModelElement.from(f, library, packageGraph) as TypeParameter; @@ -79,4 +78,7 @@ class FunctionTypedef extends Typedef { } return super.genericTypeParameters; } + + @override + CallableElementTypeMixin get modelType => super.modelType; } diff --git a/lib/src/render/element_type_renderer.dart b/lib/src/render/element_type_renderer.dart index 66124adae5..bd474c1d09 100644 --- a/lib/src/render/element_type_renderer.dart +++ b/lib/src/render/element_type_renderer.dart @@ -87,10 +87,6 @@ class CallableElementTypeRendererHtml extends ElementTypeRenderer { @override String renderLinkedName(CallableElementType elementType) { - if (elementType.name != null && elementType.name.isNotEmpty) { - return elementType.superLinkedName; - } - var buf = StringBuffer(); buf.write(elementType.nameWithGenerics); buf.write('('); @@ -168,15 +164,11 @@ class CallableElementTypeRendererMd extends ElementTypeRenderer { @override String renderLinkedName(CallableElementType elementType) { - if (elementType.name != null && elementType.name.isNotEmpty) { - return elementType.superLinkedName; - } - var buf = StringBuffer(); buf.write(elementType.nameWithGenerics); buf.write('('); buf.write(ParameterRendererMd() - .renderLinkedParams(elementType.element.parameters, showNames: false) + .renderLinkedParams(elementType.parameters, showNames: false) .trim()); buf.write(') → '); buf.write(elementType.returnType.linkedName); diff --git a/lib/src/render/parameter_renderer.dart b/lib/src/render/parameter_renderer.dart index c92c66503c..5f932e74ec 100644 --- a/lib/src/render/parameter_renderer.dart +++ b/lib/src/render/parameter_renderer.dart @@ -165,13 +165,12 @@ abstract class ParameterRenderer { if (param.isCovariant) { buf.write(covariant('covariant') + ' '); } - if (paramModelType is CallableElementTypeMixin || - paramModelType.type is FunctionType) { + if (paramModelType is CallableElementTypeMixin) { String returnTypeName; if (paramModelType.isTypedef) { returnTypeName = paramModelType.linkedName; } else { - returnTypeName = paramModelType.createLinkedReturnTypeName(); + returnTypeName = paramModelType.returnType.linkedName; } buf.write(typeName(returnTypeName)); if (showNames) { @@ -182,8 +181,10 @@ abstract class ParameterRenderer { } if (!paramModelType.isTypedef && paramModelType is DefinedElementType) { buf.write('('); - buf.write(renderLinkedParams(paramModelType.element.parameters, - showMetadata: showMetadata, showNames: showNames)); + buf.write(renderLinkedParams( + (paramModelType as DefinedElementType).element.parameters, + showMetadata: showMetadata, + showNames: showNames)); buf.write(')'); buf.write(paramModelType.nullabilitySuffix); } diff --git a/lib/templates/html/_accessor_getter.html b/lib/templates/html/_accessor_getter.html index 4bc9e08e2d..9f3cf4dcf1 100644 --- a/lib/templates/html/_accessor_getter.html +++ b/lib/templates/html/_accessor_getter.html @@ -2,7 +2,7 @@
- {{{ linkedReturnType }}} + {{{ modelType.returnType.linkedName }}} {{>name_summary}} {{>features}}
diff --git a/lib/templates/html/_callable.html b/lib/templates/html/_callable.html index 7fb911b573..bc864dc735 100644 --- a/lib/templates/html/_callable.html +++ b/lib/templates/html/_callable.html @@ -1,6 +1,6 @@
{{{linkedName}}}{{{linkedGenericParameters}}}({{{ linkedParamsNoMetadata }}}) - → {{{ linkedReturnType }}} + → {{{ modelType.returnType.linkedName }}} {{>categorization}}
diff --git a/lib/templates/html/_callable_multiline.html b/lib/templates/html/_callable_multiline.html index ab0fa11769..78afd0c7f5 100644 --- a/lib/templates/html/_callable_multiline.html +++ b/lib/templates/html/_callable_multiline.html @@ -8,5 +8,5 @@ {{/hasAnnotations}} -{{{ linkedReturnType }}} +{{{ modelType.returnType.linkedName }}} {{>name_summary}}{{{genericParameters}}}({{#hasParameters}}{{{linkedParamsLines}}}{{/hasParameters}}) diff --git a/lib/templates/html/_constant.html b/lib/templates/html/_constant.html index 72d367c667..f12c94d20a 100644 --- a/lib/templates/html/_constant.html +++ b/lib/templates/html/_constant.html @@ -1,6 +1,6 @@
{{{ linkedName }}} - → const {{{ linkedReturnType }}} + → const {{{ modelType.linkedName }}} {{>categorization}}
diff --git a/lib/templates/html/_property.html b/lib/templates/html/_property.html index 09f61f67e0..dc58959e80 100644 --- a/lib/templates/html/_property.html +++ b/lib/templates/html/_property.html @@ -1,6 +1,6 @@
{{{linkedName}}} - {{{ arrow }}} {{{ linkedReturnType }}} {{>categorization}} + {{{ arrow }}} {{{ modelType.linkedName }}} {{>categorization}}
{{{ oneLineDoc }}} {{{ extendedDocLink }}} diff --git a/lib/templates/html/_type.html b/lib/templates/html/_type.html index 7ac5632cfc..8adc172135 100644 --- a/lib/templates/html/_type.html +++ b/lib/templates/html/_type.html @@ -1,7 +1,6 @@
{{{linkedName}}}{{{linkedGenericParameters}}} - = - {{{ linkedReturnType }}} + = {{{ modelType.linkedName }}} {{>categorization}}
diff --git a/lib/templates/html/_type_multiline.html b/lib/templates/html/_type_multiline.html index 71b80368df..987a3f7e8f 100644 --- a/lib/templates/html/_type_multiline.html +++ b/lib/templates/html/_type_multiline.html @@ -7,4 +7,4 @@ {{/hasAnnotations}} -{{>name_summary}}{{{genericParameters}}} = {{{linkedReturnType}}} +{{>name_summary}}{{{genericParameters}}} = {{{modelType.linkedName}}} diff --git a/lib/templates/html/property.html b/lib/templates/html/property.html index a3dbf40e85..5044c41c05 100644 --- a/lib/templates/html/property.html +++ b/lib/templates/html/property.html @@ -14,7 +14,7 @@
{{parent.name}} {{parent.kind}}
{{#self}} {{#hasNoGetterSetter}}
- {{{ linkedReturnType }}} + {{{ modelType.linkedName }}} {{>name_summary}} {{>features}}
diff --git a/lib/templates/html/top_level_property.html b/lib/templates/html/top_level_property.html index 49565c6c01..7f9c734dc5 100644 --- a/lib/templates/html/top_level_property.html +++ b/lib/templates/html/top_level_property.html @@ -12,7 +12,7 @@
{{parent.name}} {{parent.kind}}
{{#hasNoGetterSetter}}
- {{{ linkedReturnType }}} + {{{ modelType.linkedName }}} {{>name_summary}} {{>features}}
diff --git a/lib/templates/md/_accessor_getter.md b/lib/templates/md/_accessor_getter.md index b04c749201..fb07e7f650 100644 --- a/lib/templates/md/_accessor_getter.md +++ b/lib/templates/md/_accessor_getter.md @@ -1,5 +1,5 @@ {{#getter}} -{{{ linkedReturnType }}} {{>name_summary}} {{!two spaces intentional}} +{{{ modelType.returnType.linkedName }}} {{>name_summary}} {{!two spaces intentional}} {{>features}} {{>documentation}} diff --git a/lib/templates/md/_callable.md b/lib/templates/md/_callable.md index 12560c75fd..c56df18e06 100644 --- a/lib/templates/md/_callable.md +++ b/lib/templates/md/_callable.md @@ -1,4 +1,4 @@ -##### {{{linkedName}}}{{{linkedGenericParameters}}}({{{ linkedParamsNoMetadata }}}) {{{ linkedReturnType }}} +##### {{{linkedName}}}{{{linkedGenericParameters}}}({{{ linkedParamsNoMetadata }}}) {{{ modelType.returnType.linkedName }}} {{>categorization}} {{{ oneLineDoc }}} {{{ extendedDocLink }}} {{!two spaces intentional}} diff --git a/lib/templates/md/_callable_multiline.md b/lib/templates/md/_callable_multiline.md index cec0056a7e..edb8b9d1e6 100644 --- a/lib/templates/md/_callable_multiline.md +++ b/lib/templates/md/_callable_multiline.md @@ -4,4 +4,4 @@ {{/annotations}} {{/hasAnnotations}} -{{{ linkedReturnType }}} {{>name_summary}}{{{genericParameters}}}({{#hasParameters}}{{{linkedParamsLines}}}{{/hasParameters}}) +{{{ modelType.returnType.linkedName }}} {{>name_summary}}{{{genericParameters}}}({{#hasParameters}}{{{linkedParamsLines}}}{{/hasParameters}}) diff --git a/lib/templates/md/_constant.md b/lib/templates/md/_constant.md index c7e3745c61..c36fc1d32e 100644 --- a/lib/templates/md/_constant.md +++ b/lib/templates/md/_constant.md @@ -1,4 +1,4 @@ -##### {{{ linkedName }}} const {{{ linkedReturnType }}} +##### {{{ linkedName }}} const {{{ modelType.linkedName }}} {{>categorization}} {{{ oneLineDoc }}} {{{ extendedDocLink }}} {{!two spaces intentional}} diff --git a/lib/templates/md/_property.md b/lib/templates/md/_property.md index 64883efda1..110f42c23a 100644 --- a/lib/templates/md/_property.md +++ b/lib/templates/md/_property.md @@ -1,4 +1,4 @@ -##### {{{linkedName}}} {{{ arrow }}} {{{ linkedReturnType }}} +##### {{{linkedName}}} {{{ arrow }}} {{{ modelType.linkedName }}} {{>categorization}} {{{ oneLineDoc }}} {{{ extendedDocLink }}} {{!two spaces intentional}} diff --git a/lib/templates/md/_type.md b/lib/templates/md/_type.md index 12560c75fd..39a16f3bfd 100644 --- a/lib/templates/md/_type.md +++ b/lib/templates/md/_type.md @@ -1,4 +1,4 @@ -##### {{{linkedName}}}{{{linkedGenericParameters}}}({{{ linkedParamsNoMetadata }}}) {{{ linkedReturnType }}} +##### {{{linkedName}}}{{{linkedGenericParameters}}}({{{ linkedParamsNoMetadata }}}) {{{ modelType.linkedName }}} {{>categorization}} {{{ oneLineDoc }}} {{{ extendedDocLink }}} {{!two spaces intentional}} diff --git a/lib/templates/md/_type_multiline.md b/lib/templates/md/_type_multiline.md index adfbd36058..e25431310b 100644 --- a/lib/templates/md/_type_multiline.md +++ b/lib/templates/md/_type_multiline.md @@ -4,4 +4,4 @@ {{/annotations}} {{/hasAnnotations}} -{{>name_summary}}{{{genericParameters}}} = {{{linkedReturnType}}} +{{>name_summary}}{{{genericParameters}}} = {{{modelType.linkedName}}} diff --git a/lib/templates/md/property.md b/lib/templates/md/property.md index 222c5e26c9..b59b778f4d 100644 --- a/lib/templates/md/property.md +++ b/lib/templates/md/property.md @@ -9,7 +9,7 @@ {{#self}} {{#hasNoGetterSetter}} -{{{ linkedReturnType }}} {{>name_summary}} {{!two spaces intentional}} +{{{ modelType.linkedName }}} {{>name_summary}} {{!two spaces intentional}} {{>features}} {{>documentation}} diff --git a/lib/templates/md/top_level_property.md b/lib/templates/md/top_level_property.md index 43a5ffc955..8d17ea5205 100644 --- a/lib/templates/md/top_level_property.md +++ b/lib/templates/md/top_level_property.md @@ -8,7 +8,7 @@ {{>feature_set}} {{#hasNoGetterSetter}} -{{{ linkedReturnType }}} {{>name_summary}} {{!two spaces intentional}} +{{{ modelType.linkedName }}} {{>name_summary}} {{!two spaces intentional}} {{>features}} {{>documentation}} diff --git a/test/end2end/model_special_cases_test.dart b/test/end2end/model_special_cases_test.dart index 9d8ea3ab16..893589921c 100644 --- a/test/end2end/model_special_cases_test.dart +++ b/test/end2end/model_special_cases_test.dart @@ -82,6 +82,7 @@ void main() { group('generalized typedefs', () { Library generalizedTypedefs; Typedef T0, T1, T2, T3, T4, T5, T6, T7; + Class C, C2; setUpAll(() async { generalizedTypedefs = (await _testPackageGraphExperiments) @@ -95,6 +96,8 @@ void main() { T5 = generalizedTypedefs.typedefs.firstWhere((a) => a.name == 'T5'); T6 = generalizedTypedefs.typedefs.firstWhere((a) => a.name == 'T6'); T7 = generalizedTypedefs.typedefs.firstWhere((a) => a.name == 'T7'); + C = generalizedTypedefs.classes.firstWhere((c) => c.name == 'C'); + C2 = generalizedTypedefs.classes.firstWhere((c) => c.name == 'C2'); }); void expectTypedefs(Typedef t, String modelTypeToString, @@ -104,6 +107,27 @@ void main() { orderedEquals(genericParameters)); } + test('typedef references display aliases', () { + var f = C.allFields.firstWhere((f) => f.name == 'f'); + var g = C.instanceMethods.firstWhere((m) => m.name == 'g'); + var a = generalizedTypedefs.properties.firstWhere((p) => p.name == 'a'); + var b = C2.allFields.firstWhere((f) => f.name == 'b'); + var c = C2.allFields.firstWhere((f) => f.name == 'c'); + var d = C2.instanceMethods.firstWhere((f) => f.name == 'd'); + + expect(a.modelType.name, equals('T0')); + expect(b.modelType.name, equals('T0')); + expect(c.modelType.name, equals('T1')); + expect(d.modelType.returnType.name, equals('T2')); + expect(d.parameters.first.modelType.name, equals('T3')); + expect(d.parameters.last.modelType.name, equals('T4')); + + expect(f.modelType.name, equals('T0')); + expect(g.modelType.returnType.name, equals('T1')); + expect(g.modelType.parameters.first.modelType.name, equals('T2')); + expect(g.modelType.parameters.last.modelType.name, equals('T3')); + }, skip: 'dart-lang/sdk#45921'); + test('basic non-function typedefs work', () { expectTypedefs(T0, 'void', []); expectTypedefs(T1, 'Function', []); diff --git a/test/end2end/model_test.dart b/test/end2end/model_test.dart index 1454765bbb..237fafa09a 100644 --- a/test/end2end/model_test.dart +++ b/test/end2end/model_test.dart @@ -215,19 +215,19 @@ void main() { // analyzer instead of setting up 'isLate'. expect(c.instanceFields.any((f) => f.name == 'late'), isFalse); - expect(a.modelType.returnType.name, equals('dynamic')); + expect(a.modelType.name, equals('dynamic')); expect(a.isLate, isTrue); expect(a.features, contains('late')); - expect(b.modelType.returnType.name, equals('int')); + expect(b.modelType.name, equals('int')); expect(b.isLate, isTrue); expect(b.features, contains('late')); - expect(cField.modelType.returnType.name, equals('dynamic')); + expect(cField.modelType.name, equals('dynamic')); expect(cField.isLate, isTrue); expect(cField.features, contains('late')); - expect(dField.modelType.returnType.name, equals('double')); + expect(dField.modelType.name, equals('double')); expect(dField.isLate, isTrue); expect(dField.features, contains('late')); }); @@ -235,7 +235,7 @@ void main() { test('Late final top level variables', () { var initializeMe = lateFinalWithoutInitializer.publicProperties .firstWhere((v) => v.name == 'initializeMe'); - expect(initializeMe.modelType.returnType.name, equals('String')); + expect(initializeMe.modelType.name, equals('String')); expect(initializeMe.isLate, isTrue); expect(initializeMe.features, contains('late')); }); @@ -260,12 +260,13 @@ void main() { equals( 'ComplexNullableMembers<T extends String?>')); expect( - aComplexType.linkedReturnType, + aComplexType.modelType.linkedName, equals( 'Map<T?, String?>')); - expect(aComplexSetterOnlyType.linkedReturnType, equals( - // TODO(jcollins-g): fix wrong span class for setter-only return type (#2226) - 'List<Map<T?, String?>?>')); + expect( + aComplexSetterOnlyType.modelType.linkedName, + equals( + 'List<Map<T?, String?>?>')); }); test('simple nullable elements are detected and rendered correctly', () { @@ -281,16 +282,17 @@ void main() { .firstWhere((f) => f.name == 'operator *'); expect(nullableMembers.isNullSafety, isTrue); expect( - nullableField.linkedReturnType, + nullableField.modelType.linkedName, equals( 'Iterable<BigInt>?')); expect( methodWithNullables.linkedParams, equals( 'String? foo')); - expect(methodWithNullables.linkedReturnType, equals('int?')); expect( - initialized.linkedReturnType, + methodWithNullables.modelType.returnType.linkedName, equals('int?')); + expect( + initialized.modelType.linkedName, equals( 'Map<String, Map>?')); expect( @@ -324,25 +326,44 @@ void main() { test('Set literals test', () { expect(aComplexSet.modelType.name, equals('Set')); - expect(aComplexSet.modelType.typeArguments.map((a) => a.name).toList(), + expect( + (aComplexSet.modelType as ParameterizedElementType) + .typeArguments + .map((a) => a.name) + .toList(), equals(['AClassContainingLiterals'])); expect(aComplexSet.constantValue, equals('const {const AClassContainingLiterals(3, 5)}')); expect(inferredTypeSet.modelType.name, equals('Set')); expect( - inferredTypeSet.modelType.typeArguments.map((a) => a.name).toList(), + (inferredTypeSet.modelType as ParameterizedElementType) + .typeArguments + .map((a) => a.name) + .toList(), equals(['int'])); expect(inferredTypeSet.constantValue, equals('const {1, 3, 5}')); expect(specifiedSet.modelType.name, equals('Set')); - expect(specifiedSet.modelType.typeArguments.map((a) => a.name).toList(), + expect( + (specifiedSet.modelType as ParameterizedElementType) + .typeArguments + .map((a) => a.name) + .toList(), equals(['int'])); expect(specifiedSet.constantValue, equals('const {}')); expect(untypedMap.modelType.name, equals('Map')); - expect(untypedMap.modelType.typeArguments.map((a) => a.name).toList(), + expect( + (untypedMap.modelType as ParameterizedElementType) + .typeArguments + .map((a) => a.name) + .toList(), equals(['dynamic', 'dynamic'])); expect(untypedMap.constantValue, equals('const {}')); expect(typedSet.modelType.name, equals('Set')); - expect(typedSet.modelType.typeArguments.map((a) => a.name).toList(), + expect( + (typedSet.modelType as ParameterizedElementType) + .typeArguments + .map((a) => a.name) + .toList(), equals(['String'])); expect(typedSet.constantValue, matches(RegExp(r'const <String>\s?{}'))); @@ -1908,13 +1929,14 @@ void main() { equals('${htmlBasePlaceholder}ex/Deprecated/expires.html')); }); - test('exported class should have linkedReturnType for the current library', + test( + 'exported class should have modelType.returnType.linkedName for the current library', () { var returnCool = Cool.instanceMethods .firstWhere((m) => m.name == 'returnCool', orElse: () => null); expect(returnCool, isNotNull); expect( - returnCool.linkedReturnType, + returnCool.modelType.returnType.linkedName, equals( 'Cool')); }); @@ -2416,7 +2438,7 @@ void main() { test('async function', () { expect(thisIsAsync.isAsynchronous, isTrue); - expect(thisIsAsync.linkedReturnType, equals('Future')); + expect(thisIsAsync.modelType.returnType.linkedName, equals('Future')); expect( thisIsAsync.documentation, equals( @@ -2429,13 +2451,14 @@ void main() { test('function returning FutureOr', () { expect(thisIsFutureOr.isAsynchronous, isFalse); - expect(thisIsFutureOr.linkedReturnType, equals('FutureOr')); + expect( + thisIsFutureOr.modelType.returnType.linkedName, equals('FutureOr')); }); test('function returning FutureOr', () { expect(thisIsFutureOrNull.isAsynchronous, isFalse); expect( - thisIsFutureOrNull.linkedReturnType, + thisIsFutureOrNull.modelType.returnType.linkedName, equals( 'FutureOr<Null>')); }); @@ -2443,7 +2466,7 @@ void main() { test('function returning FutureOr', () { expect(thisIsFutureOrNull.isAsynchronous, isFalse); expect( - thisIsFutureOrT.linkedReturnType, + thisIsFutureOrT.modelType.returnType.linkedName, equals( 'FutureOr<T>')); }); @@ -2541,24 +2564,21 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, .singleWhere((f) => f.name == 'explicitSetter'); // TODO(jcollins-g): really, these shouldn't be called "parameters" in // the span class. - expect( - explicitSetter.linkedReturnType, - 'dynamic Function(int, ' - 'Cool, ' - 'List<int>)'); + expect(explicitSetter.modelType.linkedName, + 'dynamic Function(int bar, Cool baz, List<int> macTruck)'); }); test('parameterized type from field is correctly displayed', () { var aField = TemplatedInterface.instanceFields .singleWhere((f) => f.name == 'aField'); - expect(aField.linkedReturnType, + expect(aField.modelType.linkedName, 'AnotherParameterizedClass<Stream<List<int>>>'); }); test('parameterized type from inherited field is correctly displayed', () { var aInheritedField = TemplatedInterface.inheritedFields .singleWhere((f) => f.name == 'aInheritedField'); - expect(aInheritedField.linkedReturnType, + expect(aInheritedField.modelType.linkedName, 'AnotherParameterizedClass<List<int>>'); }); @@ -2568,7 +2588,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, Accessor aGetter = TemplatedInterface.instanceFields .singleWhere((f) => f.name == 'aGetter') .getter; - expect(aGetter.linkedReturnType, + expect(aGetter.modelType.returnType.linkedName, 'AnotherParameterizedClass<Map<A, List<String>>>'); }); @@ -2578,7 +2598,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, Accessor aInheritedGetter = TemplatedInterface.inheritedFields .singleWhere((f) => f.name == 'aInheritedGetter') .getter; - expect(aInheritedGetter.linkedReturnType, + expect(aInheritedGetter.modelType.returnType.linkedName, 'AnotherParameterizedClass<List<int>>'); }); @@ -2590,10 +2610,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, .setter; expect(aInheritedSetter.allParameters.first.modelType.linkedName, 'AnotherParameterizedClass<List<int>>'); - // TODO(jcollins-g): really, these shouldn't be called "parameters" in - // the span class. - expect(aInheritedSetter.enclosingCombo.linkedReturnType, - 'AnotherParameterizedClass<List<int>>'); + expect(aInheritedSetter.enclosingCombo.modelType.linkedName, + 'AnotherParameterizedClass<List<int>>'); }); test( @@ -2601,7 +2619,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, () { var aMethodInterface = TemplatedInterface.instanceMethods .singleWhere((m) => m.name == 'aMethodInterface'); - expect(aMethodInterface.linkedReturnType, + expect(aMethodInterface.modelType.returnType.linkedName, 'AnotherParameterizedClass<List<int>>'); }); @@ -2610,7 +2628,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, () { var aInheritedMethod = TemplatedInterface.instanceMethods .singleWhere((m) => m.name == 'aInheritedMethod'); - expect(aInheritedMethod.linkedReturnType, + expect(aInheritedMethod.modelType.returnType.linkedName, 'AnotherParameterizedClass<List<int>>'); }); @@ -2619,7 +2637,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, () { var aTypedefReturningMethodInterface = TemplatedInterface.instanceMethods .singleWhere((m) => m.name == 'aTypedefReturningMethodInterface'); - expect(aTypedefReturningMethodInterface.linkedReturnType, + expect(aTypedefReturningMethodInterface.modelType.returnType.linkedName, 'ParameterizedTypedef<List<String>>'); }); @@ -2628,7 +2646,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, () { var aInheritedTypedefReturningMethod = TemplatedInterface.instanceMethods .singleWhere((m) => m.name == 'aInheritedTypedefReturningMethod'); - expect(aInheritedTypedefReturningMethod.linkedReturnType, + expect(aInheritedTypedefReturningMethod.modelType.returnType.linkedName, 'ParameterizedTypedef<List<int>>'); }); @@ -2636,7 +2654,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, () { var aInheritedAdditionOperator = TemplatedInterface.inheritedOperators .singleWhere((m) => m.name == 'operator +'); - expect(aInheritedAdditionOperator.linkedReturnType, + expect(aInheritedAdditionOperator.modelType.returnType.linkedName, 'ParameterizedClass<List<int>>'); expect( ParameterRendererHtml() @@ -2702,7 +2720,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, test('verify parameter types are correctly displayed', () { expect( - getAFunctionReturningVoid.linkedReturnType, + getAFunctionReturningVoid.modelType.returnType.linkedName, equals( 'void Function(T1, T2)')); }); @@ -2711,7 +2729,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, 'verify type parameters to anonymous functions are distinct from normal parameters and instantiated type parameters from method, displayed correctly', () { expect( - getAFunctionReturningBool.linkedReturnType, + getAFunctionReturningBool.modelType.returnType.linkedName, equals( 'bool Function<T4>(String, T1, T4)')); }); @@ -2781,11 +2799,11 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, }); test('return type', () { - expect(isGreaterThan.modelType.createLinkedReturnTypeName(), 'bool'); + expect(isGreaterThan.modelType.returnType.linkedName, 'bool'); }); test('return type has Future', () { - expect(m7.linkedReturnType, contains('Future')); + expect(m7.modelType.returnType.linkedName, contains('Future')); }); test('parameter has generics in signature', () { @@ -2795,7 +2813,11 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, test('parameter is a function', () { var functionArgParam = m4.parameters[1]; - expect(functionArgParam.modelType.createLinkedReturnTypeName(), 'String'); + expect( + (functionArgParam.modelType as CallableElementTypeMixin) + .returnType + .linkedName, + 'String'); }); test('method overrides another', () { @@ -3258,7 +3280,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, final fieldWithTypedef = apple.instanceFields.firstWhere((m) => m.name == 'fieldWithTypedef'); expect( - fieldWithTypedef.linkedReturnType, + fieldWithTypedef.modelType.linkedName, equals( 'ParameterizedTypedef<bool>')); }); @@ -3312,8 +3334,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, 'Verify that a map containing anonymous functions as values works correctly', () { var typeArguments = - (importantComputations.modelType.returnType as DefinedElementType) - .typeArguments; + (importantComputations.modelType as DefinedElementType).typeArguments; expect(typeArguments, isNotEmpty); expect( typeArguments.last.linkedName, @@ -3322,7 +3343,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, matches(RegExp( r'(dynamic|num) Function\(List<num> a\)'))); expect( - importantComputations.linkedReturnType, + importantComputations.modelType.linkedName, matches(RegExp( r'Map<int, (dynamic|num) Function\(List<num> a\)>'))); }); @@ -3331,7 +3352,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, 'Verify that a complex type parameter with an anonymous function works correctly', () { expect( - complicatedReturn.linkedReturnType, + complicatedReturn.modelType.linkedName, equals( 'ATypeTakingClass<String Function(int)>')); }); @@ -3369,11 +3390,10 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, }); test('type arguments are correct', () { - expect(mapWithDynamicKeys.modelType.typeArguments, hasLength(2)); - expect(mapWithDynamicKeys.modelType.typeArguments.first.name, - equals('dynamic')); - expect(mapWithDynamicKeys.modelType.typeArguments.last.name, - equals('String')); + var modelType = mapWithDynamicKeys.modelType as ParameterizedElementType; + expect(modelType.typeArguments, hasLength(2)); + expect(modelType.typeArguments.first.name, equals('dynamic')); + expect(modelType.typeArguments.last.name, equals('String')); }); test('has enclosing element', () { @@ -3385,11 +3405,11 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, }); test('linked return type is a double', () { - expect(v.linkedReturnType, 'double'); + expect(v.modelType.linkedName, 'double'); }); test('linked return type is dynamic', () { - expect(v3.linkedReturnType, 'dynamic'); + expect(v3.modelType.linkedName, 'dynamic'); }); test('just a getter has documentation', () { @@ -3608,7 +3628,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, test('a function returning a Future', () { expect( - returningFutureVoid.linkedReturnType, + returningFutureVoid.modelType.returnType.linkedName, equals( 'Future<void>')); }); @@ -3677,9 +3697,9 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, }); group('Typedef', () { - Typedef processMessage; - Typedef generic; - Typedef aComplexTypedef; + FunctionTypedef processMessage; + FunctionTypedef generic; + FunctionTypedef aComplexTypedef; Class TypedefUsingClass; setUpAll(() { @@ -3706,7 +3726,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, test('anonymous nested functions inside typedefs are handled', () { expect(aComplexTypedef, isNotNull); - expect(aComplexTypedef.linkedReturnType, startsWith('void Function')); + expect(aComplexTypedef.modelType.returnType.linkedName, + startsWith('void Function')); expect( aComplexTypedef.nameWithGenerics, equals( @@ -3716,7 +3737,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, test('anonymous nested functions inside typedefs are handled correctly', () { expect( - aComplexTypedef.linkedReturnType, + aComplexTypedef.modelType.returnType.linkedName, equals( 'void Function(A1, A2, A3)')); expect( @@ -3744,9 +3765,9 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, }); test('linked return type', () { - expect(processMessage.linkedReturnType, equals('String')); + expect(processMessage.modelType.returnType.linkedName, equals('String')); expect( - generic.linkedReturnType, + generic.modelType.returnType.linkedName, equals( 'List<S>')); }); @@ -3852,7 +3873,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, }); test('async return type', () { - expect(asyncM.linkedReturnType, 'Future'); + expect(asyncM.modelType.returnType.linkedName, 'Future'); }); test('param with generics', () { diff --git a/testing/test_package_custom_templates/templates/_accessor_getter.html b/testing/test_package_custom_templates/templates/_accessor_getter.html index 4bc9e08e2d..9f3cf4dcf1 100644 --- a/testing/test_package_custom_templates/templates/_accessor_getter.html +++ b/testing/test_package_custom_templates/templates/_accessor_getter.html @@ -2,7 +2,7 @@
- {{{ linkedReturnType }}} + {{{ modelType.returnType.linkedName }}} {{>name_summary}} {{>features}}
diff --git a/testing/test_package_custom_templates/templates/_callable.html b/testing/test_package_custom_templates/templates/_callable.html index 7fb911b573..bc864dc735 100644 --- a/testing/test_package_custom_templates/templates/_callable.html +++ b/testing/test_package_custom_templates/templates/_callable.html @@ -1,6 +1,6 @@
{{{linkedName}}}{{{linkedGenericParameters}}}({{{ linkedParamsNoMetadata }}}) - → {{{ linkedReturnType }}} + → {{{ modelType.returnType.linkedName }}} {{>categorization}}
diff --git a/testing/test_package_custom_templates/templates/_callable_multiline.html b/testing/test_package_custom_templates/templates/_callable_multiline.html index 4d0bce92a5..dc1b17290c 100644 --- a/testing/test_package_custom_templates/templates/_callable_multiline.html +++ b/testing/test_package_custom_templates/templates/_callable_multiline.html @@ -7,5 +7,5 @@ {{/hasAnnotations}} -{{{ linkedReturnType }}} +{{{ modelType.returnType.linkedName }}} {{>name_summary}}{{{genericParameters}}}({{#hasParameters}}{{{linkedParamsLines}}}{{/hasParameters}}) diff --git a/testing/test_package_custom_templates/templates/_constant.html b/testing/test_package_custom_templates/templates/_constant.html index 72d367c667..f12c94d20a 100644 --- a/testing/test_package_custom_templates/templates/_constant.html +++ b/testing/test_package_custom_templates/templates/_constant.html @@ -1,6 +1,6 @@
{{{ linkedName }}} - → const {{{ linkedReturnType }}} + → const {{{ modelType.linkedName }}} {{>categorization}}
diff --git a/testing/test_package_custom_templates/templates/_property.html b/testing/test_package_custom_templates/templates/_property.html index 09f61f67e0..dc58959e80 100644 --- a/testing/test_package_custom_templates/templates/_property.html +++ b/testing/test_package_custom_templates/templates/_property.html @@ -1,6 +1,6 @@
{{{linkedName}}} - {{{ arrow }}} {{{ linkedReturnType }}} {{>categorization}} + {{{ arrow }}} {{{ modelType.linkedName }}} {{>categorization}}
{{{ oneLineDoc }}} {{{ extendedDocLink }}} diff --git a/testing/test_package_custom_templates/templates/constant.html b/testing/test_package_custom_templates/templates/constant.html index 5ae50e8eac..0577cba6d5 100644 --- a/testing/test_package_custom_templates/templates/constant.html +++ b/testing/test_package_custom_templates/templates/constant.html @@ -13,7 +13,7 @@
{{parent.name}} {{parent.kind}}
{{#property}} - {{{ linkedReturnType }}} + {{{ modelType.returnType.linkedName }}} {{>name_summary}} = {{{ constantValue }}} diff --git a/testing/test_package_custom_templates/templates/property.html b/testing/test_package_custom_templates/templates/property.html index b8bb7e559a..691da45f25 100644 --- a/testing/test_package_custom_templates/templates/property.html +++ b/testing/test_package_custom_templates/templates/property.html @@ -14,7 +14,7 @@
{{parent.name}} {{parent.kind}}
{{#self}} {{#hasNoGetterSetter}}
- {{{ linkedReturnType }}} + {{{ modelType.returnType.linkedName }}} {{>name_summary}} {{>features}}
diff --git a/testing/test_package_custom_templates/templates/top_level_property.html b/testing/test_package_custom_templates/templates/top_level_property.html index 449244a3c3..8b587177da 100644 --- a/testing/test_package_custom_templates/templates/top_level_property.html +++ b/testing/test_package_custom_templates/templates/top_level_property.html @@ -12,7 +12,7 @@
{{parent.name}} {{parent.kind}}
{{#hasNoGetterSetter}}
- {{{ linkedReturnType }}} + {{{ modelType.returnType.linkedName }}} {{>name_summary}} {{>features}}
diff --git a/testing/test_package_experiments/lib/generalized_typedefs.dart b/testing/test_package_experiments/lib/generalized_typedefs.dart index 658c8cd22a..8bcfbf5e11 100644 --- a/testing/test_package_experiments/lib/generalized_typedefs.dart +++ b/testing/test_package_experiments/lib/generalized_typedefs.dart @@ -17,7 +17,18 @@ typedef T5 = X Function(X, {X name}); typedef T6 = X Function(Y, [Map]); typedef T7> = X Function(Y, [Map]); -class C1 {} +T0 a; + +class C2 { + T0 b; + T1 c; + T2 d(T3 e, T4 f); +} + +class C1 { + T2 a; + T0 b(T1 c, T d); +} typedef T8 = C1;