Java Code Examples for com.google.javascript.rhino.JSDocInfo#hasParameterType()

The following examples show how to use com.google.javascript.rhino.JSDocInfo#hasParameterType() . 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: Closure_90_FunctionTypeBuilder_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * @return Whether the given param is an optional param.
 */
private boolean isOptionalParameter(
    Node param, @Nullable JSDocInfo info) {
  if (codingConvention.isOptionalParameter(param)) {
    return true;
  }

  String paramName = param.getString();
  return info != null && info.hasParameterType(paramName) &&
      info.getParameterType(paramName).isOptionalArg();
}
 
Example 2
Source File: Closure_90_FunctionTypeBuilder_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Determine whether this is a var args parameter.
 * @return Whether the given param is a var args param.
 */
private boolean isVarArgsParameter(
    Node param, @Nullable JSDocInfo info) {
  if (codingConvention.isVarArgsParameter(param)) {
    return true;
  }

  String paramName = param.getString();
  return info != null && info.hasParameterType(paramName) &&
      info.getParameterType(paramName).isVarArgs();
}
 
Example 3
Source File: Closure_90_FunctionTypeBuilder_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * @return Whether the given param is an optional param.
 */
private boolean isOptionalParameter(
    Node param, @Nullable JSDocInfo info) {
  if (codingConvention.isOptionalParameter(param)) {
    return true;
  }

  String paramName = param.getString();
  return info != null && info.hasParameterType(paramName) &&
      info.getParameterType(paramName).isOptionalArg();
}
 
Example 4
Source File: Closure_90_FunctionTypeBuilder_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Determine whether this is a var args parameter.
 * @return Whether the given param is a var args param.
 */
private boolean isVarArgsParameter(
    Node param, @Nullable JSDocInfo info) {
  if (codingConvention.isVarArgsParameter(param)) {
    return true;
  }

  String paramName = param.getString();
  return info != null && info.hasParameterType(paramName) &&
      info.getParameterType(paramName).isVarArgs();
}
 
Example 5
Source File: Closure_41_FunctionTypeBuilder_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * @return Whether the given param is an optional param.
 */
private boolean isOptionalParameter(
    Node param, @Nullable JSDocInfo info) {
  if (codingConvention.isOptionalParameter(param)) {
    return true;
  }

  String paramName = param.getString();
  return info != null && info.hasParameterType(paramName) &&
      info.getParameterType(paramName).isOptionalArg();
}
 
Example 6
Source File: Closure_41_FunctionTypeBuilder_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Determine whether this is a var args parameter.
 * @return Whether the given param is a var args param.
 */
private boolean isVarArgsParameter(
    Node param, @Nullable JSDocInfo info) {
  if (codingConvention.isVarArgsParameter(param)) {
    return true;
  }

  String paramName = param.getString();
  return info != null && info.hasParameterType(paramName) &&
      info.getParameterType(paramName).isVarArgs();
}
 
Example 7
Source File: Closure_41_FunctionTypeBuilder_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * @return Whether the given param is an optional param.
 */
private boolean isOptionalParameter(
    Node param, @Nullable JSDocInfo info) {
  if (codingConvention.isOptionalParameter(param)) {
    return true;
  }

  String paramName = param.getString();
  return info != null && info.hasParameterType(paramName) &&
      info.getParameterType(paramName).isOptionalArg();
}
 
Example 8
Source File: Closure_41_FunctionTypeBuilder_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Determine whether this is a var args parameter.
 * @return Whether the given param is a var args param.
 */
private boolean isVarArgsParameter(
    Node param, @Nullable JSDocInfo info) {
  if (codingConvention.isVarArgsParameter(param)) {
    return true;
  }

  String paramName = param.getString();
  return info != null && info.hasParameterType(paramName) &&
      info.getParameterType(paramName).isVarArgs();
}
 
Example 9
Source File: FunctionTypeBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return Whether the given param is an optional param.
 */
private boolean isOptionalParameter(
    Node param, @Nullable JSDocInfo info) {
  if (codingConvention.isOptionalParameter(param)) {
    return true;
  }

  String paramName = param.getString();
  return info != null && info.hasParameterType(paramName) &&
      info.getParameterType(paramName).isOptionalArg();
}
 
Example 10
Source File: FunctionTypeBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determine whether this is a var args parameter.
 * @return Whether the given param is a var args param.
 */
