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

Unified Diff: editor/tools/plugins/com.google.dart.command.analyze/src/com/google/dart/command/analyze/AnalyzerImpl.java

Issue 15780010: Issue 10871. Fix for analyzing file without absolute path (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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_experimental/lib/options.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: editor/tools/plugins/com.google.dart.command.analyze/src/com/google/dart/command/analyze/AnalyzerImpl.java
diff --git a/editor/tools/plugins/com.google.dart.command.analyze/src/com/google/dart/command/analyze/AnalyzerImpl.java b/editor/tools/plugins/com.google.dart.command.analyze/src/com/google/dart/command/analyze/AnalyzerImpl.java
index e9388522274bf64c80f8641fe822f1f72e9ebf91..656a54502a3431c3334d9ead554a5b1b85a4015e 100644
--- a/editor/tools/plugins/com.google.dart.command.analyze/src/com/google/dart/command/analyze/AnalyzerImpl.java
+++ b/editor/tools/plugins/com.google.dart.command.analyze/src/com/google/dart/command/analyze/AnalyzerImpl.java
@@ -14,7 +14,6 @@
package com.google.dart.command.analyze;
import com.google.dart.engine.AnalysisEngine;
-import com.google.dart.engine.ast.CompilationUnit;
import com.google.dart.engine.context.AnalysisContext;
import com.google.dart.engine.context.AnalysisException;
import com.google.dart.engine.element.CompilationUnitElement;
@@ -82,37 +81,39 @@ class AnalyzerImpl {
throw new IllegalArgumentException("sourceFile cannot be null");
}
- AnalysisContext context = AnalysisEngine.getInstance().createAnalysisContext();
- ContentCache contentCache = new ContentCache();
- SourceFactory sourceFactory;
-
+ // prepare "packages" directory
+ File packageDirectory;
if (options.getPackageRootPath() != null) {
+ packageDirectory = options.getPackageRootPath();
+ } else {
+ packageDirectory = getPackageDirectoryFor(sourceFile);
+ }
+
+ // create SourceFactory
+ SourceFactory sourceFactory;
+ ContentCache contentCache = new ContentCache();
+ if (packageDirectory != null) {
sourceFactory = new SourceFactory(
contentCache,
new DartUriResolver(sdk),
new FileUriResolver(),
- new PackageUriResolver(options.getPackageRootPath()));
- } else if (getPackageDirectoryFor(sourceFile) != null) {
- sourceFactory = new SourceFactory(
- new DartUriResolver(sdk),
- new FileUriResolver(),
- new PackageUriResolver(getPackageDirectoryFor(sourceFile)));
+ new PackageUriResolver(packageDirectory));
} else {
sourceFactory = new SourceFactory(new DartUriResolver(sdk), new FileUriResolver());
}
+ // prepare AnalysisContext
+ AnalysisContext context = AnalysisEngine.getInstance().createAnalysisContext();
context.setSourceFactory(sourceFactory);
+ // analyze the given file
Source librarySource = new FileBasedSource(contentCache, sourceFile);
LibraryElement library = context.computeLibraryElement(librarySource);
+ context.resolveCompilationUnit(librarySource, library);
- @SuppressWarnings("unused")
- CompilationUnit unit = context.resolveCompilationUnit(librarySource, library);
-
+ // prepare errors
Set<Source> sources = getAllSources(library);
-
getAllErrors(context, sources, errors);
-
return getMaxErrorSeverity(errors);
}
@@ -210,22 +211,17 @@ class AnalyzerImpl {
}
private File getPackageDirectoryFor(File sourceFile) {
- // look in the containing dir
- File dir = sourceFile.getParentFile();
+ // we are going to ask parent file, so get absolute path
+ sourceFile = sourceFile.getAbsoluteFile();
- File packagesDir = new File(dir, "packages");
-
- if (packagesDir.exists()) {
- return packagesDir;
- }
-
- // and in the parent dir (to capture files in the lib directory)
- dir = dir.getParentFile();
-
- packagesDir = new File(dir, "packages");
-
- if (packagesDir.exists()) {
- return packagesDir;
+ // look in the containing directories
+ File dir = sourceFile.getParentFile();
+ while (dir != null) {
+ File packagesDir = new File(dir, "packages");
+ if (packagesDir.exists()) {
+ return packagesDir;
+ }
+ dir = dir.getParentFile();
}
return null;
« no previous file with comments | « no previous file | pkg/analyzer_experimental/lib/options.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698