OLD | NEW |
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_maps.span_wrapper; | 5 library source_maps.span_wrapper; |
6 | 6 |
| 7 import 'package:source_maps/source_maps.dart'; |
7 import 'package:source_span/source_span.dart' as source_span; | 8 import 'package:source_span/source_span.dart' as source_span; |
8 | 9 |
9 import '../span.dart'; | |
10 | |
11 /// A wrapper that exposes a [source_span.SourceSpan] as a [Span]. | 10 /// A wrapper that exposes a [source_span.SourceSpan] as a [Span]. |
12 class SpanWrapper extends Span { | 11 class SpanWrapper extends Span { |
13 final source_span.SourceSpan _inner; | 12 final source_span.SourceSpan _inner; |
14 | 13 |
15 String get text => _inner.text; | 14 String get text => _inner.text; |
16 | 15 |
17 SpanWrapper(source_span.SourceSpan inner, bool isIdentifier) | 16 SpanWrapper(source_span.SourceSpan inner, bool isIdentifier) |
18 : _inner = inner, | 17 : _inner = inner, |
19 super( | 18 super( |
20 new LocationWrapper(inner.start), | 19 new LocationWrapper(inner.start), |
(...skipping 16 matching lines...) Expand all Loading... |
37 | 36 |
38 LocationWrapper(source_span.SourceLocation inner) | 37 LocationWrapper(source_span.SourceLocation inner) |
39 : _inner = inner, | 38 : _inner = inner, |
40 super(inner.offset); | 39 super(inner.offset); |
41 | 40 |
42 static Location wrap(location) { | 41 static Location wrap(location) { |
43 if (location is Location) return location; | 42 if (location is Location) return location; |
44 return new LocationWrapper(location); | 43 return new LocationWrapper(location); |
45 } | 44 } |
46 } | 45 } |
47 | |
48 /// A wrapper that exposes a [source_span.SourceFile] as a [SourceFile]. | |
49 class SourceFileWrapper implements SourceFile { | |
50 final source_span.SourceFile _inner; | |
51 | |
52 // These are necessary to avoid analyzer warnings; | |
53 final _lineStarts = null; | |
54 final _decodedChars = null; | |
55 | |
56 String get url => _inner.url.toString(); | |
57 | |
58 SourceFileWrapper(this._inner); | |
59 | |
60 static SourceFile wrap(sourceFile) { | |
61 if (sourceFile is SourceFile) return sourceFile; | |
62 return new SourceFileWrapper(sourceFile); | |
63 } | |
64 | |
65 Span span(int start, [int end, bool isIdentifier = false]) { | |
66 if (end == null) end = start; | |
67 return new SpanWrapper(_inner.span(start, end), isIdentifier); | |
68 } | |
69 | |
70 Location location(int offset) => new LocationWrapper(_inner.location(offset)); | |
71 | |
72 int getLine(int offset) => _inner.getLine(offset); | |
73 | |
74 int getColumn(int line, int offset) => _inner.getColumn(offset, line: line); | |
75 | |
76 int getOffset(int line, int column) => _inner.getOffset(line, column); | |
77 | |
78 String getText(int start, [int end]) => _inner.getText(start, end); | |
79 | |
80 String getLocationMessage(String message, int start, int end, | |
81 {bool useColors: false, String color}) { | |
82 return span(start, end).getLocationMessage(message, | |
83 useColors: useColors, color: color); | |
84 } | |
85 } | |
OLD | NEW |