当前位置: 首页>>代码示例>>Java>>正文


Java JSType.canAssignTo方法代码示例

本文整理汇总了Java中com.google.javascript.rhino.jstype.JSType.canAssignTo方法的典型用法代码示例。如果您正苦于以下问题:Java JSType.canAssignTo方法的具体用法?Java JSType.canAssignTo怎么用?Java JSType.canAssignTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.javascript.rhino.jstype.JSType的用法示例。


在下文中一共展示了JSType.canAssignTo方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDescriptionForThrownType

import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
 * Returns the description for the given thrown type, if it
 * exists.
 */
public String getDescriptionForThrownType(JSType type,
    StaticScope<JSType> scope) {
  if (documentation == null || documentation.throwsDescriptions == null) {
    return null;
  }

  for (JSTypeExpression typeExpr :
           documentation.throwsDescriptions.keySet()) {
    if (type.canAssignTo(typeExpr.evaluate(scope))) {
      return documentation.throwsDescriptions.get(typeExpr);
    }
  }

  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:JSDocInfo.java

示例2: expectCanAssignToPropertyOf

import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
 * Expect that the first type can be assigned to a symbol of the second
 * type.
 *
 * @param t The node traversal.
 * @param n The node to issue warnings on.
 * @param rightType The type on the RHS of the assign.
 * @param leftType The type of the symbol on the LHS of the assign.
 * @param owner The owner of the property being assigned to.
 * @param propName The name of the property being assigned to.
 * @return True if the types matched, false otherwise.
 */
boolean expectCanAssignToPropertyOf(NodeTraversal t, Node n, JSType rightType,
    JSType leftType, Node owner, String propName) {
  // The NoType check is a hack to make typedefs work ok.
  if (!leftType.isNoType() && !rightType.canAssignTo(leftType)) {
    if (bothIntrinsics(rightType, leftType)) {
      // We have a superior warning for this mistake, which gives you
      // the line numbers of both types.
      registerMismatch(rightType, leftType);
    } else {
      mismatch(t, n,
          "assignment to property " + propName + " of " +
          getReadableJSTypeName(owner, true),
          rightType, leftType);
    }
    return false;
  }
  return true;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:31,代码来源:TypeValidator.java

示例3: registerMismatch

import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
private void registerMismatch(JSType found, JSType required) {
  // 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.canAssignTo(required) || required.canAssignTo(found)) {
    return;
  }

  mismatches.add(new TypeMismatch(found, required));
  if (found instanceof FunctionType &&
      required instanceof FunctionType) {
    FunctionType fnTypeA = ((FunctionType) found);
    FunctionType fnTypeB = ((FunctionType) required);
    Iterator<Node> paramItA = fnTypeA.getParameters().iterator();
    Iterator<Node> paramItB = fnTypeB.getParameters().iterator();
    while (paramItA.hasNext() && paramItB.hasNext()) {
      registerIfMismatch(paramItA.next().getJSType(),
          paramItB.next().getJSType());
    }

    registerIfMismatch(fnTypeA.getReturnType(), fnTypeB.getReturnType());
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:TypeValidator.java

示例4: expectCanAssignTo

import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
 * Expect that the first type can be assigned to a symbol of the second
 * type.
 *
 * @param t The node traversal.
 * @param n The node to issue warnings on.
 * @param rightType The type on the RHS of the assign.
 * @param leftType The type of the symbol on the LHS of the assign.
 * @param msg An extra message for the mismatch warning, if necessary.
 * @return True if the types matched, false otherwise.
 */
boolean expectCanAssignTo(NodeTraversal t, Node n, JSType rightType,
    JSType leftType, String msg) {
  if (!rightType.canAssignTo(leftType)) {
    if (bothIntrinsics(rightType, leftType)) {
      // We have a superior warning for this mistake, which gives you
      // the line numbers of both types.
      registerMismatch(rightType, leftType);
    } else {
      mismatch(t, n, msg, rightType, leftType);
    }
    return false;
  }
  return true;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:TypeValidator.java

示例5: expectCanCast

import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
 * Expect that the first type can be cast to the second type. The first type
 * should be either a subtype or supertype of the second.
 *
 * @param t The node traversal.
 * @param n The node where warnings should point.
 * @param type The type being cast from.
 * @param castType The type being cast to.
 */
void expectCanCast(NodeTraversal t, Node n, JSType type, JSType castType) {
  castType = castType.restrictByNotNullOrUndefined();
  type = type.restrictByNotNullOrUndefined();

  if (!type.canAssignTo(castType) && !castType.canAssignTo(type)) {
    compiler.report(
        JSError.make(t, n, INVALID_CAST,
            castType.toString(), type.toString()));
    registerMismatch(type, castType);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:21,代码来源:TypeValidator.java

示例6: registerIfMismatch

import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
private void registerIfMismatch(JSType found, JSType required) {
  if (found != null && required != null &&
      !found.canAssignTo(required)) {
    registerMismatch(found, required);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:7,代码来源:TypeValidator.java

示例7: expectArgumentMatchesParameter

import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
 * Expect that the type of an argument matches the type of the parameter
 * that it's fulfilling.
 *
 * @param t The node traversal.
 * @param n The node to issue warnings on.
 * @param argType The type of the argument.
 * @param paramType The type of the parameter.
 * @param callNode The call node, to help with the warning message.
 * @param ordinal The argument ordinal, to help with the warning message.
 */
void expectArgumentMatchesParameter(NodeTraversal t, Node n, JSType argType,
    JSType paramType, Node callNode, int ordinal) {
  if (!argType.canAssignTo(paramType)) {
    mismatch(t, n,
        String.format("actual parameter %d of %s does not match " +
            "formal parameter", ordinal,
            getReadableJSTypeName(callNode.getFirstChild(), false)),
        argType, paramType);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:TypeValidator.java

示例8: expectCanOverride

import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
 * Expect that the first type can override a property of the second
 * type.
 *
 * @param t The node traversal.
 * @param n The node to issue warnings on.
 * @param overridingType The overriding type.
 * @param hiddenType The type of the property being overridden.
 * @param propertyName The name of the property, for use in the
 *     warning message.
 * @param ownerType The type of the owner of the property, for use
 *     in the warning message.
 */
void expectCanOverride(NodeTraversal t, Node n, JSType overridingType,
    JSType hiddenType, String propertyName, JSType ownerType) {
  if (!overridingType.canAssignTo(hiddenType)) {
    registerMismatch(overridingType, hiddenType);
    compiler.report(
        JSError.make(t, n, HIDDEN_PROPERTY_MISMATCH,
            propertyName, ownerType.toString(),
            hiddenType.toString(), overridingType.toString()));
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:24,代码来源:TypeValidator.java


注:本文中的com.google.javascript.rhino.jstype.JSType.canAssignTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。