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


Java Token.GETELEM属性代码示例

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


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

示例1: visit

/** {@inheritDoc} */
public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.GETELEM:
      Node left = n.getFirstChild();
      Node right = left.getNext();
      if (right.getType() == Token.STRING &&
          NodeUtil.isValidPropertyName(right.getString())) {
        n.removeChild(left);
        n.removeChild(right);
        parent.replaceChild(n, new Node(Token.GETPROP, left, right));
        compiler.reportCodeChange();
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:16,代码来源:ConvertToDottedProperties.java

示例2: replaceAccessor

private void replaceAccessor(Node getPropNode) {
  /*
   *  BEFORE
      getprop
          NODE...
          string length
      AFTER
      getelem
          NODE...
          name PROP_length
   */
  Node propNameNode = getPropNode.getLastChild();
  String propName = propNameNode.getString();
  if (props.get(propName).aliasAccessor) {
    Node propSrc = getPropNode.getFirstChild();
    getPropNode.removeChild(propSrc);

    Node newNameNode =
      Node.newString(Token.NAME, getArrayNotationNameFor(propName));

    Node elemNode = new Node(Token.GETELEM, propSrc, newNameNode);
    replaceNode(getPropNode.getParent(), getPropNode, elemNode);

    compiler.reportCodeChange();
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:AliasExternals.java

示例3: mayThrowException

/**
 * Determines if the subtree might throw an exception.
 */
private static boolean mayThrowException(Node n) {
  switch (n.getType()) {
    case Token.CALL:
    case Token.GETPROP:
    case Token.GETELEM:
    case Token.THROW:
    case Token.NEW:
    case Token.ASSIGN:
    case Token.INC:
    case Token.DEC:
    case Token.INSTANCEOF:
      return true;
    case Token.FUNCTION:
      return false;
  }
  for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
    if (!ControlFlowGraph.isEnteringNewCfgNode(c) && mayThrowException(c)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:ControlFlowAnalysis.java

示例4: definitionTypeContainsFunctionType

/**
 * Determines if the type of the value of the rhs expression can
 * be a function node.
 */
private static boolean definitionTypeContainsFunctionType(Definition def) {
  Node rhs = def.getRValue();
  if (rhs == null) {
    return true;
  }

  switch (rhs.getType()) {
    case Token.ASSIGN:
    case Token.AND:
    case Token.CALL:
    case Token.GETPROP:
    case Token.GETELEM:
    case Token.FUNCTION:
    case Token.HOOK:
    case Token.NAME:
    case Token.NEW:
    case Token.OR:
      return true;
    default:
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:MarkNoSideEffectCalls.java

示例5: isSimpleOperatorType

/**
 * A "simple" operator is one whose children are expressions,
 * has no direct side-effects (unlike '+='), and has no
 * conditional aspects (unlike '||').
 */
static boolean isSimpleOperatorType(int type) {
  switch (type) {
    case Token.ADD:
    case Token.BITAND:
    case Token.BITNOT:
    case Token.BITOR:
    case Token.BITXOR:
    case Token.COMMA:
    case Token.DIV:
    case Token.EQ:
    case Token.GE:
    case Token.GETELEM:
    case Token.GETPROP:
    case Token.GT:
    case Token.INSTANCEOF:
    case Token.LE:
    case Token.LSH:
    case Token.LT:
    case Token.MOD:
    case Token.MUL:
    case Token.NE:
    case Token.NOT:
    case Token.RSH:
    case Token.SHEQ:
    case Token.SHNE:
    case Token.SUB:
    case Token.TYPEOF:
    case Token.VOID:
    case Token.POS:
    case Token.NEG:
    case Token.URSH:
      return true;

    default:
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:42,代码来源:NodeUtil.java

示例6: visit

public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.GETPROP:
    case Token.GETELEM:
      Node dest = n.getFirstChild().getNext();

      if (dest.getType() == Token.STRING) {
        if (dest.getString().equals("prototype")) {
          processPrototypeParent(t, parent);
        } else {
          // Static methods of the form Foo.bar = function() {} or
          // Static methods of the form Foo.bar = baz (where baz is a
          // function name). Parse tree looks like:
          // assign                 <- parent
          //      getprop           <- n
          //          name Foo
          //          string bar
          //      function or name  <- n.getNext()
          if (parent.getType() == Token.ASSIGN &&
              parent.getFirstChild() == n) {
            addPossibleSignature(dest.getString(), n.getNext(), t);
          }
        }
      }
      break;

    case Token.OBJECTLIT:
      // assumes the object literal is well formed
      // (has an even number of children)
      for (Node key = n.getFirstChild();
           key != null; key = key.getNext().getNext()) {
        if (key.getType() == Token.STRING) {
          Node value = key.getNext();
          addPossibleSignature(key.getString(), value, t);
        }
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:39,代码来源:MethodCompilerPass.java

示例7: addMarker

private Node addMarker(
        FunctionType funType,
        Node nodeToInsertAfter,
        @Nullable ObjectType interfaceType) {

  String className = funType.getInstanceType().getReferenceName();

  // This can happen with anonymous classes declared with the type
  // {@code Function}.
  if (className == null) {
    return nodeToInsertAfter;
  }

  Node classNode = NodeUtil.newQualifiedNameNode(className, -1, -1);

  Node marker = Node.newString(
          interfaceType == null ?
          "instance_of__" + className :
          "implements__" + interfaceType.getReferenceName());

  Node assign = new Node(Token.EXPR_RESULT, new Node(Token.ASSIGN,
      new Node(Token.GETELEM,
          new Node(Token.GETPROP,
              classNode,
              Node.newString("prototype")), marker),
      new Node(Token.TRUE)));

  nodeToInsertAfter.getParent().addChildAfter(assign, nodeToInsertAfter);
  compiler.reportCodeChange();
  nodeToInsertAfter = assign;
  return nodeToInsertAfter;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:32,代码来源:RuntimeTypeCheck.java

示例8: processPrototypeParent

/**
 * Processes the parent of a GETPROP prototype, which can either be
 * another GETPROP (in the case of Foo.prototype.bar), or can be
 * an assignment (in the case of Foo.prototype = ...).
 */
private void processPrototypeParent(NodeTraversal t, Node n) {
  switch (n.getType()) {
    // Foo.prototype.getBar = function() { ... } or
    // Foo.prototype.getBar = getBaz (where getBaz is a function)
    // parse tree looks like:
    // assign                          <- parent
    //     getprop                     <- n
    //         getprop
    //             name Foo
    //             string prototype
    //         string getBar
    //     function or name            <- assignee
    case Token.GETPROP:
    case Token.GETELEM:
      Node dest = n.getFirstChild().getNext();
      Node parent = n.getParent().getParent();

      if (dest.getType() == Token.STRING &&
          parent.getType() == Token.ASSIGN) {
        Node assignee = parent.getFirstChild().getNext();

        addPossibleSignature(dest.getString(), assignee, t);
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:31,代码来源:MethodCompilerPass.java

示例9: maybeRemoveCall

/**
 * Removes a method call if {@link #isMethodCallThatTriggersRemoval}
 * indicates that it should be removed.
 *
 * @param t The traversal
 * @param n A CALL node
 * @param parent {@code n}'s parent
 */
void maybeRemoveCall(NodeTraversal t, Node n, Node parent) {
  // CALL
  //   function
  //   arguments
  if (isMethodCallThatTriggersRemoval(t, n, parent)) {
    // Use a while loop to get up out of any nested calls. For example,
    // if we have just detected that we need to remove the a.b() call
    // in a.b().c().d(), we'll have to remove all of the calls, and it
    // will take a few iterations through this loop to get up to d().
    Node ancestor = parent;
    Node ancestorChild = n;
    int ancestorLevel = 1;
    while (true) {
      if (ancestor.getFirstChild() != ancestorChild) {
        replaceWithNull(ancestorChild, ancestor);
        break;
      }
      if (NodeUtil.isExpressionNode(ancestor)) {
        // Remove the entire expression statement.
        Node ancParent = ancestor.getParent();
        replaceWithEmpty(ancestor, ancParent);
        break;
      }
      int type = ancestor.getType();
      if (type != Token.GETPROP &&
          type != Token.GETELEM &&
          type != Token.CALL) {
        replaceWithNull(ancestorChild, ancestor);
        break;
      }
      ancestorChild = ancestor;
      ancestor = ancestor.getParent();
    }
    compiler.reportCodeChange();
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:44,代码来源:StripCode.java

示例10: isReference

/**
 * This predicate is used to determine if the node represents an expression
 * that is a Reference according to JavaScript definitions.
 *
 * @param n The node being checked.
 * @return true if the sub-tree n is a reference, false otherwise.
 */
private static boolean isReference(Node n) {
  switch (n.getType()) {
    case Token.GETELEM:
    case Token.GETPROP:
    case Token.NAME:
      return true;

    default:
      return false;
  }

}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:TypeCheck.java

示例11: visit

public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.GETPROP:
    case Token.GETELEM:
      Node dest = n.getFirstChild().getNext();
      if (dest.getType() == Token.STRING) {
        reservedNames.add(dest.getString());
      }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:10,代码来源:RenamePrototypes.java

示例12: processPrototypeParent

/**
 * Processes the parent of a GETPROP prototype, which can either be
 * another GETPROP (in the case of Foo.prototype.bar), or can be
 * an assignment (in the case of Foo.prototype = ...).
 */
private void processPrototypeParent(Node n, CompilerInput input) {
  switch (n.getType()) {
    // Foo.prototype.getBar = function() { ... }
    case Token.GETPROP:
    case Token.GETELEM:
      Node dest = n.getFirstChild().getNext();
      if (dest.getType() == Token.STRING) {
        markPrototypePropertyCandidate(dest, input);
      }
      break;

    // Foo.prototype = { "getBar" : function() { ... } }
    case Token.ASSIGN:
    case Token.CALL:
      Node map;
      if (n.getType() == Token.ASSIGN) {
        map = n.getFirstChild().getNext();
      } else {
        map = n.getLastChild();
      }
      if (map.getType() == Token.OBJECTLIT) {
        // Remember this node so that we can avoid processing it again when
        // the traversal reaches it.
        prototypeObjLits.add(map);

        // assumes the object literal is well formed
        // (has an even number of children)
        for (Node key = map.getFirstChild();
             key != null; key = key.getNext().getNext()) {
          if (key.getType() == Token.STRING) {
            markPrototypePropertyCandidate(key, input);
          }
        }
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:42,代码来源:RenamePrototypes.java

示例13: visit

public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.GETPROP:
    case Token.GETELEM:
      Node dest = n.getFirstChild().getNext();
      if (dest.getType() == Token.STRING &&
          (whitelist.isEmpty() || whitelist.contains(dest.getString()))) {
        props.put(dest.getString(), new Property(dest.getString()));
      }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:11,代码来源:AliasExternals.java

示例14: createAssignmentActions

/**
 * Returns an action for assigning the right-hand-side to the left or null
 * if this assignment should be ignored.
 */
private List<Action> createAssignmentActions(
    Node lhs, Node rhs, Node parent) {
  switch (lhs.getType()) {
    case Token.NAME:
      ConcreteSlot var = (ConcreteSlot) scope.getSlot(lhs.getString());
      Preconditions.checkState(var != null,
          "Type tightener could not find variable with name %s",
          lhs.getString());
      return Lists.<Action>newArrayList(
          new VariableAssignAction(var, rhs));

    case Token.GETPROP:
      Node receiver = lhs.getFirstChild();
      return Lists.<Action>newArrayList(
          new PropertyAssignAction(receiver, rhs));

    case Token.GETELEM:
      return Lists.newArrayList();

    case Token.GET_REF:
      // We ignore ref specials as their types should not be computed.
      if (lhs.getFirstChild().getType() == Token.REF_SPECIAL) {
        return Lists.newArrayList();
      } else {
        throw new AssertionError(
            "Bad LHS for getref: " + parent.toStringTree());
      }

    default:
      throw new AssertionError(
          "Bad LHS for assignment: " + parent.toStringTree());
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:37,代码来源:TightenTypes.java

示例15: precedence

static int precedence(int type) {
  switch (type) {
    case Token.COMMA:  return 0;
    case Token.ASSIGN_BITOR:
    case Token.ASSIGN_BITXOR:
    case Token.ASSIGN_BITAND:
    case Token.ASSIGN_LSH:
    case Token.ASSIGN_RSH:
    case Token.ASSIGN_URSH:
    case Token.ASSIGN_ADD:
    case Token.ASSIGN_SUB:
    case Token.ASSIGN_MUL:
    case Token.ASSIGN_DIV:
    case Token.ASSIGN_MOD:
    case Token.ASSIGN: return 1;
    case Token.HOOK:   return 2;  // ?: operator
    case Token.OR:     return 3;
    case Token.AND:    return 4;
    case Token.BITOR:  return 5;
    case Token.BITXOR: return 6;
    case Token.BITAND: return 7;
    case Token.EQ:
    case Token.NE:
    case Token.SHEQ:
    case Token.SHNE:   return 8;
    case Token.LT:
    case Token.GT:
    case Token.LE:
    case Token.GE:
    case Token.INSTANCEOF:
    case Token.IN:     return 9;
    case Token.LSH:
    case Token.RSH:
    case Token.URSH:   return 10;
    case Token.SUB:
    case Token.ADD:    return 11;
    case Token.MUL:
    case Token.MOD:
    case Token.DIV:    return 12;
    case Token.INC:
    case Token.DEC:
    case Token.NEW:
    case Token.DELPROP:
    case Token.TYPEOF:
    case Token.VOID:
    case Token.NOT:
    case Token.BITNOT:
    case Token.POS:
    case Token.NEG:    return 13;

    case Token.ARRAYLIT:
    case Token.CALL:
    case Token.EMPTY:
    case Token.FALSE:
    case Token.FUNCTION:
    case Token.GETELEM:
    case Token.GETPROP:
    case Token.GET_REF:
    case Token.IF:
    case Token.LP:
    case Token.NAME:
    case Token.NULL:
    case Token.NUMBER:
    case Token.OBJECTLIT:
    case Token.REGEXP:
    case Token.RETURN:
    case Token.STRING:
    case Token.THIS:
    case Token.TRUE:
      return 15;

    default: throw new Error("Unknown precedence for " +
                             Node.tokenToName(type) +
                             " (type " + type + ")");
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:76,代码来源:NodeUtil.java


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