Package org.mozilla.javascript

Examples of org.mozilla.javascript.FunctionNode


   * @return
   */
  public String getFunctionName() {
    String identifier = null;
    if (isFunction) {
      FunctionNode n = null;
      try {
        n = getAsFunctionNode();
      } catch (final WinkAstException e) {
        e.printStackTrace();
        return null;
      }
      if (n.getFunctionName() != null && n.getFunctionName() != "") {
        identifier = n.getFunctionName();
      }
      if (identifier == null) {
        final StringBuffer sb = new StringBuffer();
        sb.append(Constants.ANONYMOUS_FUNCTION_PREFIX);
        sb.append("-");
        sb.append(new File(n.getSourceName()).getName());
        sb.append("[");
        sb.append(lineStart);
        sb.append(",");
        sb.append(lineEnd);
        sb.append("]");
View Full Code Here


      final String le = (lineEnd == -1) ? "?" : new Integer(lineEnd).toString();
      sb.append(" [L:").append(ls).append(" - ").append(le).append("]");
    }

    if (isFunction) {
      FunctionNode n = null;
      try {
        n = getAsFunctionNode();
      } catch (final WinkAstException e) {
        e.printStackTrace();
      }
      sb.append(" [").append(Ast.functionTypeName(n.getFunctionType())).append("]");
    }

    return sb.toString();
  }
View Full Code Here

   *          表达式子节点生存域
   */
  public FunctionLiteral(Node node, ScriptOrFnNode root, Scope scope) {
    super(root.getFunctionNode(node.getIntProp(Node.FUNCTION_PROP, -1))
        .getLineno());
    FunctionNode fnNode = root.getFunctionNode(node.getIntProp(
        Node.FUNCTION_PROP, -1));
    fnScope = new Scope(scope);

    if (fnNode.getFunctionName().length() > 0) {
      name = scope.addIdentifier(fnNode.getFunctionName());
    }

    node = fnNode.getFirstChild().getFirstChild();
    if (node.getType() == Token.EXPR_VOID) {
      Node firstChild = node.getFirstChild();
      if (firstChild.getType() == Token.SETNAME
          && firstChild.getLastChild().getType() == Token.THISFN) {
        node = node.getNext();
      }
    }
    while (node != null) {
      IStatement statement = Utils.createStatement(node, fnNode, fnScope);
      statements.add(statement);
      node = statement.getNext();
    }

    int size = statements.size() - 1;
    if (statements.size() >= 0) {
      IStatement statement = statements.get(size);
      if (statement instanceof ControlStatement
          && ((ControlStatement) statement).getType() == Token.RETURN) {
        statements.remove(size);
      }
    }

    new NodeTransformer().transform(fnNode);
    String[] symbols = fnNode.getParamAndVarNames();
    for (int i = 0; i < symbols.length; i++) {
      String symbol = symbols[i];
      fnScope.registerLocalIdentifier(symbol);
      if (i < fnNode.getParamCount()) {
        Identifier identifier = fnScope.addIdentifier(symbol);
        identifier.inc((fnNode.getParamCount() - i) * 10000000);
        params.add(identifier);
      }
    }
  }
View Full Code Here

   * @param sofn - Script or function node
   */
  protected void searchFunctionDefsForNodes(ScriptOrFnNode sofn) {
    int count = sofn.getFunctionCount() - 1;
    while (count > -1) {
      FunctionNode fn = sofn.getFunctionNode(count);
      searchAstForNodes(fn);
      count--;
    }
  }
View Full Code Here

    // Parse inner tokens for function definitions here.
    if (node instanceof ScriptOrFnNode) {
      ScriptOrFnNode sofn = (ScriptOrFnNode) node;
      int count = sofn.getFunctionCount() - 1;
      while (count > -1) {
        FunctionNode fn = sofn.getFunctionNode(count);
        recursiveParse(fn);
        count--;
      }
    }
   
View Full Code Here

    ScriptOrFnNode nodeTree = p.parse();
    for (Node cursor = nodeTree.getFirstChild(); cursor != null; cursor = cursor.getNext()) {
      StringBuffer sb = new StringBuffer();
      if (cursor.getType() == Token.FUNCTION) {
        int fnIndex = cursor.getExistingIntProp(Node.FUNCTION_PROP);
        FunctionNode fn = nodeTree.getFunctionNode(fnIndex);
        Iterator<String> iter = null;
        StringBuffer sbParam = new StringBuffer();
        if (fn.getSymbolTable() != null) {
          iter = fn.getSymbolTable().keySet().iterator();
          while (iter.hasNext()) {
            sbParam.append(iter.next());
            sbParam.append(" ");
          }
        }
        sb.append("FUNCTION: " + fn.getFunctionName() + " [ " + sbParam + "]");
      } else if (cursor.getType() == Token.VAR) {
        Node vn = cursor.getFirstChild();
        sb.append("VAR: " + vn.getString());

      }
View Full Code Here

        e.printStackTrace();
      }
      for (Node cursor = nodeTree.getFirstChild(); cursor != null; cursor = cursor.getNext()) {
        if (cursor.getType() == Token.FUNCTION) {
          int fnIndex = cursor.getExistingIntProp(Node.FUNCTION_PROP);
          FunctionNode fn = nodeTree.getFunctionNode(fnIndex);
          Iterator<String> iter = null;
          StringBuffer sbParam = new StringBuffer();
          if (fn.getSymbolTable() != null) {
            iter = fn.getSymbolTable().keySet().iterator();
            while (iter.hasNext()) {
              sbParam.append(iter.next());
              sbParam.append(" ");
            }
          }
          details.append("FUNCTION: " + fn.getFunctionName() + " [ " + sbParam + "]\n");
        } else if (cursor.getType() == Token.VAR) {
          Node vn = cursor.getFirstChild();
          details.append("VAR: " + vn.getString() + "\n");
        }
      }
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.FunctionNode

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.