Java 类org.mozilla.javascript.Node 实例源码

项目:openbravo-brazil    文件:JavaScriptAPIChecker.java   
/**
 * Checks the parsed file against the API Map.
 * 
 * @param p
 *          an instance of {@link JavaScriptParser} to get the tree representation of it
 * @param jsFileName
 *          the JavaScript file name that is being checked
 * @throws IOException
 */
private void checkJS(JavaScriptParser p, String jsFileName) throws IOException {
  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);
      sb.append("FUNCTION: " + fn.getFunctionName());
    } else if (cursor.getType() == Token.VAR) {
      Node vn = cursor.getFirstChild();
      sb.append("VAR: " + vn.getString());

    }
    apiMap.remove(jsFileName + sb);
  }
}
项目:openbravo-brazil    文件:JavaScriptParser.java   
/**
 * @return a string with the global variables and function definitions
 */
public String getStringDetails() {
  if (jsFile == null) {
    throw new RuntimeException("You need to specify the file to parse");
  }
  if (details == null) {
    details = new StringBuffer();
    try {
      parse();
    } catch (IOException e) {
      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);
        details.append("FUNCTION: " + fn.getFunctionName() + "\n");
      } else if (cursor.getType() == Token.VAR) {
        Node vn = cursor.getFirstChild();
        details.append("VAR: " + vn.getString() + "\n");
      }
    }
  }
  return details.toString();
}
项目:birt    文件:OlapExpressionCompiler.java   
/**
 * 
 * @param expr
 * @param objectName
 * @return
 */
public static String getReferencedScriptObject( String expr,
        String objectName )
{
    if ( expr == null )
        return null;
    try
    {
        Context cx = Context.enter( );
        CompilerEnvirons ce = new CompilerEnvirons( );
        Parser p = new Parser( ce, cx.getErrorReporter( ) );
        AstRoot tree = p.parse( expr, null, 0 );
        Node root = new IRFactory( ce).transformTree(tree);

        return getScriptObjectName( root, objectName );
    }
    catch( Exception ex )
    {
        return null;
    }
    finally
    {
        Context.exit( );
    }
}
项目:birt    文件:ExpressionParserUtility.java   
/**
 * extract arguments from aggregation expression
 * 
 * @param context
 * @param callNode
 * @throws BirtException
 */
private void extractArguments( Node callNode, ScriptNode tree,
        List columnExprList ) throws BirtException
{
    Node arg = callNode.getFirstChild( ).getNext( );

    while ( arg != null )
    {
        // need to hold on to the next argument because the tree extraction
        // will cause us to lose the reference otherwise
        Node nextArg = arg.getNext( );
        processChild( arg, tree, columnExprList );

        arg = nextArg;
    }
}
项目:birt    文件:ExpressionParserUtility.java   
/**
 * compile outer column expression
 * @param refNode
 * @param tree
 * @param columnExprList
 * @throws BirtException
 */
private void compileOuterColRef( Node refNode, ScriptNode tree,
        List columnExprList ) throws BirtException
{
    int level = compileOuterColRefExpr( refNode );
    if ( level == -1 )
    {
        compileComplexExpr( refNode, tree, columnExprList );
    }
    else
    {
        Node nextNode = refNode.getLastChild( );
        if ( nextNode.getType( ) == Token.STRING )
        {
            ColumnBinding info = new ColumnBinding( nextNode.getString( ),
                    "",
                    level );
            columnExprList.add( info );
        }
    }
    return;
}
项目:birt    文件:OlapExpressionCompiler.java   
/**
 * 
 * @param n
 * @param objectName
 * @return
 */
private static void getScriptObjectName( Node n, String objectName, Set nameSet )
{
    if ( n == null )
        return;
    String result = null;
    if ( n.getType( ) == Token.NAME )
    {
        if ( objectName.equals( n.getString( ) ) )
        {
            Node dimNameNode = n.getNext( );
            if ( dimNameNode == null
                    || dimNameNode.getType( ) != Token.STRING )
                return;

            nameSet.add( dimNameNode.getString( ) );
        }
    }

    getScriptObjectName( n.getFirstChild( ), objectName, nameSet );
    getScriptObjectName( n.getNext( ), objectName, nameSet );
    getScriptObjectName( n.getLastChild( ), objectName, nameSet );
}
项目:birt    文件:ExpressionCompiler.java   
protected AggregateExpression compileAggregateExpr( Context context, Node parent, Node callNode ) throws DataException
{
    assert( callNode.getType() == Token.CALL );

    IAggrFunction aggregation = getAggregationFunction( callNode );
    // not an aggregation function being called, then it's considered 
    // a complex expression
    if( aggregation == null )
        return null;

    AggregateExpression aggregateExpression = 
        new AggregateExpression( aggregation );

    extractArguments( context, aggregateExpression, callNode );
    replaceAggregateNode( aggregateExpression, parent, callNode );

    return aggregateExpression;
}
项目:birt    文件:CubeQueryUtil.java   
/**
 * 
 * @param n
 * @param objectName
 * @return
 */
