/**
 * 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 java.util.ArrayDeque;
import java.util.Iterator;

/**
 * A single less extends
 */
class LessExtend extends LessObject {

    private String   selector;

    private String[] baseSelector;

    private boolean  all;

    private String[] extendingSelectors;

    LessExtend( LessLookAheadReader reader, String extendSelector, ArrayDeque<Rule> ruleStack ) {
        super( reader );

        int idx1 = extendSelector.indexOf( ":extend(" );
        int idx2 = extendSelector.indexOf( ')', idx1 );
        String param = extendSelector.substring( idx1 + 8, idx2 ).trim();
        all = param.endsWith( " all" );
        if( all ) {
            param = param.substring( 0, param.length() - 4 ).trim();
        }
        extendingSelectors = param.split( "," );

        this.selector = extendSelector.substring( 0, idx1 );
        baseSelector = new String[] { this.selector };
        for( Iterator<Rule> iterator = ruleStack.descendingIterator(); iterator.hasNext(); ) {
            Rule rule = iterator.next();
            String[] selectors = rule.getSelectors();
            baseSelector = SelectorUtils.merge( selectors, baseSelector );
        }
    }

    boolean isAll() {
        return all;
    }

    String getSelector() {
        return selector;
    }

    String[] getSelectors() {
        return baseSelector;
    }

    String[] getExtendingSelectors() {
        return extendingSelectors;
    }
}

@@ -2677,10 +2677,718 @@
 ;%0A    %7D%0A
+    %0A    /**%0A     * For debugging%0A     */%0A    @Override%0A    public String toString() %7B%0A        StringBuilder builder = new StringBuilder();%0A        for( int i=0; i%3CbaseSelector.length; i++ ) %7B%0A            if( i %3E 0 ) %7B%0A                builder.append( ',' );%0A            %7D%0A            builder.append( baseSelector%5Bi%5D );%0A        %7D%0A        builder.append( %22:extend(%22 );%0A        for( int i=0; i%3CextendingSelectors.length; i++ ) %7B%0A            if( i %3E 0 ) %7B%0A                builder.append( ' ' );%0A            %7D%0A            builder.append( extendingSelectors%5Bi%5D );%0A        %7D%0A        if( all ) %7B%0A            builder.append( %22 all%22 );%0A        %7D%0A        builder.append( %22)%22 );%0A        return builder.toString();%0A    %7D%0A
 %7D%0A

debug code added