diff --git a/lib/src/element_type.dart b/lib/src/element_type.dart index fd517d617c..78f0d0d318 100644 --- a/lib/src/element_type.dart +++ b/lib/src/element_type.dart @@ -273,7 +273,7 @@ abstract class DefinedElementType extends ElementType { @override List get parameters => - element.canHaveParameters ? element.parameters : []; + element.isCallable ? element.parameters : []; ModelElement get returnElement => element; ElementType _returnType; diff --git a/lib/src/generator/templates.dart b/lib/src/generator/templates.dart index 1c90f8a4af..9fd4964b75 100644 --- a/lib/src/generator/templates.dart +++ b/lib/src/generator/templates.dart @@ -42,6 +42,10 @@ const _partials_html = [ 'source_code', 'source_link', 'sidebar_for_library', + 'type', + 'type_multiline', + 'typedef', + 'typedef_multiline', 'accessor_getter', 'accessor_setter', ]; @@ -66,6 +70,10 @@ const _partials_md = [ 'property', 'source_code', 'source_link', + 'type', + 'type_multiline', + 'typedef', + 'typedef_multiline', ]; abstract class _TemplatesLoader { diff --git a/lib/src/model/getter_setter_combo.dart b/lib/src/model/getter_setter_combo.dart index 892c2a0780..7b17289bb2 100644 --- a/lib/src/model/getter_setter_combo.dart +++ b/lib/src/model/getter_setter_combo.dart @@ -190,7 +190,7 @@ mixin GetterSetterCombo on ModelElement { } @override - bool get canHaveParameters => hasSetter; + bool get isCallable => hasSetter; @override List get parameters => setter.parameters; diff --git a/lib/src/model/library.dart b/lib/src/model/library.dart index e1d2e2cb88..2ca68aae81 100644 --- a/lib/src/model/library.dart +++ b/lib/src/model/library.dart @@ -104,9 +104,9 @@ class Library extends ModelElement with Categorization, TopLevelContainer { compilationUnit.enums, compilationUnit.extensions, compilationUnit.functions, - compilationUnit.functionTypeAliases, compilationUnit.mixins, compilationUnit.topLevelVariables, + compilationUnit.typeAliases, compilationUnit.types, ]); } @@ -493,7 +493,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer { @override List get typedefs { _typedefs ??= _exportedAndLocalElements - .whereType() + .whereType() .map((e) => ModelElement.from(e, this, packageGraph) as Typedef) .toList(growable: false); return _typedefs; diff --git a/lib/src/model/model_element.dart b/lib/src/model/model_element.dart index 894b00a9b9..809b8df559 100644 --- a/lib/src/model/model_element.dart +++ b/lib/src/model/model_element.dart @@ -8,6 +8,7 @@ library dartdoc.models; import 'dart:convert'; import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/type.dart' show FunctionType; import 'package:analyzer/source/line_info.dart'; import 'package:analyzer/src/dart/element/element.dart'; import 'package:analyzer/src/dart/element/member.dart' @@ -333,7 +334,10 @@ abstract class ModelElement extends Canonicalization assert(e.enclosingElement.name != ''); return ModelFunctionTypedef(e, library, packageGraph); } - if (e is FunctionTypeAliasElement) { + if (e is TypeAliasElement) { + if (e.aliasedType is FunctionType) { + return FunctionTypedef(e, library, packageGraph); + } return Typedef(e, library, packageGraph); } if (e is ConstructorElement) { @@ -543,10 +547,8 @@ abstract class ModelElement extends Canonicalization return allFeatures.join(', '); } - bool get canHaveParameters => - element is ExecutableElement || - element is FunctionTypedElement || - element is FunctionTypeAliasElement; + bool get isCallable => + element is FunctionTypedElement || element is FunctionTypeAliasElement; ModelElement buildCanonicalModelElement() { Container preferredClass; @@ -998,9 +1000,9 @@ abstract class ModelElement extends Canonicalization } } else if (element is ClassElement) { _modelType = ElementType.from(element.thisType, library, packageGraph); - } else if (element is FunctionTypeAliasElement) { + } else if (element is TypeAliasElement) { _modelType = - ElementType.from(element.function.type, library, packageGraph); + ElementType.from(element.aliasedType, library, packageGraph); } else if (element is FunctionTypedElement) { _modelType = ElementType.from(element.type, library, packageGraph); } else if (element is ParameterElement) { @@ -1050,7 +1052,7 @@ abstract class ModelElement extends Canonicalization (this as GetterSetterCombo).setter != null) { newParameters.addAll((this as GetterSetterCombo).setter.parameters); } else { - if (canHaveParameters) newParameters.addAll(parameters); + if (isCallable) newParameters.addAll(parameters); } while (newParameters.isNotEmpty) { recursedParameters.addAll(newParameters); @@ -1070,7 +1072,7 @@ abstract class ModelElement extends Canonicalization path.Context get pathContext => packageGraph.resourceProvider.pathContext; List get parameters { - if (!canHaveParameters) { + if (!isCallable) { throw StateError('$element cannot have parameters'); } diff --git a/lib/src/model/typedef.dart b/lib/src/model/typedef.dart index af280b4f82..d49bfca6b8 100644 --- a/lib/src/model/typedef.dart +++ b/lib/src/model/typedef.dart @@ -3,17 +3,21 @@ // 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:analyzer/dart/element/type.dart'; import 'package:dartdoc/src/model/model.dart'; import 'package:dartdoc/src/render/typedef_renderer.dart'; class Typedef extends ModelElement with TypeParameters, Categorization implements EnclosedElement { - Typedef(FunctionTypeAliasElement element, Library library, - PackageGraph packageGraph) + Typedef(TypeAliasElement element, Library library, PackageGraph packageGraph) : super(element, library, packageGraph); + DartType get aliasedType => element.aliasedType; + + @override + TypeAliasElement get element => super.element; + @override ModelElement get enclosingElement => library; @@ -23,12 +27,8 @@ class Typedef extends ModelElement @override String get genericParameters => _renderer.renderGenericParameters(this); - List get genericTypeParameters { - if (element is FunctionTypeAliasElement) { - return (element as FunctionTypeAliasElement).function.typeParameters; - } - return Iterable.empty(); - } + List get genericTypeParameters => + element.typeParameters; @override String get filePath => '${library.dirName}/$fileName'; @@ -52,17 +52,31 @@ class Typedef extends ModelElement String get linkedReturnType => modelType.createLinkedReturnTypeName(); @override - // TODO(jcollins-g): change to FunctionTypeElementType after analyzer 0.41 - // ignore: unnecessary_overrides - ElementType get modelType => super.modelType; - - FunctionTypeAliasElement get _typedef => - (element as FunctionTypeAliasElement); - - @override - List get typeParameters => _typedef.typeParameters.map((f) { + List get typeParameters => element.typeParameters.map((f) { return ModelElement.from(f, library, packageGraph) as TypeParameter; }).toList(); TypedefRenderer get _renderer => packageGraph.rendererFactory.typedefRenderer; } + +/// A typedef referring to a function type. +class FunctionTypedef extends Typedef { + FunctionTypedef( + TypeAliasElement element, Library library, PackageGraph packageGraph) + : super(element, library, packageGraph); + + @override + FunctionType get aliasedType => super.aliasedType; + + @override + List get genericTypeParameters { + var aliasedTypeElement = aliasedType.element; + if (aliasedTypeElement is FunctionTypedElement) { + return aliasedTypeElement.typeParameters; + } + if (aliasedType.typeFormals.isNotEmpty == true) { + return aliasedType.typeFormals; + } + return super.genericTypeParameters; + } +} diff --git a/lib/templates/html/_callable_multiline.html b/lib/templates/html/_callable_multiline.html index 4d0bce92a5..ab0fa11769 100644 --- a/lib/templates/html/_callable_multiline.html +++ b/lib/templates/html/_callable_multiline.html @@ -7,5 +7,6 @@ {{/hasAnnotations}} + {{{ linkedReturnType }}} {{>name_summary}}{{{genericParameters}}}({{#hasParameters}}{{{linkedParamsLines}}}{{/hasParameters}}) diff --git a/lib/templates/html/_name_summary.html b/lib/templates/html/_name_summary.html index 73fca35cbb..2f2d11e526 100644 --- a/lib/templates/html/_name_summary.html +++ b/lib/templates/html/_name_summary.html @@ -1 +1 @@ -{{#isConst}}const {{/isConst}}{{name}} +{{#isConst}}const {{/isConst}}{{name}} \ No newline at end of file diff --git a/lib/templates/html/_type.html b/lib/templates/html/_type.html new file mode 100644 index 0000000000..7ac5632cfc --- /dev/null +++ b/lib/templates/html/_type.html @@ -0,0 +1,11 @@ +
+ {{{linkedName}}}{{{linkedGenericParameters}}} + = + {{{ linkedReturnType }}} + + {{>categorization}} +
+ + {{{ oneLineDoc }}} {{{ extendedDocLink }}} + {{>features}} + diff --git a/lib/templates/html/_type_multiline.html b/lib/templates/html/_type_multiline.html new file mode 100644 index 0000000000..71b80368df --- /dev/null +++ b/lib/templates/html/_type_multiline.html @@ -0,0 +1,10 @@ +{{#hasAnnotations}} +
+
    + {{#annotations}} +
  1. {{{.}}}
  2. + {{/annotations}} +
+
+{{/hasAnnotations}} +{{>name_summary}}{{{genericParameters}}} = {{{linkedReturnType}}} diff --git a/lib/templates/html/_typedef.html b/lib/templates/html/_typedef.html new file mode 100644 index 0000000000..7d2453299f --- /dev/null +++ b/lib/templates/html/_typedef.html @@ -0,0 +1,6 @@ +{{#isCallable}} + {{>callable}} +{{/isCallable}} +{{^isCallable}} + {{>type}} +{{/isCallable}} diff --git a/lib/templates/html/_typedef_multiline.html b/lib/templates/html/_typedef_multiline.html new file mode 100644 index 0000000000..c1139581c3 --- /dev/null +++ b/lib/templates/html/_typedef_multiline.html @@ -0,0 +1,6 @@ +{{#isCallable}} + {{>callable_multiline}} +{{/isCallable}} +{{^isCallable}} + {{>type_multiline}} +{{/isCallable}} diff --git a/lib/templates/html/category.html b/lib/templates/html/category.html index d021790695..733f328fe2 100644 --- a/lib/templates/html/category.html +++ b/lib/templates/html/category.html @@ -101,7 +101,7 @@

Typedefs

{{#publicTypedefsSorted}} - {{>callable}} + {{>typedef}} {{/publicTypedefsSorted}}
@@ -126,4 +126,4 @@
{{self.name}} {{self.kind}}
{{>sidebar_for_category}} -{{>footer}} \ No newline at end of file +{{>footer}} diff --git a/lib/templates/html/library.html b/lib/templates/html/library.html index 10e1121781..b683d187b0 100644 --- a/lib/templates/html/library.html +++ b/lib/templates/html/library.html @@ -103,9 +103,9 @@

Enums

Typedefs

-
+
{{#library.publicTypedefsSorted}} - {{>callable}} + {{>typedef}} {{/library.publicTypedefsSorted}}
diff --git a/lib/templates/html/typedef.html b/lib/templates/html/typedef.html index 52af2ed89f..37cc5de239 100644 --- a/lib/templates/html/typedef.html +++ b/lib/templates/html/typedef.html @@ -13,7 +13,7 @@
{{parent.name}} {{parent.kind}}
{{#typeDef}} - {{>callable_multiline}} + {{>typedef_multiline}} {{/typeDef}}
diff --git a/lib/templates/md/_type.md b/lib/templates/md/_type.md new file mode 100644 index 0000000000..12560c75fd --- /dev/null +++ b/lib/templates/md/_type.md @@ -0,0 +1,5 @@ +##### {{{linkedName}}}{{{linkedGenericParameters}}}({{{ linkedParamsNoMetadata }}}) {{{ linkedReturnType }}} +{{>categorization}} + +{{{ oneLineDoc }}} {{{ extendedDocLink }}} {{!two spaces intentional}} +{{>features}} diff --git a/lib/templates/md/_type_multiline.md b/lib/templates/md/_type_multiline.md new file mode 100644 index 0000000000..adfbd36058 --- /dev/null +++ b/lib/templates/md/_type_multiline.md @@ -0,0 +1,7 @@ +{{#hasAnnotations}} +{{#annotations}} +- {{{.}}} +{{/annotations}} +{{/hasAnnotations}} + +{{>name_summary}}{{{genericParameters}}} = {{{linkedReturnType}}} diff --git a/lib/templates/md/_typedef.md b/lib/templates/md/_typedef.md new file mode 100644 index 0000000000..7d2453299f --- /dev/null +++ b/lib/templates/md/_typedef.md @@ -0,0 +1,6 @@ +{{#isCallable}} + {{>callable}} +{{/isCallable}} +{{^isCallable}} + {{>type}} +{{/isCallable}} diff --git a/lib/templates/md/_typedef_multiline.md b/lib/templates/md/_typedef_multiline.md new file mode 100644 index 0000000000..c1139581c3 --- /dev/null +++ b/lib/templates/md/_typedef_multiline.md @@ -0,0 +1,6 @@ +{{#isCallable}} + {{>callable_multiline}} +{{/isCallable}} +{{^isCallable}} + {{>type_multiline}} +{{/isCallable}} diff --git a/lib/templates/md/category.md b/lib/templates/md/category.md index a625d030a2..aadf6c677a 100644 --- a/lib/templates/md/category.md +++ b/lib/templates/md/category.md @@ -72,7 +72,7 @@ ## Typedefs {{#publicTypedefsSorted}} -{{>callable}} +{{>typedef}} {{/publicTypedefsSorted}} {{/hasPublicTypedefs}} diff --git a/lib/templates/md/library.md b/lib/templates/md/library.md index b4fa38d91d..eb0fe60236 100644 --- a/lib/templates/md/library.md +++ b/lib/templates/md/library.md @@ -79,7 +79,7 @@ ## Typedefs {{#library.publicTypedefsSorted}} -{{>callable}} +{{>typedef}} {{/library.publicTypedefsSorted}} {{/library.hasPublicTypedefs}} diff --git a/lib/templates/md/typedef.md b/lib/templates/md/typedef.md index bed210a4a3..8e8271dcf6 100644 --- a/lib/templates/md/typedef.md +++ b/lib/templates/md/typedef.md @@ -9,7 +9,7 @@ {{/self}} {{#typeDef}} -{{>callable_multiline}} +{{>typedef_multiline}} {{>documentation}} diff --git a/pubspec.yaml b/pubspec.yaml index f68be26d6f..3f1a58110b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,7 +7,7 @@ environment: sdk: '>=2.11.99 <3.0.0' dependencies: - analyzer: ^1.0.0 + analyzer: ^1.1.0 args: ^2.0.0 charcode: ^1.2.0 collection: ^1.2.0 diff --git a/test/end2end/model_special_cases_test.dart b/test/end2end/model_special_cases_test.dart index 1f98985e08..9d8ea3ab16 100644 --- a/test/end2end/model_special_cases_test.dart +++ b/test/end2end/model_special_cases_test.dart @@ -16,10 +16,26 @@ import 'package:dartdoc/src/model/model.dart'; import 'package:dartdoc/src/package_config_provider.dart'; import 'package:dartdoc/src/package_meta.dart'; import 'package:dartdoc/src/special_elements.dart'; +import 'package:pub_semver/pub_semver.dart'; import 'package:test/test.dart'; import '../src/utils.dart' as utils; +final String _platformVersionString = Platform.version.split(' ').first; +final Version _platformVersion = Version.parse(_platformVersionString); + +final _testPackageGraphExperimentsMemo = AsyncMemoizer(); +Future get _testPackageGraphExperiments => + _testPackageGraphExperimentsMemo.runOnce(() => utils.bootBasicPackage( + 'testing/test_package_experiments', + pubPackageMetaProvider, + PhysicalPackageConfigProvider(), + additionalArguments: [ + '--enable-experiment', + 'non-nullable,nonfunction-type-aliases', + '--no-link-to-remote' + ])); + final _testPackageGraphGinormousMemo = AsyncMemoizer(); Future get _testPackageGraphGinormous => _testPackageGraphGinormousMemo.runOnce(() => utils.bootBasicPackage( @@ -58,10 +74,48 @@ void main() { exit(1); } + final _generalizedTypedefsAllowed = + VersionRange(min: Version.parse('2.13.0-0'), includeMin: true); // Experimental features not yet enabled by default. Move tests out of this // block when the feature is enabled by default. group('Experiments', () { - setUpAll(() async {}); + group('generalized typedefs', () { + Library generalizedTypedefs; + Typedef T0, T1, T2, T3, T4, T5, T6, T7; + + setUpAll(() async { + generalizedTypedefs = (await _testPackageGraphExperiments) + .libraries + .firstWhere((l) => l.name == 'generalized_typedefs'); + T0 = generalizedTypedefs.typedefs.firstWhere((a) => a.name == 'T0'); + T1 = generalizedTypedefs.typedefs.firstWhere((a) => a.name == 'T1'); + T2 = generalizedTypedefs.typedefs.firstWhere((a) => a.name == 'T2'); + T3 = generalizedTypedefs.typedefs.firstWhere((a) => a.name == 'T3'); + T4 = generalizedTypedefs.typedefs.firstWhere((a) => a.name == 'T4'); + T5 = generalizedTypedefs.typedefs.firstWhere((a) => a.name == 'T5'); + T6 = generalizedTypedefs.typedefs.firstWhere((a) => a.name == 'T6'); + T7 = generalizedTypedefs.typedefs.firstWhere((a) => a.name == 'T7'); + }); + + void expectTypedefs(Typedef t, String modelTypeToString, + Iterable genericParameters) { + expect(t.modelType.toString(), equals(modelTypeToString)); + expect(t.genericTypeParameters.map((p) => p.toString()), + orderedEquals(genericParameters)); + } + + test('basic non-function typedefs work', () { + expectTypedefs(T0, 'void', []); + expectTypedefs(T1, 'Function', []); + expectTypedefs(T2, 'List', ['out X']); + expectTypedefs(T3, 'Map', ['out X', 'out Y']); + expectTypedefs(T4, 'void Function()', []); + expectTypedefs(T5, 'X Function(X, {X name})', ['inout X']); + expectTypedefs(T6, 'X Function(Y, [Map])', ['out X', 'in Y']); + expectTypedefs(T7, 'X Function(Y, [Map])', + ['out X extends String', 'in Y extends List']); + }); + }, skip: (!_generalizedTypedefsAllowed.allows(_platformVersion))); }); group('HTML Injection when allowed', () { diff --git a/test/end2end/model_test.dart b/test/end2end/model_test.dart index 979467f38e..6a4659ace3 100644 --- a/test/end2end/model_test.dart +++ b/test/end2end/model_test.dart @@ -2746,7 +2746,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, }); test('can have params', () { - expect(isGreaterThan.canHaveParameters, isTrue); + expect(isGreaterThan.isCallable, isTrue); }); test('has parameters', () { diff --git a/test/html_generator_test.dart b/test/html_generator_test.dart index 969ca43819..e8559b9af5 100644 --- a/test/html_generator_test.dart +++ b/test/html_generator_test.dart @@ -63,6 +63,10 @@ void main() { '_sidebar_for_library', '_source_code', '_source_link', + '_type', + '_typedef', + '_type_multiline', + '_typedef_multiline', '404error', 'category', 'class', diff --git a/testing/test_package/lib/completely_empty_lib.dart b/testing/test_package/lib/completely_empty_lib.dart index 93ce5d2949..fdc4933219 100644 --- a/testing/test_package/lib/completely_empty_lib.dart +++ b/testing/test_package/lib/completely_empty_lib.dart @@ -1 +1 @@ -// @dart=2.9 \ No newline at end of file +// @dart=2.9 diff --git a/testing/test_package/lib/example.dart b/testing/test_package/lib/example.dart index de03905b49..275eb5e15c 100644 --- a/testing/test_package/lib/example.dart +++ b/testing/test_package/lib/example.dart @@ -201,7 +201,8 @@ class Apple { /** * fieldWithTypedef docs here */ - final ParameterizedTypedef fieldWithTypedef = (bool a, int b) => 'hello, ${a} ${b}'; + final ParameterizedTypedef fieldWithTypedef = + (bool a, int b) => 'hello, ${a} ${b}'; } /// Extension on Apple diff --git a/testing/test_package/lib/fake.dart b/testing/test_package/lib/fake.dart index 520c4a48eb..74734caaac 100644 --- a/testing/test_package/lib/fake.dart +++ b/testing/test_package/lib/fake.dart @@ -1229,12 +1229,11 @@ class _Super5 implements _Super2 {} class Super6 implements _Super5 {} - abstract class IntermediateAbstract extends Object { /// This is an override. @override - bool operator==(Object other) {} + bool operator ==(Object other) {} } /// This should inherit [==] from [IntermediateAbstract]. -class IntermediateAbstractSubclass extends IntermediateAbstract {} \ No newline at end of file +class IntermediateAbstractSubclass extends IntermediateAbstract {} diff --git a/testing/test_package/lib/features/late_final_without_initializer.dart b/testing/test_package/lib/features/late_final_without_initializer.dart index 27765b26a2..8585247837 100644 --- a/testing/test_package/lib/features/late_final_without_initializer.dart +++ b/testing/test_package/lib/features/late_final_without_initializer.dart @@ -17,4 +17,3 @@ class C { dField = param * 8.854 * pow(10, -12); } } - diff --git a/testing/test_package/lib/features/nnbd_class_member_declarations.dart b/testing/test_package/lib/features/nnbd_class_member_declarations.dart index 7d13186a1d..16014edf34 100644 --- a/testing/test_package/lib/features/nnbd_class_member_declarations.dart +++ b/testing/test_package/lib/features/nnbd_class_member_declarations.dart @@ -6,11 +6,14 @@ library nnbd_class_member_declarations; /// Test required and covariant parameters abstract class B { - m1(int some, regular, covariant parameters, { - required p1, - int p2 = 3, - required covariant p3, - required covariant int p4, + m1( + int some, + regular, + covariant parameters, { + required p1, + int p2 = 3, + required covariant p3, + required covariant int p4, }); m2(int sometimes, we, [String have, double optionals]); } diff --git a/testing/test_package/lib/features/nullable_elements.dart b/testing/test_package/lib/features/nullable_elements.dart index 94ee591a3a..9607b2694c 100644 --- a/testing/test_package/lib/features/nullable_elements.dart +++ b/testing/test_package/lib/features/nullable_elements.dart @@ -35,4 +35,4 @@ class ComplexNullableMembers { void set aComplexSetterOnlyType(List?> value) => null; X? aMethod(X? f) => null; -} \ No newline at end of file +} diff --git a/testing/test_package/lib/implementors.dart b/testing/test_package/lib/implementors.dart index 050d1e120b..33d041cbde 100644 --- a/testing/test_package/lib/implementors.dart +++ b/testing/test_package/lib/implementors.dart @@ -15,4 +15,5 @@ abstract class _APrivateThingToImplement implements ImplementBase {} abstract class ImplementerOfThings implements IntermediateImplementer {} -abstract class ImplementerOfDeclaredPrivateClasses implements _APrivateThingToImplement {} \ No newline at end of file +abstract class ImplementerOfDeclaredPrivateClasses + implements _APrivateThingToImplement {} diff --git a/testing/test_package/lib/src/gadget.dart b/testing/test_package/lib/src/gadget.dart index 2044fa0c81..ceb7c784eb 100644 --- a/testing/test_package/lib/src/gadget.dart +++ b/testing/test_package/lib/src/gadget.dart @@ -8,5 +8,4 @@ class _GadgetBase { int get gadgetGetter => 5; } - -class Gadget extends _GadgetBase {} \ No newline at end of file +class Gadget extends _GadgetBase {} diff --git a/testing/test_package/lib/src/intermediate_implements.dart b/testing/test_package/lib/src/intermediate_implements.dart index 8b194e03df..e9d85c1453 100644 --- a/testing/test_package/lib/src/intermediate_implements.dart +++ b/testing/test_package/lib/src/intermediate_implements.dart @@ -9,4 +9,4 @@ library intermediate_implements; import 'package:test_package/implementors.dart'; -abstract class IntermediateImplementer implements ImplementBase {} \ No newline at end of file +abstract class IntermediateImplementer implements ImplementBase {} diff --git a/testing/test_package/lib/src/nodocme.dart b/testing/test_package/lib/src/nodocme.dart index 94049dd895..36d9b3f4c2 100644 --- a/testing/test_package/lib/src/nodocme.dart +++ b/testing/test_package/lib/src/nodocme.dart @@ -11,4 +11,3 @@ library nodocme; class NodocMeImplementation {} class MeNeitherEvenWithoutADocComment {} - diff --git a/testing/test_package/lib/src/reexport_this.dart b/testing/test_package/lib/src/reexport_this.dart index 6b33557d79..77255cf53c 100644 --- a/testing/test_package/lib/src/reexport_this.dart +++ b/testing/test_package/lib/src/reexport_this.dart @@ -1,6 +1,5 @@ // @dart=2.9 - library reexport_this; /// {@template example:templateMemberTest} @@ -10,5 +9,4 @@ library reexport_this; /// /// And if I do, a test should fail. /// {@endtemplate} -class ClassTemplateOneLiner { -} \ No newline at end of file +class ClassTemplateOneLiner {} diff --git a/testing/test_package/lib/src/shadowing_lib.dart b/testing/test_package/lib/src/shadowing_lib.dart index 9491e37b20..72ea97805c 100644 --- a/testing/test_package/lib/src/shadowing_lib.dart +++ b/testing/test_package/lib/src/shadowing_lib.dart @@ -6,4 +6,4 @@ class ADuplicateClass { bool get aGetter => true; } -class SomeMoreClassDeclaration {} \ No newline at end of file +class SomeMoreClassDeclaration {} diff --git a/testing/test_package/lib/src/somelib.dart b/testing/test_package/lib/src/somelib.dart index ad3da7a8e9..b8ab5cea58 100644 --- a/testing/test_package/lib/src/somelib.dart +++ b/testing/test_package/lib/src/somelib.dart @@ -14,17 +14,16 @@ class BaseReexported { String action; } -class ExtendedBaseReexported extends BaseReexported { -} +class ExtendedBaseReexported extends BaseReexported {} /// A private extension. extension _Unseen on Object { - void doYouSeeMe() { } + void doYouSeeMe() {} } /// An extension without a name extension on List { - void somethingNew() { } + void somethingNew() {} } /// [_Unseen] is not seen, but [DocumentMe] is. diff --git a/testing/test_package/lib/unrelated_factories.dart b/testing/test_package/lib/unrelated_factories.dart index 9699fc9932..ad11cbe132 100644 --- a/testing/test_package/lib/unrelated_factories.dart +++ b/testing/test_package/lib/unrelated_factories.dart @@ -11,4 +11,4 @@ class AB { factory AB.fromMap(Map map) => AB._AB(); AB._AB(); -} \ No newline at end of file +} diff --git a/testing/test_package_experiments/analysis_options.yaml b/testing/test_package_experiments/analysis_options.yaml index fa5fdeb9eb..5d00c3a21e 100644 --- a/testing/test_package_experiments/analysis_options.yaml +++ b/testing/test_package_experiments/analysis_options.yaml @@ -2,3 +2,4 @@ analyzer: # enable for analysis on test package sources. enable-experiment: - non-nullable + - nonfunction-type-aliases diff --git a/testing/test_package_experiments/lib/generalized_typedefs.dart b/testing/test_package_experiments/lib/generalized_typedefs.dart new file mode 100644 index 0000000000..658c8cd22a --- /dev/null +++ b/testing/test_package_experiments/lib/generalized_typedefs.dart @@ -0,0 +1,42 @@ +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// This library validates that dartdoc will not crash on generalized +/// typedef syntax, and produce correct results. +library generalized_typedefs; + +// from basic_syntax_test (Dart SDK) + +typedef T0 = void; +typedef T1 = Function; +typedef T2 = List; +typedef T3 = Map; +typedef T4 = void Function(); +typedef T5 = X Function(X, {X name}); +typedef T6 = X Function(Y, [Map]); +typedef T7> = X Function(Y, [Map]); + +class C1 {} + +typedef T8 = C1; + +abstract class C extends T8 { + T0 f; + T1 g(T2 a, T3 b); + + T2 operator +(T2 other) => other; + + static final T4 h = (){}; + static T5? i; + + T7> get j; + + set k(T6 value); +} + +extension E on T6 { + static T4 f = () {}; + + T2 myMethod() => [5]; +} \ No newline at end of file diff --git a/testing/test_package_experiments/pubspec.yaml b/testing/test_package_experiments/pubspec.yaml index c0a9b33338..32c96d812b 100644 --- a/testing/test_package_experiments/pubspec.yaml +++ b/testing/test_package_experiments/pubspec.yaml @@ -1,5 +1,5 @@ name: test_package_experiments version: 0.0.1 environment: - sdk: '>=2.10.0-0 <3.0.0' + sdk: '>=2.13.0-0 <3.0.0' description: Experimental flags are tested here. diff --git a/tool/grind.dart b/tool/grind.dart index 5526c0f182..93d561ea6e 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -222,15 +222,7 @@ void updateThirdParty() async { void analyze() async { await SubprocessLauncher('analyze').runStreamed( sdkBin('dartanalyzer'), - [ - '--fatal-infos', - '--options', - 'analysis_options_presubmit.yaml', - 'bin', - 'lib', - 'test', - 'tool', - ], + ['--fatal-infos', '--options', 'analysis_options_presubmit.yaml', '.'], ); } @@ -241,22 +233,32 @@ void dartfmt() async { // Filter out test packages as they always have strange formatting. // Passing parameters to dartfmt for directories to search results in // filenames being stripped of the dirname so we have to filter here. - void addFileToFix(String fileName) { + void addFileToFix(String base, String fileName) { var pathComponents = path.split(fileName); if (pathComponents.isNotEmpty && pathComponents.first == 'testing') { return; } - filesToFix.add(fileName); + filesToFix.add(path.join(base, fileName)); } log('Validating dartfmt with version ${Platform.version}'); - await SubprocessLauncher('dartfmt').runStreamed( - sdkBin('dartfmt'), - [ - '-n', - '.', - ], - perLine: addFileToFix); + // TODO(jcollins-g): return to global once dartfmt can handle generic + // type aliases + for (var subDirectory in [ + 'bin', + 'lib', + 'test', + 'tool', + path.join('testing/test_package') + ]) { + await SubprocessLauncher('dartfmt').runStreamed( + sdkBin('dartfmt'), + [ + '-n', + subDirectory, + ], + perLine: (n) => addFileToFix(subDirectory, n)); + } if (filesToFix.isNotEmpty) { fail( 'dartfmt found files needing reformatting. Use this command to reformat:\n'