diff options
author | Marc Englund <marc@vaadin.com> | 2012-09-21 11:52:52 +0300 |
---|---|---|
committer | Marc Englund <marc@vaadin.com> | 2012-09-21 11:53:22 +0300 |
commit | 8b28ea439cf09b69574009337c2659dd653d3760 (patch) | |
tree | c7e28e1e29b5608115b84f7b0b0cc334fd312455 /theme-compiler/src/com/vaadin/sass/tree | |
parent | 9500a714336d6f08b47f7cba980fc82faf318ef3 (diff) | |
download | vaadin-framework-8b28ea439cf09b69574009337c2659dd653d3760.tar.gz vaadin-framework-8b28ea439cf09b69574009337c2659dd653d3760.zip |
Big SassCompiler change, fixes #9411 #9489 partials for #9354 #9545 #9380 (applied patch)
Diffstat (limited to 'theme-compiler/src/com/vaadin/sass/tree')
10 files changed, 284 insertions, 141 deletions
diff --git a/theme-compiler/src/com/vaadin/sass/tree/BlockNode.java b/theme-compiler/src/com/vaadin/sass/tree/BlockNode.java index cde7c9425a..bd240324ba 100644 --- a/theme-compiler/src/com/vaadin/sass/tree/BlockNode.java +++ b/theme-compiler/src/com/vaadin/sass/tree/BlockNode.java @@ -18,35 +18,32 @@ package com.vaadin.sass.tree; import java.util.ArrayList; -import org.w3c.css.sac.Selector; -import org.w3c.css.sac.SelectorList; - -import com.vaadin.sass.parser.SelectorListImpl; -import com.vaadin.sass.selector.SelectorUtil; -import com.vaadin.sass.util.Clonable; -import com.vaadin.sass.util.DeepCopy; - -public class BlockNode extends Node implements Clonable, IVariableNode { +public class BlockNode extends Node implements IVariableNode { private static final long serialVersionUID = 5742962631468325048L; - SelectorList selectorList; + ArrayList<String> selectorList; - public BlockNode(SelectorList selectorList) { + public BlockNode(ArrayList<String> selectorList) { this.selectorList = selectorList; } - public SelectorList getSelectorList() { + public ArrayList<String> getSelectorList() { return selectorList; } - public void setSelectorList(SelectorList selectorList) { + public void setSelectorList(ArrayList<String> selectorList) { this.selectorList = selectorList; } public String toString(boolean indent) { StringBuilder string = new StringBuilder(); - string.append(SelectorUtil.toString(selectorList)); + for (final String s : selectorList) { + string.append(s); + if (selectorList.indexOf(s) != selectorList.size() - 1) { + string.append(", "); + } + } string.append(" {\n"); for (Node child : children) { if (indent) { @@ -67,52 +64,17 @@ public class BlockNode extends Node implements Clonable, IVariableNode { } @Override - public Object clone() throws CloneNotSupportedException { - - SelectorListImpl clonedSelectorList = null; - - if (selectorList != null) { - clonedSelectorList = new SelectorListImpl(); - for (int i = 0; i < selectorList.getLength(); i++) { - clonedSelectorList.addSelector(selectorList.item(i)); - } - } - final BlockNode clone = new BlockNode(clonedSelectorList); - for (Node child : getChildren()) { - clone.getChildren().add((Node) DeepCopy.copy(child)); - } - return clone; - } - - @Override public void replaceVariables(ArrayList<VariableNode> variables) { - SelectorListImpl newList = new SelectorListImpl(); - - if (selectorList != null) { - for (int i = 0; i < selectorList.getLength(); i++) { - Selector selector = selectorList.item(i); - for (final VariableNode node : variables) { - - if (SelectorUtil.toString(selector) - .contains(node.getName())) { - try { - selector = SelectorUtil - .createSelectorAndreplaceSelectorVariableWithValue( - selector, node.getName(), node - .getExpr().toString()); - break; - } catch (Exception e) { - e.printStackTrace(); - return; - } - } - } - newList.addSelector(selector); - } + } - selectorList = newList; + public String getSelectors() { + StringBuilder b = new StringBuilder(); + for (final String s : selectorList) { + b.append(s); } + + return b.toString(); } } diff --git a/theme-compiler/src/com/vaadin/sass/tree/ExtendNode.java b/theme-compiler/src/com/vaadin/sass/tree/ExtendNode.java index b70c20bcfe..909e69e12f 100644 --- a/theme-compiler/src/com/vaadin/sass/tree/ExtendNode.java +++ b/theme-compiler/src/com/vaadin/sass/tree/ExtendNode.java @@ -18,52 +18,31 @@ package com.vaadin.sass.tree; import java.util.ArrayList; -import org.w3c.css.sac.Selector; -import org.w3c.css.sac.SelectorList; - -import com.vaadin.sass.parser.SelectorListImpl; -import com.vaadin.sass.selector.SelectorUtil; - public class ExtendNode extends Node implements IVariableNode { private static final long serialVersionUID = 3301805078983796878L; - SelectorList list; + ArrayList<String> list; - public ExtendNode(SelectorList list) { + public ExtendNode(ArrayList<String> list) { super(); this.list = list; } - public SelectorList getList() { + public ArrayList<String> getList() { return list; } @Override public void replaceVariables(ArrayList<VariableNode> variables) { - SelectorListImpl newList = new SelectorListImpl(); - - for (int i = 0; i < list.getLength(); i++) { - Selector selector = list.item(i); - for (final VariableNode node : variables) { + } - if (SelectorUtil.toString(selector).contains(node.getName())) { - try { - selector = SelectorUtil - .createSelectorAndreplaceSelectorVariableWithValue( - selector, node.getName(), node - .getExpr().toString()); - break; - } catch (Exception e) { - e.printStackTrace(); - return; - } - } - } - newList.addSelector(selector); + public String getListAsString() { + StringBuilder b = new StringBuilder(); + for (final String s : list) { + b.append(s); } - list = newList; + return b.toString(); } - } diff --git a/theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java b/theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java new file mode 100644 index 0000000000..71c32a5c06 --- /dev/null +++ b/theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java @@ -0,0 +1,11 @@ +package com.vaadin.sass.tree; + +public interface ListModifyNode { + + public boolean isModifyingVariable(); + + public String getVariable(); + + 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 new file mode 100644 index 0000000000..9c6400ec02 --- /dev/null +++ b/theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java @@ -0,0 +1,114 @@ +package com.vaadin.sass.tree; + +import java.util.ArrayList; + +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; + + public ListRemoveNode(ArrayList<String> list, ArrayList<String> remove, + String separator) { + this.list = list; + this.remove = remove; + this.separator = separator; + } + + @Override + public boolean isModifyingVariable() { + if (list != null) { + return list.size() == 1 && list.get(0).startsWith("$"); + } + return false; + } + + @Override + public String getVariable() { + if (list != null && list.size() == 1) { + String string = list.get(0); + return string.substring(1, string.length()); + } + return null; + } + + @Override + public VariableNode getModifiedList(VariableNode variableNode) { + + 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; + } + + private boolean shouldInclude(LexicalUnitImpl current, + LexicalUnitImpl lastAccepted) { + + if (lastAccepted != null + && lastAccepted.getLexicalUnitType() == LexicalUnitImpl.SAC_OPERATOR_COMMA + && current.getLexicalUnitType() == LexicalUnitImpl.SAC_OPERATOR_COMMA) { + return false; + } + + String string = current.getValue().toString(); + for (final String s : remove) { + if (s.equals(string)) { + return false; + } + } + return true; + } + + @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; + } + + } +} diff --git a/theme-compiler/src/com/vaadin/sass/tree/MicrosoftRuleNode.java b/theme-compiler/src/com/vaadin/sass/tree/MicrosoftRuleNode.java new file mode 100644 index 0000000000..cbd3b14289 --- /dev/null +++ b/theme-compiler/src/com/vaadin/sass/tree/MicrosoftRuleNode.java @@ -0,0 +1,29 @@ +package com.vaadin.sass.tree; + +import java.util.ArrayList; + +public class MicrosoftRuleNode extends Node implements IVariableNode { + + private final String name; + private String value; + + public MicrosoftRuleNode(String name, String value) { + this.name = name; + this.value = value; + } + + @Override + public void replaceVariables(ArrayList<VariableNode> variables) { + for (final VariableNode var : variables) { + if (value.contains("$" + var.getName())) { + value = value.replaceAll("$" + var.getName(), var.getExpr() + .toString()); + } + } + } + + @Override + public String toString() { + return name + ": " + value + ";"; + } +} diff --git a/theme-compiler/src/com/vaadin/sass/tree/MixinDefNode.java b/theme-compiler/src/com/vaadin/sass/tree/MixinDefNode.java index a872d13654..6e8f689ed1 100644 --- a/theme-compiler/src/com/vaadin/sass/tree/MixinDefNode.java +++ b/theme-compiler/src/com/vaadin/sass/tree/MixinDefNode.java @@ -70,8 +70,8 @@ public class MixinDefNode extends Node implements IVariableNode { public void replaceVariables(ArrayList<VariableNode> variables) { for (final VariableNode var : variables) { for (final VariableNode arg : new ArrayList<VariableNode>(arglist)) { - - if (arg.getName().equals(var.getName())) { + if (arg.getName().equals(var.getName()) + && arg.getExpr() == null) { arglist.add(arglist.indexOf(arg), (VariableNode) DeepCopy.copy(var)); arglist.remove(arg); diff --git a/theme-compiler/src/com/vaadin/sass/tree/MixinNode.java b/theme-compiler/src/com/vaadin/sass/tree/MixinNode.java index 2b9299bbd1..205f20b500 100644 --- a/theme-compiler/src/com/vaadin/sass/tree/MixinNode.java +++ b/theme-compiler/src/com/vaadin/sass/tree/MixinNode.java @@ -19,20 +19,18 @@ package com.vaadin.sass.tree; import java.util.ArrayList; import java.util.Collection; -import org.w3c.css.sac.LexicalUnit; - import com.vaadin.sass.parser.LexicalUnitImpl; public class MixinNode extends Node implements IVariableNode { private static final long serialVersionUID = 4725008226813110658L; private String name; - private ArrayList<LexicalUnit> arglist; + private ArrayList<LexicalUnitImpl> arglist; - public MixinNode(String name, Collection<LexicalUnit> args) { + public MixinNode(String name, Collection<LexicalUnitImpl> args) { super(); this.name = name; - arglist = new ArrayList<LexicalUnit>(); + arglist = new ArrayList<LexicalUnitImpl>(); if (args != null && !args.isEmpty()) { arglist.addAll(args); } @@ -51,21 +49,22 @@ public class MixinNode extends Node implements IVariableNode { this.name = name; } - public ArrayList<LexicalUnit> getArglist() { + public ArrayList<LexicalUnitImpl> getArglist() { return arglist; } - public void setArglist(ArrayList<LexicalUnit> arglist) { + public void setArglist(ArrayList<LexicalUnitImpl> arglist) { this.arglist = arglist; } @Override public void replaceVariables(ArrayList<VariableNode> variables) { for (final VariableNode var : variables) { - for (final LexicalUnit arg : new ArrayList<LexicalUnit>(arglist)) { + for (final LexicalUnitImpl arg : new ArrayList<LexicalUnitImpl>( + arglist)) { if (arg.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE && arg.getStringValue().equals(var.getName())) { - ((LexicalUnitImpl) arg).replaceValue(var.getExpr()); + arg.replaceValue(var.getExpr()); } } } diff --git a/theme-compiler/src/com/vaadin/sass/tree/RuleNode.java b/theme-compiler/src/com/vaadin/sass/tree/RuleNode.java index fe52844979..ee8d8145f1 100644 --- a/theme-compiler/src/com/vaadin/sass/tree/RuleNode.java +++ b/theme-compiler/src/com/vaadin/sass/tree/RuleNode.java @@ -18,19 +18,17 @@ package com.vaadin.sass.tree; import java.util.ArrayList; -import org.w3c.css.sac.LexicalUnit; - import com.vaadin.sass.parser.LexicalUnitImpl; public class RuleNode extends Node implements IVariableNode { private static final long serialVersionUID = 6653493127869037022L; String variable; - LexicalUnit value; + LexicalUnitImpl value; String comment; private boolean important; - public RuleNode(String variable, LexicalUnit value, boolean important, + public RuleNode(String variable, LexicalUnitImpl value, boolean important, String comment) { this.variable = variable; this.value = value; @@ -46,11 +44,11 @@ public class RuleNode extends Node implements IVariableNode { this.variable = variable; } - public LexicalUnit getValue() { + public LexicalUnitImpl getValue() { return value; } - public void setValue(LexicalUnit value) { + public void setValue(LexicalUnitImpl value) { this.value = value; } @@ -84,25 +82,43 @@ public class RuleNode extends Node implements IVariableNode { @Override public void replaceVariables(ArrayList<VariableNode> variables) { for (final VariableNode node : variables) { - LexicalUnit current = value; - if (current.getLexicalUnitType() == LexicalUnitImpl.SAC_FUNCTION) { - if (current.getParameters().toString().contains(node.getName())) { - LexicalUnit param = value.getParameters(); - if (param != null) { - if (param.toString().contains(node.getName())) { - ((LexicalUnitImpl) param).replaceValue(node - .getExpr()); + if (value.getLexicalUnitType() == LexicalUnitImpl.SAC_FUNCTION) { + if (value.getParameters().toString().contains(node.getName())) { + if (value.getParameters() != null) { + if (value.getParameters().toString() + .contains("$" + node.getName())) { + + LexicalUnitImpl param = value.getParameters(); + while (param != null) { + if (param.getValue().toString() + .contains(node.getName())) { + + LexicalUnitImpl expr = node.getExpr(); + + LexicalUnitImpl prev = param + .getPreviousLexicalUnit(); + LexicalUnitImpl next = param + .getNextLexicalUnit(); + + if (param.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE) { + param.replaceValue(expr); + param.setPrevLexicalUnit(prev); + param.setNextLexicalUnit(next); + } + } + param = param.getNextLexicalUnit(); + } } } } } else { + LexicalUnitImpl current = value; while (current != null) { if (current.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE - && current.toString() - .contains("$" + node.getName())) { + && current.getValue().toString() + .equals(node.getName())) { - ((LexicalUnitImpl) current) - .replaceValue(node.getExpr()); + current.replaceValue(node.getExpr()); } current = current.getNextLexicalUnit(); } diff --git a/theme-compiler/src/com/vaadin/sass/tree/VariableNode.java b/theme-compiler/src/com/vaadin/sass/tree/VariableNode.java index b7e9a21d51..ffe6b77896 100644 --- a/theme-compiler/src/com/vaadin/sass/tree/VariableNode.java +++ b/theme-compiler/src/com/vaadin/sass/tree/VariableNode.java @@ -27,27 +27,32 @@ public class VariableNode extends Node implements IVariableNode { private static final long serialVersionUID = 7003372557547748734L; private String name; - private LexicalUnit expr; + private LexicalUnitImpl expr; private boolean guarded; - public VariableNode(String name, LexicalUnit expr, boolean guarded) { + public VariableNode(String name, LexicalUnitImpl expr, boolean guarded) { super(); this.name = name; this.expr = expr; this.guarded = guarded; + checkSeparators(); } - public VariableNode(String name, String raw) { - super(raw); - this.name = name; - } - - public LexicalUnit getExpr() { + public LexicalUnitImpl getExpr() { return expr; } - public void setExpr(LexicalUnit expr) { + public void setExpr(LexicalUnitImpl expr) { this.expr = expr; + checkSeparators(); + } + + private void checkSeparators() { + if (expr != null) { + if (expr.toString().contains(",")) { + + } + } } public String getName() { @@ -75,7 +80,7 @@ public class VariableNode extends Node implements IVariableNode { if (!this.equals(node)) { if (name.equals(node.getName())) { - expr = (LexicalUnit) DeepCopy.copy(node.getExpr()); + expr = (LexicalUnitImpl) DeepCopy.copy(node.getExpr()); guarded = node.isGuarded(); continue; } @@ -93,19 +98,4 @@ public class VariableNode extends Node implements IVariableNode { } } } - - public boolean replacePossibleVariables(ArrayList<VariableNode> list) { - list.remove(this); - LexicalUnit oldExpr = (LexicalUnit) DeepCopy.copy(expr); - replaceVariables(list); - - if (!oldExpr.toString().equals(expr.toString())) { - for (VariableNode n : list) { - if (expr.toString().equals(n.getExpr().toString())) { - return true; - } - } - } - return false; - } } diff --git a/theme-compiler/src/com/vaadin/sass/tree/controldirective/EachDefNode.java b/theme-compiler/src/com/vaadin/sass/tree/controldirective/EachDefNode.java index 2cb9aeb1c3..f75d5ed7b5 100644 --- a/theme-compiler/src/com/vaadin/sass/tree/controldirective/EachDefNode.java +++ b/theme-compiler/src/com/vaadin/sass/tree/controldirective/EachDefNode.java @@ -19,20 +19,30 @@ package com.vaadin.sass.tree.controldirective; import java.util.ArrayList; import java.util.List; +import com.vaadin.sass.parser.LexicalUnitImpl; +import com.vaadin.sass.tree.IVariableNode; import com.vaadin.sass.tree.Node; +import com.vaadin.sass.tree.VariableNode; -public class EachDefNode extends Node { +public class EachDefNode extends Node implements IVariableNode { private static final long serialVersionUID = 7943948981204906221L; private String var; private ArrayList<String> list; + private String listVariable; + public EachDefNode(String var, ArrayList<String> list) { super(); this.var = var; this.list = list; } + public EachDefNode(String var, String listVariable) { + this.var = var; + this.listVariable = listVariable; + } + public List<String> getVariables() { return list; } @@ -46,4 +56,37 @@ public class EachDefNode extends Node { return "Each Definition Node: {variable : " + var + ", " + "children : " + list.size() + "}"; } + + public boolean hasListVariable() { + return listVariable != null; + } + + @Override + public void replaceVariables(ArrayList<VariableNode> variables) { + if (listVariable != null) { + for (final VariableNode var : variables) { + if (listVariable.equals(var.getName())) { + + LexicalUnitImpl current = (LexicalUnitImpl) var.getExpr(); + list = new ArrayList<String>(); + + while (current != null) { + if (current.getValue() != null + && current.getLexicalUnitType() != LexicalUnitImpl.SAC_OPERATOR_COMMA) { + list.add(current.getValue().toString()); + } + current = (LexicalUnitImpl) current + .getNextLexicalUnit(); + } + listVariable = null; + break; + } + } + + } + } + + public String getListVariable() { + return listVariable; + } } |