Java Code Examples for com.google.javascript.rhino.Node#getGrandparent()

The following examples show how to use com.google.javascript.rhino.Node#getGrandparent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeConversionPass.java    From clutz with MIT License 6 votes vote down vote up
private void replaceExpressionOrAssignment(Node n, Node parent, Node newNode) {
  if (parent.isExprResult()) {
    // Handles case: Myclass.Type;
    // AST:
    // EXPR_RESULT
    //     GETPROP
    //         NAME MyClass
    //         STRING Type
    parent.replaceWith(newNode);
  } else if (parent.isAssign()) {
    // Handles case: Myclass.Type = {};
    // AST:
    // ASSIGN
    //     GETPROP
    //         NAME MyClass
    //         STRING Type
    //     OBJECTLIST
    if (parent.getGrandparent() != null) {
      parent.getGrandparent().replaceChild(parent.getParent(), newNode);
    }
  } else {
    parent.replaceChild(n, newNode);
  }
}
 
Example 2
Source File: NodeModulePass.java    From js-dossier with Apache License 2.0 5 votes vote down vote up
private boolean isTopLevelAssign(Node n) {
  return n.isAssign()
      && n.getParent() != null
      && n.getParent().isExprResult()
      && n.getGrandparent() != null
      && n.getGrandparent().isScript();
}
 
Example 3
Source File: Nodes.java    From js-dossier with Apache License 2.0 4 votes vote down vote up
@Nullable
private static Node greatGrandparent(Node n) {
  Node gp = n.getGrandparent();
  return gp == null ? null : gp.getParent();
}