Java Code Examples for org.mozilla.javascript.Node#getDouble()
The following examples show how to use
org.mozilla.javascript.Node#getDouble() .
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: ExpressionParserUtility.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * 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 2
Source File: ExpressionCompiler.java From birt with Eclipse Public License 1.0 | 4 votes |
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 3
Source File: AbstractExpressionCompiler.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * * returns the compiled expression from processing a child node * * @param context * @param customerChecked * @param parent * @param child * @return * @throws DataException */ protected CompiledExpression processChild( Context context, boolean customerChecked, Node parent, Node child, Node grandFather ) throws DataException { CompiledExpression compiledExpr = null; switch ( child.getType( ) ) { case Token.NUMBER : compiledExpr = new ConstantExpression( child.getDouble( ) ); break; case Token.STRING : compiledExpr = new ConstantExpression( child.getString( ) ); break; case Token.NULL : compiledExpr = new ConstantExpression( ); break; case Token.TRUE : compiledExpr = new ConstantExpression( true ); break; case Token.FALSE : compiledExpr = new ConstantExpression( false ); break; case Token.GETPROP : { ConstantExpression ce = AggregationConstantsUtil.getConstantExpression( child ); if ( ce != null ) { compiledExpr = ce; break; } } case Token.GETELEM : compiledExpr = compileDirectColRefExpr( parent, child, grandFather, customerChecked, context ); break; case Token.CALL : { compiledExpr = compileAggregateExpr( context, parent, child ); break; } } if ( compiledExpr == null ) compiledExpr = compileComplexExpr( context, child, customerChecked ); return compiledExpr; }
Example 4
Source File: AbstractExpressionCompiler.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * 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; }