Java Code Examples for com.google.javascript.rhino.Node#setVarArgs()

The following examples show how to use com.google.javascript.rhino.Node#setVarArgs() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FunctionParamBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Copies the parameter specification from the given node.
 */
public Node newParameterFromNode(Node n) {
  Node newParam = newParameter(n.getJSType());
  newParam.setVarArgs(n.isVarArgs());
  newParam.setOptionalArg(n.isOptionalArg());
  return newParam;
}
 
Example 2
Source File: Closure_90_FunctionTypeBuilder_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Infer the parameter and return types of a function from
 * the parameter and return types of the function it is overriding.
 *
 * @param oldType The function being overridden. Does nothing if this is null.
 * @param paramsParent The LP node of the function that we're assigning to.
 *     If null, that just means we're not initializing this to a function
 *     literal.
 */
FunctionTypeBuilder inferFromOverriddenFunction(
    @Nullable FunctionType oldType, @Nullable Node paramsParent) {
  if (oldType == null) {
    return this;
  }

  returnType = oldType.getReturnType();
  returnTypeInferred = oldType.isReturnTypeInferred();
  if (paramsParent == null) {
    // Not a function literal.
    parametersNode = oldType.getParametersNode();
    if (parametersNode == null) {
      parametersNode = new FunctionParamBuilder(typeRegistry).build();
    }
  } else {
    // We're overriding with a function literal. Apply type information
    // to each parameter of the literal.
    FunctionParamBuilder paramBuilder =
        new FunctionParamBuilder(typeRegistry);
    Iterator<Node> oldParams = oldType.getParameters().iterator();
    boolean warnedAboutArgList = false;
    boolean oldParamsListHitOptArgs = false;
    for (Node currentParam = paramsParent.getFirstChild();
         currentParam != null; currentParam = currentParam.getNext()) {
      if (oldParams.hasNext()) {
        Node oldParam = oldParams.next();
        Node newParam = paramBuilder.newParameterFromNode(oldParam);

        oldParamsListHitOptArgs = oldParamsListHitOptArgs ||
            oldParam.isVarArgs() ||
            oldParam.isOptionalArg();

        // The subclass method might right its var_args as individual
        // arguments.
        if (currentParam.getNext() != null && newParam.isVarArgs()) {
          newParam.setVarArgs(false);
          newParam.setOptionalArg(true);
        }
      } else {
        warnedAboutArgList |= addParameter(
            paramBuilder,
            typeRegistry.getNativeType(UNKNOWN_TYPE),
            warnedAboutArgList,
            codingConvention.isOptionalParameter(currentParam) ||
                oldParamsListHitOptArgs,
            codingConvention.isVarArgsParameter(currentParam));
      }
    }
    parametersNode = paramBuilder.build();
  }
  return this;
}
 
Example 3
Source File: Closure_90_FunctionTypeBuilder_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Infer the parameter and return types of a function from
 * the parameter and return types of the function it is overriding.
 *
 * @param oldType The function being overridden. Does nothing if this is null.
 * @param paramsParent The LP node of the function that we're assigning to.
 *     If null, that just means we're not initializing this to a function
 *     literal.
 */
FunctionTypeBuilder inferFromOverriddenFunction(
    @Nullable FunctionType oldType, @Nullable Node paramsParent) {
  if (oldType == null) {
    return this;
  }

  returnType = oldType.getReturnType();
  returnTypeInferred = oldType.isReturnTypeInferred();
  if (paramsParent == null) {
    // Not a function literal.
    parametersNode = oldType.getParametersNode();
    if (parametersNode == null) {
      parametersNode = new FunctionParamBuilder(typeRegistry).build();
    }
  } else {
    // We're overriding with a function literal. Apply type information
    // to each parameter of the literal.
    FunctionParamBuilder paramBuilder =
        new FunctionParamBuilder(typeRegistry);
    Iterator<Node> oldParams = oldType.getParameters().iterator();
    boolean warnedAboutArgList = false;
    boolean oldParamsListHitOptArgs = false;
    for (Node currentParam = paramsParent.getFirstChild();
         currentParam != null; currentParam = currentParam.getNext()) {
      if (oldParams.hasNext()) {
        Node oldParam = oldParams.next();
        Node newParam = paramBuilder.newParameterFromNode(oldParam);

        oldParamsListHitOptArgs = oldParamsListHitOptArgs ||
            oldParam.isVarArgs() ||
            oldParam.isOptionalArg();

        // The subclass method might right its var_args as individual
        // arguments.
        if (currentParam.getNext() != null && newParam.isVarArgs()) {
          newParam.setVarArgs(false);
          newParam.setOptionalArg(true);
        }
      } else {
        warnedAboutArgList |= addParameter(
            paramBuilder,
            typeRegistry.getNativeType(UNKNOWN_TYPE),
            warnedAboutArgList,
            codingConvention.isOptionalParameter(currentParam) ||
                oldParamsListHitOptArgs,
            codingConvention.isVarArgsParameter(currentParam));
      }
    }
    parametersNode = paramBuilder.build();
  }
  return this;
}
 
