Allow some fields to be overridden in strong mode.
For consistency, any field in a class that's meant to be extended can be
overridden.
R=lrn@google.com, rnystrom@google.com
Review URL: https://codereview.chromium.org//1728113002 .
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ce71980..cca6f11 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+# 1.2.2
+
+* Allow `SourceSpanException.message`, `SourceSpanFormatException.source`, and
+ `SourceSpanWithContext.context` to be overridden in strong mode.
+
# 1.2.1
* Fix the declared type of `FileSpan.start` and `FileSpan.end`. In 1.2.0 these
diff --git a/lib/src/span_exception.dart b/lib/src/span_exception.dart
index 921e620..6d3448b 100644
--- a/lib/src/span_exception.dart
+++ b/lib/src/span_exception.dart
@@ -6,15 +6,19 @@
/// A class for exceptions that have source span information attached.
class SourceSpanException implements Exception {
+ // This is a getter so that subclasses can override it.
/// A message describing the exception.
- final String message;
+ String get message => _message;
+ final String _message;
+ // This is a getter so that subclasses can override it.
/// The span associated with this exception.
///
/// This may be `null` if the source location can't be determined.
- final SourceSpan span;
+ SourceSpan get span => _span;
+ final SourceSpan _span;
- SourceSpanException(this.message, this.span);
+ SourceSpanException(this._message, this._span);
/// Returns a string representation of [this].
///
@@ -32,10 +36,9 @@
/// A [SourceSpanException] that's also a [FormatException].
class SourceSpanFormatException extends SourceSpanException
implements FormatException {
- final _source;
-
- // Subclasses may narrow the type.
+ // This is a getter so that subclasses can override it.
dynamic get source => _source;
+ final _source;
int get offset => span == null ? null : span.start.offset;
diff --git a/lib/src/span_with_context.dart b/lib/src/span_with_context.dart
index 1336b12..a02d780 100644
--- a/lib/src/span_with_context.dart
+++ b/lib/src/span_with_context.dart
@@ -8,8 +8,10 @@
/// A class that describes a segment of source text with additional context.
class SourceSpanWithContext extends SourceSpanBase {
+ // This is a getter so that subclasses can override it.
/// Text around the span, which includes the line containing this span.
- final String context;
+ String get context => _context;
+ final String _context;
/// Creates a new span from [start] to [end] (exclusive) containing [text], in
/// the given [context].
@@ -20,7 +22,7 @@
/// [text] should start at `start.column` from the beginning of a line in
/// [context].
SourceSpanWithContext(
- SourceLocation start, SourceLocation end, String text, this.context)
+ SourceLocation start, SourceLocation end, String text, this._context)
: super(start, end, text) {
if (!context.contains(text)) {
throw new ArgumentError(
diff --git a/pubspec.yaml b/pubspec.yaml
index 4c703cd..7ca7de4 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: source_span
-version: 1.2.1
+version: 1.2.2
author: Dart Team <misc@dartlang.org>
description: A library for identifying source spans and locations.
homepage: https://github.com/dart-lang/source_span