Example usage for com.google.common.css.compiler.ast CssConditionalRuleNode getCondition

List of usage examples for com.google.common.css.compiler.ast CssConditionalRuleNode getCondition

Introduction

In this page you can find the example usage for com.google.common.css.compiler.ast CssConditionalRuleNode getCondition.

Prototype

public CssBooleanExpressionNode getCondition() 

Source Link

Document

Can only be called after the node is completely built (meaning it has the condition set).

Usage

From source file:com.google.gwt.resources.gss.CreateRuntimeConditionalNodes.java

private void manuallyVisitConditionalRule(CssConditionalRuleNode node, CssConditionalBlockNode parent) {

    if (node.getType() != Type.ELSE) {
        CssBooleanExpressionNode nodeCondition = node.getCondition();
        String condition = extractRuntimeCondition(nodeCondition);

        if (condition != null) {
            CssJavaExpressionNode newNode = new CssJavaExpressionNode(condition,
                    nodeCondition.getSourceCodeLocation());

            CssRuntimeConditionalRuleNode newRuleNode = new CssRuntimeConditionalRuleNode(node, newNode);

            // unfortunately visitController.replaceCurrentBlockChildWith doesn't work with
            // CssConditionnalRuleNode
            int index = parent.getChildren().indexOf(node);
            parent.replaceChildAt(index, Lists.newArrayList(newRuleNode));
        }/*from w  ww .  ja  v a2s .c o m*/
    }
}

From source file:com.google.gwt.resources.gss.ExtendedEliminateConditionalNodes.java

private boolean enterRuntimeConditionalBlock(CssConditionalBlockNode block) {
    boolean runtimeEvaluationNodeFound = false;
    List<CssConditionalRuleNode> newChildren = new ArrayList<CssConditionalRuleNode>(block.numChildren());

    for (CssConditionalRuleNode currentConditional : block.childIterable()) {
        if (currentConditional.getType() == Type.ELSE) {
            newChildren.add(currentConditional);
            break;
        }//  ww w  .j  av  a  2s .  co m

        if (currentConditional instanceof CssRuntimeConditionalRuleNode) {
            runtimeEvaluationNodeFound = true;
            newChildren.add(currentConditional);
            continue;
        }

        // The node can be evaluated at compile time
        BooleanExpressionEvaluator evaluator = new BooleanExpressionEvaluator(currentConditional.getCondition(),
                trueConditions);

        CssBooleanExpressionNode result = evaluator.evaluate();
        boolean isTrue = CssBooleanExpressionNode.Type.TRUE_CONSTANT.equals(result.getValue());

        if (!isTrue) {
            // any node evaluated to false can be removed
        } else if (!runtimeEvaluationNodeFound) {
            // node evaluated to true before the runtime condition, replace the conditional block by the
            // children of this current conditional node.
            visitController.replaceCurrentBlockChildWith(currentConditional.getBlock().getChildren(), true);
            return true;
        } else {
            // node evaluated to true before the runtime condition, transform this node to an else node
            CssConditionalRuleNode newNode = new CssConditionalRuleNode(Type.ELSE, currentConditional.getName(),
                    null, currentConditional.getBlock());

            newChildren.add(newNode);
            break;
        }
    }

    CssConditionalBlockNode newNode = new CssConditionalBlockNode();
    for (CssConditionalRuleNode child : newChildren) {
        newNode.addChildToBack(child);
    }

    visitController.replaceCurrentBlockChildWith(Lists.newArrayList(newNode), true);

    // mark this node as already visited.
    alreadyTreatedNode.add(newNode);

    return true;
}