Java Code Examples for com.google.javascript.rhino.IR#getprop()

The following examples show how to use com.google.javascript.rhino.IR#getprop() . 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: jMutRepair_003_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Creates a node representing a qualified name.
 *
 * @param name A qualified name (e.g. "foo" or "foo.bar.baz")
 * @return A NAME or GETPROP node
 */
public static Node newQualifiedNameNode(
    CodingConvention convention, String name) {
  int endPos = name.indexOf('.');
  if (endPos == -1) {
    return newName(convention, name);
  }
  Node node = newName(convention, name.substring(0, endPos));
  int startPos;
  do {
    startPos = endPos + 1;
    endPos = name.indexOf('.', startPos);
    String part = (endPos == -1
                   ? name.substring(startPos)
                   : name.substring(startPos, endPos));
    Node propNode = IR.string(part);
    if (convention.isConstantKey(part)) {
      propNode.putBooleanProp(Node.IS_CONSTANT_NAME, true);
    }
    node = IR.getprop(node, propNode);
  } while (endPos != -1);

  return node;
}
 
Example 2
Source File: Closure_10_NodeUtil_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Creates a node representing a qualified name.
 *
 * @param name A qualified name (e.g. "foo" or "foo.bar.baz")
 * @return A NAME or GETPROP node
 */
public static Node newQualifiedNameNode(
    CodingConvention convention, String name) {
  int endPos = name.indexOf('.');
  if (endPos == -1) {
    return newName(convention, name);
  }
  Node node = newName(convention, name.substring(0, endPos));
  int startPos;
  do {
    startPos = endPos + 1;
    endPos = name.indexOf('.', startPos);
    String part = (endPos == -1
                   ? name.substring(startPos)
                   : name.substring(startPos, endPos));
    Node propNode = IR.string(part);
    if (convention.isConstantKey(part)) {
      propNode.putBooleanProp(Node.IS_CONSTANT_NAME, true);
    }
    node = IR.getprop(node, propNode);
  } while (endPos != -1);

  return node;
}
 
Example 3
Source File: DefinitionsRemover.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node getLValue() {
  // TODO(user) revisit: object literal definitions are an example
  // of definitions whose LHS doesn't correspond to a node that
  // exists in the AST.  We will have to change the return type of
  // getLValue sooner or later in order to provide this added
  // flexibility.

  switch (name.getType()) {
    case Token.SETTER_DEF:
    case Token.GETTER_DEF:
    case Token.STRING_KEY:
      // TODO(johnlenz): return a GETELEM for quoted strings.
      return IR.getprop(
          IR.objectlit(),
          IR.string(name.getString()));
    default:
      throw new IllegalStateException("unexpected");
  }
}
 
Example 4
Source File: jMutRepair_003_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Creates a node representing a qualified name.
 *
 * @param name A qualified name (e.g. "foo" or "foo.bar.baz")
 * @return A NAME or GETPROP node
 */
public static Node newQualifiedNameNode(
    CodingConvention convention, String name) {
  int endPos = name.indexOf('.');
  if (endPos == -1) {
    return newName(convention, name);
  }
  Node node = newName(convention, name.substring(0, endPos));
  int startPos;
  do {
    startPos = endPos + 1;
    endPos = name.indexOf('.', startPos);
    String part = (endPos == -1
                   ? name.substring(startPos)
                   : name.substring(startPos, endPos));
    Node propNode = IR.string(part);
    if (convention.isConstantKey(part)) {
      propNode.putBooleanProp(Node.IS_CONSTANT_NAME, true);
    }
    node = IR.getprop(node, propNode);
  } while (endPos != -1);

  return node;
}
 
Example 5
Source File: Cardumen_00200_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Creates a node representing a qualified name.
 *
 * @param name A qualified name (e.g. "foo" or "foo.bar.baz")
 * @return A NAME or GETPROP node
 */
