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


Java Node.getJSDocInfo方法代码示例

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


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

示例1: testJSDocAttachment2

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testJSDocAttachment2() {
  Node varNode = parse("/** @type number */var a,b;").getFirstChild();

  // VAR
  assertEquals(Token.VAR, varNode.getType());
  JSDocInfo info = varNode.getJSDocInfo();
  assertNotNull(info);
  assertTypeEquals(NUMBER_TYPE, info.getType());

  // First NAME
  Node nameNode1 = varNode.getFirstChild();
  assertEquals(Token.NAME, nameNode1.getType());
  assertNull(nameNode1.getJSDocInfo());

  // Second NAME
  Node nameNode2 = nameNode1.getNext();
  assertEquals(Token.NAME, nameNode2.getType());
  assertNull(nameNode2.getJSDocInfo());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:ParserTest.java

示例2: isConstructorOrEnumDeclaration

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Determines whether a set operation is a constructor or enumeration
 * declaration. The set operation may either be an assignment to a name,
 * a variable declaration, or an object literal key mapping.
 *
 * @param n The node that represents the name being set
 * @param parent Parent node of {@code n} (an ASSIGN, VAR, or OBJLIT node)
 * @return Whether the set operation is either a constructor or enum
 *     declaration
 */
private boolean isConstructorOrEnumDeclaration(Node n, Node parent) {
  JSDocInfo info;
  int valueNodeType;
  switch (parent.getType()) {
    case Token.ASSIGN:
      info = parent.getJSDocInfo();
      valueNodeType = n.getNext().getType();
      break;
    case Token.VAR:
      info = n.getJSDocInfo();
      if (info == null) {
        info = parent.getJSDocInfo();
      }
      Node valueNode = n.getFirstChild();
      valueNodeType = valueNode != null ? valueNode.getType() : Token.VOID;
      break;
    default:
      return false;
  }
  // Heed the annotations only if they're sensibly used.
  return info != null &&
         (info.isConstructor() && valueNodeType == Token.FUNCTION ||
          info.hasEnumParameterType() && valueNodeType == Token.OBJECTLIT);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:35,代码来源:GlobalNamespace.java

示例3: getDocInfoForDeclaration

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Tries to get the doc info for a given declaration ref.
 */
private static JSDocInfo getDocInfoForDeclaration(Ref ref) {
  if (ref.node != null) {
    Node refParent = ref.node.getParent();
    switch (refParent.getType()) {
      case Token.FUNCTION:
      case Token.ASSIGN:
        return refParent.getJSDocInfo();
      case Token.VAR:
        return ref.node == refParent.getFirstChild() ?
            refParent.getJSDocInfo() : ref.node.getJSDocInfo();
    }
  }

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

示例4: testJSDocAttachment11

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testJSDocAttachment11() {
  Node varNode =
     parse("/** @type {{x : number, 'y' : string, z}} */var a;")
      .getFirstChild();

  // VAR
  assertEquals(Token.VAR, varNode.getType());
  JSDocInfo info = varNode.getJSDocInfo();
  assertNotNull(info);

  assertTypeEquals(createRecordTypeBuilder().
                   addProperty("x", NUMBER_TYPE).
                   addProperty("y", STRING_TYPE).
                   addProperty("z", UNKNOWN_TYPE).
                   build(),
                   info.getType());

  // NAME
  Node nameNode = varNode.getFirstChild();
  assertEquals(Token.NAME, nameNode.getType());
  assertNull(nameNode.getJSDocInfo());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:23,代码来源:ParserTest.java

示例5: testJSDocAttachment4

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testJSDocAttachment4() {
  Node varNode = parse(
      "var a, /** @define {number} */b = 5;").getFirstChild();

  // ASSIGN
  assertEquals(Token.VAR, varNode.getType());
  assertNull(varNode.getJSDocInfo());

  // a
  Node a = varNode.getFirstChild();
  assertNull(a.getJSDocInfo());

  // b
  Node b = a.getNext();
  JSDocInfo info = b.getJSDocInfo();
  assertNotNull(info);
  assertTrue(info.isDefine());
  assertTypeEquals(NUMBER_TYPE, info.getType());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:ParserTest.java

示例6: testJSDocAttachment5

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testJSDocAttachment5() {
  Node varNode = parse(
      "var /** @type number */a, /** @define {number} */b = 5;")
      .getFirstChild();

  // ASSIGN
  assertEquals(Token.VAR, varNode.getType());
  assertNull(varNode.getJSDocInfo());

  // a
  Node a = varNode.getFirstChild();
  assertNotNull(a.getJSDocInfo());
  JSDocInfo info = a.getJSDocInfo();
  assertNotNull(info);
  assertFalse(info.isDefine());
  assertTypeEquals(NUMBER_TYPE, info.getType());

  // b
  Node b = a.getNext();
  info = b.getJSDocInfo();
  assertNotNull(info);
  assertTrue(info.isDefine());
  assertTypeEquals(NUMBER_TYPE, info.getType());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:ParserTest.java

示例7: maybeCollectMember

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void maybeCollectMember(NodeTraversal t,
    Node member, Node nodeWithJsDocInfo) {
  JSDocInfo info = nodeWithJsDocInfo.getJSDocInfo();

  // Do nothing if there is no JSDoc type info, or
  // if the node is not a member expression, or
  // if the member expression is not of the form: this.someProperty.
  if (info == null ||
      member.getType() != Token.GETPROP ||
      member.getFirstChild().getType() != Token.THIS) {
    return;
  }

  member.getFirstChild().setJSType(thisType);
  JSType jsType = getDeclaredTypeInAnnotation(t, member, info);
  Node name = member.getLastChild();
  if (jsType != null &&
      (name.getType() == Token.NAME || name.getType() == Token.STRING)) {
    thisType.defineDeclaredProperty(
        name.getString(),
        jsType,
        false /* functions with implementations are not in externs */);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:TypedScopeCreator.java

示例8: getFunctionJsDocInfo

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Gets a function's JSDoc information, if it has any. Checks for a few
 * patterns (ellipses show where JSDoc would be):
 * <pre>
 * ... function() {}
 * ... x = function() {};
 * var ... x = function() {};
 * ... var x = function() {};
 * </pre>
 */
private JSDocInfo getFunctionJsDocInfo(Node n) {
  JSDocInfo jsDoc = n.getJSDocInfo();
  Node parent = n.getParent();
  if (jsDoc == null) {
    int parentType = parent.getType();
    if (parentType == Token.NAME || parentType == Token.ASSIGN) {
      jsDoc = parent.getJSDocInfo();
      if (jsDoc == null && parentType == Token.NAME) {
        Node gramps = parent.getParent();
        if (gramps.getType() == Token.VAR) {
          jsDoc = gramps.getJSDocInfo();
        }
      }
    }
  }
  return jsDoc;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:28,代码来源:CheckGlobalThis.java

示例9: getGlobalName

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void getGlobalName(NodeTraversal t, Node dest, Node parent) {
  if (dest.getType() == Token.NAME) {

    JSDocInfo docInfo = dest.getJSDocInfo() == null ?
        parent.getJSDocInfo() : dest.getJSDocInfo();
    boolean aliasable = !unaliasableGlobals.contains(dest.getString()) &&
        (docInfo == null || !docInfo.isNoAlias());

    if (aliasable) {
      String name = dest.getString();
      Scope.Var var = t.getScope().getVar(name);

      if (var != null && !var.isLocal()) {
        globals.put(name, new Property(name));
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:AliasExternals.java

示例10: check

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Reports errors for any invalid use of control structures.
 *
 * @param node Current node to check.
 */
private void check(Node node) {
  switch (node.getType()) {
    case Token.WITH:
      JSDocInfo info = node.getJSDocInfo();
      boolean allowWith =
          info != null && info.getSuppressions().contains("with");
      if (!allowWith) {
        report(node, USE_OF_WITH);
      }
      break;

    case Token.SCRIPT:
      // Remember the source file name in case we need to report an error.
      sourceName = (String) node.getProp(Node.SOURCENAME_PROP);
      break;
  }

  for (Node bChild = node.getFirstChild(); bChild != null;) {
    Node next = bChild.getNext();
    check(bChild);
    bChild = next;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:29,代码来源:ControlStructureCheck.java

示例11: visitFunctionNode

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void visitFunctionNode(Node n, Node parent) {
  Node name = null;
  JSDocInfo info = parent.getJSDocInfo();
  if (info != null && info.isConstructor()) {
    name = parent.getFirstChild();
  } else {
    // look to the child, maybe it's a named function
    info = n.getJSDocInfo();
    if (info != null && info.isConstructor()) {
      name = n.getFirstChild();
    }
  }
  if (name != null && name.isQualifiedName()) {
    String qualifiedName = name.getQualifiedName();
    if (!this.convention.isPrivate(qualifiedName)) {
      Visibility visibility = info.getVisibility();
      if (!visibility.equals(JSDocInfo.Visibility.PRIVATE)) {
        ctors.put(qualifiedName, name);
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:23,代码来源:CheckProvides.java

示例12: visit

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  JSDocInfo docInfo = n.getJSDocInfo();
  if (docInfo != null && docInfo.isExport()) {
    String export = null;
    GenerateNodeContext context = null;

    switch (n.getType()) {
      case Token.FUNCTION:
        if (parent.getType() == Token.SCRIPT) {
          export = NodeUtil.getFunctionName(n, parent);
          context = new GenerateNodeContext(n, parent, n);
        }
        break;
      case Token.ASSIGN:
        Node grandparent = parent.getParent();
        if (grandparent != null && grandparent.getType() == Token.SCRIPT &&
            parent.getType() == Token.EXPR_RESULT &&
            n.getLastChild().getType() != Token.ASSIGN) {
          export = n.getFirstChild().getQualifiedName();
          context = new GenerateNodeContext(n, grandparent, parent);
        }
        break;
      case Token.VAR:
        if (parent.getType() == Token.SCRIPT) {
          if (n.getFirstChild().hasChildren() &&
              n.getFirstChild().getFirstChild().getType() != Token.ASSIGN) {
            export = n.getFirstChild().getString();
            context = new GenerateNodeContext(n, parent, n);
          }
        }
    }

    if (export != null) {
      exports.put(export, context);
    } else {
      compiler.report(JSError.make(t, n, NON_GLOBAL_ERROR));
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:41,代码来源:FindExportableNodes.java

示例13: collectDefines

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Finds all defines, and creates a {@link DefineInfo} data structure for
 * each one.
 * @return A map of {@link DefineInfo} structures, keyed by name.
 */
private Map<String, DefineInfo> collectDefines(Node root,
    GlobalNamespace namespace) {
  // Find all the global names with a @define annotation
  List<Name> allDefines = Lists.newArrayList();
  for (Name name : namespace.getNameIndex().values()) {
    if (name.docInfo != null && name.docInfo.isDefine()) {
      allDefines.add(name);
    } else if (name.refs != null) {
      for (Ref ref : name.refs) {
        Node n = ref.node;
        Node parent = ref.node.getParent();
        JSDocInfo info = n.getJSDocInfo();
        if (info == null &&
            parent.getType() == Token.VAR && parent.hasOneChild()) {
          info = parent.getJSDocInfo();
        }

        if (info != null && info.isDefine()) {
          allDefines.add(name);
          break;
        }
      }
    }
  }

  CollectDefines pass = new CollectDefines(compiler, allDefines);
  NodeTraversal.traverse(compiler, root, pass);
  return pass.getAllDefines();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:35,代码来源:ProcessDefines.java

示例14: testJSDocAttachment6

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Tests that a JSDoc comment in an unexpected place of the code does not
 * propagate to following code due to {@link JSDocInfo} aggregation.
 */
public void testJSDocAttachment6() throws Exception {
  Node functionNode = parse(
      "var a = /** @param {number} index */5;" +
      "/** @return boolean */function f(index){}")
      .getFirstChild().getNext();

  assertEquals(Token.FUNCTION, functionNode.getType());
  JSDocInfo info = functionNode.getJSDocInfo();
  assertNotNull(info);
  assertFalse(info.hasParameter("index"));
  assertTrue(info.hasReturnType());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:17,代码来源:ParserTest.java

示例15: visitVar

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Visits a VAR node.
 *
 * @param t The node traversal object that supplies context, such as the
 * scope chain to use in name lookups as well as error reporting.
 * @param n The node being visited.
 */
private void visitVar(NodeTraversal t, Node n) {
  // TODO(nicksantos): Fix this so that the doc info always shows up
  // on the NAME node. We probably want to wait for the parser
  // merge to fix this.
  JSDocInfo varInfo = n.hasOneChild() ? n.getJSDocInfo() : null;
  for (Node name : n.children()) {
    Node value = name.getFirstChild();
    // A null var would indicate a bug in the scope creation logic.
    Var var = t.getScope().getVar(name.getString());

    if (value != null) {
      JSType valueType = getJSType(value);
      JSType nameType = var.getType();
      nameType = (nameType == null) ? getNativeType(UNKNOWN_TYPE) : nameType;

      JSDocInfo info = name.getJSDocInfo();
      if (info == null) {
        info = varInfo;
      }
      if (info != null && info.hasEnumParameterType()) {
        // var.getType() can never be null, this would indicate a bug in the
        // scope creation logic.
        checkEnumInitializer(
            t, value,  info.getEnumParameterType().evaluate(t.getScope()));
      } else if (var.isTypeInferred()) {
        ensureTyped(t, name, valueType);
      } else {
        validator.expectCanAssignTo(
            t, value, valueType, nameType, "initializing variable");
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:41,代码来源:TypeCheck.java


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