Example 4
Source File: Closure_41_FunctionTypeBuilder_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Infer the parameter and return types of a function from
 * the parameter and return types of the function it is overriding.
 *
 * @param oldType The function being overridden. Does nothing if this is null.
 * @param paramsParent The LP node of the function that we're assigning to.
 *     If null, that just means we're not initializing this to a function
 *     literal.
 */
FunctionTypeBuilder inferFromOverriddenFunction(
    @Nullable FunctionType oldType, @Nullable Node paramsParent) {
  if (oldType == null) {
    return this;
  }

  returnType = oldType.getReturnType();
  returnTypeInferred = oldType.isReturnTypeInferred();
  if (paramsParent == null) {
    // Not a function literal.
    parametersNode = oldType.getParametersNode();
    if (parametersNode == null) {
      parametersNode = new FunctionParamBuilder(typeRegistry).build();
    }
  } else {
    // We're overriding with a function literal. Apply type information
    // to each parameter of the literal.
    FunctionParamBuilder paramBuilder =
        new FunctionParamBuilder(typeRegistry);
    Iterator<Node> oldParams = oldType.getParameters().iterator();
    boolean warnedAboutArgList = false;
    boolean oldParamsListHitOptArgs = false;
    for (Node currentParam = paramsParent.getFirstChild();
         currentParam != null; currentParam = currentParam.getNext()) {
      if (oldParams.hasNext()) {
        Node oldParam = oldParams.next();
        Node newParam = paramBuilder.newParameterFromNode(oldParam);

        oldParamsListHitOptArgs = oldParamsListHitOptArgs ||
            oldParam.isVarArgs() ||
            oldParam.isOptionalArg();

        // The subclass method might write its var_args as individual
        // arguments.
        if (currentParam.getNext() != null && newParam.isVarArgs()) {
          newParam.setVarArgs(false);
          newParam.setOptionalArg(true);
        }
      } else {
        warnedAboutArgList |= addParameter(
            paramBuilder,
            typeRegistry.getNativeType(UNKNOWN_TYPE),
            warnedAboutArgList,
            codingConvention.isOptionalParameter(currentParam) ||
                oldParamsListHitOptArgs,
            codingConvention.isVarArgsParameter(currentParam));
      }
    }

    // Clone any remaining params that aren't in the function literal.

    parametersNode = paramBuilder.build();
  }
  return this;
}
 
Example 5
Source File: Closure_41_FunctionTypeBuilder_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Infer the parameter and return types of a function from
 * the parameter and return types of the function it is overriding.
 *
 * @param oldType The function being overridden. Does nothing if this is null.
 * @param paramsParent The LP node of the function that we're assigning to.
 *     If null, that just means we're not initializing this to a function
 *     literal.
 */