public static Node newQualifiedNameNode(
    CodingConvention convention, String name) {
  int endPos = name.indexOf('.');
  if (endPos == -1) {
    return newName(convention, name);
  }
  Node node = newName(convention, name.substring(0, endPos));
  int startPos;
  do {
    startPos = endPos + 1;
    endPos = name.indexOf('.', startPos);
    String part = (endPos == -1
                   ? name.substring(startPos)
                   : name.substring(startPos, endPos));
    Node propNode = IR.string(part);
    if (convention.isConstantKey(part)) {
      propNode.putBooleanProp(Node.IS_CONSTANT_NAME, true);
    }
    node = IR.getprop(node, propNode);
  } while (endPos != -1);

  return node;
}
 
Example 6
Source File: jKali_003_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Creates a node representing a qualified name.
 *
 * @param name A qualified name (e.g. "foo" or "foo.bar.baz")
 * @return A NAME or GETPROP node
 */
public static Node newQualifiedNameNode(
    CodingConvention convention, String name) {
  int endPos = name.indexOf('.');
  if (endPos == -1) {
    return newName(convention, name);
  }
  Node node = newName(convention, name.substring(0, endPos));
  int startPos;
  do {
    startPos = endPos + 1;
    endPos = name.indexOf('.', startPos);
    String part = (endPos == -1
                   ? name.substring(startPos)
                   : name.substring(startPos, endPos));
    Node propNode = IR.string(part);
    if (convention.isConstantKey(part)) {
      propNode.putBooleanProp(Node.IS_CONSTANT_NAME, true);
    }
    node = IR.getprop(node, propNode);
  } while (endPos != -1);

  return node;
}
 
Example 7
Source File: jKali_003_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Creates a node representing a qualified name.
 *
 * @param name A qualified name (e.g. "foo" or "foo.bar.baz")
 * @return A NAME or GETPROP node
 */
public static Node newQualifiedNameNode(
    CodingConvention convention, String name) {
  int endPos = name.indexOf('.');
  if (endPos == -1) {
    return newName(convention, name);
  }
  Node node = newName(convention, name.substring(0, endPos));
  int startPos;
  do {
    startPos = endPos + 1;
    endPos = name.indexOf('.', startPos);
    String part = (endPos == -1
                   ? name.substring(startPos)
                   : name.substring(startPos, endPos));
    Node propNode = IR.string(part);
    if (convention.isConstantKey(part)) {
      propNode.putBooleanProp(Node.IS_CONSTANT_NAME, true);
    }
    node = IR.getprop(node, propNode);
  } while (endPos != -1);

  return node;
}
 
Example 8
Source File: Cardumen_0087_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Creates a node representing a qualified name.
 *
 * @param name A qualified name (e.g. "foo" or "foo.bar.baz")
 * @return A NAME or GETPROP node
 */
public static Node newQualifiedNameNode(
    CodingConvention convention, String name) {
  int endPos = name.indexOf('.');
  if (endPos == -1) {
    return newName(convention, name);
  }
  Node node = newName(convention, name.substring(0, endPos));
  int startPos;
  do {
    startPos = endPos + 1;
    endPos = name.indexOf('.', startPos);
    String part = (endPos == -1
                   ? name.substring(startPos)
                   : name.substring(startPos, endPos));
    Node propNode = IR.string(part);
    if (convention.isConstantKey(part)) {
      propNode.putBooleanProp(Node.IS_CONSTANT_NAME, true);
    }
    node = IR.getprop(node, propNode);
  } while (endPos != -1);

  return node;
}
 
Example 9
Source File: Cardumen_0014_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Creates a node representing a qualified name.
 *
 * @param name A qualified name (e.g. "foo" or "foo.bar.baz")
 * @return A NAME or GETPROP node
 */
