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 all commits
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
Expand Up @@ -2,6 +2,7 @@

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

# 2.2.1

Expand Down
15 changes: 15 additions & 0 deletions lib/src/source_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2584,6 +2584,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
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