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

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

Issue 9466013: Issue 1129. Report #import errors after parsing, so after "unitAboutToCompile". (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 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/DartCompiler.java
diff --git a/compiler/java/com/google/dart/compiler/DartCompiler.java b/compiler/java/com/google/dart/compiler/DartCompiler.java
index 73b78054a27a83389642c223aea568f9a5858afb..5ff544d4048a447352359fc23b8a123e593d2b55 100644
--- a/compiler/java/com/google/dart/compiler/DartCompiler.java
+++ b/compiler/java/com/google/dart/compiler/DartCompiler.java
@@ -246,6 +246,8 @@ public class DartCompiler {
for (LibraryNode libNode : lib.getSourcePaths()) {
String relPath = libNode.getText();
newUnitPaths.add(relPath);
+
+ // Prepare DartSource for "#source" unit.
final DartSource dartSrc = libSrc.getSourceFor(relPath);
if (dartSrc == null || !dartSrc.exists()) {
// Dart Editor needs to have all missing files reported as compilation errors.
@@ -257,6 +259,18 @@ public class DartCompiler {
|| (libIsDartUri && !usePrecompiledDartLibs)
|| isSourceOutOfDate(dartSrc, libSrc)) {
DartUnit unit = parse(dartSrc, lib.getPrefixes(), false);
+
+ // If we just parsed unit of library, report problems with its "#import" declarations.
+ if (libNode == selfSourcePath) {
+ for (LibraryNode importPathNode : lib.getImportPaths()) {
+ LibrarySource dep = getImportSource(libSrc, importPathNode);
+ if (dep == null) {
+ reportMissingSource(context, libSrc, importPathNode);
+ }
+ }
+ }
+
+ // Process unit, if exists.
if (unit != null) {
if (libNode == selfSourcePath) {
lib.setSelfDartUnit(unit);
@@ -399,19 +413,10 @@ public class DartCompiler {
// Update dependencies.
for (LibraryNode libNode : lib.getImportPaths()) {
- String libSpec = libNode.getText();
- LibrarySource dep;
- if (SystemLibraryManager.isDartSpec(libSpec)) {
- dep = context.getSystemLibraryFor(libSpec);
- } else {
- dep = libSrc.getImportFor(libSpec);
- }
- if (dep == null || !dep.exists()) {
- reportMissingSource(context, libSrc, libNode);
- continue;
+ LibrarySource dep = getImportSource(libSrc, libNode);
+ if (dep != null) {
+ lib.addImport(updateLibraries(dep), libNode);
}
-
- lib.addImport(updateLibraries(dep), libNode);
}
return lib;
} finally {
@@ -420,6 +425,25 @@ public class DartCompiler {
}
/**
+ * @return the {@link LibrarySource} referenced in the "#import" from "libSrc". May be
+ * <code>null</code> if invalid URI or not existing library.
+ */
+ private LibrarySource getImportSource(LibrarySource libSrc, LibraryNode libNode)
+ throws IOException {
+ String libSpec = libNode.getText();
+ LibrarySource dep;
+ if (SystemLibraryManager.isDartSpec(libSpec)) {
+ dep = context.getSystemLibraryFor(libSpec);
+ } else {
+ dep = libSrc.getImportFor(libSpec);
+ }
+ if (dep == null || !dep.exists()) {
+ return null;
+ }
+ return dep;
+ }
+
+ /**
* Determines whether the given source is out-of-date with respect to its artifacts.
*/
private boolean isSourceOutOfDate(DartSource dartSrc, LibrarySource libSrc) {
@@ -858,6 +882,8 @@ public class DartCompiler {
if (!config.resolveDespiteParseErrors() && context.getErrorCount() > 0) {
// Dump the compiler parse tree if dump format is set in arguments
ASTWriterFactory.create(config).process(unit);
+ // We don't return this unit, so no more processing expected for it.
+ context.unitCompiled(unit);
return null;
}
return unit;

Powered by Google App Engine
This is Rietveld 408576698