Java Code Examples for org.mozilla.javascript.Context#getErrorReporter()

The following examples show how to use org.mozilla.javascript.Context#getErrorReporter() . 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 expr
 * @param objectName
 * @return
 */
private 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 );
		IRFactory ir = new IRFactory( ce );
		ScriptNode script = ir.transformTree( tree );
		return getScriptObjectName( script, objectName );
	}
	finally
	{
		Context.exit( );
	}
}
 
Example 2
Source File: OlapExpressionCompiler.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 
 * @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( );
	}
}
 
Example 3
Source File: OlapExpressionCompiler.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 
 * @param expr
 * @param bindings
 * @param onlyFromDirectReferenceExpr
 * @return
 * @throws DataException
 */
private static Set getReferencedDimLevel( IScriptExpression expr,
		List bindings, boolean onlyFromDirectReferenceExpr )
		throws DataException
{
	if ( expr == null || expr.getText( ) == null || expr.getText( ).length( ) == 0 || BaseExpression.constantId.equals( expr.getScriptId( ) ) )
		return new HashSet( );
	try
	{
		Set result = new HashSet( );
		Context cx = Context.enter( );
		CompilerEnvirons ce = new CompilerEnvirons( );
		Parser p = new Parser( ce, cx.getErrorReporter( ) );
		AstRoot tree = p.parse( expr.getText( ), null, 0 );
		Node root = new IRFactory( ce).transformTree(tree);

		populateDimLevels( null,
				root,
				result,
				bindings,
				onlyFromDirectReferenceExpr );
		return result;
	}
	finally
	{
		Context.exit( );
	}
}
 
Example 4
Source File: AbstractExpressionCompiler.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * parse the expression to script tree
 * 
 * @param expression
 * @param cx
 * @return
 * @throws DataException
 */
protected ScriptNode parse( String expression, Context cx )
		throws DataException
{
	if ( expression == null )
		throw new DataException( ResourceConstants.EXPRESSION_CANNOT_BE_NULL_OR_BLANK );

	CompilerEnvirons compilerEnv = getCompilerEnv( cx );
	Parser p = new Parser( compilerEnv, cx.getErrorReporter( ) );
	AstRoot root = p.parse( expression, null, 0 );
	IRFactory ir = new IRFactory(compilerEnv );
	ScriptNode script = ir.transformTree(root);
	return script;
}
 
Example 5
Source File: ExpressionParserUtility.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * parse the expression into a script tree
 * 
 * @param expression
 * @param cx
 * @return
 */
private ScriptNode parse( String expression, Context cx )
{
	CompilerEnvirons compilerEnv = new CompilerEnvirons( );
	Parser p = new Parser( compilerEnv, cx.getErrorReporter( ) );
	AstRoot root = p.parse( expression, null, 0 );
	IRFactory ir = new IRFactory(compilerEnv);
	return ir.transformTree(root);
}
 
Example 6
Source File: OlapExpressionCompiler.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 
 * @param expr
 * @param objectName
 * @return
 */
public static Set<String> getReferencedMeasure( String expr )
{
	if ( expr == null )
		return Collections.emptySet( );
	try
	{
		Set<String> result = new LinkedHashSet<String>( );
		Context cx = Context.enter( );
		CompilerEnvirons ce = new CompilerEnvirons( );
		Parser p = new Parser( ce, cx.getErrorReporter( ) );
		AstRoot tree = p.parse( expr, null, 0 );
		IRFactory ir = new IRFactory( ce );
		ScriptNode script = ir.transformTree( tree );
		getScriptObjectName( script, "measure", result ); //$NON-NLS-1$
		
		return result;
	}
	catch( Exception e )
	{
		return Collections.emptySet( );
	}
	finally
	{
		Context.exit( );
	}
}
 
Example 7
Source File: OlapExpressionCompiler.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 
 * @param expr
 * @param bindings
 * @param onlyFromDirectReferenceExpr
 * @return
 * @throws DataException
 */
public static Set<IDimLevel> getReferencedDimLevel( String expr )
		throws CoreException
{
	if ( expr == null  )
		return new HashSet<IDimLevel>( );
	try
	{
		Set<IDimLevel> result = new HashSet<IDimLevel>( );
		Context cx = Context.enter( );
		CompilerEnvirons ce = new CompilerEnvirons( );
		Parser p = new Parser( ce, cx.getErrorReporter( ) );
		AstRoot tree = p.parse( expr, null, 0 );
		IRFactory ir = new IRFactory( ce );
		ScriptNode script = ir.transformTree( tree );
		populateDimLevels( null, script, result );
		return result;
	}
	catch( Exception e )
	{
		return Collections.emptySet( );
	}
	finally
	{
		Context.exit( );
	}
}
 
Example 8
Source File: ExpressionUtility.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * whether the expression is column reference
 * @param expression
 * @return
 */
