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

The following examples show how to use com.google.javascript.rhino.Node#replaceWith() . 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: NameUtil.java    From clutz with MIT License 5 votes vote down vote up
/**
 * In-place replaces a prefix with a new prefix in a name node. Does nothing if prefix does not
 * exist.
 */
public void replacePrefixInName(Node name, String prefix, String newPrefix) {
  if (name.matchesQualifiedName(prefix)) {
    Node newName = NodeUtil.newQName(compiler, newPrefix);
    JSDocInfo jsdoc = NodeUtil.getBestJSDocInfo(name);
    newName.setJSDocInfo(jsdoc);
    name.replaceWith(newName);
  } else {
    if (name.isGetProp()) {
      replacePrefixInName(name.getFirstChild(), prefix, newPrefix);
    }
  }
}
 
Example 3
Source File: NodeComments.java    From clutz with MIT License 4 votes vote down vote up
public void replaceWithComment(Node oldNode, Node newNode) {
  newNode.useSourceInfoFrom(newNode);
  oldNode.replaceWith(newNode);
  moveComment(oldNode, newNode);
}