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

The following examples show how to use com.google.javascript.rhino.Node#isCatch() . 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: Cardumen_00200_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Determines whether this node is used as an L-value. Notice that sometimes
 * names are used as both L-values and R-values.
 *
 * We treat "var x;" as a pseudo-L-value, which kind of makes sense if you
 * treat it as "assignment to 'undefined' at the top of the scope". But if
 * we're honest with ourselves, it doesn't make sense, and we only do this
 * because it makes sense to treat this as syntactically similar to
 * "var x = 0;".
 *
 * @param n The node
 * @return True if n is an L-value.
 */
public static boolean isLValue(Node n) {
  Preconditions.checkArgument(n.isName() || n.isGetProp() ||
      n.isGetElem());
  Node parent = n.getParent();
  if (parent == null) {
    return false;
  }
  return (NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == n)
      || (NodeUtil.isForIn(parent) && parent.getFirstChild() == n)
      || parent.isVar()
      || (parent.isFunction() && parent.getFirstChild() == n)
      || parent.isDec()
      || parent.isInc()
      || parent.isParamList()
      || parent.isCatch();
}
 
Example 2
Source File: NodeUtil.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines whether this node is used as an L-value. Notice that sometimes
 * names are used as both L-values and R-values.
 *
 * We treat "var x;" as a pseudo-L-value, which kind of makes sense if you
 * treat it as "assignment to 'undefined' at the top of the scope". But if
 * we're honest with ourselves, it doesn't make sense, and we only do this
 * because it makes sense to treat this as syntactically similar to
 * "var x = 0;".
 *
 * @param n The node
 * @return True if n is an L-value.
 */
public static boolean isLValue(Node n) {
  Preconditions.checkArgument(n.isName() || n.isGetProp() ||
      n.isGetElem());
  Node parent = n.getParent();
  if (parent == null) {
    return false;
  }
  return (NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == n)
      || (NodeUtil.isForIn(parent) && parent.getFirstChild() == n)
      || parent.isVar()
      || (parent.isFunction() && parent.getFirstChild() == n)
      || parent.isDec()
      || parent.isInc()
      || parent.isParamList()
      || parent.isCatch();
}
 
Example 3
Source File: Closure_10_NodeUtil_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Determines whether this node is used as an L-value. Notice that sometimes
 * names are used as both L-values and R-values.
 *
 * We treat "var x;" as a pseudo-L-value, which kind of makes sense if you
 * treat it as "assignment to 'undefined' at the top of the scope". But if
 * we're honest with ourselves, it doesn't make sense, and we only do this
 * because it makes sense to treat this as syntactically similar to
 * "var x = 0;".
 *
 * @param n The node
 * @return True if n is an L-value.
 */
public static boolean isLValue(Node n) {
  Preconditions.checkArgument(n.isName() || n.isGetProp() ||
      n.isGetElem());
  Node parent = n.getParent();
  if (parent == null) {
    return false;
  }
  return (NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == n)
      || (NodeUtil.isForIn(parent) && parent.getFirstChild() == n)
      || parent.isVar()
      || (parent.isFunction() && parent.getFirstChild() == n)
      || parent.isDec()
      || parent.isInc()
      || parent.isParamList()
      || parent.isCatch();
}
 
Example 4
Source File: Closure_10_NodeUtil_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Determines whether this node is used as an L-value. Notice that sometimes
 * names are used as both L-values and R-values.
 *
 * We treat "var x;" as a pseudo-L-value, which kind of makes sense if you
 * treat it as "assignment to 'undefined' at the top of the scope". But if
 * we're honest with ourselves, it doesn't make sense, and we only do this
 * because it makes sense to treat this as syntactically similar to
 * "var x = 0;".
 *
 * @param n The node
 * @return True if n is an L-value.
 */
public static boolean isLValue(Node n) {
  Preconditions.checkArgument(n.isName() || n.isGetProp() ||
      n.isGetElem());
  Node parent = n.getParent();
  if (parent == null) {
    return false;
  }
  return (NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == n)
      || (NodeUtil.isForIn(parent) && parent.getFirstChild() == n)
      || parent.isVar()
      || (parent.isFunction() && parent.getFirstChild() == n)
      || parent.isDec()
      || parent.isInc()
      || parent.isParamList()
      || parent.isCatch();
}
 
Example 5
Source File: jMutRepair_003_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Determines whether this node is used as an L-value. Notice that sometimes
 * names are used as both L-values and R-values.
 *
 * We treat "var x;" as a pseudo-L-value, which kind of makes sense if you
 * treat it as "assignment to 'undefined' at the top of the scope". But if
 * we're honest with ourselves, it doesn't make sense, and we only do this
 * because it makes sense to treat this as syntactically similar to
 * "var x = 0;".
 *
 * @param n The node
 * @return True if n is an L-value.
 */