public static boolean isColumnExpression( String expression, boolean mode )
{
	boolean isColumn = false;
	if ( expression == null || expression.trim( ).length( ) == 0 )
		return isColumn;
	if ( getCompiledExpCacheMap( mode ).containsKey( expression ) )
	{
		return ( (Boolean)  getCompiledExpCacheMap( mode ).get( expression ) ).booleanValue( );
	}
	Context context = Context.enter( );
	ScriptNode tree;
	try
	{
		CompilerEnvirons m_compilerEnv = new CompilerEnvirons( );
		m_compilerEnv.initFromContext( context );
		Parser p = new Parser( m_compilerEnv, context.getErrorReporter( ) );
		AstRoot root = p.parse( expression, null, 0 );
		IRFactory ir = new IRFactory( m_compilerEnv );
		tree = ir.transformTree( root );
	}
	catch ( Exception e )
	{
		getCompiledExpCacheMap( mode ).put( expression,
				Boolean.valueOf( false ) );
		return false;
	}
	finally
	{
		Context.exit( );
	}

	if ( tree.getFirstChild( ) == tree.getLastChild( ) )
	{
		// A single expression
		if ( tree.getFirstChild( ).getType( ) != Token.EXPR_RESULT
				&& tree.getFirstChild( ).getType( ) != Token.EXPR_VOID
				&& tree.getFirstChild( ).getType( ) != Token.BLOCK )
		{
			isColumn = false;
		}
		Node exprNode = tree.getFirstChild( );
		Node child = exprNode.getFirstChild( );
		assert ( child != null );
		if ( child.getType( ) == Token.GETELEM
				|| child.getType( ) == Token.GETPROP )
			isColumn = getDirectColRefExpr( child, mode );
		else
			isColumn = false;
	}
	else
	{
		isColumn = false;
	}
	getCompiledExpCacheMap( mode ).put( expression,
			Boolean.valueOf( isColumn ) );
	return isColumn;
}
 
Example 9
Source File: ExpressionUtility.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * whether the expression is column reference
 * @param expression
 * @return
 */
public static boolean isColumnExpression( String expression, boolean mode )
{
	boolean isColumn = false;
	if ( expression == null || expression.trim( ).length( ) == 0 )
		return isColumn;
	if ( getCompiledExpCacheMap( mode ).containsKey( expression ) )
	{
		return ( (Boolean)  getCompiledExpCacheMap( mode ).get( expression ) ).booleanValue( );
	}
	Context context = Context.enter( );
	ScriptNode tree;
	try
	{
		CompilerEnvirons m_compilerEnv = new CompilerEnvirons( );
		m_compilerEnv.initFromContext( context );
		Parser p = new Parser( m_compilerEnv, context.getErrorReporter( ) );
		AstRoot root = p.parse( expression, null, 0 );
		IRFactory ir = new IRFactory( m_compilerEnv );
		tree = ir.transformTree( root );
	}
	catch ( Exception e )
	{
		getCompiledExpCacheMap( mode ).put( expression,
				Boolean.valueOf( false ) );
		return false;
	}
	finally
	{
		Context.exit( );
	}

	if ( tree.getFirstChild( ) == tree.getLastChild( ) )
	{
		// A single expression
		if ( tree.getFirstChild( ).getType( ) != Token.EXPR_RESULT
				&& tree.getFirstChild( ).getType( ) != Token.EXPR_VOID
				&& tree.getFirstChild( ).getType( ) != Token.BLOCK )
		{
			isColumn = false;
		}
		Node exprNode = tree.getFirstChild( );
		Node child = exprNode.getFirstChild( );
		assert ( child != null );
		if ( child.getType( ) == Token.GETELEM
				|| child.getType( ) == Token.GETPROP )
			isColumn = getDirectColRefExpr( child, mode );
		else
			isColumn = false;
	}
	else
	{
		isColumn = false;
	}
	getCompiledExpCacheMap( mode ).put( expression,
			Boolean.valueOf( isColumn ) );
	return isColumn;
}
 
Example 10
Source File: ExpressionUtility.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * whether the expression is column reference
 * 
 * @param expression
 * @return
 */
public static boolean isColumnExpression( String expression )
{
	boolean isColumn = false;
	if ( expression == null || expression.trim( ).length( ) == 0 )
		return isColumn;
	if ( compiledExprCache.containsKey( expression ) )
		return ( (Boolean) compiledExprCache.get( expression ) ).booleanValue( );
	Context context = Context.enter( );
	ScriptNode tree;
	try
	{
		CompilerEnvirons m_compilerEnv = new CompilerEnvirons( );
		m_compilerEnv.initFromContext( context );
		Parser p = new Parser( m_compilerEnv, context.getErrorReporter( ) );
		AstRoot root = p.parse( expression, null, 0 );
		IRFactory ir = new IRFactory( m_compilerEnv );
		tree = ir.transformTree( root );
	}
	catch ( Exception e )
	{
		compiledExprCache.put( expression, Boolean.valueOf( false ) );
		return false;
	}
	finally
	{
		Context.exit( );
	}

	if ( tree.getFirstChild( ) == tree.getLastChild( ) )
	{
		// A single expression
		if ( tree.getFirstChild( ).getType( ) != Token.EXPR_RESULT
				&& tree.getFirstChild( ).getType( ) != Token.EXPR_VOID
				&& tree.getFirstChild( ).getType( ) != Token.BLOCK )
		{
			isColumn = false;
		}
		Node exprNode = tree.getFirstChild( );
		Node child = exprNode.getFirstChild( );
		assert ( child != null );
		if ( child.getType( ) == Token.GETELEM
				|| child.getType( ) == Token.GETPROP )
			isColumn = getDirectColRefExpr( child );
		else
			isColumn = false;
	}
	else
	{
		isColumn = false;
	}

	compiledExprCache.put( expression, Boolean.valueOf( isColumn ) );
	return isColumn;
}