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

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

Issue 147983005: Improved linebreaking for imports (darbug.com/16366) and non-breaking line support. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 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 | « pkg/analyzer/lib/src/services/formatter_impl.dart ('k') | pkg/analyzer/test/services/data/cu_tests.data » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/services/writer.dart
===================================================================
--- pkg/analyzer/lib/src/services/writer.dart (revision 32082)
+++ pkg/analyzer/lib/src/services/writer.dart (working copy)
@@ -152,11 +152,15 @@
curr = merge(curr, token);
}
} else {
- if (curr != null) {
- tokens.add(curr);
- curr = null;
+ if (isNonbreaking(token)) {
+ curr = merge(curr, token);
+ } else {
+ if (curr != null) {
+ tokens.add(curr);
+ curr = null;
+ }
+ tokens.add(token);
}
- tokens.add(token);
}
});
@@ -167,6 +171,9 @@
return tokens;
}
+ static bool isNonbreaking(SpaceToken token) =>
+ token.breakWeight == UNBREAKABLE_SPACE_WEIGHT;
+
static LineToken merge(LineToken first, LineToken second) =>
new LineToken(first.value + second.value);
@@ -187,7 +194,8 @@
/// Special token indicating a line start
final LINE_START = new SpaceToken(0);
-const DEFAULT_SPACE_WEIGHT = -1;
+const DEFAULT_SPACE_WEIGHT = 0;
+const UNBREAKABLE_SPACE_WEIGHT = -1;
/// Simple non-breaking printer
class SimpleLinePrinter extends LinePrinter {
« no previous file with comments | « pkg/analyzer/lib/src/services/formatter_impl.dart ('k') | pkg/analyzer/test/services/data/cu_tests.data » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698