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


Java JSDocInfo.hasType方法代码示例

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


在下文中一共展示了JSDocInfo.hasType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getDeclaredGetPropType

import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
/**
 * Look for a type declaration on a GETPROP node.
 *
 * @param info The doc info for this property.
 * @param n A top-level GETPROP node (it should not be contained inside
 *     another GETPROP).
 * @param rhsValue The node that {@code n} is being initialized to,
 *     or {@code null} if this is a stub declaration.
 */
private JSType getDeclaredGetPropType(NodeTraversal t, JSDocInfo info,
    Node n, Node rhsValue) {
  if (info != null && info.hasType()) {
    return getDeclaredTypeInAnnotation(t, n, info);
  } else if (info != null && info.hasEnumParameterType()) {
    return n.getJSType();
  } else if (rhsValue != null &&
      rhsValue.getType() == Token.FUNCTION) {
    return rhsValue.getJSType();
  } else {
    return getDeclaredTypeInAnnotation(t, n, info);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:23,代码来源:TypedScopeCreator.java

示例3: inferThisType

import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
/**
 * Infers the type of {@code this}.
 * @param type The type of this.
 */
FunctionTypeBuilder inferThisType(JSDocInfo info, JSType type) {
  ObjectType objType = ObjectType.cast(type);
  if (objType != null && (info == null || !info.hasType())) {
    thisType = objType;
  }
  return this;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:12,代码来源:FunctionTypeBuilder.java

示例4: getDeclaredTypeInAnnotation

import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
JSType getDeclaredTypeInAnnotation(String sourceName,
    Node node, JSDocInfo info) {
  JSType jsType = null;
  Node objNode = node.getType() == Token.GETPROP ?
      node.getFirstChild() : null;
  if (info != null) {
    if (info.hasType()) {
      jsType = info.getType().evaluate(scope);
    } else if (FunctionTypeBuilder.isFunctionTypeDeclaration(info)) {
      String fnName = node.getQualifiedName();

      // constructors are often handled separately.
      if (info.isConstructor() && typeRegistry.getType(fnName) != null) {
        return null;
      }

      FunctionTypeBuilder builder =
          new FunctionTypeBuilder(
              fnName, compiler, node, sourceName, scope)
          .inferTemplateTypeName(info)
          .inferReturnType(info)
          .inferParameterTypes(info)
          .inferInheritance(info);

      // Infer the context type.
      boolean searchedForThisType = false;
      if (objNode != null) {
        if (objNode.getType() == Token.GETPROP &&
            objNode.getLastChild().getString().equals("prototype")) {
          builder.inferThisType(info, objNode.getFirstChild());
          searchedForThisType = true;
        } else if (objNode.getType() == Token.THIS) {
          builder.inferThisType(info, objNode.getJSType());
          searchedForThisType = true;
        }
      }

      if (!searchedForThisType) {
        builder.inferThisType(info, (Node) null);
      }

      jsType = builder.buildAndRegister();
    }
  }
  return jsType;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:47,代码来源:TypedScopeCreator.java


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