• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

i-net-software / jlessc / 281

pending completion
281

push

travis-ci-com

volker
Handle doubled rule correctly in the compressed formatter if previous
rule ends with an block

5 of 5 new or added lines in 1 file covered. (100.0%)

3586 of 3873 relevant lines covered (92.59%)

2.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

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

29

30
/**
31
 * A single less extends in the less file.
32
 */
33
class LessExtend extends LessObject implements Formattable {
34

35
    private String   selector;
36

37
    private String[] baseSelector;
38

39
    private boolean  all;
40

41
    private String extendingSelector;
42

43
    /**
44
     * Parse the extendSelector,create the needed LessExtend objects and add it to the container.
45
     * 
46
     * @param container
47
     *            the container that should add the created LessExtend
48
     * @param obj
49
     *            another LessObject with parse position.
50
     * @param extendSelector
51
     *            the completely selector like "foo:extends(bar all)"
52
     * @return the base selector
53
     */
54
    static String addLessExtendsTo( FormattableContainer container, LessObject obj, String extendSelector ) {
55
        String baseSelectors = null;
3✔
56
        do {
57
            int idx1 = extendSelector.indexOf( ":extend(" );
3✔
58
            int idx2 = extendSelector.indexOf( ')', idx1 );
3✔
59
            int idx3 = extendSelector.lastIndexOf( ',', idx1 );
3✔
60
            String selector = extendSelector.substring( idx3 + 1, idx1 ).trim();
3✔
61
            String[] baseSelector = new String[] { selector };
3✔
62
            if( baseSelectors == null ) {
3✔
63
                baseSelectors = selector;
3✔
64
            } else {
65
                baseSelectors = baseSelectors + ',' + selector;
3✔
66
            }
67
            String params = extendSelector.substring( idx1 + 8, idx2 ).trim();
3✔
68
    
69
            for( String param : params.split( "," ) ) {
3✔
70
                boolean all = param.endsWith( " all" );
3✔
71
                if( all ) {
3✔
72
                    param = param.substring( 0, param.length() - 4 ).trim();
3✔
73
                }
74
                container.add( new LessExtend( obj, baseSelector, param, all ) );
3✔
75
            }
76
            idx2++;
3✔
77
            if( idx2 < extendSelector.length() ) {
3✔
78
                while( idx2 < extendSelector.length() ) {
3✔
79
                    char ch = extendSelector.charAt( idx2++ );
3✔
80
                    switch( ch ) {
3✔
81
                        case ',':
82
                            break;
3✔
83
                        case ' ':
84
                            continue;
×
85
                        default:
86
                            throw obj.createException("Unrecognized input: '" + extendSelector + "'" );
×
87
                    }
88
                    break;
89
                }
90
                extendSelector = extendSelector.substring( idx2 ).trim();
3✔
91
                if( extendSelector.length() > 0 ) {
3✔
92
                    continue;
3✔
93
                }
94
            }
95
            break;
96
        } while(true);
97
        return baseSelectors;
3✔
98
    }
99

100
    /**
101
     * Create a new instance.
102
     * 
103
     * @param obj
104
     *            another LessObject with parse position.
105
     * @param baseSelector
106
     *            the base selector as single size array.
107
     * @param extendingSelector
108
     *            selector to extends
109
     * @param all
110
     *            If keyword "all" was set
111
     */
112
    private LessExtend( LessObject obj, String[] baseSelector, String extendingSelector, boolean all ) {
113
        super( obj );
3✔
114

115
        this.selector = baseSelector[0];
3✔
116
        this.baseSelector = baseSelector;
3✔
117
        this.extendingSelector = extendingSelector;
3✔
118
        this.all = all;
3✔
119
    }
3✔
120

121
    /**
122
     * If keyword "all" was set
123
     * @return true, if all was available
124
     */
125
    boolean isAll() {
126
        return all;
3✔
127
    }
128

129
    /**
130
     * Get the base selector.
131
     * @return the selector
132
     */
133
    String getSelector() {
134
        return selector;
×
135
    }
136

137
    /**
138
     * Get the base selector as single size array.
139
     * @return the selector
140
     */
141
    String[] getSelectors() {
142
        return baseSelector;
3✔
143
    }
144

145
    /**
146
     * Get selector to extends.
147
     * @return the selector
148
     */
149
    String getExtendingSelector() {
150
        return extendingSelector;
3✔
151
    }
152

153
    /**
154
     * For debugging of the library.
155
     * @return the debug string
156
     */
157
    @Override
158
    public String toString() {
159
        StringBuilder builder = new StringBuilder();
×
160
        for( int i=0; i<baseSelector.length; i++ ) {
×
161
            if( i > 0 ) {
×
162
                builder.append( ',' );
×
163
            }
164
            builder.append( baseSelector[i] );
×
165
        }
166
        builder.append( ":extend(" );
×
167
        builder.append( extendingSelector );
×
168
        if( all ) {
×
169
            builder.append( " all" );
×
170
        }
171
        builder.append( ")" );
×
172
        return builder.toString();
×
173
    }
174

175
    /**
176
     * {@inheritDoc}
177
     */
178
    @Override
179
    public int getType() {
180
        return EXTENDS;
3✔
181
    }
182

183
    /**
184
     * {@inheritDoc}
185
     */
186
    @Override
187
    public void prepare( CssFormatter formatter ) {
188
        // nothing
189
    }
3✔
190

191
    /**
192
     * {@inheritDoc}
193
     */
194
    @Override
195
    public void appendTo( CssFormatter formatter ) {
196
        formatter.add( this );
3✔
197
    }
3✔
198
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc