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

Unified Diff: compiler/java/com/google/dart/compiler/UrlLibrarySource.java

Issue 11027006: Dart analyzer fixes to improve pluggability. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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: compiler/java/com/google/dart/compiler/UrlLibrarySource.java
===================================================================
--- compiler/java/com/google/dart/compiler/UrlLibrarySource.java (revision 13079)
+++ compiler/java/com/google/dart/compiler/UrlLibrarySource.java (working copy)
@@ -1,4 +1,4 @@
-// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2012, 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.
package com.google.dart.compiler;
@@ -10,6 +10,7 @@
* A {@link LibrarySource} backed by a URL.
*/
public class UrlLibrarySource extends UrlSource implements LibrarySource {
+
public UrlLibrarySource(URI uri, PackageLibraryManager slm) {
super(uri, slm);
}
@@ -28,20 +29,6 @@
}
@Override
- public DartSource getSourceFor(final String relPath) {
- if (relPath == null || relPath.isEmpty()) {
- return null;
- }
- try {
- // Force the creation of an escaped relative URI to deal with spaces, etc.s
- URI uri = getUri().resolve(new URI(null, null, relPath, null, null)).normalize();
- return new UrlDartSource(uri, relPath, this, packageLibraryManager);
- } catch (Throwable e) {
- return null;
- }
- }
-
- @Override
public LibrarySource getImportFor(String relPath) {
if (relPath == null || relPath.isEmpty()) {
return null;
@@ -52,26 +39,81 @@
String path = uri.getPath();
// Resolve relative reference out of one system library into another
if (PackageLibraryManager.isDartUri(uri)) {
- if(path != null && path.startsWith("/..")) {
+ if (path != null && path.startsWith("/..")) {
URI fileUri = packageLibraryManager.resolveDartUri(uri);
URI shortUri = packageLibraryManager.getShortUri(fileUri);
if (shortUri != null) {
uri = shortUri;
}
}
- } else if (PackageLibraryManager.isPackageUri(uri)){
+ } else if (PackageLibraryManager.isPackageUri(uri)) {
URI fileUri = packageLibraryManager.resolveDartUri(uri);
- if (fileUri != null){
+ if (fileUri != null) {
uri = fileUri;
}
- } else if (path != null && !(new File(path).exists())){
+ } else if (!resourceExists(uri)) {
// resolve against package root directories to find file
- uri = packageLibraryManager.findExistingFileInPackages(uri);
+ uri = packageLibraryManager.findExistingFileInPackages(uri);
}
-
- return new UrlLibrarySource(uri, packageLibraryManager);
+
+ return createLibrarySource(uri, packageLibraryManager);
} catch (Throwable e) {
return null;
}
}
+
+ @Override
+ public DartSource getSourceFor(final String relPath) {
+ if (relPath == null || relPath.isEmpty()) {
+ return null;
+ }
+ try {
+ // Force the creation of an escaped relative URI to deal with spaces, etc.
+ URI uri = getUri().resolve(new URI(null, null, relPath, null, null)).normalize();
+ return createDartSource(uri, relPath, this, packageLibraryManager);
+ } catch (Throwable e) {
+ return null;
+ }
+ }
+
+ /**
+ * Create a URL library source.
+ *
+ * (Clients can override.)
+ *
+ * @param uri the URI of the library
+ * @param relPath relative path to the dart source
+ * @param libSource the library source
+ * @param packageManager the package library manager
+ * @return the resulting dart source
+ */
+ protected UrlDartSource createDartSource(URI uri, String relPath, UrlLibrarySource libSource, PackageLibraryManager packageManager) {
+ return new UrlDartSource(uri, relPath, libSource, packageManager);
+ }
+
+ /**
+ * Create a URL library source.
+ *
+ * (Clients can override.)
+ *
+ * @param uri the URI of the library
+ * @return the resulting library source
+ */
+ protected UrlLibrarySource createLibrarySource(URI uri, PackageLibraryManager packageManager) {
+ return new UrlLibrarySource(uri, packageManager);
+ }
+
+ /**
+ * Check if a resource exists at this URI.
+ *
+ * (Clients can override.)
+ *
+ * @param uri the URI to test
+ * @return <code>true</code> if a resource exists at this URI, <code>false</code> otherwise
+ */
+ protected boolean resourceExists(URI uri) {
+ String path = uri.getPath();
+ return path == null || new File(path).exists();
+ }
+
}

Powered by Google App Engine
This is Rietveld 408576698