@@ -38,27 +38,55 @@ class LessExtend extends LessObject implements Formattable {
3838
3939 private boolean all ;
4040
41- private String [] extendingSelectors ;
41+ private String extendingSelector ;
4242
4343 /**
44- * Create a new instance.
45- * @param obj another LessObject with parse position.
46- * @param extendSelector the completely selector like "foo:extends(bar all)"
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
4753 */
48- LessExtend ( LessObject obj , String extendSelector ) {
49- super ( obj );
50-
54+ static String addLessExtendsTo ( FormattableContainer container , LessObject obj , String extendSelector ) {
5155 int idx1 = extendSelector .indexOf ( ":extend(" );
5256 int idx2 = extendSelector .indexOf ( ')' , idx1 );
53- String param = extendSelector .substring ( idx1 + 8 , idx2 ).trim ();
54- all = param .endsWith ( " all" );
55- if ( all ) {
56- param = param .substring ( 0 , param .length () - 4 ).trim ();
57+ String selector = extendSelector .substring ( 0 , idx1 );
58+ String [] baseSelector = new String [] { selector };
59+ String params = extendSelector .substring ( idx1 + 8 , idx2 ).trim ();
60+
61+ for ( String param : params .split ( "," ) ) {
62+ boolean all = param .endsWith ( " all" );
63+ if ( all ) {
64+ param = param .substring ( 0 , param .length () - 4 ).trim ();
65+ }
66+ container .add ( new LessExtend ( obj , baseSelector , param , all ) );
5767 }
58- extendingSelectors = param .split ( "," );
68+ return selector ;
69+ }
70+
71+ /**
72+ * Create a new instance.
73+ *
74+ * @param obj
75+ * another LessObject with parse position.
76+ * @param baseSelector
77+ * the base selector as single size array.
78+ * @param extendingSelector
79+ * selector to extends
80+ * @param all
81+ * If keyword "all" was set
82+ */
83+ private LessExtend ( LessObject obj , String [] baseSelector , String extendingSelector , boolean all ) {
84+ super ( obj );
5985
60- this .selector = extendSelector .substring ( 0 , idx1 );
61- baseSelector = new String [] { this .selector };
86+ this .selector = baseSelector [0 ];
87+ this .baseSelector = baseSelector ;
88+ this .extendingSelector = extendingSelector ;
89+ this .all = all ;
6290 }
6391
6492 /**
@@ -78,19 +106,19 @@ String getSelector() {
78106 }
79107
80108 /**
81- * Get the base selectors as single size array.
109+ * Get the base selector as single size array.
82110 * @return the selector
83111 */
84112 String [] getSelectors () {
85113 return baseSelector ;
86114 }
87115
88116 /**
89- * Get the list of selectors to extends
90- * @return the selector list
117+ * Get selector to extends.
118+ * @return the selector
91119 */
92- String [] getExtendingSelectors () {
93- return extendingSelectors ;
120+ String getExtendingSelector () {
121+ return extendingSelector ;
94122 }
95123
96124 /**
@@ -107,12 +135,7 @@ public String toString() {
107135 builder .append ( baseSelector [i ] );
108136 }
109137 builder .append ( ":extend(" );
110- for ( int i =0 ; i <extendingSelectors .length ; i ++ ) {
111- if ( i > 0 ) {
112- builder .append ( ' ' );
113- }
114- builder .append ( extendingSelectors [i ] );
115- }
138+ builder .append ( extendingSelector );
116139 if ( all ) {
117140 builder .append ( " all" );
118141 }
0 commit comments