public static Node newQualifiedNameNode(
    CodingConvention convention, String name) {
  int endPos = name.indexOf('.');
  if (endPos == -1) {
    return newName(convention, name);
  }
  Node node = newName(convention, name.substring(0, endPos));
  int startPos;
  do {
    startPos = endPos + 1;
    endPos = name.indexOf('.', startPos);
    String part = (endPos == -1
                   ? name.substring(startPos)
                   : name.substring(startPos, endPos));
    Node propNode = IR.string(part);
    if (convention.isConstantKey(part)) {
      propNode.putBooleanProp(Node.IS_CONSTANT_NAME, true);
    }
    node = IR.getprop(node, propNode);
  } while (endPos != -1);

  return node;
}
 
Example 10
Source File: Cardumen_00149_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Creates a node representing a qualified name.
 *
 * @param name A qualified name (e.g. "foo" or "foo.bar.baz")
 * @return A NAME or GETPROP node
 */
public static Node newQualifiedNameNode(
    CodingConvention convention, String name) {
  int endPos = name.indexOf('.');
  if (endPos == -1) {
    return newName(convention, name);
  }
  Node node = newName(convention, name.substring(0, endPos));
  int startPos;
  do {
    startPos = endPos + 1;
    endPos = name.indexOf('.', startPos);
    String part = (endPos == -1
                   ? name.substring(startPos)
                   : name.substring(startPos, endPos));
    Node propNode = IR.string(part);
    if (convention.isConstantKey(part)) {
      propNode.putBooleanProp(Node.IS_CONSTANT_NAME, true);
    }
    node = IR.getprop(node, propNode);
  } while (endPos != -1);

  return node;
}
 
Example 11
Source File: Cardumen_00149_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Creates a node representing a qualified name.
 *
 * @param name A qualified name (e.g. "foo" or "foo.bar.baz")
 * @return A NAME or GETPROP node
 */
public static Node newQualifiedNameNode(
    CodingConvention convention, String name) {
  int endPos = name.indexOf('.');
  if (endPos == -1) {
    return newName(convention, name);
  }
  Node node = newName(convention, name.substring(0, endPos));
  int startPos;
  do {
    startPos = endPos + 1;
    endPos = name.indexOf('.', startPos);
    String part = (endPos == -1
                   ? name.substring(startPos)
                   : name.substring(startPos, endPos));
    Node propNode = IR.string(part);
    if (convention.isConstantKey(part)) {
      propNode.putBooleanProp(Node.IS_CONSTANT_NAME, true);
    }
    node = IR.getprop(node, propNode);
  } while (endPos != -1);

  return node;
}
 
Example 12
Source File: Cardumen_00200_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Creates a node representing a qualified name.
 *
 * @param name A qualified name (e.g. "foo" or "foo.bar.baz")
 * @return A NAME or GETPROP node
 */
public static Node newQualifiedNameNode(
    CodingConvention convention, String name) {
  int endPos = name.indexOf('.');
  if (endPos == -1) {
    return newName(convention, name);
  }
  Node node = newName(convention, name.substring(0, endPos));
  int startPos;
  do {
    startPos = endPos + 1;
    endPos = name.indexOf('.', startPos);
    String part = (endPos == -1
                   ? name.substring(startPos)
                   : name.substring(startPos, endPos));
    Node propNode = IR.string(part);
    if (convention.isConstantKey(part)) {
      propNode.putBooleanProp(Node.IS_CONSTANT_NAME, true);
    }
    node = IR.getprop(node, propNode);
  } while (endPos != -1);

  return node;
}
 
Example 13
Source File: ProcessCommonJSModules.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Emit <code>if (moduleName.module$exports) {
 *    moduleName = moduleName.module$export;
 * }</code> at end of file.
 */
