/** * Build the type environment where type transformations will be evaluated. * It only considers the template type variables that do not have a type * transformation. */ private Map<String, JSType> buildTypeVariables( Map<TemplateType, JSType> inferredTypes) { Map<String, JSType> typeVars = new LinkedHashMap<>(); for (Entry<TemplateType, JSType> e : inferredTypes.entrySet()) { // Only add the template type that do not have a type transformation if (!e.getKey().isTypeTransformation()) { typeVars.put(e.getKey().getReferenceName(), e.getValue()); } } return typeVars; }
/** * Build the type environment where type transformations will be evaluated. * It only considers the template type variables that do not have a type * transformation. */ private Map<String, JSType> buildTypeVariables( Map<TemplateType, JSType> inferredTypes) { Map<String, JSType> typeVars = new LinkedHashMap<String, JSType>(); for (Entry<TemplateType, JSType> e : inferredTypes.entrySet()) { // Only add the template type that do not have a type transformation if (!e.getKey().isTypeTransformation()) { typeVars.put(e.getKey().getReferenceName(), e.getValue()); } } return typeVars; }
/** * This function will evaluate the type transformations associated to the * template types */ private Map<TemplateType, JSType> evaluateTypeTransformations( ImmutableList<TemplateType> templateTypes, Map<TemplateType, JSType> inferredTypes) { Map<String, JSType> typeVars = null; Map<TemplateType, JSType> result = null; TypeTransformation ttlObj = null; for (TemplateType type : templateTypes) { if (type.isTypeTransformation()) { // Lazy initialization when the first type transformation is found if (ttlObj == null) { ttlObj = new TypeTransformation(compiler, syntacticScope); typeVars = buildTypeVariables(inferredTypes); result = new LinkedHashMap<TemplateType, JSType>(); } // Evaluate the type transformation expression using the current // known types for the template type variables JSType transformedType = ttlObj.eval(type.getTypeTransformation(), ImmutableMap.<String, JSType>copyOf(typeVars)); result.put(type, transformedType); // Add the transformed type to the type variables typeVars.put(type.getReferenceName(), transformedType); } } return result; }
/** This function will evaluate the type transformations associated to the template types */ private Map<TemplateType, JSType> evaluateTypeTransformations( ImmutableList<TemplateType> templateTypes, Map<TemplateType, JSType> inferredTypes, FlowScope scope) { Map<String, JSType> typeVars = null; Map<TemplateType, JSType> result = null; TypeTransformation ttlObj = null; for (TemplateType type : templateTypes) { if (type.isTypeTransformation()) { // Lazy initialization when the first type transformation is found if (ttlObj == null) { ttlObj = new TypeTransformation(compiler, scope.getDeclarationScope()); typeVars = buildTypeVariables(inferredTypes); result = new LinkedHashMap<>(); } // Evaluate the type transformation expression using the current // known types for the template type variables JSType transformedType = ttlObj.eval( type.getTypeTransformation(), ImmutableMap.copyOf(typeVars)); result.put(type, transformedType); // Add the transformed type to the type variables typeVars.put(type.getReferenceName(), transformedType); } } return result; }