| 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 93e5ec862da2e7d315563c29859529624c782944..f730a334e81ba66c5eeb1fb3f492bffe58a608e3 100644
|
| --- a/compiler/java/com/google/dart/compiler/type/Types.java
|
| +++ b/compiler/java/com/google/dart/compiler/type/Types.java
|
| @@ -5,6 +5,7 @@
|
| package com.google.dart.compiler.type;
|
|
|
| import com.google.common.annotations.VisibleForTesting;
|
| +import com.google.common.collect.MapMaker;
|
| import com.google.dart.compiler.ast.DartNewExpression;
|
| import com.google.dart.compiler.ast.DartNode;
|
| import com.google.dart.compiler.ast.DartPropertyAccess;
|
| @@ -17,6 +18,9 @@ import com.google.dart.compiler.resolver.ResolutionErrorListener;
|
| import com.google.dart.compiler.resolver.TypeVariableElement;
|
| import com.google.dart.compiler.resolver.VariableElement;
|
|
|
| +import java.lang.reflect.InvocationHandler;
|
| +import java.lang.reflect.Method;
|
| +import java.lang.reflect.Proxy;
|
| import java.util.ArrayList;
|
| import java.util.Collections;
|
| import java.util.HashSet;
|
| @@ -31,6 +35,7 @@ import java.util.Set;
|
| * Utility class for types.
|
| */
|
| public class Types {
|
| + private static Map<Type, Type> inferredTypes = new MapMaker().weakKeys().weakValues().makeMap();
|
| private final CoreTypeProvider typeProvider;
|
|
|
| private Types(CoreTypeProvider typeProvider) { // Prevent subclassing.
|
| @@ -440,4 +445,36 @@ public class Types {
|
| DartTypeNode typeNode = constructorTypeNode(node);
|
| return (InterfaceType) typeNode.getType();
|
| }
|
| +
|
| + /**
|
| + * @return the wrapper of the given {@link Type} which returns <code>true</code> from
|
| + * {@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);
|
| + }
|
| + return type;
|
| + }
|
| +
|
| + private static Type makeInferred(final Type type, Class<?> typeInterface) {
|
| + Type inferred = inferredTypes.get(type);
|
| + if (inferred == null) {
|
| + inferred = (Type) Proxy.newProxyInstance(type.getClass().getClassLoader(),
|
| + new Class<?>[] {typeInterface}, new InvocationHandler() {
|
| + @Override
|
| + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
| + if (args == null && method.getName().equals("isInferred")) {
|
| + return true;
|
| + }
|
| + return method.invoke(type, args);
|
| + }
|
| + });
|
| + inferredTypes.put(type, inferred);
|
| + }
|
| + return inferred;
|
| + }
|
| }
|
|
|