private void emitOptionalModuleExportsOverride(Node script,
    String moduleName) {
  if (!modulesWithExports.contains(moduleName)) {
    return;
  }

  Node moduleExportsProp = IR.getprop(IR.name(moduleName),
      IR.string("module$exports"));
  script.addChildToBack(IR.ifNode(
      moduleExportsProp,
      IR.block(IR.exprResult(IR.assign(IR.name(moduleName),
          moduleExportsProp.cloneTree())))).copyInformationFromForTree(
      script));
}
 
Example 14
Source File: Closure_26_ProcessCommonJSModules_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Emit <code>if (moduleName.module$exports) {
 *    moduleName = moduleName.module$export;
 * }</code> at end of file.
 */
private void emitOptionalModuleExportsOverride(Node script,
    String moduleName) {
  if (!modulesWithExports.contains(moduleName)) {
    return;
  }

  Node moduleExportsProp = IR.getprop(IR.name(moduleName),
      IR.string("module$exports"));
  script.addChildToBack(IR.ifNode(
      moduleExportsProp,
      IR.block(IR.exprResult(IR.assign(IR.name(moduleName),
          moduleExportsProp.cloneTree())))).copyInformationFromForTree(
      script));
}
 
Example 15
Source File: Closure_132_PeepholeSubstituteAlternateSyntax_t.java    From coming with MIT License 5 votes vote down vote up
private Node tryFoldImmediateCallToBoundFunction(Node n) {
  // Rewriting "(fn.bind(a,b))()" to "fn.call(a,b)" makes it inlinable
  Preconditions.checkState(n.isCall());
  Node callTarget = n.getFirstChild();
  Bind bind = getCodingConvention().describeFunctionBind(callTarget, false);
  if (bind != null) {
    // replace the call target
    bind.target.detachFromParent();
    n.replaceChild(callTarget, bind.target);
    callTarget = bind.target;

    // push the parameters
    addParameterAfter(bind.parameters, callTarget);

    // add the this value before the parameters if necessary
    if (bind.thisValue != null && !NodeUtil.isUndefined(bind.thisValue)) {
      // rewrite from "fn(a, b)" to "fn.call(thisValue, a, b)"
      Node newCallTarget = IR.getprop(
          callTarget.cloneTree(),
          IR.string("call").srcref(callTarget));
      n.replaceChild(callTarget, newCallTarget);
      n.addChildAfter(bind.thisValue.cloneTree(), newCallTarget);
      n.putBooleanProp(Node.FREE_CALL, false);
    } else {
      n.putBooleanProp(Node.FREE_CALL, true);
    }
    reportCodeChange();
  }
  return n;
}
 
Example 16
Source File: Closure_132_PeepholeSubstituteAlternateSyntax_s.java    From coming with MIT License 5 votes vote down vote up
private Node tryFoldImmediateCallToBoundFunction(Node n) {
  // Rewriting "(fn.bind(a,b))()" to "fn.call(a,b)" makes it inlinable
  Preconditions.checkState(n.isCall());
  Node callTarget = n.getFirstChild();
  Bind bind = getCodingConvention().describeFunctionBind(callTarget, false);
  if (bind != null) {
    // replace the call target
    bind.target.detachFromParent();
    n.replaceChild(callTarget, bind.target);
    callTarget = bind.target;

    // push the parameters
    addParameterAfter(bind.parameters, callTarget);

    // add the this value before the parameters if necessary
    if (bind.thisValue != null && !NodeUtil.isUndefined(bind.thisValue)) {
      // rewrite from "fn(a, b)" to "fn.call(thisValue, a, b)"
      Node newCallTarget = IR.getprop(
          callTarget.cloneTree(),
          IR.string("call").srcref(callTarget));
      n.replaceChild(callTarget, newCallTarget);
      n.addChildAfter(bind.thisValue.cloneTree(), newCallTarget);
      n.putBooleanProp(Node.FREE_CALL, false);
    } else {
      n.putBooleanProp(Node.FREE_CALL, true);
    }
    reportCodeChange();
  }
  return n;
}
 
