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

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

Issue 24180004: Source selection API abstraction first cut. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 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
Index: pkg/analyzer_experimental/lib/src/services/formatter_impl.dart
===================================================================
--- pkg/analyzer_experimental/lib/src/services/formatter_impl.dart (revision 27530)
+++ pkg/analyzer_experimental/lib/src/services/formatter_impl.dart (working copy)
@@ -78,11 +78,37 @@
/// Format the specified portion (from [offset] with [length]) of the given
/// [source] string, optionally providing an [indentationLevel].
- String format(CodeKind kind, String source, {int offset, int end,
- int indentationLevel: 0});
+ FormattedSource format(CodeKind kind, String source, {int offset, int end,
+ int indentationLevel: 0, Selection selection: null});
}
+/// Source selection state information.
+class Selection {
+
+ /// The offset of the source selection.
+ final int offset;
+
+ /// The length of the selection.
+ final int length;
+
+ Selection(this.offset, this.length);
+}
+
+/// Formatted source.
+class FormattedSource {
+
+ /// Selection state or null if unspecified.
+ final Selection selection;
+
+ /// Formatted source string.
+ final String source;
+
+ /// Create a formatted [source] result, with optional [selection] information.
+ FormattedSource(this.source, [this.selection = null]);
+}
+
+
class CodeFormatterImpl implements CodeFormatter, AnalysisErrorListener {
final FormatterOptions options;
@@ -93,8 +119,8 @@
CodeFormatterImpl(this.options);
- String format(CodeKind kind, String source, {int offset, int end,
- int indentationLevel: 0}) {
+ FormattedSource format(CodeKind kind, String source, {int offset, int end,
+ int indentationLevel: 0, Selection selection: null}) {
var startToken = tokenize(source);
checkForErrors();
@@ -109,7 +135,7 @@
checkTokenStreams(startToken, tokenize(formattedSource));
- return formattedSource;
+ return new FormattedSource(formattedSource);
}
checkTokenStreams(Token t1, Token t2) =>
« no previous file with comments | « pkg/analyzer_experimental/bin/formatter.dart ('k') | pkg/analyzer_experimental/test/services/formatter_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698