f4ff72aadd
This change migrates the analyzer_utilities package to use the new constructor declaration syntax, described in https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md#abbreviations-of-in-body-constructor-declarations. This change was performed in an automated fashion, by (a) bumping the packages' SDK constraints to `3.13.0-0`, (b) enabling the lints `unnecessary_type_name_in_constructor` and `unnecessary_const_in_enum_constructor`, (c) fixing the resulting lint failures using `dart fix`, and then (d) reformatting the affected files. To ease code review, I've reverted unrelated formatting changes. Since this change requires bumping SDK constaints to `3.13.0-0`, it was only performed on packages that are *not* published on pub. (Packages that *are* published on pub should remain on lower language versions until at least after the stable version of 3.13 is released, so that we don't block users on the stable channel from receiving updates to those packages.) Change-Id: Ib9564fe588b1118f7e810bd39ff9c6576a6a6964 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505066 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
45 lines
1.3 KiB
Dart
45 lines
1.3 KiB
Dart
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'package:source_span/source_span.dart';
|
|
|
|
/// An error with an associated source span.
|
|
class LocatedError {
|
|
final SourceSpan span;
|
|
final String message;
|
|
|
|
new(this.message, {required this.span});
|
|
|
|
@override
|
|
String toString() => '${span.location}: $message';
|
|
|
|
/// Executes [callback], converting any exceptions it generates to a
|
|
/// [LocatedError] that points to [node].
|
|
static T wrap<T>(T Function() callback, {required SourceSpan span}) {
|
|
try {
|
|
return callback();
|
|
} catch (error, stackTrace) {
|
|
if (error is! LocatedError) {
|
|
Error.throwWithStackTrace(
|
|
LocatedError(error.toString(), span: span),
|
|
stackTrace,
|
|
);
|
|
} else {
|
|
rethrow;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
extension SourceSpanLocation on SourceSpan {
|
|
/// A string suitable for identifying this span in the source YAML file.
|
|
String get location {
|
|
var path = start.sourceUrl?.toFilePath() ?? '<unknown>';
|
|
// Convert line/column to 1-based because that's what most editors expect
|
|
var line = start.line + 1;
|
|
var column = start.column + 1;
|
|
return '$path:$line:$column';
|
|
}
|
|
}
|