Example usage for com.google.common.collect Maps newIdentityHashMap

List of usage examples for com.google.common.collect Maps newIdentityHashMap

Introduction

In this page you can find the example usage for com.google.common.collect Maps newIdentityHashMap.

Prototype

public static <K, V> IdentityHashMap<K, V> newIdentityHashMap() 

Source Link

Document

Creates an IdentityHashMap instance.

Usage

From source file:com.google.javascript.jscomp.TypeInference.java

/**
 * For functions with function(this: T, ...) and T as parameters, type
 * inference will set the type of this on a function literal argument to the
 * the actual type of T./*w  w  w. j a  v a 2  s .c  o  m*/
 */
private boolean inferTemplatedTypesForCall(Node n, FunctionType fnType) {
    final ImmutableList<TemplateType> keys = fnType.getTemplateTypeMap().getTemplateKeys();
    if (keys.isEmpty()) {
        return false;
    }

    // Try to infer the template types
    Map<TemplateType, JSType> rawInferrence = inferTemplateTypesFromParameters(fnType, n);
    Map<TemplateType, JSType> inferred = Maps.newIdentityHashMap();
    for (TemplateType key : keys) {
        JSType type = rawInferrence.get(key);
        if (type == null) {
            type = unknownType;
        }
        inferred.put(key, type);
    }

    // Try to infer the template types using the type transformations
    Map<TemplateType, JSType> typeTransformations = evaluateTypeTransformations(keys, inferred);
    if (typeTransformations != null) {
        inferred.putAll(typeTransformations);
    }

    // Replace all template types. If we couldn't find a replacement, we
    // replace it with UNKNOWN.
    TemplateTypeReplacer replacer = new TemplateTypeReplacer(registry, inferred);
    Node callTarget = n.getFirstChild();

    FunctionType replacementFnType = fnType.visit(replacer).toMaybeFunctionType();
    Preconditions.checkNotNull(replacementFnType);

    callTarget.setJSType(replacementFnType);
    n.setJSType(replacementFnType.getReturnType());

    return replacer.madeChanges;
}