FunctionTypeBuilder inferFromOverriddenFunction(
    @Nullable FunctionType oldType, @Nullable Node paramsParent) {
  if (oldType == null) {
    return this;
  }

  returnType = oldType.getReturnType();
  returnTypeInferred = oldType.isReturnTypeInferred();
  if (paramsParent == null) {
    // Not a function literal.
    parametersNode = oldType.getParametersNode();
    if (parametersNode == null) {
      parametersNode = new FunctionParamBuilder(typeRegistry).build();
    }
  } else {
    // We're overriding with a function literal. Apply type information
    // to each parameter of the literal.
    FunctionParamBuilder paramBuilder =
        new FunctionParamBuilder(typeRegistry);
    Iterator<Node> oldParams = oldType.getParameters().iterator();
    boolean warnedAboutArgList = false;
    boolean oldParamsListHitOptArgs = false;
    for (Node currentParam = paramsParent.getFirstChild();
         currentParam != null; currentParam = currentParam.getNext()) {
      if (oldParams.hasNext()) {
        Node oldParam = oldParams.next();
        Node newParam = paramBuilder.newParameterFromNode(oldParam);

        oldParamsListHitOptArgs = oldParamsListHitOptArgs ||
            oldParam.isVarArgs() ||
            oldParam.isOptionalArg();

        // The subclass method might write its var_args as individual
        // arguments.
        if (currentParam.getNext() != null && newParam.isVarArgs()) {
          newParam.setVarArgs(false);
          newParam.setOptionalArg(true);
        }
      } else {
        warnedAboutArgList |= addParameter(
            paramBuilder,
            typeRegistry.getNativeType(UNKNOWN_TYPE),
            warnedAboutArgList,
            codingConvention.isOptionalParameter(currentParam) ||
                oldParamsListHitOptArgs,
            codingConvention.isVarArgsParameter(currentParam));
      }
    }

    // Clone any remaining params that aren't in the function literal.
    while (oldParams.hasNext()) {
      paramBuilder.newParameterFromNode(oldParams.next());
    }

    parametersNode = paramBuilder.build();
  }
  return this;
}
 
Example 6
Source File: FunctionTypeBuilder.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Infer the parameter and return types of a function from
 * the parameter and return types of the function it is overriding.
 *
 * @param oldType The function being overridden. Does nothing if this is null.
 * @param paramsParent The LP node of the function that we're assigning to.
 *     If null, that just means we're not initializing this to a function
 *     literal.
 */
FunctionTypeBuilder inferFromOverriddenFunction(
    @Nullable FunctionType oldType, @Nullable Node paramsParent) {
  if (oldType == null) {
    return this;
  }

  returnType = oldType.getReturnType();
  returnTypeInferred = oldType.isReturnTypeInferred();
  if (paramsParent == null) {
    // Not a function literal.
    parametersNode = oldType.getParametersNode();
    if (parametersNode == null) {
      parametersNode = new FunctionParamBuilder(typeRegistry).build();
    }
  } else {
    // We're overriding with a function literal. Apply type information
    // to each parameter of the literal.
    FunctionParamBuilder paramBuilder =
        new FunctionParamBuilder(typeRegistry);
    Iterator<Node> oldParams = oldType.getParameters().iterator();
    boolean warnedAboutArgList = false;
    boolean oldParamsListHitOptArgs = false;
    for (Node currentParam = paramsParent.getFirstChild();
         currentParam != null; currentParam = currentParam.getNext()) {
      if (oldParams.hasNext()) {
        Node oldParam = oldParams.next();
        Node newParam = paramBuilder.newParameterFromNode(oldParam);

        oldParamsListHitOptArgs = oldParamsListHitOptArgs ||
            oldParam.isVarArgs() ||
            oldParam.isOptionalArg();

        // The subclass method might write its var_args as individual
        // arguments.
        if (currentParam.getNext() != null && newParam.isVarArgs()) {
          newParam.setVarArgs(false);
          newParam.setOptionalArg(true);
        }
      } else {
        warnedAboutArgList |= addParameter(
            paramBuilder,
            typeRegistry.getNativeType(UNKNOWN_TYPE),
            warnedAboutArgList,
            codingConvention.isOptionalParameter(currentParam) ||
                oldParamsListHitOptArgs,
            codingConvention.isVarArgsParameter(currentParam));
      }
    }

    // Clone any remaining params that aren't in the function literal,
    // but make them optional.
    while (oldParams.hasNext()) {
      paramBuilder.newOptionalParameterFromNode(oldParams.next());
    }

    parametersNode = paramBuilder.build();
  }
  return this;
}