List of usage examples for com.google.common.css.compiler.passes BooleanExpressionEvaluator BooleanExpressionEvaluator
public BooleanExpressionEvaluator(CssBooleanExpressionNode expression, Set<String> trueConditions)
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 w w . ja v a2 s . c o 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; }