private static String getScriptObjectName( Node n, String objectName )
{
    if ( n == null )
        return null;
    String result = null;
    if ( n.getType( ) == Token.NAME )
    {
        if ( objectName.equals( n.getString( ) ) )
        {
            Node dimNameNode = n.getNext( );
            if ( dimNameNode == null
                    || dimNameNode.getType( ) != Token.STRING )
                return null;

            return dimNameNode.getString( );
        }
    }

    result = getScriptObjectName( n.getFirstChild( ), objectName );
    if ( result == null )
        result = getScriptObjectName( n.getLastChild( ), objectName );

    return result;
}
项目:HL4A    文件:Scope.java   
/**
 * Returns a copy of the child list, with each child cast to an
 * {@link AstNode}.
 * @throws ClassCastException if any non-{@code AstNode} objects are
 * in the child list, e.g. if this method is called after the code
 * generator begins the tree transformation.
 */
public List<AstNode> getStatements() {
    List<AstNode> stmts = new ArrayList<AstNode>();
    Node n = getFirstChild();
    while (n != null) {
        stmts.add((AstNode)n);
        n = n.getNext();
    }
    return stmts;
}
项目:HL4A    文件:Scope.java   
@Override
public String toSource(int depth) {
    StringBuilder sb = new StringBuilder();
    sb.append(makeIndent(depth));
    sb.append("{\n");
    for (Node kid : this) {
        sb.append(((AstNode)kid).toSource(depth+1));
    }
    sb.append(makeIndent(depth));
    sb.append("}\n");
    return sb.toString();
}
项目:HL4A    文件:Scope.java   
@Override
public void visit(NodeVisitor v) {
    if (v.visit(this)) {
        for (Node kid : this) {
            ((AstNode)kid).visit(v);
        }
    }
}
项目:HL4A    文件:FunctionNode.java   
/**
 * Sets function body, and sets its parent to this node.
 * Also sets the encoded source bounds based on the body bounds.
 * Assumes the function node absolute position has already been set,
 * and the body node's absolute position and length are set.<p>
 *
 * @param body function body.  Its parent is set to this node, and its
 * position is updated to be relative to this node.
 *
 * @throws IllegalArgumentException if body is {@code null}
 */
public void setBody(AstNode body) {
    assertNotNull(body);
    this.body = body;
    if (Boolean.TRUE.equals(body.getProp(Node.EXPRESSION_CLOSURE_PROP))) {
        setIsExpressionClosure(true);
    }
    int absEnd = body.getPosition() + body.getLength();
    body.setParent(this);
    this.setLength(absEnd - this.position);
    setEncodedSourceBounds(this.position, absEnd);
}
项目:HL4A    文件:Block.java   
@Override
public String toSource(int depth) {
    StringBuilder sb = new StringBuilder();
    sb.append(makeIndent(depth));
    sb.append("{\n");
    for (Node kid : this) {
        sb.append(((AstNode)kid).toSource(depth+1));
    }
    sb.append(makeIndent(depth));
    sb.append("}\n");
    return sb.toString();
}
项目:HL4A    文件:Block.java   
@Override
public void visit(NodeVisitor v) {
    if (v.visit(this)) {
        for (Node kid : this) {
            ((AstNode)kid).visit(v);
        }
    }
}
项目:HL4A    文件:ScriptNode.java   
public int getIndexForNameNode(Node nameNode) {
    if (variableNames == null) codeBug();
    Scope node = nameNode.getScope();
    Symbol symbol = node == null
        ? null
        : node.getSymbol(((Name)nameNode).getIdentifier());
    return (symbol == null) ? -1 : symbol.getIndex();
}
项目:HL4A    文件:ScriptNode.java   
@Override
public void visit(NodeVisitor v) {
    if (v.visit(this)) {
        for (Node kid : this) {
            ((AstNode)kid).visit(v);
        }
    }
}
项目:HL4A    文件:Jump.java   
public void setDefault(Node defaultTarget)
{
    if (type != Token.SWITCH) codeBug();
    if (defaultTarget.getType() != Token.TARGET) codeBug();
    if (target2 != null) codeBug(); //only once
    target2 = defaultTarget;
}
项目:HL4A    文件:Jump.java   
public void setFinally(Node finallyTarget)
{
    if (type != Token.TRY) codeBug();
    if (finallyTarget.getType() != Token.TARGET) codeBug();
    if (target2 != null) codeBug(); //only once
    target2 = finallyTarget;
}
项目:HL4A    文件:Jump.java   
public void setContinue(Node continueTarget)
{
    if (type != Token.LOOP) codeBug();
    if (continueTarget.getType() != Token.TARGET) codeBug();
    if (target2 != null) codeBug(); //only once
    target2 = continueTarget;
}
项目:HL4A    文件:AstRoot.java   
@Override
public String toSource(int depth) {
    StringBuilder sb = new StringBuilder();
    for (Node node : this) {
        sb.append(((AstNode)node).toSource(depth));
    }
    return sb.toString();
}
项目:whackpad    文件:Scope.java   
/**
 * Returns a copy of the child list, with each child cast to an
 * {@link AstNode}.
 * @throws ClassCastException if any non-{@code AstNode} objects are
 * in the child list, e.g. if this method is called after the code
 * generator begins the tree transformation.
 */
