Java Code Examples for org.mozilla.javascript.Node#getNext()

The following examples show how to use org.mozilla.javascript.Node#getNext() . 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: CubeQueryUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 
 * @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;
}
 
Example 2
Source File: ExpressionParserUtility.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
	}
}
 
Example 3
Source File: OlapExpressionCompiler.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 
 * @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 );
}
 
Example 4
Source File: Scope.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: Scope.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source File: OlapExpressionCompiler.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 
 * @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 );
	
	if ( result == null )
		result = getScriptObjectName( n.getNext(), objectName );

	return result;
}
 
Example 7
Source File: ExpressionCompiler.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param context
 * @param aggregateExpression
 * @param callNode
 * @throws DataException
 */
private void extractArguments( Context context,
		AggregateExpression aggregateExpression, Node callNode )
		throws DataException
{
	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();
		
		CompiledExpression expr = processChild( context,
				false,
				callNode,
				arg,
				null );
		if( ! ( expr instanceof BytecodeExpression ) )
		{
			aggregateExpression.addArgument( expr );
			arg = nextArg;
			continue;
		}
		
		AstRoot tree = new AstRoot( Token.SCRIPT );
		Node exprNode = new Node( Token.EXPR_RESULT);
		exprNode.addChildToFront( arg );
		tree.addChildrenToFront( exprNode );
		compileForBytecodeExpr( context, tree, expr );
		aggregateExpression.addArgument( expr );
		
		arg = nextArg;
	}
}
 
Example 8
Source File: MultiPassExpressionCompiler.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * parse the aggregate expression's arguments
 * 
 * @param context
 * @param aggregateExpression
 * @param callNode
 * @throws DataException
 */
private void extractArguments( Context context,
		AggregateExpression aggregateExpression, Node callNode )
		throws DataException
{
	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( );
		CompiledExpression expr = processChild( context,
				true,
				callNode,
				arg,
				null );
		if ( !( expr instanceof BytecodeExpression ) )
		{
			aggregateExpression.addArgument( expr );
			arg = nextArg;
			continue;
		}

		AstRoot tree = new AstRoot( Token.SCRIPT );
		Node exprNode = new Node( Token.EXPR_RESULT );
		exprNode.addChildToFront( arg );
		tree.addChildrenToFront( exprNode );
		if ( expr instanceof AggregateExpression )
		{
			int registry = getRegisterId( new AggregateObject( (AggregateExpression) expr ) );
			if ( registry >= 0 )
				replaceAggregateNode( registry, exprNode, arg );
		}
		
		compileForBytecodeExpr( context, tree, expr );
		aggregateExpression.addArgument( expr );
		arg = nextArg;
	}
}
 
Example 9
Source File: ExpressionUtility.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * if the Node is row Node, return true
 * 
 * @param refNode
 * @return
 */
private static boolean getDirectColRefExpr( Node refNode, boolean mode )
{
	assert ( refNode.getType( ) == Token.GETPROP || refNode.getType( ) == Token.GETELEM );

	Node rowName = refNode.getFirstChild( );
	assert ( rowName != null );
	if ( rowName.getType( ) != Token.NAME )
		return false;

	String str = rowName.getString( );
	assert ( str != null );
	if ( mode && !str.equals( STRING_ROW ) )
		return false;
	else if ( !mode && !str.equals( STRING_DATASET_ROW ) )
		return false;

	Node rowColumn = rowName.getNext( );
	assert ( rowColumn != null );

	if ( refNode.getType( ) == Token.GETPROP
			&& rowColumn.getType( ) == Token.STRING )
	{
		return true;
	}
	else if ( refNode.getType( ) == Token.GETELEM )
	{
		if ( rowColumn.getType( ) == Token.NUMBER
				|| rowColumn.getType( ) == Token.STRING )
			return true;
	}

	return false;
}
 
Example 10
Source File: ExpressionUtility.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * if the Node is row Node, return true
 * 
 * @param refNode
 * @return
 */
private static boolean getDirectColRefExpr( Node refNode, boolean mode )
{
	assert ( refNode.getType( ) == Token.GETPROP || refNode.getType( ) == Token.GETELEM );

	Node rowName = refNode.getFirstChild( );
	assert ( rowName != null );
	if ( rowName.getType( ) != Token.NAME )
		return false;

	String str = rowName.getString( );
	assert ( str != null );
	if ( mode && !str.equals( STRING_ROW ) )
		return false;
	else if ( !mode && !str.equals( STRING_DATASET_ROW ) )
		return false;

	Node rowColumn = rowName.getNext( );
	assert ( rowColumn != null );

	if ( refNode.getType( ) == Token.GETPROP
			&& rowColumn.getType( ) == Token.STRING )
	{
		return true;
	}
	else if ( refNode.getType( ) == Token.GETELEM )
	{
		if ( rowColumn.getType( ) == Token.NUMBER
				|| rowColumn.getType( ) == Token.STRING )
			return true;
	}

	return false;
}
 
