@Override public Void caseTemplateType(TemplateType templateType) { emit(templateType.getReferenceName()); return null; }
public TemplateType createTemplateTypeWithTransformation( String name, Node expr) { return new TemplateType(this, name, expr); }
/** * 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; }
/** * 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; }
if (templateKey.getTypeTransformation() != null) { hasTTE = true; break;
private List<String> getTemplateTypeNames(ObjectType objType) { if (objType.getTemplateTypeMap() == null) { return Collections.emptyList(); } return objType .getTemplateTypeMap() .getTemplateKeys() .stream() .map(jsType -> jsType != null ? jsType.getDisplayName() : "") .collect(toCollection(ArrayList::new)); }
/** 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; }
/** * 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; }
String displayName = templateType.getDisplayName();
public TemplateType getTemplateTypeKeyByName(String keyName) { for (TemplateType key : templateKeys) { if (key.getReferenceName().equals(keyName)) { return key; } } return null; }
public TemplateType createTemplateType(String name) { return new TemplateType(this, name); }
/** * Registers template types on the given scope root. This takes a Node rather than a * StaticScope because at the time it is called, the scope has not yet been created. */ public void registerTemplateTypeNamesInScope(Iterable<TemplateType> keys, Node scopeRoot) { for (TemplateType key : keys) { scopedNameTable.put(scopeRoot, key.getReferenceName(), key); } }
public TemplateType createTemplateTypeWithTransformation( String name, Node expr) { return new TemplateType(this, name, expr); }
public TemplateType getTemplateTypeKeyByName(String keyName) { for (TemplateType key : templateKeys) { if (key.getReferenceName().equals(keyName)) { return key; } } return null; }
public TemplateType createTemplateType(String name) { return new TemplateType(this, name); }
/** * Sets the template type name. */ public void setTemplateTypeNames(List<TemplateType> keys) { Preconditions.checkNotNull(keys); for (TemplateType key : keys) { templateTypes.put(key.getReferenceName(), key); } }
iObjectIndexTemplateKey = new TemplateType(this, "IObject#KEY1"); iObjectElementTemplateKey = new TemplateType(this, I_OBJECT_ELEMENT_TEMPLATE); arrayElementTemplateKey = new TemplateType(this, "T"); iteratorTemplate = new TemplateType(this, "VALUE"); asyncIteratorTemplate = new TemplateType(this, "VALUE"); generatorTemplate = new TemplateType(this, "VALUE"); asyncGeneratorTemplate = new TemplateType(this, "VALUE"); iterableTemplate = new TemplateType(this, "VALUE"); asyncIterableTemplate = new TemplateType(this, "VALUE"); iThenableTemplateKey = new TemplateType(this, "TYPE"); promiseTemplateKey = new TemplateType(this, "TYPE");
SyntheticTemplateScope(StaticTypedScope delegate, Iterable<TemplateType> templates) { this.delegate = delegate; PMap<String, TemplateType> types = delegate instanceof SyntheticTemplateScope ? ((SyntheticTemplateScope) delegate).types : HamtPMap.<String, TemplateType>empty(); for (TemplateType key : templates) { types = types.plus(key.getReferenceName(), key); } this.types = types; }
iObjectIndexTemplateKey = new TemplateType(this, "IObject#KEY1"); iObjectElementTemplateKey = new TemplateType(this, I_OBJECT_ELEMENT_TEMPLATE); arrayElementTemplateKey = new TemplateType(this, "T");