Example 17
Source File: Closure_9_ProcessCommonJSModules_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Emit <code>if (moduleName.module$exports) {
 *    moduleName = moduleName.module$export;
 * }</code> at end of file.
 */
private void emitOptionalModuleExportsOverride(Node script,
    String moduleName) {
  if (!modulesWithExports.contains(moduleName)) {
    return;
  }

  Node moduleExportsProp = IR.getprop(IR.name(moduleName),
      IR.string("module$exports"));
  script.addChildToBack(IR.ifNode(
      moduleExportsProp,
      IR.block(IR.exprResult(IR.assign(IR.name(moduleName),
          moduleExportsProp.cloneTree())))).copyInformationFromForTree(
      script));
}
 
Example 18
Source File: Closure_20_PeepholeSubstituteAlternateSyntax_s.java    From coming with MIT License 5 votes vote down vote up
private Node tryFoldImmediateCallToBoundFunction(Node n) {
  // Rewriting "(fn.bind(a,b))()" to "fn.call(a,b)" makes it inlinable
  Preconditions.checkState(n.isCall());
  Node callTarget = n.getFirstChild();
  Bind bind = getCodingConvention().describeFunctionBind(callTarget, false);
  if (bind != null) {
    // replace the call target
    bind.target.detachFromParent();
    n.replaceChild(callTarget, bind.target);
    callTarget = bind.target;

    // push the parameters
    addParameterAfter(bind.parameters, callTarget);

    // add the this value before the parameters if necessary
    if (bind.thisValue != null && !NodeUtil.isUndefined(bind.thisValue)) {
      // rewrite from "fn(a, b)" to "fn.call(thisValue, a, b)"
      Node newCallTarget = IR.getprop(
          callTarget.cloneTree(),
          IR.string("call").srcref(callTarget));
      n.replaceChild(callTarget, newCallTarget);
      n.addChildAfter(bind.thisValue.cloneTree(), newCallTarget);
      n.putBooleanProp(Node.FREE_CALL, false);
    } else {
      n.putBooleanProp(Node.FREE_CALL, true);
    }
    reportCodeChange();
  }
  return n;
}
 
Example 19
Source File: Closure_20_PeepholeSubstituteAlternateSyntax_t.java    From coming with MIT License 5 votes vote down vote up
private Node tryFoldImmediateCallToBoundFunction(Node n) {
  // Rewriting "(fn.bind(a,b))()" to "fn.call(a,b)" makes it inlinable
  Preconditions.checkState(n.isCall());
  Node callTarget = n.getFirstChild();
  Bind bind = getCodingConvention().describeFunctionBind(callTarget, false);
  if (bind != null) {
    // replace the call target
    bind.target.detachFromParent();
    n.replaceChild(callTarget, bind.target);
    callTarget = bind.target;

    // push the parameters
    addParameterAfter(bind.parameters, callTarget);

    // add the this value before the parameters if necessary
    if (bind.thisValue != null && !NodeUtil.isUndefined(bind.thisValue)) {
      // rewrite from "fn(a, b)" to "fn.call(thisValue, a, b)"
      Node newCallTarget = IR.getprop(
          callTarget.cloneTree(),
          IR.string("call").srcref(callTarget));
      n.replaceChild(callTarget, newCallTarget);
      n.addChildAfter(bind.thisValue.cloneTree(), newCallTarget);
      n.putBooleanProp(Node.FREE_CALL, false);
    } else {
      n.putBooleanProp(Node.FREE_CALL, true);
    }
    reportCodeChange();
  }
  return n;
}
 
Example 20
Source File: ReplaceMessagesForChrome.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
private static Node getChromeI18nGetMessageNode(String messageId) {
  Node chromeI18n = IR.getprop(IR.name("chrome"), IR.string("i18n"));
  Node getMessage =  IR.getprop(chromeI18n, IR.string("getMessage"));
  return IR.call(getMessage, IR.string(messageId));
}