private boolean isVarArgsParameter(
    Node param, @Nullable JSDocInfo info) {
  if (codingConvention.isVarArgsParameter(param)) {
    return true;
  }

  String paramName = param.getString();
  return info != null && info.hasParameterType(paramName) &&
      info.getParameterType(paramName).isVarArgs();
}
 
Example 11
Source File: Closure_90_FunctionTypeBuilder_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Infer the parameter types from the list of argument names and
 * the doc info.
 */
FunctionTypeBuilder inferParameterTypes(@Nullable Node argsParent,
    @Nullable JSDocInfo info) {
  if (argsParent == null) {
    if (info == null) {
      return this;
    } else {
      return inferParameterTypes(info);
    }
  }

  // arguments
  Node oldParameterType = null;
  if (parametersNode != null) {
    oldParameterType = parametersNode.getFirstChild();
  }

  FunctionParamBuilder builder = new FunctionParamBuilder(typeRegistry);
  boolean warnedAboutArgList = false;
  Set<String> allJsDocParams = (info == null) ?
      Sets.<String>newHashSet() :
      Sets.newHashSet(info.getParameterNames());
  boolean foundTemplateType = false;
  for (Node arg : argsParent.children()) {
    String argumentName = arg.getString();
    allJsDocParams.remove(argumentName);

    // type from JSDocInfo
    JSType parameterType = null;
    boolean isOptionalParam = isOptionalParameter(arg, info);
    boolean isVarArgs = isVarArgsParameter(arg, info);
    if (info != null && info.hasParameterType(argumentName)) {
      parameterType =
          info.getParameterType(argumentName).evaluate(scope, typeRegistry);
    } else if (oldParameterType != null &&
        oldParameterType.getJSType() != null) {
      parameterType = oldParameterType.getJSType();
      isOptionalParam = oldParameterType.isOptionalArg();
      isVarArgs = oldParameterType.isVarArgs();
    } else {
      parameterType = typeRegistry.getNativeType(UNKNOWN_TYPE);
    }

    if (templateTypeName != null &&
        parameterType.restrictByNotNullOrUndefined().isTemplateType()) {
      if (foundTemplateType) {
        reportError(TEMPLATE_TYPE_DUPLICATED, fnName);
      }
      foundTemplateType = true;
    }
    warnedAboutArgList |= addParameter(
        builder, parameterType, warnedAboutArgList,
        isOptionalParam,
        isVarArgs);

    if (oldParameterType != null) {
      oldParameterType = oldParameterType.getNext();
    }
  }

  if (templateTypeName != null && !foundTemplateType) {
    reportError(TEMPLATE_TYPE_EXPECTED, fnName);
  }

  for (String inexistentName : allJsDocParams) {
    reportWarning(INEXISTANT_PARAM, inexistentName, fnName);
  }

  parametersNode = builder.build();
  return this;
}
 
Example 12
Source File: Closure_90_FunctionTypeBuilder_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Infer the parameter types from the list of argument names and
 * the doc info.
 */
FunctionTypeBuilder inferParameterTypes(@Nullable Node argsParent,
    @Nullable JSDocInfo info) {
  if (argsParent == null) {
    if (info == null) {
      return this;
    } else {
      return inferParameterTypes(info);
    }
  }

  // arguments
  Node oldParameterType = null;
  if (parametersNode != null) {
    oldParameterType = parametersNode.getFirstChild();
  }

  FunctionParamBuilder builder = new FunctionParamBuilder(typeRegistry);
  boolean warnedAboutArgList = false;
  Set<String> allJsDocParams = (info == null) ?
      Sets.<String>newHashSet() :
      Sets.newHashSet(info.getParameterNames());
  boolean foundTemplateType = false;
  for (Node arg : argsParent.children()) {
    String argumentName = arg.getString();
    allJsDocParams.remove(argumentName);

    // type from JSDocInfo
    JSType parameterType = null;
    boolean isOptionalParam = isOptionalParameter(arg, info);
    boolean isVarArgs = isVarArgsParameter(arg, info);
    if (info != null && info.hasParameterType(argumentName)) {
      parameterType =
          info.getParameterType(argumentName).evaluate(scope, typeRegistry);
    } else if (oldParameterType != null &&
        oldParameterType.getJSType() != null) {
      parameterType = oldParameterType.getJSType();
      isOptionalParam = oldParameterType.isOptionalArg();
      isVarArgs = oldParameterType.isVarArgs();
    } else {
      parameterType = typeRegistry.getNativeType(UNKNOWN_TYPE);
    }

    if (templateTypeName != null &&
        parameterType.restrictByNotNullOrUndefined().isTemplateType()) {
      if (foundTemplateType) {
        reportError(TEMPLATE_TYPE_DUPLICATED, fnName);
      }
      foundTemplateType = true;
    }
    warnedAboutArgList |= addParameter(
        builder, parameterType, warnedAboutArgList,
        isOptionalParam,
        isVarArgs);

    if (oldParameterType != null) {
      oldParameterType = oldParameterType.getNext();
    }
  }

  if (templateTypeName != null && !foundTemplateType) {
    reportError(TEMPLATE_TYPE_EXPECTED, fnName);
  }

  for (String inexistentName : allJsDocParams) {
    reportWarning(INEXISTANT_PARAM, inexistentName, fnName);
  }

  parametersNode = builder.build();
  return this;
}
 
