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

Unified Diff: editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/internal/scope/LibraryImportScopeTest.java

Issue 23481015: Fix for issue 12726 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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: editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/internal/scope/LibraryImportScopeTest.java
diff --git a/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/internal/scope/LibraryImportScopeTest.java b/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/internal/scope/LibraryImportScopeTest.java
index 73bc57500f20fad69867831168614960e2cf212e..44d95670f335b3e087887a8d9215974373bdb060 100644
--- a/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/internal/scope/LibraryImportScopeTest.java
+++ b/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/internal/scope/LibraryImportScopeTest.java
@@ -15,6 +15,7 @@ package com.google.dart.engine.internal.scope;
import com.google.dart.engine.ast.Identifier;
import com.google.dart.engine.context.AnalysisContext;
+import com.google.dart.engine.context.AnalysisContextFactory;
import com.google.dart.engine.element.ClassElement;
import com.google.dart.engine.element.Element;
import com.google.dart.engine.element.ImportElement;
@@ -74,9 +75,14 @@ public class LibraryImportScopeTest extends ResolverTestCase {
assertInstanceOf(MultiplyDefinedElement.class, element);
Element[] conflictingElements = ((MultiplyDefinedElement) element).getConflictingElements();
- assertEquals(typeB1, conflictingElements[0]);
- assertEquals(typeB2, conflictingElements[1]);
- assertEquals(2, conflictingElements.length);
+ assertLength(2, conflictingElements);
+ if (conflictingElements[0] == typeB1) {
+ assertSame(typeB2, conflictingElements[1]);
+ } else if (conflictingElements[0] == typeB2) {
+ assertSame(typeB1, conflictingElements[1]);
+ } else {
+ assertSame(typeB1, conflictingElements[0]);
+ }
}
{
@@ -126,6 +132,54 @@ public class LibraryImportScopeTest extends ResolverTestCase {
assertEquals(errorListener, scope.getErrorListener());
}
+ public void test_nonConflictingImports_fromSdk() {
+ AnalysisContext context = AnalysisContextFactory.contextWithCore();
+ String typeName = "List";
+ ClassElement type = classElement(typeName);
+
+ LibraryElement importedLibrary = createTestLibrary(context, "lib");
+ ((CompilationUnitElementImpl) importedLibrary.getDefiningCompilationUnit()).setTypes(new ClassElement[] {type});
+ ImportElementImpl importCore = importFor(
+ context.getLibraryElement(context.getSourceFactory().forUri("dart:core")),
+ null);
+ ImportElementImpl importLib = importFor(importedLibrary, null);
+
+ LibraryElementImpl importingLibrary = createTestLibrary(context, "importing");
+ importingLibrary.setImports(new ImportElement[] {importCore, importLib});
+
+ GatheringErrorListener errorListener = new GatheringErrorListener();
+ Scope scope = new LibraryImportScope(importingLibrary, errorListener);
+
+ assertEquals(type, scope.lookup(identifier(typeName), importingLibrary));
+ errorListener.assertNoErrors();
+ }
+
+ public void test_nonConflictingImports_sameElement() {
+ AnalysisContext context = new AnalysisContextImpl();
+ String typeNameA = "A";
+ String typeNameB = "B";
+ ClassElement typeA = classElement(typeNameA);
+ ClassElement typeB = classElement(typeNameB);
+
+ LibraryElement importedLibrary = createTestLibrary(context, "imported");
+ ((CompilationUnitElementImpl) importedLibrary.getDefiningCompilationUnit()).setTypes(new ClassElement[] {
+ typeA, typeB});
+ ImportElementImpl import1 = importFor(importedLibrary, null);
+ ImportElementImpl import2 = importFor(importedLibrary, null);
+
+ LibraryElementImpl importingLibrary = createTestLibrary(context, "importing");
+ importingLibrary.setImports(new ImportElement[] {import1, import2});
+
+ GatheringErrorListener errorListener = new GatheringErrorListener();
+ Scope scope = new LibraryImportScope(importingLibrary, errorListener);
+
+ assertEquals(typeA, scope.lookup(identifier(typeNameA), importingLibrary));
+ errorListener.assertNoErrors();
+
+ assertEquals(typeB, scope.lookup(identifier(typeNameB), importingLibrary));
+ errorListener.assertNoErrors();
+ }
+
public void test_prefixedAndNonPrefixed() {
AnalysisContext context = new AnalysisContextImpl();
String typeName = "C";

Powered by Google App Engine
This is Rietveld 408576698