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

Side by Side Diff: lib/src/span.dart

Issue 1028813002: Introduce span with line context (Closed) Base URL: git@github.com:dart-lang/source_span.git@master
Patch Set: Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library source_span.span; 5 library source_span.span;
6 6
7 import 'location.dart'; 7 import 'location.dart';
8 import 'span_context.dart';
8 import 'span_mixin.dart'; 9 import 'span_mixin.dart';
9 10
10 /// A class that describes a segment of source text. 11 /// A class that describes a segment of source text.
11 abstract class SourceSpan implements Comparable<SourceSpan> { 12 abstract class SourceSpan implements Comparable<SourceSpan> {
12 /// The start location of this span. 13 /// The start location of this span.
13 final SourceLocation start; 14 final SourceLocation start;
14 15
15 /// The end location of this span, exclusive. 16 /// The end location of this span, exclusive.
16 final SourceLocation end; 17 final SourceLocation end;
17 18
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 throw new ArgumentError("Source URLs \"${start.sourceUrl}\" and " 70 throw new ArgumentError("Source URLs \"${start.sourceUrl}\" and "
70 " \"${end.sourceUrl}\" don't match."); 71 " \"${end.sourceUrl}\" don't match.");
71 } else if (end.offset < start.offset) { 72 } else if (end.offset < start.offset) {
72 throw new ArgumentError('End $end must come after start $start.'); 73 throw new ArgumentError('End $end must come after start $start.');
73 } else if (text.length != start.distance(end)) { 74 } else if (text.length != start.distance(end)) {
74 throw new ArgumentError('Text "$text" must be ${start.distance(end)} ' 75 throw new ArgumentError('Text "$text" must be ${start.distance(end)} '
75 'characters long.'); 76 'characters long.');
76 } 77 }
77 } 78 }
78 } 79 }
80
81 /// A class that describes a segment of source text.
nweiz 2015/03/24 23:01:17 Update this doc comment.
Siggi Cherem (dart-lang) 2015/03/25 00:33:25 Done.
82 class SourceSpanWithContext extends SourceSpanBase
83 implements SourceSpanContext {
84 /// Line containing the source-span
nweiz 2015/03/24 23:01:17 "The text of the line containing this span. If th
Siggi Cherem (dart-lang) 2015/03/25 00:33:25 Sounds good. Done
85 final String contextLine;
86
87 /// Creates a new span from [start] to [end] (exclusive) containing [text], in
88 /// the context of [contextLine].
89 ///
90 /// [start] and [end] must have the same source URL and [start] must come
91 /// before [end]. [text] must have a number of characters equal to the
92 /// distance between [start] and [end]. [contextLine] must contain [text], and
93 /// [text] should start at `start.column`.
94 SourceSpanWithContext(SourceLocation start, SourceLocation end, String text,
95 this.contextLine) : super(start, end, text) {
nweiz 2015/03/24 23:01:17 Nit: put the super call on its own line.
Siggi Cherem (dart-lang) 2015/03/25 00:33:25 Done. This made me realized I was not running the
nweiz 2015/03/25 01:10:39 I actually prefer to have format-everything CLs se
Siggi Cherem (dart-lang) 2015/03/26 21:07:29 OK reverted all other formatter changes. In dev_c
96 var index = contextLine.indexOf(text);
97 if (index != start.column) {
98 throw new ArgumentError('The context line "$contextLine" must '
99 'contain "$text" starting at column ${start.column + 1}.');
nweiz 2015/03/24 23:01:17 I'd throw separate errors for [contextLine] not co
Siggi Cherem (dart-lang) 2015/03/25 00:33:25 Done.
100 }
101 }
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698