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

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

Issue 11416307: Triage and fixes for co19 library tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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 | compiler/java/com/google/dart/compiler/DartCompilerErrorCode.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6900a507d630e9db99ed3276d80327399a25e845..f8dd7d954d2ff61016df55ab0760c96aeaad2ab7 100644
--- a/compiler/java/com/google/dart/compiler/DartCompiler.java
+++ b/compiler/java/com/google/dart/compiler/DartCompiler.java
@@ -19,6 +19,7 @@ import com.google.dart.compiler.ast.DartNode;
import com.google.dart.compiler.ast.DartPartOfDirective;
import com.google.dart.compiler.ast.DartToSourceVisitor;
import com.google.dart.compiler.ast.DartUnit;
+import com.google.dart.compiler.ast.LibraryExport;
import com.google.dart.compiler.ast.LibraryNode;
import com.google.dart.compiler.ast.LibraryUnit;
import com.google.dart.compiler.ast.Modifiers;
@@ -626,7 +627,24 @@ public class DartCompiler {
}
}
+ // check that each exported library has a library directive
+ for (LibraryExport libraryExport : lib.getExports()) {
+ LibraryUnit exportedLibrary = libraryExport.getLibrary();
+ String exportedLibraryName = getLibraryName(exportedLibrary);
+ // no => error
+ if (exportedLibraryName == null) {
+ SourceInfo info = findExportDirective(lib, exportedLibrary);
+ if (info != null) {
+ Source expSource = exportedLibrary.getSelfDartUnit().getSourceInfo().getSource();
+ context.onError(new DartCompilationError(info,
+ DartCompilerErrorCode.MISSING_LIBRARY_DIRECTIVE_EXPORT,
+ ((DartSource) expSource).getRelativePath()));
+ }
+ }
+ }
+
// check that each imported library has a library directive
+ Map<String, LibraryUnit> nameToImportedLibrary = Maps.newHashMap();
for (LibraryUnit importedLib : lib.getImportedLibraries()) {
if (PackageLibraryManager.isDartUri(importedLib.getSource().getUri())) {
@@ -641,28 +659,35 @@ public class DartCompiler {
continue;
}
- boolean foundLibraryDirective = false;
- for (DartDirective directive : unit.getDirectives()) {
- if (directive instanceof DartLibraryDirective) {
- foundLibraryDirective = true;
- break;
- }
- }
- if (!foundLibraryDirective) {
- // find the imported path node (which corresponds to the import directive node)
- SourceInfo info = null;
- for (LibraryNode importPath : lib.getImportPaths()) {
- if (importPath.getText().equals(importedLib.getSelfSourcePath().getText())) {
- info = importPath.getSourceInfo();
- break;
- }
- }
+ // find imported library name
+ String importedLibraryName = getLibraryName(importedLib);
+
+ // no name => error
+ if (importedLibraryName == null) {
+ SourceInfo info = findImportDirective(lib, importedLib);
if (info != null) {
context.onError(new DartCompilationError(info,
- DartCompilerErrorCode.MISSING_LIBRARY_DIRECTIVE,
+ DartCompilerErrorCode.MISSING_LIBRARY_DIRECTIVE_IMPORT,
((DartSource) unit.getSourceInfo().getSource()).getRelativePath()));
}
}
+
+ // has already library with such name => error
+ if (importedLibraryName != null) {
+ LibraryUnit prevLibraryWithSameName = nameToImportedLibrary.get(importedLibraryName);
+ if (prevLibraryWithSameName != null) {
+ SourceInfo info = findImportDirective(lib, importedLib);
+ if (info != null) {
+ Source prevSource = prevLibraryWithSameName.getSelfDartUnit().getSourceInfo().getSource();
+ context.onError(new DartCompilationError(info,
+ DartCompilerErrorCode.DUPLICATE_IMPORTED_LIBRARY_NAME,
+ importedLibraryName,
+ ((DartSource) prevSource).getRelativePath()));
+ }
+ } else {
+ nameToImportedLibrary.put(importedLibraryName, importedLib);
+ }
+ }
}
// check that all sourced units have no directives
@@ -699,6 +724,43 @@ public class DartCompiler {
}
}
}
+
+ /**
+ * @return the name of the given {@link LibraryUnit} specified in {@link DartLibraryDirective}.
+ */
+ private static String getLibraryName(LibraryUnit libraryUnit) {
+ DartUnit unit = libraryUnit.getSelfDartUnit();
+ for (DartDirective directive : unit.getDirectives()) {
+ if (directive instanceof DartLibraryDirective) {
+ return ((DartLibraryDirective) directive).getLibraryName();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return the {@link SourceInfo} of the import directive in "lib" for "importedLib".
+ */
+ private static SourceInfo findImportDirective(LibraryUnit lib, LibraryUnit importedLib) {
+ for (LibraryNode importPath : lib.getImportPaths()) {
+ if (importPath.getText().equals(importedLib.getSelfSourcePath().getText())) {
+ return importPath.getSourceInfo();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return the {@link SourceInfo} of the export directive in "lib" for "importedLib".
+ */
+ private static SourceInfo findExportDirective(LibraryUnit lib, LibraryUnit importedLib) {
+ for (LibraryNode exportPath : lib.getExportPaths()) {
+ if (exportPath.getText().equals(importedLib.getSelfSourcePath().getText())) {
+ return exportPath.getSourceInfo();
+ }
+ }
+ return null;
+ }
private static boolean isLibrarySelfUnit(LibraryUnit lib, DartSource unitSource) {
String unitRelativePath = unitSource.getRelativePath();
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/DartCompilerErrorCode.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698