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

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

Issue 105613003: Fix for map and list literal indentation (dartbug.com/15453). (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 30874)
+++ pkg/analyzer/lib/src/services/formatter_impl.dart (working copy)
@@ -355,6 +355,10 @@
/// A counter for spaces that should be emitted preceding the next token.
int leadingSpaces = 0;
+ /// A flag to specify whether line-leading spaces should be preserved (and
+ /// addded to the indent level).
+ bool allowLineLeadingSpaces;
+
/// Used for matching EOL comments
final twoSlashes = new RegExp(r'//[^/]');
@@ -598,7 +602,7 @@
// preceding comma
token(node.initializers[i].beginToken.previous);
newlines();
- space(2);
+ space(n: 2, allowLineLeading: true);
}
node.initializers[i].accept(this);
}
@@ -936,8 +940,10 @@
modifier(node.constKeyword);
visit(node.typeArguments);
token(node.leftBracket);
+ indent();
visitCommaSeparatedNodes(node.elements);
optionalTrailingComma(node.rightBracket);
+ unindent();
token(node.rightBracket);
}
@@ -945,8 +951,10 @@
modifier(node.constKeyword);
visitNode(node.typeArguments, followedBy: space);
token(node.leftBracket);
+ indent();
visitCommaSeparatedNodes(node.entries);
optionalTrailingComma(node.rightBracket);
+ unindent();
token(node.rightBracket);
}
@@ -1351,7 +1359,10 @@
emitSpaces() {
while (leadingSpaces > 0) {
- writer.print(' ');
+ if (!writer.currentLine.isWhitespace() || allowLineLeadingSpaces) {
+ writer.print(' ');
+ }
+ allowLineLeadingSpaces = false;
leadingSpaces--;
}
}
@@ -1370,10 +1381,13 @@
}
}
- /// Emit a non-breakable space.
- space([n = 1]) {
+ /// Emit a non-breakable space. If [allowLineLeading] is specified, spaces
+ /// will be preserved at the start of a line (in addition to the
+ /// indent-level), otherwise line-leading spaces will be ignored.
+ space({n: 1, allowLineLeading: false}) {
//TODO(pquitslund): replace with a proper space token
leadingSpaces+=n;
+ allowLineLeadingSpaces = allowLineLeading;
}
/// Emit a breakable space
« 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