List of usage examples for com.google.common.css.compiler.ast CssConditionalRuleNode getType
public Type getType()
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 va2 s .com*/ } }
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)); }/* ww w. j ava2 s .com*/ } }
From source file:com.google.gwt.resources.gss.CssPrinter.java
@Override public boolean enterConditionalRule(CssConditionalRuleNode node) { if (node.getType() == Type.ELSE) { elseNodeFound.pop();/*from w w w . ja va2 s . co m*/ elseNodeFound.push(true); masterStringBuilder.append(LEFT_BRACKET); } else { CssRuntimeConditionalRuleNode conditionalRuleNode = (CssRuntimeConditionalRuleNode) node; masterStringBuilder.append(LEFT_BRACKET); masterStringBuilder.append(conditionalRuleNode.getRuntimeCondition().getValue()); masterStringBuilder.append(") ? ("); // reset concatenation counter concatenationNumber = 0; } return true; }
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. j a va 2 s. 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; }
From source file:com.google.gwt.resources.gss.CssPrinter.java
@Override public void leaveConditionalRule(CssConditionalRuleNode node) { masterStringBuilder.append(flushInternalStringBuilder()).append(RIGHT_BRACKET); if (node.getType() != Type.ELSE) { masterStringBuilder.append(" : "); }/*from w ww .j a v a2 s .c om*/ }