Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Unified Diff: pkg/analyzer/lib/source/embedder.dart

Issue 2208503004: Move embedder locator and convert context builder to use the new API (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/context/builder.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/source/embedder.dart
diff --git a/pkg/analyzer/lib/source/embedder.dart b/pkg/analyzer/lib/source/embedder.dart
index 56abc6a586c848014abadeae93ef46263b12962d..0dd84c0784eb1fb21c9d6b2391e7eec1b4ce9a4d 100644
--- a/pkg/analyzer/lib/source/embedder.dart
+++ b/pkg/analyzer/lib/source/embedder.dart
@@ -19,6 +19,8 @@ import 'package:analyzer/src/generated/source_io.dart' show FileBasedSource;
import 'package:analyzer/src/summary/idl.dart';
import 'package:yaml/yaml.dart';
+export 'package:analyzer/src/context/builder.dart' show EmbedderYamlLocator;
+
const String _DART_COLON_PREFIX = 'dart:';
const String _EMBEDDED_LIB_MAP_KEY = 'embedded_libs';
@@ -175,74 +177,3 @@ class EmbedderUriResolver implements DartUriResolver {
return sdkSource?.uri;
}
}
-
-/// Given a packageMap, 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 {
- static const String EMBEDDER_FILE_NAME = '_embedder.yaml';
-
- /// Map from package's library directory to the parsed YamlMap.
- final Map<Folder, YamlMap> embedderYamls = new HashMap<Folder, YamlMap>();
-
- EmbedderYamlLocator(Map<String, List<Folder>> packageMap) {
- if (packageMap != null) {
- _processPackageMap(packageMap);
- }
- }
-
- /// Programatically add an _embedder.yaml mapping.
- void addEmbedderYaml(Folder libDir, String embedderYaml) {
- _processEmbedderYaml(libDir, embedderYaml);
- }
-
- 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) {
- YamlNode yaml;
- try {
- yaml = loadYaml(embedderYaml);
- } catch (_) {
- return;
- }
- if (yaml is! YamlMap) {
- return;
- }
- embedderYamls[libDir] = yaml;
- }
-
- /// Given a package [name] and a list of folders ([libDirs]),
- /// add any found `_embedder.yaml` files.
- void _processPackage(String name, List<Folder> libDirs) {
- for (Folder libDir in libDirs) {
- String embedderYaml = _readEmbedderYaml(libDir);
- if (embedderYaml != null) {
- _processEmbedderYaml(libDir, embedderYaml);
- }
- }
- }
-
- void _processPackageMap(Map<String, List<Folder>> packageMap) {
- packageMap.forEach(_processPackage);
- }
-
- /// Read the contents of [libDir]/[EMBEDDER_FILE_NAME] as a string.
- /// Returns null if the file doesn't exist.
- String _readEmbedderYaml(Folder libDir) {
- File file = libDir.getChild(EMBEDDER_FILE_NAME);
- try {
- return file.readAsStringSync();
- } on FileSystemException {
- // File can't be read.
- return null;
- }
- }
-}
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/context/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698