Example 13
Source File: Closure_41_FunctionTypeBuilder_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Infer the parameter types from the list of argument names and
 * the doc info.
 */
FunctionTypeBuilder inferParameterTypes(@Nullable Node argsParent,
    @Nullable JSDocInfo info) {
  if (argsParent == null) {
    if (info == null) {
      return this;
    } else {
      return inferParameterTypes(info);
    }
  }

  // arguments
  Node oldParameterType = null;
  if (parametersNode != null) {
    oldParameterType = parametersNode.getFirstChild();
  }

  FunctionParamBuilder builder = new FunctionParamBuilder(typeRegistry);
  boolean warnedAboutArgList = false;
  Set<String> allJsDocParams = (info == null) ?
      Sets.<String>newHashSet() :
      Sets.newHashSet(info.getParameterNames());
  boolean foundTemplateType = false;
  boolean isVarArgs = false;
  for (Node arg : argsParent.children()) {
    String argumentName = arg.getString();
    allJsDocParams.remove(argumentName);

    // type from JSDocInfo
    JSType parameterType = null;
    boolean isOptionalParam = isOptionalParameter(arg, info);
    isVarArgs = isVarArgsParameter(arg, info);

    if (info != null && info.hasParameterType(argumentName)) {
      parameterType =
          info.getParameterType(argumentName).evaluate(scope, typeRegistry);
    } else if (oldParameterType != null &&
        oldParameterType.getJSType() != null) {
      parameterType = oldParameterType.getJSType();
      isOptionalParam = oldParameterType.isOptionalArg();
      isVarArgs = oldParameterType.isVarArgs();
    } else {
      parameterType = typeRegistry.getNativeType(UNKNOWN_TYPE);
    }

    if (templateTypeName != null &&
        parameterType.restrictByNotNullOrUndefined().isTemplateType()) {
      if (foundTemplateType) {
        reportError(TEMPLATE_TYPE_DUPLICATED, fnName);
      }
      foundTemplateType = true;
    }
    warnedAboutArgList |= addParameter(
        builder, parameterType, warnedAboutArgList,
        isOptionalParam,
        isVarArgs);

    if (oldParameterType != null) {
      oldParameterType = oldParameterType.getNext();
    }
  }

  // Copy over any old parameters that aren't in the param list.

  if (templateTypeName != null && !foundTemplateType) {
    reportError(TEMPLATE_TYPE_EXPECTED, fnName);
  }

  for (String inexistentName : allJsDocParams) {
    reportWarning(INEXISTANT_PARAM, inexistentName, fnName);
  }

  parametersNode = builder.build();
  return this;
}
 
Example 14
Source File: Closure_41_FunctionTypeBuilder_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Infer the parameter types from the list of argument names and
 * the doc info.
 */
