Package org.mozilla.javascript

Examples of org.mozilla.javascript.Node$Target


   
    node = node.getFirstChild().getFirstChild();
    bodyStatement = addStatement(node, root, scope);

    node = node.getNext().getNext().getNext();
    Node childNode = node.getFirstChild();
    if (childNode != null) {
      catchScope = true;
//      catchScope = new Scope(scope);

      Node tmpNode = childNode.getFirstChild();
      scope.registerLocalIdentifier(tmpNode.getString());
//      catchScope.registerLocalIdentifier(tmpNode.getString());

      exception = addExpression(tmpNode, root, scope);
//      exception = addExpression(tmpNode, root, catchScope);

      childNode = childNode.getNext().getFirstChild().getNext().getFirstChild();

      for (tmpNode = childNode.getFirstChild(); tmpNode != null; tmpNode = tmpNode
          .getNext()) {
        if (tmpNode.getType() == Token.LEAVEWITH) {
          childNode.removeChild(tmpNode.getNext());
          childNode.removeChild(tmpNode);
        }
      }

      catchStatement = addStatement(childNode, root, scope);
View Full Code Here


   * @param scope
   *          语句子节点生存域
   */
  public LoopStatement(Node node, ScriptOrFnNode root, Scope scope) {
    super(node);
    Node childNode = node.getFirstChild();

    switch (childNode.getType()) {
    case Token.EXPR_VOID:
      tokenType = Token.FOR;
      startNode = addExpression(childNode.getFirstChild(), root, scope);
      childNode = childNode.getNext();
      break;

    case Token.VAR:
      tokenType = Token.FOR;
      startNode = addStatement(childNode, root, scope);
      childNode = childNode.getNext();
      break;
    }

    if (childNode.getType() == Token.TARGET) {
      bodyStatement = addStatement(childNode.getNext(), root, scope);
      childNode = bodyStatement.getNext().getNext();
      checkExpression = addExpression(childNode.getFirstChild(), root, scope);
      if (tokenType == 0) {
        tokenType = Token.DO;
      }
    } else if (childNode.getType() == Token.GOTO) {
      bodyStatement = addStatement(childNode.getNext().getNext(), root, scope);
      childNode = bodyStatement.getNext().getNext();

      if (childNode.getType() == Token.EXPR_VOID) {
        tokenType = Token.FOR;
        endExpression = addExpression(childNode.getFirstChild(), root, scope);
        childNode = childNode.getNext().getNext();
      }

      childNode = childNode.getNext();
      if (childNode.getType() == Token.TARGET) {
        checkExpression = addExpression(childNode.getNext().getFirstChild(),
            root, scope);
        tokenType = Token.FOR;
      } else {
        checkExpression = addExpression(childNode.getFirstChild(), root, scope);
        if (tokenType == 0) {
          tokenType = Token.WHILE;
        }
      }
    }
View Full Code Here

    case Token.GETELEM:
      return new MemberExpression(node, root, scope);

    case Token.CALL:
    case Token.NEW: {
      Node firstChild = node.getFirstChild();
      if (firstChild.getType() == Token.NAME) {
        String target = firstChild.getString();
        Node next = firstChild.getNext();
        if (target.equals("Object")) {
          // Object类不需要使用new
          node.setType(Token.CALL);
          if (next == null) {
            return new ObjectLiteral(node.getLineno());
          }
        } else if (target.equals("Array")) {
          // Array类可以使用[]代替
          node.setType(Token.CALL);
          if (next == null
              || (next.getType() == Token.NUMBER && next.getDouble() == 0)
              || next.getNext() != null) {
            if (next != null && next.getType() == Token.NUMBER
                && next.getDouble() == 0) {
              node.removeChild(next);
            }
            node.removeChild(firstChild);
            return new ArrayLiteral(node, root, scope);
          }
View Full Code Here

   * @param scope
   *          表达式子节点生存域
   */
  public ConditionalExpression(Node node, ScriptOrFnNode root, Scope scope) {
    super(node.getLineno());
    Node firstChild = node.getFirstChild();
    checkExpression = addExpression(firstChild, root, scope);
    trueExpression = addExpression(firstChild.getNext(), root, scope);
    falseExpression = addExpression(node.getLastChild(), root, scope);
  }
View Full Code Here

   * @param scope
   *          表达式子节点生存域
   */
  public MemberExpression(Node node, ScriptOrFnNode root, Scope scope) {
    super(node.getLineno());
    Node firstChild = node.getFirstChild();
    target = addExpression(firstChild, root, scope);

    node = firstChild.getNext();
    if (node.getType() == Token.STRING) {
      member = scope.addConstant(node.getString(), true);
    } else {
      memberExpression = addExpression(node, root, scope);
    }
View Full Code Here

    ScriptOrFnNode root = parser.parse(reader, null, 1);

    Environment env = new Environment(keepLineno, mode);
    GlobalScope globalScope = new GlobalScope();
    StatementList statements = new StatementList();
    Node node = root.getFirstChild();
    while (node != null) {
      IStatement statement = Utils.createStatement(node, root, globalScope);
      statements.add(statement);
      node = statement.getNext();
    }
View Full Code Here

   * @param scope
   *          表达式子节点生存域
   */
  public BinaryExpression(Node node, ScriptOrFnNode root, Scope scope) {
    super(node.getLineno());
    Node firstChild = node.getFirstChild();

    tokenType = node.getType();

    if (firstChild.getType() != Token.USE_STACK) {
      if (tokenType == Token.SETPROP || tokenType == Token.SETELEM
          || tokenType == Token.SETPROP_OP || tokenType == Token.SETELEM_OP) {
        leftExpression = new MemberExpression(node, root, scope);
        leftExpression.setParent(this);
      } else {
View Full Code Here

            Object value;
            try {
              if(!(expression.getFirstChild().getType() == Token.GETPROP && expression.getFirstChild().getFirstChild().getType() == Token.THIS))
                throw new QueryCantBeHandled("Can't handle non-direct property comparisons");
              property = expression.getFirstChild().getLastChild().getString();
              Node valueNode = expression.getLastChild();
              switch(valueNode.getType()){
                case Token.STRING:
                  value = valueNode.getString();
                  break;
                case Token.NUMBER:
                  value = valueNode.getDouble();
                  break;
                case Token.NULL:
                  value = null;
                  break;
                case Token.TRUE:
                  value = true;
                  break;
                case Token.FALSE:
                  value = false;
                  break;
                case Token.AND:
                  if(valueNode.getLastChild().getType() == Token.GETPROP && "__ids__".equals(valueNode.getLastChild().getFirstChild().getString())){
                    value = Identification.idForString(valueNode.getFirstChild().getString());
                    break;
                  }
                  throw new QueryCantBeHandled("unknown value type");
                case Token.CALL:
                  if(valueNode.getFirstChild().getType() == Token.NAME &&
                      "date".equals(valueNode.getFirstChild().getString())){
                    value = new Date((long) valueNode.getLastChild().getDouble());
                    break;
                  }
                default:
                  throw new QueryCantBeHandled("unknown value type");
              }
View Full Code Here

    newQuery.source = oldQuery.source;
    newQuery.subObjectId = oldQuery.subObjectId;
    Parser p = new Parser(compilerEnvirons, compilerEnvirons.getErrorReporter());
        ScriptOrFnNode tree;
        tree = p.parse("(" + queryStr + ")", "jsonpath-sub-expression", 0);
        Node functionBody = tree.getFunctionNode(0).getFirstChild();
        Node returnNode = functionBody.getFirstChild();
        if(returnNode.getType() != Token.RETURN){
          returnNode = returnNode.getFirstChild().getFirstChild().getFirstChild();
        }
        Node queryNode = returnNode.getFirstChild();
        replaceStrings(queryNode, returnNode, parameters);
        if(condition){
          if(oldQuery.condition == null)
            newQuery.condition = queryNode;
          else{
            Node andNode = new Node(Token.AND);
            andNode.addChildToBack(oldQuery.condition);
            andNode.addChildToBack(queryNode);
            newQuery.condition = andNode;
          }
        }
        else {
          newQuery.condition = oldQuery.condition;
View Full Code Here

        }
    return newQuery;
  }
  static void replaceStrings(Node node, Node parent, Scriptable parameters) {
    if (node.getType() == Token.CALL) {
      Node caller = node.getFirstChild();
    }
    if (node.getType() == Token.NAME && ("$obj".equals(node.getString()) || "$obj".equals(node.getString()))) {
      node.setType(Token.THIS);
    }
    if (node.getType() == Token.GETPROP && node.getFirstChild().getType() == Token.NAME &&
        "args".equals(node.getFirstChild().getString()) && node.getLastChild().getType() == Token.STRING &&
        node.getLastChild().getString().startsWith("param")) {
      Object value = parameters.get(node.getLastChild().getString(),parameters);
      if (value instanceof String) {
        parent.replaceChild(node,Node.newString((String) value));
      }
      else if (value instanceof Number) {
        parent.replaceChild(node,Node.newNumber(((Number) value).doubleValue()));
      }
      else if (value instanceof Persistable) {
        node.setType(Token.EQ);
        while(node.getFirstChild() != null)
          node.removeChild(node.getFirstChild());
        node.addChildToFront(new Node(Token.DOT,new Node(Token.THIS),new Node(Token.NAME)));
        node.addChildToFront(new Node(Token.STRING));
        node.getFirstChild().getLastChild().setString("id");
        node.getLastChild().setString(((Persistable)value).getId().subObjectId);
      }
      //TODO: Do the rest of these
    }
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.Node$Target

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.