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

Unified Diff: pkg/analysis_server/lib/src/package_uri_resolver.dart

Issue 422973002: Move PackageMapUriResolver into analyzer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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
Index: pkg/analysis_server/lib/src/package_uri_resolver.dart
diff --git a/pkg/analysis_server/lib/src/package_uri_resolver.dart b/pkg/analysis_server/lib/src/package_uri_resolver.dart
deleted file mode 100644
index 9f6d0421af36bbb21afe5d8468e82f99a4187fb5..0000000000000000000000000000000000000000
--- a/pkg/analysis_server/lib/src/package_uri_resolver.dart
+++ /dev/null
@@ -1,94 +0,0 @@
-// Copyright (c) 2014, 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.
-
-library resolver.package;
-
-import 'package:analyzer/file_system/file_system.dart';
-import 'package:analyzer/src/generated/source.dart';
-
-
-/**
- * A [UriResolver] implementation for the `package:` scheme that uses a map of
- * package names to their directories.
- */
-class PackageMapUriResolver extends UriResolver {
- /**
- * The name of the `package` scheme.
- */
- static const String PACKAGE_SCHEME = "package";
-
- /**
- * A table mapping package names to the path of the directories containing
- * the package.
- */
- final Map<String, List<Folder>> packageMap;
-
- /**
- * The [ResourceProvider] for this resolver.
- */
- final ResourceProvider resourceProvider;
-
- /**
- * Create a new [PackageMapUriResolver].
- *
- * [packageMap] is a table mapping package names to the paths of the
- * directories containing the package
- */
- PackageMapUriResolver(this.resourceProvider, this.packageMap);
-
- @override
- Source fromEncoding(UriKind kind, Uri uri) {
- if (kind == UriKind.PACKAGE_URI) {
- Resource resource = resourceProvider.getResource(uri.path);
- if (resource is File) {
- return resource.createSource(kind);
- }
- }
- return null;
- }
-
- @override
- Source resolveAbsolute(Uri uri) {
- if (!isPackageUri(uri)) {
- return null;
- }
- // Prepare path.
- String path = uri.path;
- // Prepare path components.
- String pkgName;
- String relPath;
- int index = path.indexOf('/');
- if (index == -1 || index == 0) {
- return null;
- } else {
- // <pkgName>/<relPath>
- pkgName = path.substring(0, index);
- relPath = path.substring(index + 1);
- }
- // Try to find an existing file.
- List<Folder> packageDirs = packageMap[pkgName];
- if (packageDirs != null) {
- for (Folder packageDir in packageDirs) {
- if (packageDir.exists) {
- Resource result = packageDir.getChild(relPath);
- if (result is File && result.exists) {
- return result.createSource(UriKind.PACKAGE_URI);
- }
- }
- }
- }
- // Return a NonExistingSource instance.
- // This helps provide more meaningful error messages to users
- // (a missing file error, as opposed to an invalid URI error).
- // TODO(scheglov) move NonExistingSource to "source.dart"
- return new NonExistingSource(uri.toString(), UriKind.PACKAGE_URI);
- }
-
- /**
- * Returns `true` if [uri] is a `package` URI.
- */
- static bool isPackageUri(Uri uri) {
- return uri.scheme == PACKAGE_SCHEME;
- }
-}
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | pkg/analysis_server/test/package_uri_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698