diff options
author | Marc Englund <marc@vaadin.com> | 2012-10-12 17:07:26 +0300 |
---|---|---|
committer | Marc Englund <marc@vaadin.com> | 2012-10-15 16:02:20 +0300 |
commit | 16452cbb7fff0441cde4d2d303297e83e8c58ce1 (patch) | |
tree | d4abc1e23a8ee4a23b9c9fdf97172e3e1845ed49 /theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java | |
parent | 6075149eb323d9d63414e917b5b9d43519682217 (diff) | |
download | vaadin-framework-16452cbb7fff0441cde4d2d303297e83e8c58ce1.tar.gz vaadin-framework-16452cbb7fff0441cde4d2d303297e83e8c58ce1.zip |
list append and contains for #9380
Originally c/76 (I413452d08b48a0fa21d027064ce2d35e687129cd) by Seba; received missing file, and fixed
Change-Id: Ib814b13c6ce7bb6f29bdab2ee65274c1fade099e
Diffstat (limited to 'theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java')
-rw-r--r-- | theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java | 127 |
1 files changed, 4 insertions, 123 deletions
diff --git a/theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java b/theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java index 9c61c9f636..22fb216c9e 100644 --- a/theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java +++ b/theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java @@ -1,107 +1,19 @@ 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; -public class ListRemoveNode extends Node implements ListModifyNode, - IVariableNode { - - private ArrayList<String> list; - private ArrayList<String> remove; - private String separator = " "; - private String variable; +public class ListRemoveNode extends ListModifyNode { public ListRemoveNode(String variable, String list, String remove, String separator) { this.variable = variable; checkSeparator(separator, list); - populateList(list, remove); } - 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 = " "; - } - } - - 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 getNewVariable() { - return variable; - } - - @Override - public VariableNode getModifiedList(VariableNode variableNode) { - - if (variableNode != null) { - VariableNode clone = (VariableNode) DeepCopy.copy(variableNode); - - 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 (lastAccepted != null) { - lastAccepted.setNextLexicalUnit(temp); - } - - lastAccepted = temp; - - if (first == null) { - first = lastAccepted; - } - } - current = (LexicalUnitImpl) current.getNextLexicalUnit(); - } - - clone.setExpr(first); - - return clone; - } else { - - 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, LexicalUnitImpl lastAccepted) { @@ -112,7 +24,7 @@ public class ListRemoveNode extends Node implements ListModifyNode, } String string = current.getValue().toString(); - for (final String s : remove) { + for (final String s : modify) { if (s.equals(string)) { return false; } @@ -121,38 +33,7 @@ public class ListRemoveNode extends Node implements ListModifyNode, } @Override - public void replaceVariables(ArrayList<VariableNode> variables) { - ArrayList<String> newList = new ArrayList<String>(); - - for (final String removeVar : remove) { - if (!removeVar.startsWith("$")) { - continue; - } - - for (final VariableNode var : variables) { - if (removeVar.equals("$" + var.getName())) { - LexicalUnitImpl expr = var.getExpr(); - while (expr != null) { - newList.add(expr.getValue().toString()); - expr = expr.getNextLexicalUnit(); - } - - } - } - } - if (newList.size() > 0) { - remove = newList; - } - - } - - @Override - public String getModifyingList() { - String firstListEntry = list.get(0); - if (list.size() == 1 && firstListEntry.startsWith("$")) { - return firstListEntry.substring(1, firstListEntry.length()); - } - - return null; + protected void modifyList(ArrayList<String> newList) { + newList.removeAll(modify); } } |