private FunctionType createNativeFunctionType( JSType returnType, Node parameters) { return new FunctionBuilder(this) .withParamsNode(parameters) .withReturnType(returnType) .forNativeType() .build(); }
/** * Creates a new function type based on an existing function type but * with a new return type. * @param existingFunctionType the existing function type. * @param returnType the new return type. */ public FunctionType createFunctionTypeWithNewReturnType( FunctionType existingFunctionType, JSType returnType) { return new FunctionBuilder(this) .copyFromOtherFunction(existingFunctionType) .withReturnType(returnType) .build(); }
boolean isAbstract) { checkArgument(source == null || source.isFunction() || source.isClass()); return new FunctionBuilder(this) .forConstructor() .withName(name) .withSourceNode(source) .withParamsNode(parameters) .withReturnType(returnType) .withTemplateKeys(templateKeys) .withIsAbstract(isAbstract) .build();
private FunctionBuilder nativeConstructorBuilder(String name) { return new FunctionBuilder(this) .forNativeType() .forConstructor() .withName(name); }
/** * Take the current function type, and try to match the expected function * type. This is a form of backwards-inference, like record-type constraint * matching. */ private FunctionType matchFunction( FunctionType expectedType, FunctionType currentType, boolean declared) { if (declared) { // If the function was declared but it doesn't have a known "this" // but the expected type does, back fill it. if (currentType.getTypeOfThis().isUnknownType() && !expectedType.getTypeOfThis().isUnknownType()) { FunctionType replacement = new FunctionBuilder(registry) .copyFromOtherFunction(currentType) .withTypeOfThis(expectedType.getTypeOfThis()) .build(); return replacement; } } else { // For now, we just make sure the current type has enough // arguments to match the expected type, and return the // expected type if it does. if (currentType.getMaxArguments() <= expectedType.getMaxArguments()) { return expectedType; } } return currentType; }
/** * Creates an interface function type. * * @param name the function's name * @param source the node defining this function. Its type ({@link Node#getToken()}) must be * {@link Token#FUNCTION}. * @param templateKeys the templatized types for the interface. */ public FunctionType createInterfaceType( String name, Node source, ImmutableList<TemplateType> templateKeys, boolean struct) { FunctionType fn = new FunctionBuilder(this) .forInterface() .withName(name) .withSourceNode(source) .withEmptyParams() .withTemplateKeys(templateKeys) .build(); if (struct) { fn.setStruct(); } return fn; }
private FunctionType nativeInterface(String name, TemplateType... templateKeys) { FunctionBuilder builder = new FunctionBuilder(this) .forNativeType() .forInterface() .withName(name); if (templateKeys.length > 0) { builder.withTemplateKeys(templateKeys); } return builder.build(); } }
/** Create a new constructor with the parameters and return type stripped. */ public final FunctionType forgetParameterAndReturnTypes() { FunctionType result = new FunctionBuilder(registry) .withName(getReferenceName()) .withSourceNode(source) .withTypeOfThis(getInstanceType()) .withKind(kind) .build(); result.setPrototypeBasedOn(getInstanceType()); return result; }
.withParamsNode(createOptionalParameters(allType)) .withReturnsOwnInstanceType() .withTemplateKeys(iObjectIndexTemplateKey, iObjectElementTemplateKey) .build(); objectFunctionType.setPrototype(topLevelPrototype, null); registerNativeType(JSTypeNative.OBJECT_FUNCTION_TYPE, objectFunctionType); .withParamsNode(createParametersWithVarArgs(allType)) .withReturnType(unknownType) .withPrototypeBasedOn(objectType) .build(); functionFunctionType.setPrototypeBasedOn(objectType); registerNativeType(JSTypeNative.FUNCTION_FUNCTION_TYPE, functionFunctionType); .withParamsNode(createParametersWithVarArgs(allType)) .withReturnsOwnInstanceType() .withTemplateTypeMap( new TemplateTypeMap( this, ImmutableList.of(iObjectElementTemplateKey, arrayElementTemplateKey), ImmutableList.<JSType>of(arrayElementTemplateKey))) .build(); .withParamsNode(createEmptyParams()) .build(); registerNativeType( JSTypeNative.I_TEMPLATE_ARRAY_TYPE, iTemplateArrayFunctionType.getInstanceType());
IR.block(returnNode)); if (shouldAddTypesOnNewAstNodes) { FunctionBuilder functionBuilder = new FunctionBuilder(compiler.getTypeRegistry()); functionBuilder .withName("") .withSourceNode(iife) .withParamsNode(compiler.getTypeRegistry().createParameters(objectTypes)) .withReturnType(function.getJSType()); iife.setJSType(functionBuilder.build());
private SuperPropertyWrapperInfo createNewInfo(Node firstSuperDotPropertyNode) { checkArgument(firstSuperDotPropertyNode.isGetProp(), firstSuperDotPropertyNode); String propertyName = firstSuperDotPropertyNode.getLastChild().getString(); JSType propertyType = firstSuperDotPropertyNode.getJSType(); final String wrapperFunctionName = ASYNC_SUPER_PROP_GETTER_PREFIX + propertyName; final JSType wrapperFunctionType; if (propertyType == null) { // type checking hasn't run, so we don't need type information. wrapperFunctionType = null; } else { wrapperFunctionType = new FunctionBuilder(registry).withReturnType(propertyType).build(); } return new SuperPropertyWrapperInfo( firstSuperDotPropertyNode, wrapperFunctionName, wrapperFunctionType); }
/** * Take the current function type, and try to match the expected function * type. This is a form of backwards-inference, like record-type constraint * matching. */ private FunctionType matchFunction( FunctionType expectedType, FunctionType currentType, boolean declared) { if (declared) { // If the function was declared but it doesn't have a known "this" // but the expected type does, back fill it. if (currentType.getTypeOfThis().isUnknownType() && !expectedType.getTypeOfThis().isUnknownType()) { FunctionType replacement = new FunctionBuilder(registry) .copyFromOtherFunction(currentType) .withTypeOfThis(expectedType.getTypeOfThis()) .build(); return replacement; } } else { // For now, we just make sure the current type has enough // arguments to match the expected type, and return the // expected type if it does. if (currentType.getMaxArity() <= expectedType.getMaxArity()) { return expectedType; } } return currentType; }
private FunctionType createNativeFunctionType( JSType returnType, Node parameters) { return new FunctionBuilder(this) .withParamsNode(parameters) .withReturnType(returnType) .forNativeType() .build(); }
} else { fnType = new FunctionBuilder(typeRegistry) .withName(fnName) .withSourceNode(contents.getSourceNode()) .withParamsNode(parametersNode) .withReturnType(returnType, returnTypeInferred) .withTypeOfThis(thisType) .withTemplateKeys(templateTypeNames) .withIsAbstract(isAbstract) .build(); maybeSetBaseType(fnType);
if (thisType.toObjectType() != null && !thisType.isUnknownType() && callTargetFn.getTypeOfThis().isUnknownType()) { callTargetFn = new FunctionBuilder(registry) .copyFromOtherFunction(callTargetFn) .withTypeOfThis(thisType.toObjectType()) .build(); target.setJSType(callTargetFn);
/** * Creates a new function type based on an existing function type but * with a new return type. * @param existingFunctionType the existing function type. * @param returnType the new return type. */ public FunctionType createFunctionTypeWithNewReturnType( FunctionType existingFunctionType, JSType returnType) { return new FunctionBuilder(this) .copyFromOtherFunction(existingFunctionType) .withReturnType(returnType) .build(); }
/** * @param parameters the function's parameters or {@code null} to indicate that the parameter * types are unknown. * @param returnType the function's return type or {@code null} to indicate that the return type * is unknown. */ public FunctionType createFunctionType(JSType returnType, Node parameters) { return new FunctionBuilder(this).withParamsNode(parameters).withReturnType(returnType).build(); }
fnType = new FunctionBuilder(typeRegistry) .withName(fnName) .withSourceNode(contents.getSourceNode()) .withParamsNode(parametersNode) .withReturnType(returnType, returnTypeInferred) .withTypeOfThis(thisType) .withTemplateKeys(templateTypeNames) .build(); maybeSetBaseType(fnType);
if (thisType.toObjectType() != null && !thisType.isUnknownType() && callTargetFn.getTypeOfThis().isUnknownType()) { callTargetFn = new FunctionBuilder(registry) .copyFromOtherFunction(callTargetFn) .withTypeOfThis(thisType.toObjectType()) .build(); target.setJSType(callTargetFn);
/** * @param parameters the function's parameters or {@code null} * to indicate that the parameter types are unknown. * @param returnType the function's return type or {@code null} to indicate * that the return type is unknown. */ public FunctionType createFunctionType( JSType returnType, Node parameters) { return new FunctionBuilder(this) .withParamsNode(parameters) .withReturnType(returnType) .build(); }