Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: lib/src/source_visitor.dart

Issue 889943004: Indent the parameter list more if the body is a wrapped "=>". Fix #144. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Update changelog. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | test/regression/144.unit » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/source_visitor.dart
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index ef110b82b4d198dce7352011b023048c2010b8f5..98513066083a97f2049c14791f1e914d09c2ddc6 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -456,7 +456,6 @@ class SourceVisitor implements AstVisitor {
visitConstructorDeclaration(ConstructorDeclaration node) {
visitMemberMetadata(node.metadata);
- _writer.nestExpression();
modifier(node.externalKeyword);
modifier(node.constKeyword);
modifier(node.factoryKeyword);
@@ -469,18 +468,14 @@ class SourceVisitor implements AstVisitor {
// line that the initialization list gets pushed to its own line too.
if (node.initializers.length == 1) _writer.startMultisplit();
- visit(node.parameters);
-
- // Check for redirects or initializer lists.
- if (node.redirectedConstructor != null) {
- _visitConstructorRedirects(node);
- } else if (node.initializers.isNotEmpty) {
- _visitConstructorInitializers(node);
- }
-
- _writer.unnest();
-
- visitBody(node.body);
+ _visitBody(node.parameters, node.body, () {
+ // Check for redirects or initializer lists.
+ if (node.redirectedConstructor != null) {
+ _visitConstructorRedirects(node);
+ } else if (node.initializers.isNotEmpty) {
+ _visitConstructorInitializers(node);
+ }
+ });
}
void _visitConstructorInitializers(ConstructorDeclaration node) {
@@ -710,6 +705,7 @@ class SourceVisitor implements AstVisitor {
}
visitFormalParameterList(FormalParameterList node) {
+ _writer.nestExpression();
token(node.leftParenthesis);
// Allow splitting after the "(" in non-empty parameter lists, but not for
@@ -754,6 +750,7 @@ class SourceVisitor implements AstVisitor {
token(node.rightDelimiter);
token(node.rightParenthesis);
+ _writer.unnest();
_writer.endSpan();
}
@@ -825,8 +822,7 @@ class SourceVisitor implements AstVisitor {
}
visitFunctionExpression(FunctionExpression node) {
- visit(node.parameters);
- visitBody(node.body);
+ _visitBody(node.parameters, node.body);
}
visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
@@ -1005,18 +1001,14 @@ class SourceVisitor implements AstVisitor {
visitMethodDeclaration(MethodDeclaration node) {
visitMemberMetadata(node.metadata);
- _writer.nestExpression();
modifier(node.externalKeyword);
modifier(node.modifierKeyword);
visit(node.returnType, after: space);
modifier(node.propertyKeyword);
modifier(node.operatorKeyword);
visit(node.name);
- if (!node.isGetter) visit(node.parameters);
- _writer.unnest();
-
- visitBody(node.body);
+ _visitBody(node.parameters, node.body);
}
visitMethodInvocation(MethodInvocation node) {
@@ -1481,9 +1473,29 @@ class SourceVisitor implements AstVisitor {
visitNodes(metadata, between: space, after: space);
}
- /// Visit the given function [body], printing a space before it if it's not
- /// empty.
- void visitBody(FunctionBody body) {
+ /// Visit the given function [parameters] followed by its [body], printing a
+ /// space before it if it's not empty.
+ ///
+ /// If [afterParameters] is provided, it is invoked between the parameters
+ /// and body. (It's used for constructor initialization lists.)
+ void _visitBody(FormalParameterList parameters, FunctionBody body,
+ [afterParameters()]) {
+ if (parameters != null) {
+ // If the body is "=>", add an extra level of indentation around the
+ // parameters. This ensures that if they wrap, they wrap more deeply than
+ // the "=>" does, as in:
+ //
+ // someFunction(parameter,
+ // parameter, parameter) =>
+ // "the body";
+ if (body is ExpressionFunctionBody) _writer.nestExpression();
+
+ visit(parameters);
+ if (afterParameters != null) afterParameters();
+
+ if (body is ExpressionFunctionBody) _writer.unnest();
+ }
+
if (body is! EmptyFunctionBody) space();
visit(body);
}
« no previous file with comments | « CHANGELOG.md ('k') | test/regression/144.unit » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698