public List<AstNode> getStatements() {
    List<AstNode> stmts = new ArrayList<AstNode>();
    Node n = getFirstChild();
    while (n != null) {
        stmts.add((AstNode)n);
        n = n.getNext();
    }
    return stmts;
}
项目:whackpad    文件:Scope.java   
@Override
public String toSource(int depth) {
    StringBuilder sb = new StringBuilder();
    sb.append(makeIndent(depth));
    sb.append("{\n");
    for (Node kid : this) {
        sb.append(((AstNode)kid).toSource(depth+1));
    }
    sb.append(makeIndent(depth));
    sb.append("}\n");
    return sb.toString();
}
项目:whackpad    文件:Scope.java   
@Override
public void visit(NodeVisitor v) {
    if (v.visit(this)) {
        for (Node kid : this) {
            ((AstNode)kid).visit(v);
        }
    }
}
项目:whackpad    文件:FunctionNode.java   
/**
 * Sets function body, and sets its parent to this node.
 * Also sets the encoded source bounds based on the body bounds.
 * Assumes the function node absolute position has already been set,
 * and the body node's absolute position and length are set.<p>
 *
 * @param body function body.  Its parent is set to this node, and its
 * position is updated to be relative to this node.
 *
 * @throws IllegalArgumentException if body is {@code null}
 */
public void setBody(AstNode body) {
    assertNotNull(body);
    this.body = body;
    if (Boolean.TRUE.equals(body.getProp(Node.EXPRESSION_CLOSURE_PROP))) {
        setIsExpressionClosure(true);
    }
    int absEnd = body.getPosition() + body.getLength();
    body.setParent(this);
    this.setLength(absEnd - this.position);
    setEncodedSourceBounds(this.position, absEnd);
}
项目:whackpad    文件:Block.java   
@Override
public String toSource(int depth) {
    StringBuilder sb = new StringBuilder();
    sb.append(makeIndent(depth));
    sb.append("{\n");
    for (Node kid : this) {
        sb.append(((AstNode)kid).toSource(depth+1));
    }
    sb.append(makeIndent(depth));
    sb.append("}\n");
    return sb.toString();
}
项目:whackpad    文件:Block.java   
@Override
public void visit(NodeVisitor v) {
    if (v.visit(this)) {
        for (Node kid : this) {
            ((AstNode)kid).visit(v);
        }
    }
}
项目:whackpad    文件:ScriptNode.java   
public int getIndexForNameNode(Node nameNode) {
    if (variableNames == null) codeBug();
    Scope node = nameNode.getScope();
    Symbol symbol = node == null
        ? null
        : node.getSymbol(((Name)nameNode).getIdentifier());
    return (symbol == null) ? -1 : symbol.getIndex();
}
项目:whackpad    文件:ScriptNode.java   
@Override
public void visit(NodeVisitor v) {
    if (v.visit(this)) {
        for (Node kid : this) {
            ((AstNode)kid).visit(v);
        }
    }
}
项目:whackpad    文件:Jump.java   
public void setDefault(Node defaultTarget)
{
    if (type != Token.SWITCH) codeBug();
    if (defaultTarget.getType() != Token.TARGET) codeBug();
    if (target2 != null) codeBug(); //only once
    target2 = defaultTarget;
}
项目:whackpad    文件:Jump.java   
public void setFinally(Node finallyTarget)
{
    if (type != Token.TRY) codeBug();
    if (finallyTarget.getType() != Token.TARGET) codeBug();
    if (target2 != null) codeBug(); //only once
    target2 = finallyTarget;
}
项目:whackpad    文件:Jump.java   
public void setContinue(Node continueTarget)
{
    if (type != Token.LOOP) codeBug();
    if (continueTarget.getType() != Token.TARGET) codeBug();
    if (target2 != null) codeBug(); //only once
    target2 = continueTarget;
}
项目:whackpad    文件:AstRoot.java   
@Override
public String toSource(int depth) {
    StringBuilder sb = new StringBuilder();
    for (Node node : this) {
        sb.append(((AstNode)node).toSource(depth));
    }
    return sb.toString();
}
项目:TaleCraft    文件:Scope.java   
/**
 * Returns a copy of the child list, with each child cast to an
 * {@link AstNode}.
 * @throws ClassCastException if any non-{@code AstNode} objects are
 * in the child list, e.g. if this method is called after the code
 * generator begins the tree transformation.
 */
