/** * Creates a function type in which {@code this} refers to an object instance. * * @param instanceType the type of {@code this} * @param returnType the function's return type * @param parameterTypes the parameters' types */ public JSType createFunctionTypeWithInstanceType(ObjectType instanceType, JSType returnType, List<JSType> parameterTypes) { Node paramsNode = createParameters(parameterTypes.toArray(new JSType[parameterTypes.size()])); return new FunctionBuilder(this) .withParamsNode(paramsNode) .withReturnType(returnType) .withTypeOfThis(instanceType) .build(); }
/** * Creates a function type in which {@code this} refers to an object instance. * * @param instanceType the type of {@code this} * @param returnType the function's return type * @param parameterTypes the parameters' types */ public JSType createFunctionTypeWithInstanceType(ObjectType instanceType, JSType returnType, List<JSType> parameterTypes) { Node paramsNode = createParameters(parameterTypes.toArray(new JSType[parameterTypes.size()])); return new FunctionBuilder(this) .withParamsNode(paramsNode) .withReturnType(returnType) .withTypeOfThis(instanceType) .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; }
/** * 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; }
/** * 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; }
.withParamsNode(parametersNode) .withReturnType(returnType, returnTypeInferred) .withTypeOfThis(thisType) .withTemplateKeys(templateTypeNames) .withIsAbstract(isAbstract)
.withParamsNode(newParamsNode) .withReturnType(newReturnType, newReturnTypeInferred) .withTypeOfThis(newTypeOfThis) .build();
.withParamsNode(parametersNode) .withReturnType(returnType, returnTypeInferred) .withTypeOfThis(thisType) .withTemplateKeys(templateTypeNames) .build();
callTargetFn = new FunctionBuilder(registry) .copyFromOtherFunction(callTargetFn) .withTypeOfThis(thisType.toObjectType()) .build(); target.setJSType(callTargetFn);
callTargetFn = new FunctionBuilder(registry) .copyFromOtherFunction(callTargetFn) .withTypeOfThis(thisType.toObjectType()) .build(); target.setJSType(callTargetFn);
.withParamsNode(paramBuilder.build()) .withReturnType(returnType) .withTypeOfThis(thisType) .setIsConstructor(isConstructor) .build();
.withParamsNode(paramBuilder.build()) .withReturnType(afterReturn) .withTypeOfThis(afterThis) .withTemplateKeys(type.getTemplateTypeMap().getUnfilledTemplateKeys()) .build();
.withParamsNode(paramBuilder.build()) .withReturnType(returnType) .withTypeOfThis(thisType) .withKind(isConstructor ? FunctionType.Kind.CONSTRUCTOR : FunctionType.Kind.ORDINARY) .build();
.withParamsNode(paramBuilder.build()) .withReturnType(afterReturn) .withTypeOfThis(afterThis) .withTemplateKeys( type.getTemplateTypeMap().getUnfilledTemplateKeys());