public String toGetSourceString()

in src/main/java/org/apache/commons/ognl/ComparisonExpression.java [49:126]


    public String toGetSourceString( OgnlContext context, Object target )
    {
        if ( target == null )
        {
            throw new UnsupportedCompilationException( "Current target is null, can't compile." );
        }

        try
        {

            Object value = getValueBody( context, target );

            if ( value != null && Boolean.class.isAssignableFrom( value.getClass() ) )
            {
                getterClass = Boolean.TYPE;
            }
            else if ( value != null )
            {
                getterClass = value.getClass();
            }
            else
            {
                getterClass = Boolean.TYPE;
            }

            // iterate over children to make numeric type detection work properly

            OgnlRuntime.getChildSource( context, target, children[0] );
            OgnlRuntime.getChildSource( context, target, children[1] );

            // System.out.println("comparison expression currentType: " + context.getCurrentType() + " previousType: " +
            // context.getPreviousType());

            boolean conversion = OgnlRuntime.shouldConvertNumericTypes( context );

            StringBuilder result = new StringBuilder( "(" );
            if ( conversion )
            {
                result.append( getComparisonFunction() ).append( "( ($w) (" );
            }

            result.append( OgnlRuntime.getChildSource( context, target, children[0], conversion ) )
                    .append( " " );

            if ( conversion )
            {
                result.append( "), ($w) " );
            }
            else
            {
                result.append( getExpressionOperator( 0 ) );
            }

            result.append( "" ).append( OgnlRuntime.getChildSource( context, target, children[1], conversion ) );

            if ( conversion )
            {
                result.append( ")" );
            }

            context.setCurrentType( Boolean.TYPE );

            result.append( ")" );

            return result.toString();
        }
        catch ( NullPointerException e )
        {

            // expected to happen in some instances

            throw new UnsupportedCompilationException( "evaluation resulted in null expression." );
        }
        catch ( Throwable t )
        {
            throw OgnlOps.castToRuntime( t );
        }
    }