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

Unified Diff: pkg/kernel/lib/analyzer/loader.dart

Issue 2532053005: Store library paths relative to a given application root folder. (Closed)
Patch Set: Revert changes to testcase baseline Created 4 years, 1 month 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 | « pkg/kernel/bin/dartk.dart ('k') | pkg/kernel/lib/application_root.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/analyzer/loader.dart
diff --git a/pkg/kernel/lib/analyzer/loader.dart b/pkg/kernel/lib/analyzer/loader.dart
index 1591bcf71f4e70afb4d1899d10b8e272ddb880c5..fb523000daa7dfbe3c33803eee39bcfd0881b10f 100644
--- a/pkg/kernel/lib/analyzer/loader.dart
+++ b/pkg/kernel/lib/analyzer/loader.dart
@@ -16,6 +16,7 @@ import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/parser.dart';
import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/source_io.dart';
+import 'package:kernel/application_root.dart';
import 'package:package_config/discovery.dart';
import 'package:package_config/packages.dart';
@@ -35,6 +36,7 @@ class DartOptions {
bool strongModeSdk;
String sdk;
String packagePath;
+ ApplicationRoot applicationRoot;
Map<Uri, Uri> customUriMappings;
Map<String, String> declaredVariables;
@@ -43,12 +45,14 @@ class DartOptions {
bool strongModeSdk,
this.sdk,
this.packagePath,
+ ApplicationRoot applicationRoot,
Map<Uri, Uri> customUriMappings,
Map<String, String> declaredVariables})
: this.customUriMappings = customUriMappings ?? <Uri, Uri>{},
this.declaredVariables = declaredVariables ?? <String, String>{},
this.strongMode = strongMode,
- this.strongModeSdk = strongModeSdk ?? strongMode;
+ this.strongModeSdk = strongModeSdk ?? strongMode,
+ this.applicationRoot = applicationRoot ?? new ApplicationRoot.none();
}
abstract class ReferenceLevelLoader {
@@ -68,6 +72,7 @@ abstract class ReferenceLevelLoader {
class DartLoader implements ReferenceLevelLoader {
final Repository repository;
+ final ApplicationRoot applicationRoot;
final Bimap<ClassElement, ast.Class> _classes =
new Bimap<ClassElement, ast.Class>();
final Bimap<Element, ast.Member> _members = new Bimap<Element, ast.Member>();
@@ -90,19 +95,16 @@ class DartLoader implements ReferenceLevelLoader {
DartLoader(this.repository, DartOptions options, Packages packages,
{DartSdk dartSdk})
- : this.context = createContext(options, packages, dartSdk: dartSdk);
-
- LibraryElement getLibraryElement(ast.Library node) {
- return context
- .getLibraryElement(context.sourceFactory.forUri2(node.importUri));
- }
+ : this.context = createContext(options, packages, dartSdk: dartSdk),
+ this.applicationRoot = options.applicationRoot;
String getLibraryName(LibraryElement element) {
return element.name.isEmpty ? null : element.name;
}
ast.Library getLibraryReference(LibraryElement element) {
- return repository.getLibraryReference(element.source.uri)
+ var uri = applicationRoot.relativeUri(element.source.uri);
+ return repository.getLibraryReference(uri)
..name ??= getLibraryName(element)
..fileUri = "file://${element.source.fullName}";
}
@@ -579,7 +581,8 @@ class DartLoader implements ReferenceLevelLoader {
void ensureLibraryIsLoaded(ast.Library node) {
if (!node.isExternal) return;
node.isExternal = false;
- var source = context.sourceFactory.forUri2(node.importUri);
+ var source = context.sourceFactory
+ .forUri2(applicationRoot.absoluteUri(node.importUri));
assert(source != null);
var element = context.computeLibraryElement(source);
context.resolveCompilationUnit(source, element);
@@ -623,8 +626,9 @@ class DartLoader implements ReferenceLevelLoader {
List<String> getLoadedFileNames() {
var list = <String>[];
for (var library in repository.libraries) {
- LibraryElement element = context.computeLibraryElement(
- context.sourceFactory.forUri2(library.importUri));
+ LibraryElement element = context.computeLibraryElement(context
+ .sourceFactory
+ .forUri2(applicationRoot.absoluteUri(library.importUri)));
for (var unit in element.units) {
list.add(unit.source.fullName);
}
@@ -639,8 +643,9 @@ class DartLoader implements ReferenceLevelLoader {
}
}
- ast.Program loadProgram(String mainLibrary, {Target target}) {
- ast.Library library = repository.getLibrary(mainLibrary);
+ ast.Program loadProgram(Uri mainLibrary, {Target target}) {
+ ast.Library library = repository
+ .getLibraryReference(applicationRoot.relativeUri(mainLibrary));
ensureLibraryIsLoaded(library);
loadEverything(target: target);
var program = new ast.Program(repository.libraries);
@@ -661,8 +666,9 @@ class DartLoader implements ReferenceLevelLoader {
return program;
}
- ast.Library loadLibrary(String mainLibrary) {
- ast.Library library = repository.getLibrary(mainLibrary);
+ ast.Library loadLibrary(Uri uri) {
+ ast.Library library =
+ repository.getLibraryReference(applicationRoot.relativeUri(uri));
ensureLibraryIsLoaded(library);
return library;
}
« no previous file with comments | « pkg/kernel/bin/dartk.dart ('k') | pkg/kernel/lib/application_root.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698