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

Unified Diff: compiler/java/com/google/dart/compiler/type/InterfaceTypeUnion.java

Issue 10870058: Use intersection of types as type of conditional (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/type/InterfaceTypeUnion.java
diff --git a/compiler/java/com/google/dart/compiler/type/InterfaceTypeUnion.java b/compiler/java/com/google/dart/compiler/type/InterfaceTypeUnion.java
new file mode 100644
index 0000000000000000000000000000000000000000..4fcf9a24a5390088c11bf7c51b970cdc2b3d9ac3
--- /dev/null
+++ b/compiler/java/com/google/dart/compiler/type/InterfaceTypeUnion.java
@@ -0,0 +1,98 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package com.google.dart.compiler.type;
+
+import com.google.common.collect.ImmutableList;
+import com.google.dart.compiler.resolver.ClassElement;
+import com.google.dart.compiler.resolver.ClassElementUnion;
+
+import java.util.List;
+
+/**
+ * Artificial {@link InterfaceType} which is union of several {@link InterfaceType}s.
+ */
+class InterfaceTypeUnion implements InterfaceType {
+
+ private final List<InterfaceType> types;
+ private final ClassElement element;
+
+ public InterfaceTypeUnion(List<InterfaceType> types) {
+ this.types = types;
+ this.element = new ClassElementUnion(this, types);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof InterfaceTypeUnion) {
+ InterfaceTypeUnion other = (InterfaceTypeUnion) obj;
+ return getElement().equals(other.getElement());
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ int hashCode = 31;
+ hashCode += getElement().hashCode();
+ hashCode += 31 * hashCode + getArguments().hashCode();
+ return hashCode;
+ }
+
+ @Override
+ public String toString() {
+ return types.toString();
+ }
+
+ @Override
+ public TypeKind getKind() {
+ return TypeKind.INTERFACE;
+ }
+
+ @Override
+ public boolean isInferred() {
+ return false;
+ }
+
+ @Override
+ public InterfaceType subst(List<Type> arguments, List<Type> parameters) {
+ return null;
+ }
+
+ @Override
+ public ClassElement getElement() {
+ return element;
+ }
+
+ @Override
+ public List<Type> getArguments() {
+ return ImmutableList.of();
+ }
+
+ @Override
+ public boolean isRaw() {
+ return true;
+ }
+
+ @Override
+ public boolean hasDynamicTypeArgs() {
+ return false;
+ }
+
+ @Override
+ public InterfaceType asRawType() {
+ return this;
+ }
+
+ @Override
+ public Member lookupMember(String name) {
+ for (InterfaceType type : types) {
+ Member member = type.lookupMember(name);
+ if (member != null) {
+ return member;
+ }
+ }
+ return null;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698