diff options
Diffstat (limited to 'theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java')
-rw-r--r-- | theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java | 112 |
1 files changed, 78 insertions, 34 deletions
diff --git a/theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java b/theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java index 9c6400ec02..9c61c9f636 100644 --- a/theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java +++ b/theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java @@ -1,6 +1,7 @@ package com.vaadin.sass.tree; import java.util.ArrayList; +import java.util.Arrays; import com.vaadin.sass.parser.LexicalUnitImpl; import com.vaadin.sass.util.DeepCopy; @@ -10,62 +11,95 @@ public class ListRemoveNode extends Node implements ListModifyNode, private ArrayList<String> list; private ArrayList<String> remove; - private String separator; + private String separator = " "; + private String variable; - public ListRemoveNode(ArrayList<String> list, ArrayList<String> remove, + public ListRemoveNode(String variable, String list, String remove, String separator) { - this.list = list; - this.remove = remove; - this.separator = separator; + this.variable = variable; + checkSeparator(separator, list); + + populateList(list, remove); + } - @Override - public boolean isModifyingVariable() { - if (list != null) { - return list.size() == 1 && list.get(0).startsWith("$"); + private void checkSeparator(String separator, String list) { + String lowerCase = ""; + if (separator == null + || (lowerCase = separator.toLowerCase()).equals("auto")) { + if (list.contains(",")) { + this.separator = ","; + } + } else if (lowerCase.equals("comma")) { + this.separator = ","; + } else if (lowerCase.equals("space")) { + this.separator = " "; } - return false; + } + + private void populateList(String list, String remove) { + this.list = new ArrayList<String>(Arrays.asList(list.split(separator))); + this.remove = new ArrayList<String>(Arrays.asList(remove + .split(separator))); } @Override - public String getVariable() { - if (list != null && list.size() == 1) { - String string = list.get(0); - return string.substring(1, string.length()); - } - return null; + public String getNewVariable() { + return variable; } @Override public VariableNode getModifiedList(VariableNode variableNode) { - VariableNode clone = (VariableNode) DeepCopy.copy(variableNode); + if (variableNode != null) { + VariableNode clone = (VariableNode) DeepCopy.copy(variableNode); - LexicalUnitImpl first = null; - LexicalUnitImpl current = (LexicalUnitImpl) clone.getExpr(); - LexicalUnitImpl lastAccepted = null; - while (current != null) { + LexicalUnitImpl first = null; + LexicalUnitImpl current = (LexicalUnitImpl) clone.getExpr(); + LexicalUnitImpl lastAccepted = null; + while (current != null) { - if (shouldInclude(current, lastAccepted)) { - LexicalUnitImpl temp = current.clone(); - temp.setNextLexicalUnit(null); + if (shouldInclude(current, lastAccepted)) { + LexicalUnitImpl temp = current.clone(); + temp.setNextLexicalUnit(null); - if (lastAccepted != null) { - lastAccepted.setNextLexicalUnit(temp); - } + if (lastAccepted != null) { + lastAccepted.setNextLexicalUnit(temp); + } - lastAccepted = temp; + lastAccepted = temp; - if (first == null) { - first = lastAccepted; + if (first == null) { + first = lastAccepted; + } } + current = (LexicalUnitImpl) current.getNextLexicalUnit(); } - current = (LexicalUnitImpl) current.getNextLexicalUnit(); - } - clone.setExpr(first); + clone.setExpr(first); + + return clone; + } else { - return clone; + final ArrayList<String> newList = new ArrayList<String>(list); + newList.removeAll(remove); + + LexicalUnitImpl unit = null; + if (newList.size() > 0) { + unit = LexicalUnitImpl.createString(newList.get(0)); + LexicalUnitImpl last = unit; + for (int i = 1; i < newList.size(); i++) { + LexicalUnitImpl current = LexicalUnitImpl + .createString(newList.get(i)); + last.setNextLexicalUnit(current); + last = current; + } + + } + VariableNode node = new VariableNode(variable, unit, false); + return node; + + } } private boolean shouldInclude(LexicalUnitImpl current, @@ -111,4 +145,14 @@ public class ListRemoveNode extends Node implements ListModifyNode, } } + + @Override + public String getModifyingList() { + String firstListEntry = list.get(0); + if (list.size() == 1 && firstListEntry.startsWith("$")) { + return firstListEntry.substring(1, firstListEntry.length()); + } + + return null; + } } |