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

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 31200)
+++ pkg/analyzer/lib/src/services/formatter_impl.dart (working copy)
@@ -422,8 +422,10 @@
visit(node.leftHandSide);
space();
token(node.operator);
- space();
- visit(node.rightHandSide);
+ allowContinuedLines((){
+ space();
+ visit(node.rightHandSide);
+ });
}
visitBinaryExpression(BinaryExpression node) {
@@ -492,11 +494,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 +558,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 +669,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 +692,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 +847,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 +876,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 +1087,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 +1225,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 +1253,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 +1342,12 @@
}
}
+ /// Allow [code] to be continued across lines.
+ allowContinuedLines(code()) {
+ //TODO(pquitslund): add before
+ code();
+ //TODO(pquitslund): add after
+ }
/// Emit the given [modifier] if it's non null, followed by non-breaking
/// whitespace.
@@ -1447,7 +1479,7 @@
}
var lines = max(min, countNewlinesBetween(previousToken, currentToken));
- writer.newlines(lines);
+ emitNewlines(lines);
previousToken =
currentToken.previous != null ? currentToken.previous : token.previous;
@@ -1459,7 +1491,7 @@
var nextToken = comment.next != null ? comment.next : token;
var newlines = calculateNewlinesBetweenComments(comment, nextToken);
if (newlines > 0) {
- writer.newlines(newlines);
+ emitNewlines(newlines);
lines += newlines;
} else {
var spaces = countSpacesBetween(comment, nextToken);
@@ -1476,6 +1508,10 @@
return lines;
}
+ void emitNewlines(lines) {
+ writer.newlines(lines);
+ }
+
ensureTrailingNewline() {
if (writer.lastToken is! NewlineToken) {
writer.newline();
« 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