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


Java JSDocInfo.isImplicitCast方法代码示例

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


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

示例1: ensureTyped

import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
/**
 * Enforces type casts, and ensures the node is typed.
 *
 * A cast in the way that we use it in JSDoc annotations never
 * alters the generated code and therefore never can induce any runtime
 * operation. What this means is that a 'cast' is really just a compile
 * time constraint on the underlying value. In the future, we may add
 * support for run-time casts for compiled tests.
 *
 * To ensure some shred of sanity, we enforce the notion that the
 * type you are casting to may only meaningfully be a narrower type
 * than the underlying declared type. We also invalidate optimizations
 * on bad type casts.
 *
 * @param t The traversal object needed to report errors.
 * @param n The node getting a type assigned to it.
 * @param type The type to be assigned.
 */
private void ensureTyped(NodeTraversal t, Node n, JSType type) {
  // Make sure FUNCTION nodes always get function type.
  Preconditions.checkState(n.getType() != Token.FUNCTION ||
          type instanceof FunctionType ||
          type.isUnknownType());
  JSDocInfo info = n.getJSDocInfo();
  if (info != null) {
    if (info.hasType()) {
      JSType infoType = info.getType().evaluate(t.getScope());
      validator.expectCanCast(t, n, infoType, type);
      type = infoType;
    }

    if (info.isImplicitCast() && !inExterns) {
      String propName = n.getType() == Token.GETPROP ?
          n.getLastChild().getString() : "(missing)";
      compiler.report(
          JSError.make(t, n, ILLEGAL_IMPLICIT_CAST, propName));
    }
  }

  if (n.getJSType() == null) {
    n.setJSType(type);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:44,代码来源:TypeCheck.java

示例2: propertyIsImplicitCast

import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
/**
 * Returns true if any type in the chain has an implictCast annotation for
 * the given property.
 */
private boolean propertyIsImplicitCast(ObjectType type, String prop) {
  for (; type != null; type = type.getImplicitPrototype()) {
    JSDocInfo docInfo = type.getOwnPropertyJSDocInfo(prop);
    if (docInfo != null && docInfo.isImplicitCast()) {
      return true;
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:14,代码来源:TypeCheck.java


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