public List<AstNode> getStatements() {
    List<AstNode> stmts = new ArrayList<AstNode>();
    Node n = getFirstChild();
    while (n != null) {
        stmts.add((AstNode)n);
        n = n.getNext();
    }
    return stmts;
}
项目:TaleCraft    文件:Scope.java   
@Override
public String toSource(int depth) {
    StringBuilder sb = new StringBuilder();
    sb.append(makeIndent(depth));
    sb.append("{\n");
    for (Node kid : this) {
        sb.append(((AstNode)kid).toSource(depth+1));
    }
    sb.append(makeIndent(depth));
    sb.append("}\n");
    return sb.toString();
}
项目:TaleCraft    文件:Scope.java   
@Override
public void visit(NodeVisitor v) {
    if (v.visit(this)) {
        for (Node kid : this) {
            ((AstNode)kid).visit(v);
        }
    }
}
项目:TaleCraft    文件:FunctionNode.java   
/**
 * Sets function body, and sets its parent to this node.
 * Also sets the encoded source bounds based on the body bounds.
 * Assumes the function node absolute position has already been set,
 * and the body node's absolute position and length are set.<p>
 *
 * @param body function body.  Its parent is set to this node, and its
 * position is updated to be relative to this node.
 *
 * @throws IllegalArgumentException if body is {@code null}
 */
public void setBody(AstNode body) {
    assertNotNull(body);
    this.body = body;
    if (Boolean.TRUE.equals(body.getProp(Node.EXPRESSION_CLOSURE_PROP))) {
        setIsExpressionClosure(true);
    }
    int absEnd = body.getPosition() + body.getLength();
    body.setParent(this);
    this.setLength(absEnd - this.position);
    setEncodedSourceBounds(this.position, absEnd);
}
项目:TaleCraft    文件:Block.java   
@Override
public String toSource(int depth) {
    StringBuilder sb = new StringBuilder();
    sb.append(makeIndent(depth));
    sb.append("{\n");
    for (Node kid : this) {
        sb.append(((AstNode)kid).toSource(depth+1));
    }
    sb.append(makeIndent(depth));
    sb.append("}\n");
    return sb.toString();
}
项目:TaleCraft    文件:Block.java   
@Override
public void visit(NodeVisitor v) {
    if (v.visit(this)) {
        for (Node kid : this) {
            ((AstNode)kid).visit(v);
        }
    }
}
项目:TaleCraft    文件:ScriptNode.java   
public int getIndexForNameNode(Node nameNode) {
    if (variableNames == null) codeBug();
    Scope node = nameNode.getScope();
    Symbol symbol = node == null
        ? null
        : node.getSymbol(((Name)nameNode).getIdentifier());
    return (symbol == null) ? -1 : symbol.getIndex();
}
项目:TaleCraft    文件:ScriptNode.java   
@Override
public void visit(NodeVisitor v) {
    if (v.visit(this)) {
        for (Node kid : this) {
            ((AstNode)kid).visit(v);
        }
    }
}