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

Unified Diff: compiler/java/com/google/dart/compiler/resolver/TopLevelElementBuilder.java

Issue 10139017: Support for same prefix for multiple imports. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Detect top-level duplicates in libraries with same prefix Created 8 years, 8 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/resolver/TopLevelElementBuilder.java
diff --git a/compiler/java/com/google/dart/compiler/resolver/TopLevelElementBuilder.java b/compiler/java/com/google/dart/compiler/resolver/TopLevelElementBuilder.java
index e743e191a3458d7f314a4d1f3f1fbd15de7a1cd0..d360d783e083d50da5e2cf2e63e6821c5a8ffba7 100644
--- a/compiler/java/com/google/dart/compiler/resolver/TopLevelElementBuilder.java
+++ b/compiler/java/com/google/dart/compiler/resolver/TopLevelElementBuilder.java
@@ -5,6 +5,7 @@
package com.google.dart.compiler.resolver;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Maps;
import com.google.dart.compiler.DartCompilationError;
import com.google.dart.compiler.DartCompilerContext;
import com.google.dart.compiler.DartCompilerListener;
@@ -25,8 +26,10 @@ import com.google.dart.compiler.type.Type;
import com.google.dart.compiler.type.TypeVariable;
import com.google.dart.compiler.type.Types;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
/**
* Builds all class elements and types of a library. Once all libraries
@@ -60,11 +63,22 @@ public class TopLevelElementBuilder {
Scope scope = library.getElement().getScope();
assert scope.getElements().isEmpty();
+ Map<String, LibraryPrefixElement> libraryPrefixElements = Maps.newHashMap();
for (LibraryUnit lib : library.getImports()) {
String prefix = library.getPrefixOf(lib);
if (prefix != null) {
// Put the prefix in the scope.
- scope.declareElement(prefix, lib.getElement());
+ LibraryPrefixElement libraryPrefixElement = libraryPrefixElements.get(prefix);
+ if (libraryPrefixElement == null) {
+ libraryPrefixElement = new LibraryPrefixElementImplementation(prefix, scope);
+ libraryPrefixElements.put(prefix, libraryPrefixElement);
+ scope.declareElement(prefix, libraryPrefixElement);
+ }
+ libraryPrefixElement.addLibrary(lib.getElement());
+ // Fill library prefix scope.
+ for (DartUnit unit : lib.getUnits()) {
+ fillInUnitScope(unit, listener, libraryPrefixElement.getScope());
+ }
} else {
// Put the elements of the library in the scope.
for (DartUnit unit : lib.getUnits()) {

Powered by Google App Engine
This is Rietveld 408576698