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

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

Issue 10541159: Generate inferred types using all implemented interfaces. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.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/type/Types.java
diff --git a/compiler/java/com/google/dart/compiler/type/Types.java b/compiler/java/com/google/dart/compiler/type/Types.java
index 241bc48d1a19f0c0a1ea2218c8c412ecf77bd831..04b9c992a904732223ba9b92a3e1e47f01a5e3bc 100644
--- a/compiler/java/com/google/dart/compiler/type/Types.java
+++ b/compiler/java/com/google/dart/compiler/type/Types.java
@@ -7,6 +7,7 @@ package com.google.dart.compiler.type;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import com.google.common.collect.MapMaker;
+import com.google.common.collect.Sets;
import com.google.dart.compiler.ast.DartNewExpression;
import com.google.dart.compiler.ast.DartNode;
import com.google.dart.compiler.ast.DartPropertyAccess;
@@ -505,20 +506,21 @@ public class Types {
* {@link Type#isInferred()}.
*/
public static Type makeInferred(Type type) {
- if (type instanceof DynamicType) {
- return makeInferred(type, DynamicType.class);
- }
- if (type instanceof InterfaceType) {
- return makeInferred(type, InterfaceType.class);
+ if (type != null) {
+ Set<Class<?>> interfaceSet = getAllImplementedInterfaces(type.getClass());
+ if (!interfaceSet.isEmpty()) {
+ Class<?>[] interfaces = (Class[]) interfaceSet.toArray(new Class[interfaceSet.size()]);
+ type = makeInferred(type, interfaces);
+ }
}
return type;
}
- private static Type makeInferred(final Type type, Class<?> typeInterface) {
+ private static Type makeInferred(final Type type, Class<?>[] interfaces) {
Type inferred = inferredTypes.get(type);
if (inferred == null) {
inferred = (Type) Proxy.newProxyInstance(type.getClass().getClassLoader(),
- new Class<?>[] {typeInterface}, new InvocationHandler() {
+ interfaces, new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (args == null && method.getName().equals("isInferred")) {
@@ -531,4 +533,16 @@ public class Types {
}
return inferred;
}
+
+ /**
+ * @return all interfaces implemented by given {@link Class}.
+ */
+ private static Set<Class<?>> getAllImplementedInterfaces(Class<?> c) {
+ Set<Class<?>> result = Sets.newHashSet();
+ for (Class<?> intf : c.getInterfaces()) {
+ result.add(intf);
+ result.addAll(getAllImplementedInterfaces(intf));
+ }
+ return result;
+ }
}
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698