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

Unified Diff: compiler/java/com/google/dart/compiler/ast/LibraryImport.java

Issue 10832321: Issue 4048. Support for revised library/import syntax (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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/ast/LibraryImport.java
diff --git a/compiler/java/com/google/dart/compiler/ast/LibraryImport.java b/compiler/java/com/google/dart/compiler/ast/LibraryImport.java
index e14f6c8be314b3dc0224b21855e30c89401f1151..e6f32f557768403c2c508d200b7b0ed18bd334b3 100644
--- a/compiler/java/com/google/dart/compiler/ast/LibraryImport.java
+++ b/compiler/java/com/google/dart/compiler/ast/LibraryImport.java
@@ -5,17 +5,28 @@
package com.google.dart.compiler.ast;
import com.google.common.base.Objects;
+import com.google.common.collect.Sets;
+
+import java.util.List;
+import java.util.Set;
/**
* Information about import - prefix and {@link LibraryUnit}.
*/
public class LibraryImport {
- private final String prefix;
private final LibraryUnit library;
+ private final String prefix;
+ private final Set<String> showNames;
+ private final Set<String> hideNames;
+ private final boolean exported;
- public LibraryImport(String prefix, LibraryUnit library) {
- this.prefix = prefix;
+ public LibraryImport(LibraryUnit library, String prefix, List<ImportCombinator> combinators,
+ boolean exported) {
this.library = library;
+ this.prefix = prefix;
+ this.showNames = createCombinatorsSet(combinators, true);
+ this.hideNames = createCombinatorsSet(combinators, false);
+ this.exported = exported;
}
@Override
@@ -27,16 +38,57 @@ public class LibraryImport {
public boolean equals(Object obj) {
if (obj instanceof LibraryImport) {
LibraryImport other = (LibraryImport) obj;
- return Objects.equal(prefix, other.prefix) && Objects.equal(library, other.library);
+ return Objects.equal(library, other.library) && Objects.equal(prefix, other.prefix)
+ && Objects.equal(showNames, other.showNames) && Objects.equal(hideNames, other.hideNames)
+ && exported == other.exported;
}
return false;
}
+ public LibraryUnit getLibrary() {
+ return library;
+ }
+
public String getPrefix() {
return prefix;
}
+
+ public boolean isVisible(String name) {
+ if (hideNames.contains(name)) {
+ return false;
+ }
+ if (!showNames.isEmpty()) {
+ return showNames.contains(name);
+ }
+ return true;
+ }
- public LibraryUnit getLibrary() {
- return library;
+ public boolean isExported() {
+ return exported;
+ }
+
+ private static Set<String> createCombinatorsSet(List<ImportCombinator> combinators, boolean show) {
+ Set<String> result = Sets.newHashSet();
+ for (ImportCombinator combinator : combinators) {
+ // show
+ if (show && combinator instanceof ImportShowCombinator) {
+ ImportShowCombinator showCombinator = (ImportShowCombinator) combinator;
+ for (DartIdentifier showName : showCombinator.getShownNames()) {
+ if (showName != null) {
+ result.add(showName.getName());
+ }
+ }
+ }
+ // hide
+ if (!show && combinator instanceof ImportHideCombinator) {
+ ImportHideCombinator hideCombinator = (ImportHideCombinator) combinator;
+ for (DartIdentifier hideName : hideCombinator.getHiddenNames()) {
+ if (hideName != null) {
+ result.add(hideName.getName());
+ }
+ }
+ }
+ }
+ return result;
}
}

Powered by Google App Engine
This is Rietveld 408576698