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


Java Token.FOR属性代码示例

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


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

示例1: isControlStructureCodeBlock

/**
 * Determines whether the given node is code node for FOR, DO,
 * WHILE, WITH, or IF node.
 */
static boolean isControlStructureCodeBlock(Node parent, Node n) {
  switch (parent.getType()) {
    case Token.FOR:
    case Token.WHILE:
    case Token.LABEL:
    case Token.WITH:
      return parent.getLastChild() == n;
    case Token.DO:
      return parent.getFirstChild() == n;
    case Token.IF:
      return parent.getFirstChild() != n;
    case Token.TRY:
      return parent.getFirstChild() == n || parent.getLastChild() == n;
    case Token.CATCH:
      return parent.getLastChild() == n;
    case Token.SWITCH:
    case Token.CASE:
      return parent.getFirstChild() != n;
    case Token.DEFAULT:
      return true;
    default:
      Preconditions.checkState(isControlStructure(parent));
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:29,代码来源:NodeUtil.java

示例2: isBreakStructure

/**
 * Determines whether the given node can be terminated with a BREAK node.
 */
static boolean isBreakStructure(Node n, boolean labeled) {
  switch (n.getType()) {
    case Token.FOR:
    case Token.DO:
    case Token.WHILE:
    case Token.SWITCH:
      return true;
    case Token.BLOCK:
    case Token.IF:
    case Token.TRY:
      return labeled;
    default:
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:18,代码来源:ControlFlowAnalysis.java

示例3: normalizeLabels

/**
 * Limit the number of special cases where LABELs need to be handled. Only
 * BLOCK and loops are allowed to be labeled.  Loop labels must remain in
 * place as the named continues are not allowed for labeled blocks.
 */
private void normalizeLabels(Node n) {
  Preconditions.checkArgument(n.getType() == Token.LABEL);

  Node last = n.getLastChild();
  switch (last.getType()) {
    case Token.LABEL:
    case Token.BLOCK:
    case Token.FOR:
    case Token.WHILE:
    case Token.DO:
      return;
    default:
      Node block = new Node(Token.BLOCK);
      n.replaceChild(last, block);
      block.addChildToFront(last);
      reportCodeChange("LABEL normalization");
      return;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:24,代码来源:Normalize.java

示例4: consumesDanglingElse

/**
 * Does a statement consume a 'dangling else'? A statement consumes
 * a 'dangling else' if an 'else' token following the statement
 * would be considered by the parser to be part of the statement.
 */
private boolean consumesDanglingElse(Node n) {
  while (true) {
    switch (n.getType()) {
      case Token.IF:
        if (n.getChildCount() < 3) return true;
        // This IF node has no else clause.
        n = n.getLastChild();
        continue;
      case Token.WITH:
      case Token.WHILE:
      case Token.FOR:
        n = n.getLastChild();
        continue;
      default:
        return false;
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:23,代码来源:FoldConstants.java

示例5: isPropertyTest

/**
 * Determines whether this node is testing for the existence of a property.
 * If true, we will not emit warnings about a missing property.
 *
 * @param getProp The GETPROP being tested.
 */
private boolean isPropertyTest(Node getProp) {
  Node parent = getProp.getParent();
  switch (parent.getType()) {
    case Token.CALL:
      return parent.getFirstChild() != getProp &&
          compiler.getCodingConvention().isPropertyTestFunction(parent);

    case Token.IF:
    case Token.WHILE:
    case Token.DO:
    case Token.FOR:
      return NodeUtil.getConditionExpression(parent) == getProp;

    case Token.INSTANCEOF:
    case Token.TYPEOF:
      return true;

    case Token.AND:
    case Token.HOOK:
      return parent.getFirstChild() == getProp;
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:29,代码来源:TypeCheck.java

示例6: isLoopStructure

/**
 * Determines whether the given node is a FOR, DO, or WHILE node.
 */
static boolean isLoopStructure(Node n) {
  switch (n.getType()) {
    case Token.FOR:
    case Token.DO:
    case Token.WHILE:
      return true;
    default:
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:13,代码来源:NodeUtil.java

示例7: getLoopCodeBlock

/**
 * @param n The node to inspect.
 * @return If the node, is a FOR, WHILE, or DO, it returns the node for
 * the code BLOCK, null otherwise.
 */
static Node getLoopCodeBlock(Node n) {
  switch (n.getType()) {
    case Token.FOR:
    case Token.WHILE:
      return n.getLastChild();
    case Token.DO:
      return n.getFirstChild();
    default:
      return null;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:16,代码来源:NodeUtil.java

示例8: isContinueStructure

/**
 * Determines whether the given node can be advanced with a CONTINUE node.
 */
static boolean isContinueStructure(Node n) {
  switch (n.getType()) {
    case Token.FOR:
    case Token.DO:
    case Token.WHILE:
      return true;
    default:
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:13,代码来源:ControlFlowAnalysis.java

示例9: hasConditionalAncestor

/**
 * return true if the node has any form of conditional in its ancestry
 * TODO(nicksantos) keep track of the conditionals in the ancestory, so
 * that we don't have to recrawl it.
 */
private boolean hasConditionalAncestor(Node n) {
  for (Node ancestor : n.getAncestors()) {
    switch (ancestor.getType()) {
      case Token.DO:
      case Token.FOR:
      case Token.HOOK:
      case Token.IF:
      case Token.SWITCH:
      case Token.WHILE:
        return true;
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:CrossModuleCodeMotion.java

示例10: visit

public void visit(NodeTraversal t, Node n, Node parent) {
  Node child;
  switch (n.getType()) {
    case Token.IF:
      child = n.getFirstChild().getNext();  // skip the condition child
      break;

    case Token.WHILE:
    case Token.FOR:
      child = NodeUtil.getLoopCodeBlock(n);
      break;

    default:
      return;  // don't check other types
  }

  // semicolons cause VOID children. Empty blocks are allowed because
  // that's usually intentional, especially with loops.
  for (; child != null; child = child.getNext()) {
    if ((child.getType() == Token.BLOCK) && (!child.hasChildren())) {
      // Only warn on empty blocks that replaced EMPTY nodes.  BLOCKs with no
      // children are considered OK.
      if (child.wasEmptyNode()) {
        t.getCompiler().report(
            JSError.make(t, n, level, SUSPICIOUS_SEMICOLON));
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:29,代码来源:CheckAccidentalSemicolon.java

示例11: processForInLoop

@Override
Node processForInLoop(ForInLoop loopNode) {
  return new Node(
      Token.FOR,
      transform(loopNode.getIterator()),
      transform(loopNode.getIteratedObject()),
      transform(loopNode.getBody()));
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:8,代码来源:IRFactory.java

示例12: replaceWithRhs

/**
 * Replace n with a simpler expression, while preserving program
 * behavior.
 *
 * If the n's value is used, replace it with its rhs; otherwise
 * replace it with the subexpressions that have side effects.
 */
private void replaceWithRhs(Node parent, Node n) {
  if (valueConsumedByParent(n, parent)) {
    // parent reads from n directly; replace it with n's rhs + lhs
    // subexpressions with side effects.
    List<Node> replacements = getRhsSubexpressions(n);
    List<Node> newReplacements = Lists.newArrayList();
    for (int i = 0; i < replacements.size() - 1; i++) {
      newReplacements.addAll(getSideEffectNodes(replacements.get(i)));
    }
    Node valueExpr = replacements.get(replacements.size() - 1);
    valueExpr.detachFromParent();
    newReplacements.add(valueExpr);
    changeProxy.replaceWith(
        parent, n, collapseReplacements(newReplacements));
  } else if (n.getType() == Token.ASSIGN && parent.getType() != Token.FOR) {
    // assignment appears in a RHS expression.  we have already
    // considered names in the assignment's RHS as being referenced;
    // replace the assignment with its RHS.
    // TODO(user) make the pass smarter about these cases and/or run
    // this pass and RemoveConstantExpressions together in a loop.
    Node replacement = n.getLastChild();
    replacement.detachFromParent();
    changeProxy.replaceWith(parent, n, replacement);
  } else {
    replaceTopLevelExpressionWithRhs(parent, n);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:NameAnalyzer.java

示例13: isForIn

/**
 * @return Whether the node represents a FOR-IN loop.
 */
static boolean isForIn(Node n) {
  return n.getType() == Token.FOR
      && n.getChildCount() == 3;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:7,代码来源:NodeUtil.java

示例14: maybeCollapseIntoForStatements

/**
 * Collapse VARs and EXPR_RESULT node into FOR loop initializers where
 * possible.
 */
private void maybeCollapseIntoForStatements(Node n, Node parent) {
  // Only SCRIPT, BLOCK, and LABELs can have FORs that can be collapsed into.
  // LABELs are not supported here.
  if (parent == null || !NodeUtil.isStatementBlock(parent)) {
    return;
  }

  // Is the current node something that can be in a for loop initializer?
  if (!NodeUtil.isExpressionNode(n) && !NodeUtil.isVar(n)) {
    return;
  }

  // Is the next statement a valid FOR?
  Node nextSibling = n.getNext();
  if (nextSibling != null
      && nextSibling.getType() == Token.FOR
      && !NodeUtil.isForIn(nextSibling)
      && nextSibling.getFirstChild().getType() == Token.EMPTY) {

    // Does the current node contain an in operator?  If so, embedding
    // the expression in a for loop can cause some Javascript parsers (such
    // as the Playstation 3's browser based on Access's NetFront
    // browser) to fail to parse the code.
    // See bug 1778863 for details.
    if (NodeUtil.containsType(n, Token.IN)) {
      return;
    }

    // Move the current node into the FOR loop initializer.
    Node forNode = nextSibling;
    Node oldInitializer = forNode.getFirstChild();
    parent.removeChild(n);

    Node newInitializer;
    if (NodeUtil.isVar(n)) {
      newInitializer = n;
    } else {
      // Extract the expression from EXPR_RESULT node.
      Preconditions.checkState(n.hasOneChild());
      newInitializer = n.getFirstChild();
      n.removeChild(newInitializer);
    }

    forNode.replaceChild(oldInitializer, newInitializer);

    compiler.reportCodeChange();
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:52,代码来源:Denormalize.java

示例15: determineGetTypeForHookOrBooleanExpr

/**
 * Determines whether the result of a hook (x?y:z) or boolean expression
 * (x||y) or (x&&y) is assigned to a specific global name.
 *
 * @param t The traversal
 * @param parent The parent of the current node in the traversal. This node
 *     should already be known to be a HOOK, AND, or OR node.
 * @param name A name that is already known to be global in the current
 *     scope (e.g. "a" or "a.b.c.d")
 * @return The expression's get type, either {@link Ref.Type#DIRECT_GET} or
 *     {@link Ref.Type#ALIASING_GET}
 */
Ref.Type determineGetTypeForHookOrBooleanExpr(
    NodeTraversal t, Node parent, String name) {
  Node prev = parent;
  for (Node anc : parent.getAncestors()) {
    switch (anc.getType()) {
      case Token.EXPR_RESULT:
      case Token.VAR:
      case Token.IF:
      case Token.WHILE:
      case Token.FOR:
      case Token.TYPEOF:
      case Token.VOID:
      case Token.NOT:
      case Token.BITNOT:
      case Token.POS:
      case Token.NEG:
        return Ref.Type.DIRECT_GET;
      case Token.HOOK:
        if (anc.getFirstChild() == prev) {
          return Ref.Type.DIRECT_GET;
        }
        break;
      case Token.ASSIGN:
        if (!name.equals(anc.getFirstChild().getQualifiedName())) {
          return Ref.Type.ALIASING_GET;
        }
        break;
      case Token.NAME:  // a variable declaration
        if (!name.equals(anc.getString())) {
          return Ref.Type.ALIASING_GET;
        }
        break;
      case Token.CALL:
        if (anc.getFirstChild() != prev) {
          return Ref.Type.ALIASING_GET;
        }
        break;
    }
    prev = anc;
  }
  return Ref.Type.ALIASING_GET;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:54,代码来源:GlobalNamespace.java


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