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

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

Introduction

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

Prototype

@Override
    public CssBlockNode getBlock() 

Source Link

Usage

From source file:com.google.gwt.resources.gss.ast.CssRuntimeConditionalRuleNode.java

public CssRuntimeConditionalRuleNode(CssConditionalRuleNode node, @Nullable CssJavaExpressionNode condition) {
    super(node.getType(), node.getName().deepCopy(), null,
            node.getBlock() != null ? node.getBlock().deepCopy() : null);
    setSourceCodeLocation(node.getSourceCodeLocation());

    if (condition != null) {
        setRuntimeCondition(condition);/*from  ww w.  j a v  a 2s  . 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;
        }/*from w  ww  . j  a va 2  s.  com*/

        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;
}