@Override public void startMedia(SACMediaList media) throws CSSException { MediaNode node = new MediaNode(media); nodeStack.peek().appendChild(node); nodeStack.push(node); }
public void removeEmptyBlocks(Node node) { // depth first for avoiding re-checking parents of removed nodes for (Node child : new ArrayList<Node>(node.getChildren())) { removeEmptyBlocks(child); } Node parent = node.getParentNode(); if (node instanceof BlockNode && node.getChildren().isEmpty() && parent != null) { // remove empty block parent.removeChild(node); } }
public void appendChild(Node node) { if (node != null) { children.add(node); if (node.getParentNode() != null) { node.getParentNode().removeChild(node); } node.setParentNode(this); } }
public void setParentNode(Node node) { parentNode.removeChild(this); node.appendChild(this); }
private static void replaceDefNodeWithCorrectChild(IfElseDefNode defNode, Node parent, final Node child) { for (final Node n : new ArrayList<Node>(child.getChildren())) { parent.appendChild(n, defNode); } } }
} else { Node parent = node.getParentNode(); while (parent != null && !(parent instanceof ScssStylesheet)) { parent = parent.getParentNode(); throw new ParseException("Nested import in an invalid context"); ArrayList<Node> c = new ArrayList<Node>(node.getChildren()); for (Node n : c) { if (n instanceof ImportNode) { node.appendChildrenAfter( new ArrayList<Node>(imported.getChildren()), importNode); node.removeChild(importNode); } catch (CSSException e) { e.printStackTrace();
Node originalParent = node.getParentNode(); node.traverse(); for (int i = 0; i < node.getChildren().size(); i++) { Node current = node.getChildren().get(i); if (traverse(current)) { boolean removed = !originalParent.getChildren().contains(node); return removed; } else {
private static void replaceMixinNode(MixinNode mixinNode, MixinDefNode mixinDef) { MixinDefNode defClone = (MixinDefNode) DeepCopy.copy(mixinDef); defClone.traverse(); defClone.replaceContentDirective(mixinNode); if (mixinDef.getArglist().isEmpty()) { mixinNode.getParentNode().appendChildrenAfter( new ArrayList<Node>(defClone.getChildren()), mixinNode); } else { if (mixinNode.getArglist() != null && !mixinNode.getArglist().isEmpty()) { replacePossibleArguments(mixinNode, defClone); } Node previous = mixinNode; for (final Node child : new ArrayList<Node>(defClone.getChildren())) { replaceChildVariables(defClone, child); mixinNode.getParentNode().appendChild(child, previous); previous = child; } } mixinNode.getParentNode().removeChild(mixinNode); }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("@font-face {\n"); for (final Node child : children) { builder.append("\t" + child.toString() + "\n"); } builder.append("}"); return builder.toString(); }
public MixinDefNode replaceContentNode(ContentNode contentNode, MixinNode mixinNode) { if (contentNode != null) { contentNode.getParentNode().appendChildrenAfter( DeepCopy.copy(mixinNode.getChildren()), contentNode); contentNode.getParentNode().removeChild(contentNode); } return this; } }
private static void combineParentSelectorListToChild(BlockNode node) { ArrayList<String> newList = new ArrayList<String>(); BlockNode parentBlock = (BlockNode) node.getParentNode(); for (String parentSelector : parentBlock.getSelectorList()) { for (String childSelector : node.getSelectorList()) { // handle parent selector if (childSelector.contains("&")) { newList.add(childSelector.replace("&", parentSelector)); } else { newList.add(parentSelector + " " + childSelector); } } } node.setSelectorList(newList); Node oldParent = node.getParentNode(); HashMap<Node, Node> lastNodeAdded = ScssStylesheet.getLastNodeAdded(); Node lastAdded = lastNodeAdded.get(oldParent.getParentNode()); if (lastAdded == null) { lastAdded = oldParent; } oldParent.getParentNode().appendChild(node, lastAdded); lastNodeAdded.put(oldParent.getParentNode(), node); } }
private MixinDefNode findAndReplaceContentNodeInChildren(Node node, MixinNode mixinNode) { ContentNode contentNode = null; for (Node child : new ArrayList<Node>(node.getChildren())) { if (child instanceof ContentNode) { contentNode = (ContentNode) child; replaceContentNode(contentNode, mixinNode); } else { findAndReplaceContentNodeInChildren(child, mixinNode); } } return this; }
throw new ParseException( "Invalid @if/@else in scss file, not a boolean expression : " + child.toString()); } catch (NullPointerException ex) { throw new ParseException( throw new ParseException( "Invalid @if/@else in scss file for " + child.toString()); node.getParentNode().removeChild(node);
@Override public void traverse() { try { ExtendNodeHandler.traverse(this); getParentNode().removeChild(this); } catch (Exception e) { e.printStackTrace(); } } }
public void removeChild(Node node) { if (node != null) { boolean removed = children.remove(node); if (removed) { node.setParentNode(null); } } }
@Override public void traverse() { try { for (final Node child : children) { child.traverse(); } IfElseNodeHandler.traverse(this); } catch (Exception e) { e.printStackTrace(); } }
protected static void checkExtraParameters(MixinNode mixinNode, int remainingNodesSize, int remainingUnitsSize) { if (remainingUnitsSize > remainingNodesSize) { String fileName = null; Node root = mixinNode.getParentNode(); while (root != null && !(root instanceof ScssStylesheet)) { root = root.getParentNode(); } if (root != null) { fileName = ((ScssStylesheet) root).getFileName(); } StringBuilder builder = new StringBuilder(); builder.append("More parameters than expected, in Mixin ").append( mixinNode.getName()); if (fileName != null) { builder.append(", in file ").append(fileName); } throw new RuntimeException(builder.toString()); } }
public static void traverse(NestPropertiesNode node) { Node previous = node; for (RuleNode unNested : node.unNesting()) { node.getParentNode().appendChild(unNested, previous); previous = unNested; } node.getParentNode().removeChild(node); } }
@Override public String toString() { StringBuilder string = new StringBuilder(); string.append(selector).append(" {\n"); for (Node child : children) { string.append("\t\t").append(child.toString()).append("\n"); } string.append("\t}"); return string.toString(); }
private static void replaceInterpolation(Node copy, ArrayList<VariableNode> variables) { if (copy instanceof IVariableNode) { IVariableNode n = (IVariableNode) copy; n.replaceVariables(variables); } for (Node c : copy.getChildren()) { replaceInterpolation(c, variables); } }