a5912c6c58
Broadly, this _adds_ text to the code, as making something explicit which was previously implicit generally requires adding characters. The fixes are of the form: * `int x = y /* dynamic */;` --> `var x = y as int;` * `Map<A, B> x = y; --> `var x = y.cast<A, B>();` Most of the changes are in code which has parsed YAML or which has parsed arguments. Go figure. :) Change-Id: I1107688bf4ce9c1ec3ed6a4cef56d4d968048e2e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278522 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Samuel Rawlins <srawlins@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
89 lines
2.9 KiB
Dart
89 lines
2.9 KiB
Dart
// Copyright (c) 2016, 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 'dart:collection';
|
|
|
|
import 'package:analyzer/file_system/file_system.dart';
|
|
import 'package:yaml/yaml.dart';
|
|
|
|
/// Given a package map, check in each package's lib directory for the existence
|
|
/// of an `_embedder.yaml` file. If the file contains a top level YamlMap, it
|
|
/// will be added to the [embedderYamls] map.
|
|
class EmbedderYamlLocator {
|
|
/// The name of the embedder files being searched for.
|
|
static const String _embedderFileName = '_embedder.yaml';
|
|
|
|
/// A mapping from a package's library directory to the parsed YamlMap.
|
|
final Map<Folder, YamlMap> embedderYamls = HashMap<Folder, YamlMap>();
|
|
|
|
/// Initialize a newly created locator by processing the packages in the given
|
|
/// [packageMap].
|
|
EmbedderYamlLocator(Map<String, List<Folder>>? packageMap) {
|
|
if (packageMap != null) {
|
|
_processPackageMap(packageMap);
|
|
}
|
|
}
|
|
|
|
/// Initialize with the given [libFolder] of `sky_engine` package.
|
|
EmbedderYamlLocator.forLibFolder(Folder libFolder) {
|
|
_processPackage([libFolder]);
|
|
}
|
|
|
|
/// Programmatically add an `_embedder.yaml` mapping.
|
|
void addEmbedderYaml(Folder libDir, String embedderYaml) {
|
|
_processEmbedderYaml(libDir, embedderYaml);
|
|
}
|
|
|
|
/// Refresh the map of located files to those found by processing the given
|
|
/// [packageMap].
|
|
void refresh(Map<String, List<Folder>>? packageMap) {
|
|
// Clear existing.
|
|
embedderYamls.clear();
|
|
if (packageMap != null) {
|
|
_processPackageMap(packageMap);
|
|
}
|
|
}
|
|
|
|
/// Given the yaml for an embedder ([embedderYaml]) and a folder ([libDir]),
|
|
/// setup the uri mapping.
|
|
void _processEmbedderYaml(Folder libDir, String embedderYaml) {
|
|
try {
|
|
var yaml = loadYaml(embedderYaml);
|
|
if (yaml is YamlMap) {
|
|
embedderYamls[libDir] = yaml;
|
|
}
|
|
} catch (_) {
|
|
// Ignored
|
|
}
|
|
}
|
|
|
|
/// Given a package list of folders ([libDirs]), process any
|
|
/// `_embedder.yaml` files that are found in any of the folders.
|
|
void _processPackage(List<Folder> libDirs) {
|
|
for (Folder libDir in libDirs) {
|
|
String? embedderYaml = _readEmbedderYaml(libDir);
|
|
if (embedderYaml != null) {
|
|
_processEmbedderYaml(libDir, embedderYaml);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Process each of the entries in the [packageMap].
|
|
void _processPackageMap(Map<String, List<Folder>> packageMap) {
|
|
packageMap.values.forEach(_processPackage);
|
|
}
|
|
|
|
/// Read and return the contents of [libDir]/[_embedderFileName], or `null`
|
|
/// if the file doesn't exist.
|
|
String? _readEmbedderYaml(Folder libDir) {
|
|
var file = libDir.getChildAssumingFile(_embedderFileName);
|
|
try {
|
|
return file.readAsStringSync();
|
|
} on FileSystemException {
|
|
// File can't be read.
|
|
return null;
|
|
}
|
|
}
|
|
}
|