Example 11
Source File: ExpressionUtility.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * if the Node is row Node, return true
 * 
 * @param refNode
 * @return
 */
private static boolean getDirectColRefExpr( Node refNode )
{
	assert ( refNode.getType( ) == Token.GETPROP || refNode.getType( ) == Token.GETELEM );

	Node rowName = refNode.getFirstChild( );
	assert ( rowName != null );
	if ( rowName.getType( ) != Token.NAME )
		return false;

	String str = rowName.getString( );
	assert ( str != null );
	if ( !str.equals( STRING_ROW ) )
		return false;

	Node rowColumn = rowName.getNext( );
	assert ( rowColumn != null );

	if ( refNode.getType( ) == Token.GETPROP
			&& rowColumn.getType( ) == Token.STRING )
	{
		return true;
	}
	else if ( refNode.getType( ) == Token.GETELEM )
	{
		if ( rowColumn.getType( ) == Token.NUMBER
				|| rowColumn.getType( ) == Token.STRING )
			return true;
	}

	return false;
}
 
Example 12
Source File: ExpressionParserUtility.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * compile row position expression
 * @param refNode
 * @param tree
 * @param columnExprList
 * @throws BirtException
 */
private void compileRowPositionRef( Node refNode, ScriptNode tree,
		List columnExprList ) throws BirtException
{
	Node rowFirstNode = refNode.getFirstChild( );

	if ( rowFirstNode.getType( ) == Token.GETELEM
			|| rowFirstNode.getType( ) == Token.SETELEM )
	{
		Node rowNode = rowFirstNode.getFirstChild( );
		if ( rowNode != null
				&& rowNode.getType( ) == Token.NAME
				&& rowNode.getString( ).equals( ROWS_0_INDICATOR ) )
		{
			Node rowColumn = rowNode.getNext( );
			if ( rowColumn.getDouble( ) == 0.0 )
			{
				rowColumn = rowFirstNode.getNext( );
				if ( rowColumn.getType( ) == Token.STRING
						&& ( refNode.getType( ) == Token.GETELEM || refNode.getType( ) == Token.SETELEM ) )
				{
					ColumnBinding binding = new ColumnBinding( rowColumn.getString( ),
							ExpressionUtil.createJSDataSetRowExpression( rowColumn.getString( ) ),
							1 );
					columnExprList.add( binding );;
				}
			}
		}
	}
}
 
Example 13
Source File: ExpressionParserUtility.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * compile the complex expression
 * 
 * @param complexNode
 * @throws BirtException
 */
private void compileComplexExpr( Node complexNode, ScriptNode tree,
		List columnExprList ) throws BirtException
{
	Node child = complexNode.getFirstChild( );
	while ( child != null )
	{
		if ( child.getType( ) == Token.FUNCTION )
		{
			int index = getFunctionIndex( child.getString( ), tree );
			compileFunctionNode( tree.getFunctionNode( index ),
					tree,
					columnExprList );
		}
		// keep reference to next child, since subsequent steps could
		// lose
		// the reference to it
		Node nextChild = child.getNext( );

		// do not include constants into the sub-expression list
		if ( child.getType( ) == Token.NUMBER
				|| child.getType( ) == Token.STRING
				|| child.getType( ) == Token.TRUE
				|| child.getType( ) == Token.FALSE
				|| child.getType( ) == Token.NULL )
		{
			processChild( child, tree, columnExprList );
			child = nextChild;
			continue;
		}

		processChild( child, tree, columnExprList );
		child = nextChild;
	}
}
 
