| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library source_maps.span_wrapper; |
| 6 |
| 7 import 'package:source_span/source_span.dart' as source_span; |
| 8 |
| 9 import '../span.dart'; |
| 10 |
| 11 /// A wrapper that exposes a [source_span.SourceSpan] as a [Span]. |
| 12 class SpanWrapper extends Span { |
| 13 final source_span.SourceSpan _inner; |
| 14 |
| 15 String get text => _inner.text; |
| 16 |
| 17 SpanWrapper(source_span.SourceSpan inner, bool isIdentifier) |
| 18 : _inner = inner, |
| 19 super( |
| 20 new LocationWrapper(inner.start), |
| 21 new LocationWrapper(inner.end), |
| 22 isIdentifier); |
| 23 |
| 24 static Span wrap(span, [bool isIdentifier = false]) { |
| 25 if (span is Span) return span; |
| 26 return new SpanWrapper(span, isIdentifier); |
| 27 } |
| 28 } |
| 29 |
| 30 /// A wrapper that exposes a [source_span.SourceLocation] as a [Location]. |
| 31 class LocationWrapper extends Location { |
| 32 final source_span.SourceLocation _inner; |
| 33 |
| 34 String get sourceUrl => _inner.sourceUrl.toString(); |
| 35 int get line => _inner.line; |
| 36 int get column => _inner.column; |
| 37 |
| 38 LocationWrapper(source_span.SourceLocation inner) |
| 39 : _inner = inner, |
| 40 super(inner.offset); |
| 41 |
| 42 static Location wrap(location) { |
| 43 if (location is Location) return location; |
| 44 return new LocationWrapper(location); |
| 45 } |
| 46 } |
| 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 |