* the same selectors as has input RuleSetNode
*/
@Override
public boolean enter(RuleSetNode ruleSetNode) {
ScopeNode scopeNode = NodeTreeUtils.getFirstChild(ruleSetNode, ScopeNode.class);
SelectorGroupNode selectorGroupNode = NodeTreeUtils.getFirstChild(ruleSetNode, SelectorGroupNode.class);
if (selectorGroupNode == null) {
return true;
}
List<SelectorNode> selectorNodes = NodeTreeUtils.getChildren(selectorGroupNode, SelectorNode.class);
if (selectorNodes.size() < 0) {
return true;
}
List<MediaQueryNode> mediaQueryNodes = NodeTreeUtils.getAndRemoveChildren(scopeNode, MediaQueryNode.class);
for (MediaQueryNode mediaQueryNode : mediaQueryNodes) {
ScopeNode mediaScopeNode = NodeTreeUtils.getFirstChild(mediaQueryNode, ScopeNode.class);
List<RuleSetNode> nestedRuleSets = NodeTreeUtils.getAndRemoveChildren(mediaScopeNode, RuleSetNode.class);
// if scope node for media query has anything more but whitespaces and rule sets than wrap it with rule set with the same selector group as outer rule set has
if (mediaScopeNode.getChildren().size() > NodeTreeUtils.getChildren(mediaScopeNode, WhiteSpaceCollectionNode.class).size()) {
RuleSetNode newRuleSetNode = new RuleSetNode();
ScopeNode newScopeNode = new ScopeNode();
newRuleSetNode.addChild(selectorGroupNode.clone());
newRuleSetNode.addChild(newScopeNode);
NodeTreeUtils.moveChildren(mediaScopeNode, newScopeNode);