FunctionTypeBuilder inferParameterTypes(@Nullable Node argsParent,
    @Nullable JSDocInfo info) {
  if (argsParent == null) {
    if (info == null) {
      return this;
    } else {
      return inferParameterTypes(info);
    }
  }

  // arguments
  Node oldParameterType = null;
  if (parametersNode != null) {
    oldParameterType = parametersNode.getFirstChild();
  }

  FunctionParamBuilder builder = new FunctionParamBuilder(typeRegistry);
  boolean warnedAboutArgList = false;
  Set<String> allJsDocParams = (info == null) ?
      Sets.<String>newHashSet() :
      Sets.newHashSet(info.getParameterNames());
  boolean foundTemplateType = false;
  boolean isVarArgs = false;
  for (Node arg : argsParent.children()) {
    String argumentName = arg.getString();
    allJsDocParams.remove(argumentName);

    // type from JSDocInfo
    JSType parameterType = null;
    boolean isOptionalParam = isOptionalParameter(arg, info);
    isVarArgs = isVarArgsParameter(arg, info);

    if (info != null && info.hasParameterType(argumentName)) {
      parameterType =
          info.getParameterType(argumentName).evaluate(scope, typeRegistry);
    } else if (oldParameterType != null &&
        oldParameterType.getJSType() != null) {
      parameterType = oldParameterType.getJSType();
      isOptionalParam = oldParameterType.isOptionalArg();
      isVarArgs = oldParameterType.isVarArgs();
    } else {
      parameterType = typeRegistry.getNativeType(UNKNOWN_TYPE);
    }

    if (templateTypeName != null &&
        parameterType.restrictByNotNullOrUndefined().isTemplateType()) {
      if (foundTemplateType) {
        reportError(TEMPLATE_TYPE_DUPLICATED, fnName);
      }
      foundTemplateType = true;
    }
    warnedAboutArgList |= addParameter(
        builder, parameterType, warnedAboutArgList,
        isOptionalParam,
        isVarArgs);

    if (oldParameterType != null) {
      oldParameterType = oldParameterType.getNext();
    }
  }

  // Copy over any old parameters that aren't in the param list.
  if (!isVarArgs) {
    while (oldParameterType != null && !isVarArgs) {
      builder.newParameterFromNode(oldParameterType);
      oldParameterType = oldParameterType.getNext();
    }
  }

  if (templateTypeName != null && !foundTemplateType) {
    reportError(TEMPLATE_TYPE_EXPECTED, fnName);
  }

  for (String inexistentName : allJsDocParams) {
    reportWarning(INEXISTANT_PARAM, inexistentName, fnName);
  }

  parametersNode = builder.build();
  return this;
}
 
Example 15
Source File: FunctionTypeBuilder.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Infer the parameter types from the list of argument names and
 * the doc info.
 */
FunctionTypeBuilder inferParameterTypes(@Nullable Node argsParent,
    @Nullable JSDocInfo info) {
  if (argsParent == null) {
    if (info == null) {
      return this;
    } else {
      return inferParameterTypes(info);
    }
  }

  // arguments
  Node oldParameterType = null;
  if (parametersNode != null) {
    oldParameterType = parametersNode.getFirstChild();
  }

  FunctionParamBuilder builder = new FunctionParamBuilder(typeRegistry);
  boolean warnedAboutArgList = false;
  Set<String> allJsDocParams = (info == null) ?
      Sets.<String>newHashSet() :
      Sets.newHashSet(info.getParameterNames());
  boolean foundTemplateType = false;
  boolean isVarArgs = false;
  for (Node arg : argsParent.children()) {
    String argumentName = arg.getString();
    allJsDocParams.remove(argumentName);

    // type from JSDocInfo
    JSType parameterType = null;
    boolean isOptionalParam = isOptionalParameter(arg, info);
    isVarArgs = isVarArgsParameter(arg, info);

    if (info != null && info.hasParameterType(argumentName)) {
      parameterType =
          info.getParameterType(argumentName).evaluate(scope, typeRegistry);
    } else if (oldParameterType != null &&
        oldParameterType.getJSType() != null) {
      parameterType = oldParameterType.getJSType();
      isOptionalParam = oldParameterType.isOptionalArg();
      isVarArgs = oldParameterType.isVarArgs();
    } else {
      parameterType = typeRegistry.getNativeType(UNKNOWN_TYPE);
    }

    warnedAboutArgList |= addParameter(
        builder, parameterType, warnedAboutArgList,
        isOptionalParam,
        isVarArgs);

    if (oldParameterType != null) {
      oldParameterType = oldParameterType.getNext();
    }
  }

  // Copy over any old parameters that aren't in the param list.
  if (!isVarArgs) {
    while (oldParameterType != null && !isVarArgs) {
      builder.newParameterFromNode(oldParameterType);
      oldParameterType = oldParameterType.getNext();
    }
  }

  for (String inexistentName : allJsDocParams) {
    reportWarning(INEXISTANT_PARAM, inexistentName, fnName);
  }

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