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/ListModifyNode.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/ListModifyNode.java')
-rw-r--r-- | theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java | 99 |
1 files changed, 95 insertions, 4 deletions
diff --git a/theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java b/theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java index 0e9f727c53..d54f56f8a7 100644 --- a/theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java +++ b/theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java @@ -1,11 +1,102 @@ package com.vaadin.sass.tree; -public interface ListModifyNode { +import java.util.ArrayList; +import java.util.Arrays; - public String getNewVariable(); +import com.vaadin.sass.parser.LexicalUnitImpl; - public String getModifyingList(); +public abstract class ListModifyNode extends Node implements IVariableNode { - public VariableNode getModifiedList(VariableNode variableNode); + protected ArrayList<String> list; + protected ArrayList<String> modify; + protected String separator = " "; + protected String variable; + + public String getNewVariable() { + return variable; + } + + public VariableNode getModifiedList() { + final ArrayList<String> newList = new ArrayList<String>(list); + modifyList(newList); + + LexicalUnitImpl unit = null; + if (newList.size() > 0) { + unit = LexicalUnitImpl.createIdent(newList.get(0)); + LexicalUnitImpl last = unit; + for (int i = 1; i < newList.size(); i++) { + LexicalUnitImpl current = LexicalUnitImpl.createIdent(newList + .get(i)); + last.setNextLexicalUnit(current); + last = current; + } + + } + VariableNode node = new VariableNode(variable.substring(1), unit, false); + return node; + } + + protected abstract void modifyList(ArrayList<String> newList); + + protected 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 = " "; + } + } + + protected void populateList(String list, String modify) { + this.list = new ArrayList<String>(Arrays.asList(list.split(separator))); + this.modify = new ArrayList<String>(Arrays.asList(modify + .split(separator))); + } + + @Override + public void replaceVariables(ArrayList<VariableNode> variables) { + for (final String listVar : new ArrayList<String>(list)) { + replacePossibleVariable(variables, listVar, list); + } + + for (final String listVar : new ArrayList<String>(modify)) { + replacePossibleVariable(variables, listVar, modify); + } + + } + + private void replacePossibleVariable(ArrayList<VariableNode> variables, + final String listVar, ArrayList<String> list) { + if (listVar.startsWith("$")) { + + for (final VariableNode var : variables) { + + if (var.getName().equals(listVar.substring(1))) { + + String[] split = null; + if (var.getExpr().toString().contains(",")) { + split = var.getExpr().toString().split(","); + } else { + split = var.getExpr().toString().split(" "); + } + int i = list.indexOf(listVar); + for (final String s : split) { + list.add(i, s.trim()); + i++; + } + + list.remove(listVar); + break; + + } + } + + } + } } |