From e7710cb988476c3a726451dbf48cea09c09011d5 Mon Sep 17 00:00:00 2001 From: Robert Nystrom Date: Wed, 2 Mar 2022 16:55:40 -0800 Subject: [PATCH] Format "super." parameters. Fix #1091. --- CHANGELOG.md | 1 + lib/src/source_visitor.dart | 33 ++++++++++++++++++++++--------- pubspec.lock | 22 ++++++++++----------- pubspec.yaml | 2 +- test/whitespace/constructors.unit | 22 +++++++++++++++++++++ test/whitespace/metadata.unit | 9 +++++++++ 6 files changed, 68 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a73d1619..a9f83fc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 2.2.2 * Format named arguments anywhere (#1072). +* Format "super." parameters (#1091). # 2.2.1 diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart index b2081bd6..aeaa2795 100644 --- a/lib/src/source_visitor.dart +++ b/lib/src/source_visitor.dart @@ -802,7 +802,7 @@ class SourceVisitor extends ThrowingAstVisitor { token(node.equals); space(); - visit(node.superclass2); + visit(node.superclass); builder.startRule(CombinatorRule()); visit(node.withClause); @@ -1068,7 +1068,7 @@ class SourceVisitor extends ThrowingAstVisitor { @override void visitConstructorName(ConstructorName node) { - visit(node.type2); + visit(node.type); token(node.period); visit(node.name); } @@ -1373,7 +1373,7 @@ class SourceVisitor extends ThrowingAstVisitor { soloSplit(); token(node.extendsKeyword); space(); - visit(node.superclass2); + visit(node.superclass); } @override @@ -1999,7 +1999,7 @@ class SourceVisitor extends ThrowingAstVisitor { @override void visitImplementsClause(ImplementsClause node) { - _visitCombinator(node.implementsKeyword, node.interfaces2); + _visitCombinator(node.implementsKeyword, node.interfaces); } @override @@ -2264,18 +2264,18 @@ class SourceVisitor extends ThrowingAstVisitor { // If there is only a single superclass constraint, format it like an // "extends" in a class. var onClause = node.onClause; - if (onClause != null && onClause.superclassConstraints2.length == 1) { + if (onClause != null && onClause.superclassConstraints.length == 1) { soloSplit(); token(onClause.onKeyword); space(); - visit(onClause.superclassConstraints2.single); + visit(onClause.superclassConstraints.single); } builder.startRule(CombinatorRule()); // If there are multiple superclass constraints, format them like the // "implements" clause. - if (onClause != null && onClause.superclassConstraints2.length > 1) { + if (onClause != null && onClause.superclassConstraints.length > 1) { visit(onClause); } @@ -2326,7 +2326,7 @@ class SourceVisitor extends ThrowingAstVisitor { @override void visitOnClause(OnClause node) { - _visitCombinator(node.onKeyword, node.superclassConstraints2); + _visitCombinator(node.onKeyword, node.superclassConstraints); } @override @@ -2528,6 +2528,21 @@ class SourceVisitor extends ThrowingAstVisitor { token(node.superKeyword); } + @override + void visitSuperFormalParameter(SuperFormalParameter node) { + visitParameterMetadata(node.metadata, () { + _beginFormalParameter(node); + token(node.keyword, after: space); + visit(node.type, after: split); + token(node.superKeyword); + token(node.period); + visit(node.identifier); + visit(node.parameters); + token(node.question); + _endFormalParameter(node); + }); + } + @override void visitSwitchCase(SwitchCase node) { _visitLabels(node.labels); @@ -2730,7 +2745,7 @@ class SourceVisitor extends ThrowingAstVisitor { @override void visitWithClause(WithClause node) { - _visitCombinator(node.withKeyword, node.mixinTypes2); + _visitCombinator(node.withKeyword, node.mixinTypes); } @override diff --git a/pubspec.lock b/pubspec.lock index 4fbb2daf..edcf821b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,14 +7,14 @@ packages: name: _fe_analyzer_shared url: "https://pub.dartlang.org" source: hosted - version: "34.0.0" + version: "36.0.0" analyzer: dependency: "direct main" description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "3.2.0" + version: "3.3.1" args: dependency: "direct main" description: @@ -70,7 +70,7 @@ packages: name: coverage url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.1.0" crypto: dependency: transitive description: @@ -112,7 +112,7 @@ packages: name: http_multi_server url: "https://pub.dartlang.org" source: hosted - version: "3.0.1" + version: "3.2.0" http_parser: dependency: transitive description: @@ -133,7 +133,7 @@ packages: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.3" + version: "0.6.4" lints: dependency: "direct dev" description: @@ -189,7 +189,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" pool: dependency: transitive description: @@ -252,7 +252,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" stack_trace: dependency: transitive description: @@ -287,7 +287,7 @@ packages: name: test url: "https://pub.dartlang.org" source: hosted - version: "1.20.0" + version: "1.20.1" test_api: dependency: transitive description: @@ -301,7 +301,7 @@ packages: name: test_core url: "https://pub.dartlang.org" source: hosted - version: "0.4.10" + version: "0.4.11" test_descriptor: dependency: "direct dev" description: @@ -329,7 +329,7 @@ packages: name: vm_service url: "https://pub.dartlang.org" source: hosted - version: "7.5.0" + version: "8.2.0" watcher: dependency: transitive description: @@ -359,4 +359,4 @@ packages: source: hosted version: "3.1.0" sdks: - dart: ">=2.14.0 <3.0.0" + dart: ">=2.16.0-100.0.dev <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 6096aff5..475dc08e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,7 +9,7 @@ environment: sdk: ">=2.12.0-0 <3.0.0" dependencies: - analyzer: ">=3.2.0 <4.0.0" + analyzer: ^3.3.1 args: ">=1.0.0 <3.0.0" path: ^1.0.0 pub_semver: ">=1.4.4 <3.0.0" diff --git a/test/whitespace/constructors.unit b/test/whitespace/constructors.unit index 107bf1b5..6797b589 100644 --- a/test/whitespace/constructors.unit +++ b/test/whitespace/constructors.unit @@ -68,4 +68,26 @@ class Foo { <<< class Foo { Foo(this.bar(), baz); +} +>>> "super." parameters +class Foo { + Foo(super . a, int super . b , int super . bar()); + Foo.optional([ super . a, int super . b = 123 , int super . bar() ]); + Foo.named({ required super . a, int super . b : 123 , required int super . bar() }); + Foo.other( final int super.x, super.bar() ? ); +} +<<< +class Foo { + Foo(super.a, int super.b, + int super.bar()); + Foo.optional( + [super.a, + int super.b = 123, + int super.bar()]); + Foo.named( + {required super.a, + int super.b: 123, + required int super.bar()}); + Foo.other( + final int super.x, super.bar()?); } \ No newline at end of file diff --git a/test/whitespace/metadata.unit b/test/whitespace/metadata.unit index 37a311a2..2d7f1992 100644 --- a/test/whitespace/metadata.unit +++ b/test/whitespace/metadata.unit @@ -209,6 +209,15 @@ class Foo { class Foo { Foo(@bar this.field); } +>>> metadata on "super." parameter +class Foo { + Foo(@bar super.field, [ @foo() @baz super.another ]); +} +<<< +class Foo { + Foo(@bar super.field, + [@foo() @baz super.another]); +} >>> metadata on function-typed formal parameter withReturnType(@foo @bar int fn(@foo param)) {} withoutReturnType(@foo @bar fn(@foo param)) {}