Skip to content
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

Format "super." parameters. #1097

Merged
merged 2 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 2.2.2

* Format named arguments anywhere (#1072).
* Format "super." parameters (#1091).

# 2.2.1

Expand Down
33 changes: 24 additions & 9 deletions lib/src/source_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ class SourceVisitor extends ThrowingAstVisitor {
token(node.equals);
space();

visit(node.superclass2);
visit(node.superclass);

builder.startRule(CombinatorRule());
visit(node.withClause);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -1373,7 +1373,7 @@ class SourceVisitor extends ThrowingAstVisitor {
soloSplit();
token(node.extendsKeyword);
space();
visit(node.superclass2);
visit(node.superclass);
}

@override
Expand Down Expand Up @@ -1999,7 +1999,7 @@ class SourceVisitor extends ThrowingAstVisitor {

@override
void visitImplementsClause(ImplementsClause node) {
_visitCombinator(node.implementsKeyword, node.interfaces2);
_visitCombinator(node.implementsKeyword, node.interfaces);
}

@override
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -2326,7 +2326,7 @@ class SourceVisitor extends ThrowingAstVisitor {

@override
void visitOnClause(OnClause node) {
_visitCombinator(node.onKeyword, node.superclassConstraints2);
_visitCombinator(node.onKeyword, node.superclassConstraints);
}

@override
Expand Down Expand Up @@ -2528,6 +2528,21 @@ class SourceVisitor extends ThrowingAstVisitor {
token(node.superKeyword);
}

@override
void visitSuperFormalParameter(SuperFormalParameter node) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is virtually identical to the code for visitFieldFormalParameter() (this. parameters), which is to be expected. Unfortunately, I couldn't easily hoist it out to something reusable because FieldFormalParameter and SuperFormalParameter don't define their fields on any shared base class.

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);
Expand Down Expand Up @@ -2730,7 +2745,7 @@ class SourceVisitor extends ThrowingAstVisitor {

@override
void visitWithClause(WithClause node) {
_visitCombinator(node.withKeyword, node.mixinTypes2);
_visitCombinator(node.withKeyword, node.mixinTypes);
}

@override
Expand Down
22 changes: 11 additions & 11 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 22 additions & 0 deletions test/whitespace/constructors.unit
Original file line number Diff line number Diff line change
Expand Up @@ -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()?);
}
9 changes: 9 additions & 0 deletions test/whitespace/metadata.unit
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {}
Expand Down