/**
 * File: DeclarationTransformer.java
 *
 * Author: David Hay (dhay@localmatters.com)
 * Creation Date: Apr 28, 2010
 * Creation Time: 8:40:12 AM
 *
 * Copyright 2010 Local Matters, Inc.
 * All Rights Reserved
 *
 * Last checkin:
 *  $Author$
 *  $Revision$
 *  $Date$
 */
package org.lesscss4j.transform;

import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;

import org.lesscss4j.error.ErrorUtils;
import org.lesscss4j.error.LessCssException;
import org.lesscss4j.model.Declaration;
import org.lesscss4j.model.PositionAware;
import org.lesscss4j.model.expression.Expression;
import org.lesscss4j.transform.manager.TransformerManager;

public class DeclarationTransformer extends AbstractTransformer<Declaration> {

    public DeclarationTransformer() {
    }

    public DeclarationTransformer(TransformerManager transformerManager) {
        super(transformerManager);
    }

    public List<Declaration> transform(Declaration declaration, EvaluationContext context) {
        if (declaration.getValues() == null) return null;

        Declaration transformed = new Declaration(declaration, false);
        for (ListIterator<Object> iter = declaration.getValues().listIterator(); iter.hasNext();) {
            Object value = iter.next();
            value = transformDeclarationValue(value, context);
            transformed.addValue(value);
        }

        return Arrays.asList(transformed);
    }

    protected Object transformDeclarationValue(Object value, EvaluationContext context) {
        if (value instanceof Expression) {
            try {
                value = ((Expression) value).evaluate(context);
            }
            catch (LessCssException ex) {
                ErrorUtils.handleError(context.getErrorHandler(), (PositionAware) value, ex);
            }
        }
        return value;
    }
}

@@ -1316,16 +1316,29 @@
 e(value,
+ declaration,
  context
@@ -1502,16 +1502,41 @@
 t value,
+ Declaration declaration,
  Evaluat

Include Declaration element in transformDeclarationElement in case subclasses need it