Skip to content

Commit aaecab2

Browse files
stereotype441Commit Queue
authored andcommitted
[messages] Add LocatableDiagnostic.atSourceRange.
This expands the analyzer's literate API for diagnostic reporting so that diagnostic locations can be specified using a `SourceRange` object. Change-Id: I6a6a696470fd1ef2682e88e6c4dc7b467ed3e39b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467643 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
1 parent 5d199d6 commit aaecab2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pkg/_fe_analyzer_shared/lib/src/base/errors.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'dart:math';
1010
import 'package:_fe_analyzer_shared/src/base/analyzer_public_api.dart';
1111
import 'package:_fe_analyzer_shared/src/base/diagnostic_message.dart';
1212
import 'package:_fe_analyzer_shared/src/base/source.dart';
13+
import 'package:_fe_analyzer_shared/src/base/source_range.dart';
1314
import 'package:_fe_analyzer_shared/src/base/syntactic_entity.dart';
1415
import 'package:source_span/source_span.dart';
1516

@@ -571,6 +572,10 @@ base mixin DiagnosticWithoutArguments on DiagnosticCodeImpl
571572
LocatedDiagnostic atOffset({required int offset, required int length}) =>
572573
new LocatedDiagnostic(this, offset, length);
573574

575+
@override
576+
LocatedDiagnostic atSourceRange(SourceRange sourceRange) =>
577+
atOffset(offset: sourceRange.offset, length: sourceRange.length);
578+
574579
@override
575580
LocatedDiagnostic atSourceSpan(SourceSpan span) =>
576581
atOffset(offset: span.start.offset, length: span.length);
@@ -633,6 +638,12 @@ abstract final class LocatableDiagnostic {
633638
/// The result may be passed to [DiagnosticReporter.reportError].
634639
LocatedDiagnostic atOffset({required int offset, required int length});
635640

641+
/// Converts this diagnostic to a [LocatedDiagnostic] by applying it to a
642+
/// location in the source code.
643+
///
644+
/// The result may be passed to [DiagnosticReporter.reportError].
645+
LocatedDiagnostic atSourceRange(SourceRange sourceRange);
646+
636647
/// Converts this diagnostic to a [LocatedDiagnostic] by applying it to a
637648
/// location in the source code.
638649
///
@@ -683,6 +694,10 @@ final class LocatableDiagnosticImpl implements LocatableDiagnostic {
683694
LocatedDiagnostic atOffset({required int offset, required int length}) =>
684695
new LocatedDiagnostic(this, offset, length);
685696

697+
@override
698+
LocatedDiagnostic atSourceRange(SourceRange sourceRange) =>
699+
atOffset(offset: sourceRange.offset, length: sourceRange.length);
700+
686701
@override
687702
LocatedDiagnostic atSourceSpan(SourceSpan span) =>
688703
atOffset(offset: span.start.offset, length: span.length);

0 commit comments

Comments
 (0)