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

Unified Diff: pkg/analyzer/lib/src/services/formatter_impl.dart

Issue 109423004: Formatter line continuation awareness hooks. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years 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 | « no previous file | pkg/analyzer/test/services/formatter_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/services/formatter_impl.dart
===================================================================
--- pkg/analyzer/lib/src/services/formatter_impl.dart (revision 31147)
+++ pkg/analyzer/lib/src/services/formatter_impl.dart (working copy)
@@ -397,7 +397,9 @@
visitArgumentList(ArgumentList node) {
token(node.leftParenthesis);
- visitCommaSeparatedNodes(node.arguments);
+ allowContinuedLines((){
+ visitCommaSeparatedNodes(node.arguments);
+ });
token(node.rightParenthesis);
}
@@ -422,8 +424,10 @@
visit(node.leftHandSide);
space();
token(node.operator);
- space();
- visit(node.rightHandSide);
+ allowContinuedLines((){
+ space();
+ visit(node.rightHandSide);
+ });
}
visitBinaryExpression(BinaryExpression node) {
@@ -492,11 +496,13 @@
token(node.classKeyword);
space();
visit(node.name);
- visit(node.typeParameters);
- visitNode(node.extendsClause, precededBy: space);
- visitNode(node.withClause, precededBy: space);
- visitNode(node.implementsClause, precededBy: space);
- space();
+ allowContinuedLines((){
+ visit(node.typeParameters);
+ visitNode(node.extendsClause, precededBy: space);
+ visitNode(node.withClause, precededBy: space);
+ visitNode(node.implementsClause, precededBy: space);
+ space();
+ });
token(node.leftBracket);
indent();
visitNodes(node.members, precededBy: newlines, separatedBy: newlines);
@@ -554,12 +560,14 @@
visit(node.condition);
space();
token(node.question);
- space();
- visit(node.thenExpression);
- space();
- token(node.colon);
- space();
- visit(node.elseExpression);
+ allowContinuedLines((){
+ space();
+ visit(node.thenExpression);
+ space();
+ token(node.colon);
+ space();
+ visit(node.elseExpression);
+ });
}
visitConstructorDeclaration(ConstructorDeclaration node) {
@@ -663,8 +671,10 @@
token(node.whileKeyword);
space();
token(node.leftParenthesis);
- visit(node.condition);
- token(node.rightParenthesis);
+ allowContinuedLines((){
+ visit(node.condition);
+ token(node.rightParenthesis);
+ });
token(node.semicolon);
}
@@ -684,7 +694,9 @@
token(node.keyword);
space();
visit(node.uri);
- visitNodes(node.combinators, precededBy: space, separatedBy: space);
+ allowContinuedLines((){
+ visitNodes(node.combinators, precededBy: space, separatedBy: space);
+ });
token(node.semicolon);
}
@@ -837,11 +849,13 @@
visitIfStatement(IfStatement node) {
var hasElse = node.elseStatement != null;
token(node.ifKeyword);
+ allowContinuedLines((){
+ space();
+ token(node.leftParenthesis);
+ visit(node.condition);
+ token(node.rightParenthesis);
+ });
space();
- token(node.leftParenthesis);
- visit(node.condition);
- token(node.rightParenthesis);
- space();
if (hasElse) {
printAsBlock(node.thenStatement);
space();
@@ -864,8 +878,10 @@
space();
visit(node.uri);
token(node.asToken, precededBy: space, followedBy: space);
- visit(node.prefix);
- visitNodes(node.combinators, precededBy: space, separatedBy: space);
+ allowContinuedLines((){
+ visit(node.prefix);
+ visitNodes(node.combinators, precededBy: space, separatedBy: space);
+ });
token(node.semicolon);
}
@@ -1073,9 +1089,11 @@
token(node.semicolon);
} else {
token(node.keyword);
- space();
- expression.accept(this);
- token(node.semicolon);
+ allowContinuedLines((){
+ space();
+ expression.accept(this);
+ token(node.semicolon);
+ });
}
}
@@ -1209,8 +1227,16 @@
if (node.initializer != null) {
space();
token(node.equals);
- space();
- visit(node.initializer);
+ var initializer = node.initializer;
+ if (initializer is! ListLiteral && initializer is! MapLiteral) {
+ allowContinuedLines((){
+ space();
+ visit(initializer);
+ });
+ } else {
+ space();
+ visit(initializer);
+ }
}
}
@@ -1229,8 +1255,10 @@
token(node.keyword);
space();
token(node.leftParenthesis);
- visit(node.condition);
- token(node.rightParenthesis);
+ allowContinuedLines((){
+ visit(node.condition);
+ token(node.rightParenthesis);
+ });
if (node.body is! EmptyStatement) {
space();
}
@@ -1316,6 +1344,12 @@
}
}
+ /// Allow [code] to be continued across lines.
+ allowContinuedLines(code()) {
+ indent(2);
Brian Wilkerson 2013/12/13 22:38:03 Do we want to increase the indentation if allowCon
+ code();
+ unindent(2);
+ }
/// Emit the given [modifier] if it's non null, followed by non-breaking
/// whitespace.
« no previous file with comments | « no previous file | pkg/analyzer/test/services/formatter_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698