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

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

Issue 136453008: Interpolated String hack-around. (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 | « no previous file | pkg/analyzer/lib/src/services/writer.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 31810)
+++ pkg/analyzer/lib/src/services/formatter_impl.dart (working copy)
@@ -133,7 +133,7 @@
var node = parse(kind, startToken);
checkForErrors();
- var formatter = new SourceVisitor(options, lineInfo, selection);
+ var formatter = new SourceVisitor(options, lineInfo, source, selection);
node.accept(formatter);
var formattedSource = formatter.writer.toString();
@@ -374,18 +374,23 @@
final bool codeTransforms;
+
+ /// The source being formatted (used in interpolation handling)
+ final String source;
+
/// Post format selection information.
Selection selection;
/// Initialize a newly created visitor to write source code representing
/// the visited nodes to the given [writer].
- SourceVisitor(FormatterOptions options, this.lineInfo, this.preSelection):
- writer = new SourceWriter(indentCount: options.initialIndentationLevel,
+ SourceVisitor(FormatterOptions options, this.lineInfo, this.source,
+ this.preSelection)
+ : writer = new SourceWriter(indentCount: options.initialIndentationLevel,
lineSeparator: options.lineSeparator,
useTabs: options.tabsForIndent,
spacesPerIndent: options.spacesPerIndent),
- codeTransforms = options.codeTransforms;
+ codeTransforms = options.codeTransforms;
visitAdjacentStrings(AdjacentStrings node) {
visitNodes(node.strings, separatedBy: space);
@@ -1169,7 +1174,15 @@
}
visitStringInterpolation(StringInterpolation node) {
- visitNodes(node.elements);
+ // Ensure that interpolated strings don't get broken up by treating them as
+ // a single String token
+ // Process token (for comments etc. but don't print the lexeme)
+ token(node.beginToken, printToken: (tok) => null);
+ var start = node.beginToken.offset;
+ var end = node.endToken.end;
+ String string = source.substring(start, end);
+ append(string);
+ //visitNodes(node.elements);
}
visitSuperConstructorInvocation(SuperConstructorInvocation node) {
@@ -1438,7 +1451,8 @@
preserveNewlines = true;
}
- token(Token token, {precededBy(), followedBy(), int minNewlines: 0}) {
+ token(Token token, {precededBy(), followedBy(),
+ printToken(tok), int minNewlines: 0}) {
if (token != null) {
if (needsNewline) {
minNewlines = max(1, minNewlines);
@@ -1451,7 +1465,11 @@
precededBy();
}
checkForSelectionUpdate(token);
- append(token.lexeme);
+ if (printToken == null) {
+ append(token.lexeme);
+ } else {
+ printToken(token);
+ }
if (followedBy != null) {
followedBy();
}
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/services/writer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698