public final Iterable<JSType> getParameterTypes() { List<JSType> types = new ArrayList<>(); for (Node n : getParameters()) { types.add(n.getJSType()); } return types; }
/** Visits the parameters of a CALL or a NEW node. */ private void visitArgumentList(NodeTraversal t, Node call, FunctionType functionType) { Iterator<Node> parameters = functionType.getParameters().iterator(); Iterator<Node> arguments = NodeUtil.getInvocationArgsAsIterable(call).iterator(); checkArgumentsMatchParameters(t, call, functionType, arguments, parameters, 0); }
/** * If a constructor statement is not emitted TS will assume a constructor with no arguments and * no body (default ctor) for base classes, or the constructor of the superclass. * * <p>Omitting the constructor is correct only if the closure class and *all* its superclasses * have zero argument constructors. If the supertype is NoResolvedType we cannot know whether * that's the case so we must return true. */ private boolean mustEmitConstructor(FunctionType type) { while (type != null) { if (type.getParameters().iterator().hasNext()) return true; ObjectType oType = getSuperType(type); if (oType == null) return false; if (oType.isNoResolvedType()) return true; type = oType.getConstructor(); } return false; }
/** Gets the minimum number of arguments that this function requires. */ public int getMinArguments() { // NOTE(nicksantos): There are some native functions that have optional // parameters before required parameters. This algorithm finds the position // of the last required parameter. int i = 0; int min = 0; for (Node n : getParameters()) { i++; if (!n.isOptionalArg() && !n.isVarArgs()) { min = i; } } return min; }
/** Gets the minimum number of arguments that this function requires. */ public final int getMinArity() { // NOTE(nicksantos): There are some native functions that have optional // parameters before required parameters. This algorithm finds the position // of the last required parameter. int i = 0; int min = 0; for (Node n : getParameters()) { i++; if (!n.isOptionalArg() && !n.isVarArgs()) { min = i; } } return min; }
@Override public TypeI convertMethodToFunction() { List<JSType> paramTypes = new ArrayList<JSType>(); paramTypes.add(getTypeOfThis()); for (Node param : getParameters()) { paramTypes.add(param.getJSType()); } return registry.createFunctionTypeWithInstanceType( registry.getNativeObjectType(JSTypeNative.UNKNOWN_TYPE), getReturnType(), paramTypes); }
public final boolean acceptsArguments(List<? extends JSType> argumentTypes) { // NOTE(aravindpg): This code is essentially lifted from TypeCheck::visitParameterList, // but what small differences there are make it very painful to refactor out the shared code. Iterator<? extends JSType> arguments = argumentTypes.iterator(); Iterator<Node> parameters = this.getParameters().iterator(); Node parameter = null; JSType argument = null; while (arguments.hasNext() && (parameters.hasNext() || parameter != null && parameter.isVarArgs())) { // If there are no parameters left in the list, then the while loop // above implies that this must be a var_args function. if (parameters.hasNext()) { parameter = parameters.next(); } argument = arguments.next(); if (!argument.isSubtypeOf(parameter.getJSType())) { return false; } } int numArgs = argumentTypes.size(); return this.getMinArity() <= numArgs && numArgs <= this.getMaxArity(); }
private boolean allParametersUnknown(FunctionType ftype) { for (Node param : ftype.getParameters()) { JSType type = param.getJSType(); // Note: template types (e.g. the T in Array<T>) return true for isUnknownType, // so we check that first. if (type.isTemplateType() || !type.isUnknownType()) return false; } return true; }
private JSType convertMethodToFunction(FunctionType method) { List<JSType> paramTypes = new ArrayList<>(); paramTypes.add(method.getTypeOfThis()); for (Node param : method.getParameters()) { paramTypes.add(param.getJSType()); } ObjectType unknown = compiler.getTypeRegistry().getNativeObjectType(JSTypeNative.UNKNOWN_TYPE); return compiler.getTypeRegistry().createFunctionTypeWithInstanceType( unknown, method.getReturnType(), paramTypes); }
Iterator<Node> parameters = functionType.getParameters().iterator(); Node parameter = null; Node argument = null;
Iterator<Node> parameters = functionType.getParameters().iterator(); int ordinal = 0; Node parameter = null;
private void registerMismatch(JSType found, JSType required, JSError error) { // Don't register a mismatch for differences in null or undefined or if the // code didn't downcast. found = found.restrictByNotNullOrUndefined(); required = required.restrictByNotNullOrUndefined(); if (found.isSubtype(required) || required.isSubtype(found)) { boolean strictMismatch = !found.isSubtypeWithoutStructuralTyping(required) && !required.isSubtypeWithoutStructuralTyping(found); if (strictMismatch) { implicitStructuralInterfaceUses.add(new TypeMismatch(found, required, error)); } return; } mismatches.add(new TypeMismatch(found, required, error)); if (found.isFunctionType() && required.isFunctionType()) { FunctionType fnTypeA = found.toMaybeFunctionType(); FunctionType fnTypeB = required.toMaybeFunctionType(); Iterator<Node> paramItA = fnTypeA.getParameters().iterator(); Iterator<Node> paramItB = fnTypeB.getParameters().iterator(); while (paramItA.hasNext() && paramItB.hasNext()) { registerIfMismatch(paramItA.next().getJSType(), paramItB.next().getJSType(), error); } registerIfMismatch( fnTypeA.getReturnType(), fnTypeB.getReturnType(), error); } }
/** * Special handling for simple typing returning polymorphic this type in TypeScript. Prefer * `func(): this` instead of `func<T>(this: T): T` when any params are not templatized. */ private boolean shouldSkipEmittingThisTemplateAndParam(FunctionType ftype) { final JSType typeOfThis = ftype.getTypeOfThis(); if (typeOfThis == null || !typeOfThis.isTemplateType() || !typeOfThis.equals(ftype.getReturnType())) { return false; } Iterator<Node> parameters = ftype.getParameters().iterator(); while (parameters.hasNext()) { final JSType paramType = parameters.next().getJSType(); if (!paramType.isTemplatizedType()) { continue; } final TemplateTypeMap templateTypeMap = paramType.getTemplateTypeMap(); for (TemplateType key : templateTypeMap.getTemplateKeys()) { if (templateTypeMap.getResolvedTemplateType(key).equals(typeOfThis)) { return false; } } } return true; }
Iterator<Node> parameters = tagFnType.getParameters().iterator();
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 (Node param : type.getParameters()) { visitOnce(param.getJSType());
for (Node parameter : function.getParameters()) { JSType result = findObjectWithNonStringifiableKey(parameter.getJSType()); if (result != null) {
for (Node paramType : funType.getParameters()) {
int i = 0; int childCount = n.getChildCount(); for (Node iParameter : fnType.getParameters()) { if (i + 1 >= childCount) {
for (Node paramNode : type.getParameters()) { JSType beforeParamType = paramNode.getJSType(); JSType afterParamType = beforeParamType.visit(this);