Example 14
Source File: ExpressionCompiler.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected CompiledExpression compileDirectColRefExpr( Node parent, Node refNode,
		Node grandFather, boolean customerChecked, Context context )
		throws DataException
{
	// if it's a GETPROP or GETELEM with row on the left side,
	// and either a STRING or NUMBER on the right side, then it's
	// a direct column reference
	assert ( refNode.getType( ) == Token.GETPROP || refNode.getType( ) == Token.GETELEM );

	Node rowName = refNode.getFirstChild( );
	assert ( rowName != null );
	if ( rowName.getType( ) != Token.NAME )
		return null;

	String str = rowName.getString( );
	assert ( str != null );
	if ( !str.equals( rowIndicator ) )
		return null;

	Node rowColumn = rowName.getNext( );
	assert ( rowColumn != null );

	if ( refNode.getType( ) == Token.GETPROP
			&& rowColumn.getType( ) == Token.STRING )
	{
		if ( ScriptConstants.OUTER_RESULT_KEYWORD.equals( rowColumn.getString( ) )
				|| ScriptConstants.ROW_NUM_KEYWORD.equals( rowColumn.getString( ) )
				|| "0".equals( rowColumn.getString( ) ) )
			return null;

		return new ColumnReferenceExpression( getDataSetMode( )
				? STRING_ROW : STRING_DATASETROW, rowColumn.getString( ) );
	}
	if ( refNode.getType( ) == Token.GETELEM )
	{
		if ( rowColumn.getType( ) == Token.NUMBER )
		{
			if ( 0 == rowColumn.getDouble( ) )
				return null;
			return new ColumnReferenceExpression( getDataSetMode( )
					? STRING_ROW : STRING_DATASETROW,
					(int) rowColumn.getDouble( ) );
		}
		else if ( rowColumn.getType( ) == Token.STRING )
		{
			if ( "_rownum".equals( rowColumn.getString( ) ) )
				return null;
			return new ColumnReferenceExpression( getDataSetMode( )
					? STRING_ROW : STRING_DATASETROW, rowColumn.getString( ) );
		}
	}

	// right side is not a STRING or a NUMBER, which is what is needed for
	// a direct column reference. so it could be something
	// like row[getColumnIndex()] and that would be a complex expression
	return null;
}
 
Example 15
Source File: AbstractExpressionCompiler.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Check if the expression is a direct column reference type. If so, returns
 * an instance of DirectColRefExpr that represents it; otherwise returns
 * null.
 * 
 * @param refNode
 * @param customerChecked
 * @return
 * @throws DataException
 */
protected ColumnReferenceExpression compileColRefExpr( Node refNode,
		boolean customerChecked ) throws DataException
{
	// if it's a GETPROP or GETELEM with row on the left side,
	// and either a STRING or NUMBER on the right side, then it's
	// a direct column reference
	assert ( refNode.getType( ) == Token.GETPROP || refNode.getType( ) == Token.GETELEM );

	Node rowName = refNode.getFirstChild( );
	assert ( rowName != null );
	if ( rowName.getType( ) != Token.NAME )
		return null;

	String str = rowName.getString( );
	assert ( str != null );
	if ( !str.equals( rowIndicator ) )
		return null;

	Node rowColumn = rowName.getNext( );
	assert ( rowColumn != null );

	if ( refNode.getType( ) == Token.GETPROP
			&& rowColumn.getType( ) == Token.STRING )
	{
		return new ColumnReferenceExpression(
				this.isDataSetMode ? STRING_ROW : STRING_DATASETROW,
				rowColumn.getString());
	}
	if ( refNode.getType( ) == Token.GETELEM )
	{
		if ( rowColumn.getType( ) == Token.NUMBER )
		{
			return new ColumnReferenceExpression(
					this.isDataSetMode ? STRING_ROW : STRING_DATASETROW,
					(int) rowColumn.getDouble());
		}
		else if ( rowColumn.getType( ) == Token.STRING )
		{
			return new ColumnReferenceExpression(
					this.isDataSetMode ? STRING_ROW : STRING_DATASETROW,
					rowColumn.getString());
		}
	}
	// right side is not a STRING or a NUMBER, which is what is needed for
	// a direct column reference. so it could be something
	// like row[getColumnIndex()] and that would be a complex expression
	return null;
}
 
Example 16
Source File: ExpressionParserUtility.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 
 * @param refNode
 * @return
 */
private int compileOuterColRefExpr( Node refNode )
{
	int count = 0;
	Node rowFirstNode = refNode.getFirstChild( );
	if ( refNode.getType( ) == Token.GETPROP
			|| refNode.getType( ) == Token.GETELEM
			|| refNode.getType( ) == Token.SETPROP
			|| refNode.getType( ) == Token.SETELEM )
	{
		if ( rowFirstNode.getType( ) == Token.NAME
				&& rowFirstNode.getString( ).equals( ROW_INDICATOR ) )
		{
			Node rowColumn = rowFirstNode.getNext( );
			if ( rowColumn.getType( ) == Token.STRING )
			{
				if ( "_outer".equals( rowColumn.getString( ) ) )
					count++;
			}
			return count;
		}
		else if ( rowFirstNode.getType( ) == Token.GETPROP
				|| rowFirstNode.getType( ) == Token.SETPROP )
		{
			if ( compileOuterColRefExpr( rowFirstNode ) == -1 )
				return -1;
			else
				count = count + compileOuterColRefExpr( rowFirstNode );
			Node nextChild = rowFirstNode.getNext( );
			if ( nextChild.getType( ) == Token.STRING )
			{
				if ( "_outer".equals( nextChild.getString( ) ) )
					count++;
			}
		}
		else
			return -1;
		return count;
	}
	else
		return -1;
}