public static boolean isLValue(Node n) {
  Preconditions.checkArgument(n.isName() || n.isGetProp() ||
      n.isGetElem());
  Node parent = n.getParent();
  if (parent == null) {
    return false;
  }
  return (NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == n)
      || (NodeUtil.isForIn(parent) && parent.getFirstChild() == n)
      || parent.isVar()
      || (parent.isFunction() && parent.getFirstChild() == n)
      || parent.isDec()
      || parent.isInc()
      || parent.isParamList()
      || parent.isCatch();
}
 
Example 6
Source File: jMutRepair_003_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Determines whether this node is used as an L-value. Notice that sometimes
 * names are used as both L-values and R-values.
 *
 * We treat "var x;" as a pseudo-L-value, which kind of makes sense if you
 * treat it as "assignment to 'undefined' at the top of the scope". But if
 * we're honest with ourselves, it doesn't make sense, and we only do this
 * because it makes sense to treat this as syntactically similar to
 * "var x = 0;".
 *
 * @param n The node
 * @return True if n is an L-value.
 */
public static boolean isLValue(Node n) {
  Preconditions.checkArgument(n.isName() || n.isGetProp() ||
      n.isGetElem());
  Node parent = n.getParent();
  if (parent == null) {
    return false;
  }
  return (NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == n)
      || (NodeUtil.isForIn(parent) && parent.getFirstChild() == n)
      || parent.isVar()
      || (parent.isFunction() && parent.getFirstChild() == n)
      || parent.isDec()
      || parent.isInc()
      || parent.isParamList()
      || parent.isCatch();
}
 
Example 7
Source File: jKali_003_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Determines whether this node is used as an L-value. Notice that sometimes
 * names are used as both L-values and R-values.
 *
 * We treat "var x;" as a pseudo-L-value, which kind of makes sense if you
 * treat it as "assignment to 'undefined' at the top of the scope". But if
 * we're honest with ourselves, it doesn't make sense, and we only do this
 * because it makes sense to treat this as syntactically similar to
 * "var x = 0;".
 *
 * @param n The node
 * @return True if n is an L-value.
 */
public static boolean isLValue(Node n) {
  Preconditions.checkArgument(n.isName() || n.isGetProp() ||
      n.isGetElem());
  Node parent = n.getParent();
  if (parent == null) {
    return false;
  }
  return (NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == n)
      || (NodeUtil.isForIn(parent) && parent.getFirstChild() == n)
      || parent.isVar()
      || (parent.isFunction() && parent.getFirstChild() == n)
      || parent.isDec()
      || parent.isInc()
      || parent.isParamList()
      || parent.isCatch();
}
 
Example 8
Source File: jKali_003_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Determines whether this node is used as an L-value. Notice that sometimes
 * names are used as both L-values and R-values.
 *
 * We treat "var x;" as a pseudo-L-value, which kind of makes sense if you
 * treat it as "assignment to 'undefined' at the top of the scope". But if
 * we're honest with ourselves, it doesn't make sense, and we only do this
 * because it makes sense to treat this as syntactically similar to
 * "var x = 0;".
 *
 * @param n The node
 * @return True if n is an L-value.
 */
public static boolean isLValue(Node n) {
  Preconditions.checkArgument(n.isName() || n.isGetProp() ||
      n.isGetElem());
  Node parent = n.getParent();
  if (parent == null) {
    return false;
  }
  return (NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == n)
      || (NodeUtil.isForIn(parent) && parent.getFirstChild() == n)
      || parent.isVar()
      || (parent.isFunction() && parent.getFirstChild() == n)
      || parent.isDec()
      || parent.isInc()
      || parent.isParamList()
      || parent.isCatch();
}
 
Example 9
Source File: Cardumen_0087_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Determines whether this node is used as an L-value. Notice that sometimes
 * names are used as both L-values and R-values.
 *
 * We treat "var x;" as a pseudo-L-value, which kind of makes sense if you
 * treat it as "assignment to 'undefined' at the top of the scope". But if
 * we're honest with ourselves, it doesn't make sense, and we only do this
 * because it makes sense to treat this as syntactically similar to
 * "var x = 0;".
 *
 * @param n The node
 * @return True if n is an L-value.
 */
public static boolean isLValue(Node n) {
  Preconditions.checkArgument(n.isName() || n.isGetProp() ||
      n.isGetElem());
  Node parent = n.getParent();
  if (parent == null) {
    return false;
  }
  return (NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == n)
      || (NodeUtil.isForIn(parent) && parent.getFirstChild() == n)
      || parent.isVar()
      || (parent.isFunction() && parent.getFirstChild() == n)
      || parent.isDec()
      || parent.isInc()
      || parent.isParamList()
      || parent.isCatch();
}
 
