diff options
author | Marc Englund <marc@vaadin.com> | 2012-09-27 10:24:35 +0300 |
---|---|---|
committer | Marc Englund <marc@vaadin.com> | 2012-09-27 10:24:35 +0300 |
commit | 0cf6705e9a53c3c2b476a99cf7e6d048881b298c (patch) | |
tree | f133e60a5d30af43ecc87152df29c26ebdb05715 /theme-compiler/src/com/vaadin/sass/tree | |
parent | abea9d1ce0fdcad2e344cfa2417a09c29d903648 (diff) | |
download | vaadin-framework-0cf6705e9a53c3c2b476a99cf7e6d048881b298c.tar.gz vaadin-framework-0cf6705e9a53c3c2b476a99cf7e6d048881b298c.zip |
Improves remove() for #9380
Diffstat (limited to 'theme-compiler/src/com/vaadin/sass/tree')
3 files changed, 82 insertions, 44 deletions
diff --git a/theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java b/theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java index 71c32a5c06..0e9f727c53 100644 --- a/theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java +++ b/theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java @@ -2,9 +2,9 @@ package com.vaadin.sass.tree; public interface ListModifyNode { - public boolean isModifyingVariable(); + public String getNewVariable(); - public String getVariable(); + public String getModifyingList(); public VariableNode getModifiedList(VariableNode variableNode); 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; + } } diff --git a/theme-compiler/src/com/vaadin/sass/tree/VariableNode.java b/theme-compiler/src/com/vaadin/sass/tree/VariableNode.java index ffe6b77896..d18ff54138 100644 --- a/theme-compiler/src/com/vaadin/sass/tree/VariableNode.java +++ b/theme-compiler/src/com/vaadin/sass/tree/VariableNode.java @@ -35,7 +35,6 @@ public class VariableNode extends Node implements IVariableNode { this.name = name; this.expr = expr; this.guarded = guarded; - checkSeparators(); } public LexicalUnitImpl getExpr() { @@ -44,15 +43,10 @@ public class VariableNode extends Node implements IVariableNode { public void setExpr(LexicalUnitImpl expr) { this.expr = expr; - checkSeparators(); } - private void checkSeparators() { - if (expr != null) { - if (expr.toString().contains(",")) { - - } - } + public void setName(String name) { + this.name = name; } public String getName() { |