InstanceObjectType(JSTypeRegistry registry, FunctionType constructor, boolean isNativeType) { super(registry, null, null, isNativeType, constructor.getTemplateTypeMap()); Preconditions.checkNotNull(constructor); this.constructor = constructor; }
InstanceObjectType( JSTypeRegistry registry, FunctionType constructor, boolean isNativeType, TemplateTypeMap templateTypeMap) { super(registry, null, null, isNativeType, templateTypeMap); this.constructor = checkNotNull(constructor); }
/** Returns a list of template types present on the constructor but not on the instance. */ public final ImmutableList<TemplateType> getConstructorOnlyTemplateParameters() { TemplateTypeMap ctorMap = getTemplateTypeMap(); TemplateTypeMap instanceMap = getInstanceType().getTemplateTypeMap(); if (ctorMap == instanceMap) { return ImmutableList.of(); } ImmutableList.Builder<TemplateType> ctorKeys = ImmutableList.builder(); Set<TemplateType> instanceKeys = ImmutableSet.copyOf(instanceMap.getUnfilledTemplateKeys()); for (TemplateType ctorKey : ctorMap.getUnfilledTemplateKeys()) { if (!instanceKeys.contains(ctorKey)) { ctorKeys.add(ctorKey); } } return ctorKeys.build(); }
@Override final boolean hasAnyTemplateTypesInternal() { return getTemplateTypeMap().numUnfilledTemplateKeys() > 0 || typeOfThis.hasAnyTemplateTypes() || call.hasAnyTemplateTypes(); }
@Override public boolean hasAnyTemplateTypesInternal() { return getTemplateTypeMap().numUnfilledTemplateKeys() > 0 || typeOfThis.hasAnyTemplateTypes() || call.hasAnyTemplateTypes(); }
ImmutableList<TemplateType> keys = fnType.getTemplateTypeMap().getTemplateKeys(); if (keys.isEmpty()) { return false;
final ImmutableList<TemplateType> keys = fnType.getTemplateTypeMap() .getTemplateKeys(); if (keys.isEmpty()) {
/** Copies all the information from another function type. */ public FunctionBuilder copyFromOtherFunction(FunctionType otherType) { this.name = otherType.getReferenceName(); this.sourceNode = otherType.getSource(); this.parametersNode = otherType.getParametersNode(); this.returnType = otherType.getReturnType(); this.typeOfThis = otherType.getTypeOfThis(); this.templateTypeMap = otherType.getTemplateTypeMap(); this.isConstructor = otherType.isConstructor(); this.isNativeType = otherType.isNativeObjectType(); return this; }
/** Copies all the information from another function type. */ public FunctionBuilder copyFromOtherFunction(FunctionType otherType) { int isNative = otherType.isNativeObjectType() ? IS_NATIVE : 0; int isAbstract = otherType.isAbstract() ? IS_ABSTRACT : 0; int inferredReturnType = otherType.isReturnTypeInferred() ? INFERRED_RETURN_TYPE : 0; this.name = otherType.getReferenceName(); this.sourceNode = otherType.getSource(); this.parametersNode = otherType.getParametersNode(); this.returnType = otherType.getReturnType(); this.typeOfThis = otherType.getTypeOfThis(); this.templateTypeMap = otherType.getTemplateTypeMap(); this.kind = otherType.getKind(); this.properties = isNative | isAbstract | inferredReturnType; return this; }
private Map<TemplateType, JSType> inferTemplateTypesFromParameters( FunctionType fnType, Node call) { if (fnType.getTemplateTypeMap().getTemplateKeys().isEmpty()) { return Collections.emptyMap(); } Map<TemplateType, JSType> resolvedTypes = Maps.newIdentityHashMap(); Set<JSType> seenTypes = Sets.newIdentityHashSet(); Node callTarget = call.getFirstChild(); if (NodeUtil.isGet(callTarget)) { Node obj = callTarget.getFirstChild(); maybeResolveTemplatedType( fnType.getTypeOfThis(), getJSType(obj), resolvedTypes, seenTypes); } if (call.hasMoreThanOneChild()) { maybeResolveTemplateTypeFromNodes( fnType.getParameters(), call.getSecondChild().siblings(), resolvedTypes, seenTypes); } return resolvedTypes; }
for (TemplateType templateKey : ftype.getTemplateTypeMap().getTemplateKeys()) { if (templateKey.getTypeTransformation() != null) { hasTTE = true;
@Override public final JSType getPropertyType(String name) { if (!hasOwnProperty(name)) { // Define the "call", "apply", and "bind" functions lazily. boolean isCall = "call".equals(name); boolean isBind = "bind".equals(name); if (isCall || isBind) { defineDeclaredProperty(name, getCallOrBindSignature(isCall), source); } else if ("apply".equals(name)) { // Define the "apply" function lazily. FunctionParamBuilder builder = new FunctionParamBuilder(registry); // ECMA-262 says that apply's second argument must be an Array // or an arguments object. We don't model the arguments object, // so let's just be forgiving for now. // TODO(nicksantos): Model the Arguments object. builder.addOptionalParams( registry.createNullableType(getTypeOfThis()), registry.createNullableType(registry.getNativeType(JSTypeNative.OBJECT_TYPE))); defineDeclaredProperty( name, new FunctionBuilder(registry) .withParamsNode(builder.build()) .withReturnType(getReturnType()) .withTemplateKeys(getTemplateTypeMap().getTemplateKeys()) .build(), source); } } return super.getPropertyType(name); }
@Override public JSType getPropertyType(String name) { if (!hasOwnProperty(name)) { // Define the "call", "apply", and "bind" functions lazily. boolean isCall = "call".equals(name); boolean isBind = "bind".equals(name); if (isCall || isBind) { defineDeclaredProperty(name, getCallOrBindSignature(isCall), source); } else if ("apply".equals(name)) { // Define the "apply" function lazily. FunctionParamBuilder builder = new FunctionParamBuilder(registry); // ECMA-262 says that apply's second argument must be an Array // or an arguments object. We don't model the arguments object, // so let's just be forgiving for now. // TODO(nicksantos): Model the Arguments object. builder.addOptionalParams( registry.createNullableType(getTypeOfThis()), registry.createNullableType( registry.getNativeType(JSTypeNative.OBJECT_TYPE))); defineDeclaredProperty(name, new FunctionBuilder(registry) .withParamsNode(builder.build()) .withReturnType(getReturnType()) .withTemplateKeys(getTemplateTypeMap().getTemplateKeys()) .build(), source); } } return super.getPropertyType(name); }
if (fnType.getTemplateTypeMap().getTemplateKeys().isEmpty()) { return Collections.emptyMap();
/** * Get the return value of calling "bind" on this function with the specified number of arguments. * * <p>If -1 is passed, then we will return a result that accepts any parameters. */ public final FunctionType getBindReturnType(int argsToBind) { FunctionBuilder builder = new FunctionBuilder(registry) .withReturnType(getReturnType()) .withTemplateKeys(getTemplateTypeMap().getTemplateKeys()); if (argsToBind >= 0) { Node origParams = getParametersNode(); if (origParams != null) { Node params = origParams.cloneTree(); for (int i = 1; i < argsToBind && params.getFirstChild() != null; i++) { if (params.getFirstChild().isVarArgs()) { break; } params.removeFirstChild(); } builder.withParamsNode(params); } } return builder.build(); }
/** * Get the return value of calling "bind" on this function * with the specified number of arguments. * * If -1 is passed, then we will return a result that accepts * any parameters. */ public FunctionType getBindReturnType(int argsToBind) { FunctionBuilder builder = new FunctionBuilder(registry) .withReturnType(getReturnType()) .withTemplateKeys(getTemplateTypeMap().getTemplateKeys()); if (argsToBind >= 0) { Node origParams = getParametersNode(); if (origParams != null) { Node params = origParams.cloneTree(); for (int i = 1; i < argsToBind && params.getFirstChild() != null; i++) { if (params.getFirstChild().isVarArgs()) { break; } params.removeFirstChild(); } builder.withParamsNode(params); } } return builder.build(); }
new FunctionBuilder(registry) .withReturnType(isCall ? getReturnType() : getBindReturnType(-1)) .withTemplateKeys(getTemplateTypeMap().getTemplateKeys());
FunctionBuilder builder = new FunctionBuilder(registry) .withReturnType(isCall ? getReturnType() : getBindReturnType(-1)) .withTemplateKeys(getTemplateTypeMap().getTemplateKeys());
.withTypeOfThis(afterThis) .withTemplateKeys( type.getTemplateTypeMap().getUnfilledTemplateKeys()); return builder.build();
.withReturnType(afterReturn) .withTypeOfThis(afterThis) .withTemplateKeys(type.getTemplateTypeMap().getUnfilledTemplateKeys()) .build(); return ft;