Example 10
Source File: Cardumen_0087_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Determines whether this node is used as an L-value. Notice that sometimes
 * names are used as both L-values and R-values.
 *
 * We treat "var x;" as a pseudo-L-value, which kind of makes sense if you
 * treat it as "assignment to 'undefined' at the top of the scope". But if
 * we're honest with ourselves, it doesn't make sense, and we only do this
 * because it makes sense to treat this as syntactically similar to
 * "var x = 0;".
 *
 * @param n The node
 * @return True if n is an L-value.
 */
public static boolean isLValue(Node n) {
  Preconditions.checkArgument(n.isName() || n.isGetProp() ||
      n.isGetElem());
  Node parent = n.getParent();
  if (parent == null) {
    return false;
  }
  return (NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == n)
      || (NodeUtil.isForIn(parent) && parent.getFirstChild() == n)
      || parent.isVar()
      || (parent.isFunction() && parent.getFirstChild() == n)
      || parent.isDec()
      || parent.isInc()
      || parent.isParamList()
      || parent.isCatch();
}
 
Example 11
Source File: Cardumen_0014_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Determines whether this node is used as an L-value. Notice that sometimes
 * names are used as both L-values and R-values.
 *
 * We treat "var x;" as a pseudo-L-value, which kind of makes sense if you
 * treat it as "assignment to 'undefined' at the top of the scope". But if
 * we're honest with ourselves, it doesn't make sense, and we only do this
 * because it makes sense to treat this as syntactically similar to
 * "var x = 0;".
 *
 * @param n The node
 * @return True if n is an L-value.
 */
public static boolean isLValue(Node n) {
  Preconditions.checkArgument(n.isName() || n.isGetProp() ||
      n.isGetElem());
  Node parent = n.getParent();
  if (parent == null) {
    return false;
  }
  return (NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == n)
      || (NodeUtil.isForIn(parent) && parent.getFirstChild() == n)
      || parent.isVar()
      || (parent.isFunction() && parent.getFirstChild() == n)
      || parent.isDec()
      || parent.isInc()
      || parent.isParamList()
      || parent.isCatch();
}
 
Example 12
Source File: Cardumen_0014_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Determines whether this node is used as an L-value. Notice that sometimes
 * names are used as both L-values and R-values.
 *
 * We treat "var x;" as a pseudo-L-value, which kind of makes sense if you
 * treat it as "assignment to 'undefined' at the top of the scope". But if
 * we're honest with ourselves, it doesn't make sense, and we only do this
 * because it makes sense to treat this as syntactically similar to
 * "var x = 0;".
 *
 * @param n The node
 * @return True if n is an L-value.
 */
public static boolean isLValue(Node n) {
  Preconditions.checkArgument(n.isName() || n.isGetProp() ||
      n.isGetElem());
  Node parent = n.getParent();
  if (parent == null) {
    return false;
  }
  return (NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == n)
      || (NodeUtil.isForIn(parent) && parent.getFirstChild() == n)
      || parent.isVar()
      || (parent.isFunction() && parent.getFirstChild() == n)
      || parent.isDec()
      || parent.isInc()
      || parent.isParamList()
      || parent.isCatch();
}
 
Example 13
Source File: Cardumen_00149_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Determines whether this node is used as an L-value. Notice that sometimes
 * names are used as both L-values and R-values.
 *
 * We treat "var x;" as a pseudo-L-value, which kind of makes sense if you
 * treat it as "assignment to 'undefined' at the top of the scope". But if
 * we're honest with ourselves, it doesn't make sense, and we only do this
 * because it makes sense to treat this as syntactically similar to
 * "var x = 0;".
 *
 * @param n The node
 * @return True if n is an L-value.
 */
public static boolean isLValue(Node n) {
  Preconditions.checkArgument(n.isName() || n.isGetProp() ||
      n.isGetElem());
  Node parent = n.getParent();
  if (parent == null) {
    return false;
  }
  return (NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == n)
      || (NodeUtil.isForIn(parent) && parent.getFirstChild() == n)
      || parent.isVar()
      || (parent.isFunction() && parent.getFirstChild() == n)
      || parent.isDec()
      || parent.isInc()
      || parent.isParamList()
      || parent.isCatch();
}
 
Example 14
Source File: Cardumen_00149_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Determines whether this node is used as an L-value. Notice that sometimes
 * names are used as both L-values and R-values.
 *
 * We treat "var x;" as a pseudo-L-value, which kind of makes sense if you
 * treat it as "assignment to 'undefined' at the top of the scope". But if
 * we're honest with ourselves, it doesn't make sense, and we only do this
 * because it makes sense to treat this as syntactically similar to
 * "var x = 0;".
 *
 * @param n The node
 * @return True if n is an L-value.
 */
