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


Java Node.getAncestor方法代码示例

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


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

示例1: shouldTraverse

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
  Node gramps = n.getAncestor(2);
  return gramps == null || gramps.getType() != Token.SCRIPT;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:6,代码来源:MoveFunctionDeclarations.java

示例2: checkNameUsage

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Find functions that can be inlined.
 */
private void checkNameUsage(NodeTraversal t, Node n, Node parent) {
  Preconditions.checkState(n.getType() == Token.NAME);

  if (parent.getType() == Token.VAR || parent.getType() == Token.FUNCTION) {
    // This is a declaration.  Duplicate declarations are handle during
    // function candidate gathering.
    return;
  }

  if (parent.getType() == Token.CALL && parent.getFirstChild() == n) {
    // This is a normal reference to the function.
    return;
  }

  // Check for a ".call" to the named function:
  //   CALL
  //     GETPROP/GETELEM
  //       NAME
  //       STRING == "call"
  //     This-Value
  //     Function-parameter-1
  //     ...
  if (NodeUtil.isGet(parent)
       && n == parent.getFirstChild()
       && n.getNext().getType() == Token.STRING
       && n.getNext().getString().equals("call")) {
    Node gramps = n.getAncestor(2);
    if (gramps.getType() == Token.CALL
        && gramps.getFirstChild() == parent) {
      // Yep, a ".call".
      return;
    }
  }

  // Other refs to a function name remove its candidacy for inlining
  String name = n.getString();
  FunctionState fs = fns.get(name);
  if (fs == null) {
    return;
  }

  // If the name is being assigned to it can not be inlined.
  if (parent.getType() == Token.ASSIGN && parent.getFirstChild() == n) {
    // e.g. bar = something; <== we can't inline "bar"
    // so mark the function as uninlinable.
    // TODO(johnlenz): Should we just remove it from fns here?
    fs.setInline(false);
  } else {
    // e.g. var fn = bar; <== we can't inline "bar"
    // As this reference can't be inlined mark the function as
    // unremovable.
    fs.setRemove(false);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:58,代码来源:InlineFunctions.java


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