/**
 * MIT License (MIT)
 *
 * Copyright (c) 2014 Volker Berlin
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * UT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * @author Volker Berlin
 * @license: The MIT license <http://opensource.org/licenses/MIT>
 */
package com.inet.lib.less;

import static com.inet.lib.less.ColorUtils.*;

import java.io.IOException;

/**
 * Base expression with value formating.
 */
abstract class AbstractExpression extends LessObject implements Expression {

    private String str;

    /**
     * Create a new instance.
     * 
     * @param obj
     *            another LessObject with parse position.
     * @param str
     *            a string from the parser
     */
    AbstractExpression( LessObject obj, String str ) {
        super( obj );
        this.str = str;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final int getType() {
        return EXPRESSION;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void appendTo( CssFormatter formatter ) throws IOException {
        switch( getDataType( formatter ) ) {
            case BOOLEAN:
                formatter.append( Boolean.toString( booleanValue( formatter ) ) );
                return;
            case PERCENT:
                double d = doubleValue( formatter );
                formatter.append( d );
                formatter.append( '%' );
                return;
            case NUMBER:
                d = doubleValue( formatter );
                formatter.appendValue( d, unit( formatter ) );
                return;
            case COLOR:
                formatter.appendColor( doubleValue( formatter ), null );
                return;
            case RGBA:
                double color = doubleValue( formatter );
                final double alpha = alpha( color );
                if( alpha >= 1 ) {
                    formatter.appendColor( color, null );
                } else {
                    formatter.append( "rgba(" );
                    formatter.append( red( color ) ).append( ',' ).space();
                    formatter.append( green( color ) ).append( ',' ).space();
                    formatter.append( blue( color ) ).append( ',' ).space();
                    formatter.append( alpha ).append( ')' );
                }
                return;
        }
        formatter.append( str );
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String stringValue( CssFormatter formatter ) {
        try {
            formatter.addOutput();
            appendTo( formatter );
            return formatter.releaseOutput();
        } catch( IOException ex ) {
            throw createException( ex );
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return str;
    }
}

@@ -2739,32 +2739,195 @@
 e( formatter );%0A
+                if( color == 0 && Double.doubleToRawLongBits( color ) == 0 ) %7B%0A                    formatter.append( %22transparent%22 );%0A                %7D else %7B%0A    
                 
@@ -2975,24 +2975,28 @@
             
+    
 if( alpha %3E=
@@ -2998,24 +2998,28 @@
 ha %3E= 1 ) %7B%0A
+    
             
@@ -3072,32 +3072,36 @@
                 
+    
 %7D else %7B%0A       
@@ -3105,32 +3105,36 @@
                 
+  
+  
 formatter.append
@@ -3142,24 +3142,28 @@
  %22rgba(%22 );%0A
+    
             
@@ -3238,32 +3238,36 @@
                 
+ 
+   
 formatter.append
@@ -3320,32 +3320,36 @@
                 
+   
+ 
 formatter.append
@@ -3401,32 +3401,36 @@
                 
+    
 formatter.append
@@ -3450,24 +3450,46 @@
 end( ')' );%0A
+                    %7D%0A
             

rgba(0,0,0,0) write as transparent