public static boolean isLValue(Node n) {
  Preconditions.checkArgument(n.isName() || n.isGetProp() ||
      n.isGetElem());
  Node parent = n.getParent();
  if (parent == null) {
    return false;
  }
  return (NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == n)
      || (NodeUtil.isForIn(parent) && parent.getFirstChild() == n)
      || parent.isVar()
      || (parent.isFunction() && parent.getFirstChild() == n)
      || parent.isDec()
      || parent.isInc()
      || parent.isParamList()
      || parent.isCatch();
}
 
Example 15
Source File: Cardumen_00200_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Determines whether this node is used as an L-value. Notice that sometimes
 * names are used as both L-values and R-values.
 *
 * We treat "var x;" as a pseudo-L-value, which kind of makes sense if you
 * treat it as "assignment to 'undefined' at the top of the scope". But if
 * we're honest with ourselves, it doesn't make sense, and we only do this
 * because it makes sense to treat this as syntactically similar to
 * "var x = 0;".
 *
 * @param n The node
 * @return True if n is an L-value.
 */
public static boolean isLValue(Node n) {
  Preconditions.checkArgument(n.isName() || n.isGetProp() ||
      n.isGetElem());
  Node parent = n.getParent();
  if (parent == null) {
    return false;
  }
  return (NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == n)
      || (NodeUtil.isForIn(parent) && parent.getFirstChild() == n)
      || parent.isVar()
      || (parent.isFunction() && parent.getFirstChild() == n)
      || parent.isDec()
      || parent.isInc()
      || parent.isParamList()
      || parent.isCatch();
}
 
Example 16
Source File: SyntacticScopeCreator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onRedeclaration(
    Scope s, String name, Node n, CompilerInput input) {
  Node parent = n.getParent();

  // Don't allow multiple variables to be declared at the top-level scope
  if (scope.isGlobal()) {
    Scope.Var origVar = scope.getVar(name);
    Node origParent = origVar.getParentNode();
    if (origParent.isCatch() &&
        parent.isCatch()) {
      // Okay, both are 'catch(x)' variables.
      return;
    }

    boolean allowDupe = hasDuplicateDeclarationSuppression(n, origVar);

    if (!allowDupe) {
      compiler.report(
          JSError.make(NodeUtil.getSourceName(n), n,
                       VAR_MULTIPLY_DECLARED_ERROR,
                       name,
                       (origVar.input != null
                        ? origVar.input.getName()
                        : "??")));
    }
  } else if (name.equals(ARGUMENTS) && !NodeUtil.isVarDeclaration(n)) {
    // Disallow shadowing "arguments" as we can't handle with our current
    // scope modeling.
    compiler.report(
        JSError.make(NodeUtil.getSourceName(n), n,
            VAR_ARGUMENTS_SHADOWED_ERROR));
  }
}
 
Example 17
Source File: NodeIterators.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
private void advanceLookAhead(boolean atStart) {
  if (!atStart) {
    if (lookAhead == null) {
      return;
    }

    // Don't advance past a reference to the variable that we're trying
    // to inline.
    Node curNode = iterator.current();
    if (curNode.isName() &&
        varName.equals(curNode.getString())) {
      lookAhead = null;
      return;
    }
  }

  if (!iterator.hasNext()) {
    lookAhead = null;
    return;
  }

  Node nextNode = iterator.next();
  Node nextParent = iterator.currentParent();
  int type = nextNode.getType();

  if (valueHasSideEffects) {
    // Reject anything that might read state
    boolean readsState = false;

    if (// Any read of a different variable.
        (nextNode.isName() && !varName.equals(nextNode.getString())) ||
        // Any read of a property.
        (nextNode.isGetProp() || nextNode.isGetElem())) {

      // If this is a simple assign, we'll be ok.
      if (nextParent == null ||
          !NodeUtil.isVarOrSimpleAssignLhs(nextNode, nextParent)) {
        readsState = true;
      }

    } else if (nextNode.isCall() || nextNode.isNew()) {
      // This isn't really an important case. In most cases when we use
      // CALL or NEW, we're invoking it on a NAME or a GETPROP. And in the
      // few cases where we're not, it's because we have an anonymous
      // function that escapes the variable we're worried about. But we
      // include this for completeness.
      readsState = true;
    }

    if (readsState) {
      lookAhead = null;
      return;
    }
  }

  // Reject anything that might modify relevant state. We assume that
  // nobody relies on variables being undeclared, which will break
  // constructions like:
  //   var a = b;
  //   var b = 3;
  //   alert(a);
  if (NodeUtil.nodeTypeMayHaveSideEffects(nextNode) && type != Token.NAME
      || type == Token.NAME && nextParent.isCatch()) {
    lookAhead = null;
    return;
  }

  lookAhead = nextNode;
}