36c0788137
add sdk_packages.yaml file (describes SDK vendored package locations) delete old macro code in _fe_analyzer_shared, move tests/benchmarks adds a top level `pkg` directory to the Dart SDK, which is where vendored packages live BUG: https://github.com/dart-lang/sdk/issues/54976 Change-Id: Ib3503a27fb5644fa8a39ab5a3e5b568df330cfd6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359040 Auto-Submit: Jake Macdonald <jakemac@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Jonas Termansen <sortie@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com> Commit-Queue: Jake Macdonald <jakemac@google.com> Reviewed-by: Devon Carew <devoncarew@google.com>
55 lines
1.7 KiB
Dart
55 lines
1.7 KiB
Dart
// Copyright (c) 2023, 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.
|
|
//
|
|
// ignore_for_file: deprecated_member_use
|
|
// ignore_for_file: deprecated_member_use_from_same_package
|
|
|
|
import 'package:macros/macros.dart';
|
|
|
|
extension TypePhaseIntrospecterExtension on TypePhaseIntrospector {
|
|
/// Converts [string] into `Code`.
|
|
///
|
|
/// Identifiers to resolve must be marked with backticks, for example:
|
|
///
|
|
/// ```
|
|
/// `int` get x => 3;
|
|
/// ```
|
|
///
|
|
/// They will be resolved in the context of `dart:core`.
|
|
///
|
|
/// If [string] is `null`, just return `null`; or throw if `T` is not
|
|
/// nullable.
|
|
Future<T> code<T extends Code>(String string) async {
|
|
final parts = <Object>[];
|
|
final chunks = string.split('`');
|
|
var isIdentifier = false;
|
|
for (final chunk in chunks) {
|
|
if (isIdentifier) {
|
|
parts.add(await this.resolveIdentifier(Uri.parse('dart:core'), chunk));
|
|
} else {
|
|
parts.add(chunk);
|
|
}
|
|
isIdentifier = !isIdentifier;
|
|
}
|
|
|
|
if (T == CommentCode) {
|
|
return CommentCode.fromParts(parts) as T;
|
|
} else if (T == DeclarationCode) {
|
|
return DeclarationCode.fromParts(parts) as T;
|
|
} else if (T == ExpressionCode) {
|
|
return ExpressionCode.fromParts(parts) as T;
|
|
} else if (T == FunctionBodyCode) {
|
|
return FunctionBodyCode.fromParts(parts) as T;
|
|
} else {
|
|
throw UnsupportedError(T.runtimeType.toString());
|
|
}
|
|
}
|
|
|
|
/// As [code] but returns `null` for `null` input
|
|
Future<T?> maybeCode<T extends Code>(String? string) async {
|
|
if (string == null) return null;
|
|
return await code<T>(string);
|
|
}
|
|
}
|