summaryrefslogtreecommitdiffstats
path: root/theme-compiler/src/com/vaadin
diff options
context:
space:
mode:
authorSebastian Nyholm <sebastian@vaadin.com>2012-10-22 11:11:04 +0300
committerSebastian Nyholm <sebastian@vaadin.com>2012-11-08 17:16:10 +0200
commita0da163fd5c23f1d961fc5c686efd6ffc50ecd61 (patch)
tree093e40a12de854d48920335b67b08144b98556bf /theme-compiler/src/com/vaadin
parente8ae9f7d6427f7f6daae300dee7931a6e8394bdb (diff)
downloadvaadin-framework-a0da163fd5c23f1d961fc5c686efd6ffc50ecd61.tar.gz
vaadin-framework-a0da163fd5c23f1d961fc5c686efd6ffc50ecd61.zip
Fixes #9546, #9974, #10100, #10105
Change-Id: I1baccb5604899707960b1cf06887ada0fe217d08
Diffstat (limited to 'theme-compiler/src/com/vaadin')
-rw-r--r--theme-compiler/src/com/vaadin/sass/ScssStylesheet.java126
-rw-r--r--theme-compiler/src/com/vaadin/sass/parser/MediaListImpl.java8
-rw-r--r--theme-compiler/src/com/vaadin/sass/parser/Parser.java292
-rw-r--r--theme-compiler/src/com/vaadin/sass/parser/Parser.jj8
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/BlockNode.java33
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/CommentNode.java5
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/ExtendNode.java12
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/FontFaceNode.java5
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/ForNode.java5
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/FunctionNode.java7
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/ImportNode.java9
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/InterpolationNode.java7
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java8
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java21
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/MediaNode.java5
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/MicrosoftRuleNode.java7
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/MixinDefNode.java12
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/MixinNode.java23
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/NestPropertiesNode.java11
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/Node.java50
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/RuleNode.java95
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/SimpleNode.java7
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/VariableNode.java8
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/WhileNode.java5
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/controldirective/EachDefNode.java8
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/controldirective/ElseNode.java5
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/controldirective/IfElseDefNode.java14
-rw-r--r--theme-compiler/src/com/vaadin/sass/tree/controldirective/IfNode.java13
-rw-r--r--theme-compiler/src/com/vaadin/sass/visitor/BlockNodeHandler.java63
-rw-r--r--theme-compiler/src/com/vaadin/sass/visitor/BlockVisitor.java75
-rw-r--r--theme-compiler/src/com/vaadin/sass/visitor/EachNodeHandler.java57
-rw-r--r--theme-compiler/src/com/vaadin/sass/visitor/EachVisitor.java72
-rw-r--r--theme-compiler/src/com/vaadin/sass/visitor/ExtendNodeHandler.java (renamed from theme-compiler/src/com/vaadin/sass/visitor/ExtendVisitor.java)49
-rw-r--r--theme-compiler/src/com/vaadin/sass/visitor/IfElseNodeHandler.java102
-rw-r--r--theme-compiler/src/com/vaadin/sass/visitor/IfElseVisitor.java122
-rw-r--r--theme-compiler/src/com/vaadin/sass/visitor/ImportNodeHandler.java (renamed from theme-compiler/src/com/vaadin/sass/visitor/ImportVisitor.java)26
-rw-r--r--theme-compiler/src/com/vaadin/sass/visitor/ListModifyVisitor.java27
-rw-r--r--theme-compiler/src/com/vaadin/sass/visitor/MixinNodeHandler.java (renamed from theme-compiler/src/com/vaadin/sass/visitor/MixinVisitor.java)65
-rw-r--r--theme-compiler/src/com/vaadin/sass/visitor/NestedNodeHandler.java (renamed from theme-compiler/src/com/vaadin/sass/visitor/NestPropertiesVisitor.java)24
-rw-r--r--theme-compiler/src/com/vaadin/sass/visitor/ParentSelectorHandler.java69
-rw-r--r--theme-compiler/src/com/vaadin/sass/visitor/ParentSelectorVisitor.java60
-rw-r--r--theme-compiler/src/com/vaadin/sass/visitor/VariableNodeHandler.java32
-rw-r--r--theme-compiler/src/com/vaadin/sass/visitor/VariableVisitor.java94
43 files changed, 905 insertions, 841 deletions
diff --git a/theme-compiler/src/com/vaadin/sass/ScssStylesheet.java b/theme-compiler/src/com/vaadin/sass/ScssStylesheet.java
index d0b4b732ea..45578deb19 100644
--- a/theme-compiler/src/com/vaadin/sass/ScssStylesheet.java
+++ b/theme-compiler/src/com/vaadin/sass/ScssStylesheet.java
@@ -20,7 +20,9 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.InputSource;
@@ -31,24 +33,27 @@ import com.vaadin.sass.handler.SCSSErrorHandler;
import com.vaadin.sass.parser.Parser;
import com.vaadin.sass.resolver.ScssStylesheetResolver;
import com.vaadin.sass.resolver.VaadinResolver;
+import com.vaadin.sass.tree.MixinDefNode;
import com.vaadin.sass.tree.Node;
import com.vaadin.sass.tree.VariableNode;
-import com.vaadin.sass.visitor.BlockVisitor;
-import com.vaadin.sass.visitor.EachVisitor;
-import com.vaadin.sass.visitor.ExtendVisitor;
-import com.vaadin.sass.visitor.IfElseVisitor;
-import com.vaadin.sass.visitor.ImportVisitor;
-import com.vaadin.sass.visitor.ListModifyVisitor;
-import com.vaadin.sass.visitor.MixinVisitor;
-import com.vaadin.sass.visitor.NestPropertiesVisitor;
-import com.vaadin.sass.visitor.ParentSelectorVisitor;
-import com.vaadin.sass.visitor.VariableVisitor;
-import com.vaadin.sass.visitor.Visitor;
+import com.vaadin.sass.tree.controldirective.IfElseDefNode;
+import com.vaadin.sass.visitor.ImportNodeHandler;
+import com.vaadin.sass.visitor.ParentSelectorHandler;
public class ScssStylesheet extends Node {
private static final long serialVersionUID = 3849790204404961608L;
+ private static ScssStylesheet mainStyleSheet = null;
+
+ private static final HashMap<String, VariableNode> variables = new HashMap<String, VariableNode>();
+
+ private static final Map<String, MixinDefNode> mixinDefs = new HashMap<String, MixinDefNode>();
+
+ private static final HashSet<IfElseDefNode> ifElseDefNodes = new HashSet<IfElseDefNode>();
+
+ private String fileName;
+
/**
* Read in a file SCSS and parse it into a ScssStylesheet
*
@@ -121,20 +126,32 @@ public class ScssStylesheet extends Node {
* @throws Exception
*/
public void compile() throws Exception {
- List<Visitor> visitors = new ArrayList<Visitor>();
- visitors.add(new ImportVisitor());
- visitors.add(new VariableVisitor());
- visitors.add(new MixinVisitor());
- visitors.add(new IfElseVisitor());
- visitors.add(new ParentSelectorVisitor());
- visitors.add(new BlockVisitor());
- visitors.add(new NestPropertiesVisitor());
- visitors.add(new ExtendVisitor());
- visitors.add(new EachVisitor());
- visitors.add(new ListModifyVisitor());
- for (Visitor visitor : visitors) {
- visitor.traverse(this);
+ mainStyleSheet = this;
+ mixinDefs.clear();
+ variables.clear();
+ ifElseDefNodes.clear();
+ ParentSelectorHandler.clear();
+ importOtherFiles(this);
+ populateDefinitions(this);
+ traverse(this);
+ }
+
+ private void importOtherFiles(ScssStylesheet node) {
+ ImportNodeHandler.traverse(node);
+ }
+
+ private void populateDefinitions(Node node) {
+ if (node instanceof MixinDefNode) {
+ mixinDefs.put(((MixinDefNode) node).getName(), (MixinDefNode) node);
+ node.getParentNode().removeChild(node);
+ } else if (node instanceof IfElseDefNode) {
+ ifElseDefNodes.add((IfElseDefNode) node);
+ }
+
+ for (final Node child : new ArrayList<Node>(node.getChildren())) {
+ populateDefinitions(child);
}
+
}
/**
@@ -169,4 +186,63 @@ public class ScssStylesheet extends Node {
}
}
+ public static ScssStylesheet get() {
+ return mainStyleSheet;
+ }
+
+ @Override
+ public void traverse() {
+ // Not used for ScssStylesheet
+ }
+
+ public void traverse(Node node) {
+ node.traverse();
+
+ @SuppressWarnings("unchecked")
+ HashMap<String, VariableNode> variableScope = (HashMap<String, VariableNode>) variables
+ .clone();
+
+ int maxSize = node.getChildren().size();
+ ArrayList<Node> oldChildren = new ArrayList<Node>(node.getChildren());
+ for (int i = 0; i < maxSize; i++) {
+
+ Node current = node.getChildren().get(i);
+ traverse(current);
+
+ if (!node.getChildren().equals(oldChildren)) {
+ oldChildren = new ArrayList<Node>(node.getChildren());
+ maxSize = node.getChildren().size();
+ i = i - 1;
+ }
+
+ }
+
+ variables.clear();
+ variables.putAll(variableScope);
+ }
+
+ public static void addVariable(VariableNode node) {
+ variables.put(node.getName(), node);
+ }
+
+ public static VariableNode getVariable(String string) {
+ return variables.get(string);
+ }
+
+ public static ArrayList<VariableNode> getVariables() {
+ return new ArrayList<VariableNode>(variables.values());
+ }
+
+ public static MixinDefNode getMixinDefinition(String name) {
+ return mixinDefs.get(name);
+ }
+
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
}
diff --git a/theme-compiler/src/com/vaadin/sass/parser/MediaListImpl.java b/theme-compiler/src/com/vaadin/sass/parser/MediaListImpl.java
index 042e385cb3..bb321ea3cd 100644
--- a/theme-compiler/src/com/vaadin/sass/parser/MediaListImpl.java
+++ b/theme-compiler/src/com/vaadin/sass/parser/MediaListImpl.java
@@ -8,14 +8,20 @@
*/
package com.vaadin.sass.parser;
+import java.io.Serializable;
+
import org.w3c.css.sac.SACMediaList;
/**
* @version $Revision: 1.4 $
* @author Philippe Le Hegaret
*/
-public class MediaListImpl implements SACMediaList {
+public class MediaListImpl implements SACMediaList, Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
String[] array = new String[10];
int current;
diff --git a/theme-compiler/src/com/vaadin/sass/parser/Parser.java b/theme-compiler/src/com/vaadin/sass/parser/Parser.java
index 33411bd57d..996a15d9c8 100644
--- a/theme-compiler/src/com/vaadin/sass/parser/Parser.java
+++ b/theme-compiler/src/com/vaadin/sass/parser/Parser.java
@@ -3427,6 +3427,13 @@ boolean isPseudoElement = false;
case IDENT:
name = property();
break;
+ case VARIABLE:
+ name = variableName();
+ name = "$"+name;
+ break;
+ case INTERPOLATION:
+ name = interpolation();
+ break;
case FUNCTION:
name = functionName();
args = argValuelist();
@@ -3464,6 +3471,13 @@ boolean isPseudoElement = false;
documentHandler.includeDirective(name, args);
}
+ final public String interpolation() throws ParseException {
+ Token n;
+ n = jj_consume_token(INTERPOLATION);
+ {if (true) return n.image;}
+ throw new Error("Missing return statement in function");
+ }
+
final public void listModifyDirective() throws ParseException {
if (jj_2_12(5)) {
removeDirective();
@@ -5648,26 +5662,6 @@ LexicalUnitImpl result = null;
finally { jj_save(14, xla); }
}
- private boolean jj_3R_205() {
- if (jj_scan_token(DEG)) return true;
- return false;
- }
-
- private boolean jj_3R_204() {
- if (jj_scan_token(EXS)) return true;
- return false;
- }
-
- private boolean jj_3R_203() {
- if (jj_scan_token(EMS)) return true;
- return false;
- }
-
- private boolean jj_3_1() {
- if (jj_3R_156()) return true;
- return false;
- }
-
private boolean jj_3R_202() {
if (jj_scan_token(PX)) return true;
return false;
@@ -5683,6 +5677,11 @@ LexicalUnitImpl result = null;
return false;
}
+ private boolean jj_3_1() {
+ if (jj_3R_156()) return true;
+ return false;
+ }
+
private boolean jj_3R_199() {
if (jj_scan_token(MM)) return true;
return false;
@@ -5708,22 +5707,11 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3_4() {
- if (jj_3R_159()) return true;
- if (jj_3R_160()) return true;
- return false;
- }
-
private boolean jj_3R_185() {
if (jj_3R_221()) return true;
return false;
}
- private boolean jj_3_7() {
- if (jj_3R_156()) return true;
- return false;
- }
-
private boolean jj_3R_195() {
if (jj_scan_token(NUMBER)) return true;
return false;
@@ -5734,16 +5722,6 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3R_191() {
- if (jj_scan_token(COLON)) return true;
- return false;
- }
-
- private boolean jj_3_6() {
- if (jj_3R_161()) return true;
- return false;
- }
-
private boolean jj_3R_181() {
Token xsp;
xsp = jj_scanpos;
@@ -5807,6 +5785,12 @@ LexicalUnitImpl result = null;
return false;
}
+ private boolean jj_3_4() {
+ if (jj_3R_159()) return true;
+ if (jj_3R_160()) return true;
+ return false;
+ }
+
private boolean jj_3R_179() {
if (jj_3R_193()) return true;
return false;
@@ -5826,6 +5810,21 @@ LexicalUnitImpl result = null;
return false;
}
+ private boolean jj_3_7() {
+ if (jj_3R_156()) return true;
+ return false;
+ }
+
+ private boolean jj_3R_191() {
+ if (jj_scan_token(COLON)) return true;
+ return false;
+ }
+
+ private boolean jj_3_6() {
+ if (jj_3R_161()) return true;
+ return false;
+ }
+
private boolean jj_3R_161() {
if (jj_3R_178()) return true;
if (jj_scan_token(COLON)) return true;
@@ -5873,21 +5872,11 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3_5() {
- if (jj_3R_161()) return true;
- return false;
- }
-
private boolean jj_3_14() {
if (jj_3R_166()) return true;
return false;
}
- private boolean jj_3_2() {
- if (jj_3R_156()) return true;
- return false;
- }
-
private boolean jj_3R_240() {
if (jj_scan_token(URL)) return true;
return false;
@@ -5908,11 +5897,21 @@ LexicalUnitImpl result = null;
return false;
}
+ private boolean jj_3_5() {
+ if (jj_3R_161()) return true;
+ return false;
+ }
+
private boolean jj_3R_167() {
if (jj_3R_183()) return true;
return false;
}
+ private boolean jj_3_2() {
+ if (jj_3R_156()) return true;
+ return false;
+ }
+
private boolean jj_3R_164() {
if (jj_scan_token(VARIABLE)) return true;
Token xsp;
@@ -5977,11 +5976,6 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3R_248() {
- if (jj_scan_token(INTERPOLATION)) return true;
- return false;
- }
-
private boolean jj_3R_241() {
if (jj_scan_token(UNICODERANGE)) return true;
return false;
@@ -5992,11 +5986,6 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3_10() {
- if (jj_3R_161()) return true;
- return false;
- }
-
private boolean jj_3R_165() {
if (jj_scan_token(VARIABLE)) return true;
Token xsp;
@@ -6018,13 +6007,8 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3R_192() {
- if (jj_scan_token(LBRACKET)) return true;
- return false;
- }
-
- private boolean jj_3R_158() {
- if (jj_3R_161()) return true;
+ private boolean jj_3R_248() {
+ if (jj_scan_token(INTERPOLATION)) return true;
return false;
}
@@ -6038,16 +6022,6 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3R_178() {
- if (jj_scan_token(IDENT)) return true;
- Token xsp;
- while (true) {
- xsp = jj_scanpos;
- if (jj_scan_token(1)) { jj_scanpos = xsp; break; }
- }
- return false;
- }
-
private boolean jj_3R_237() {
if (jj_scan_token(FUNCTION)) return true;
Token xsp;
@@ -6061,13 +6035,8 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3R_242() {
- if (jj_scan_token(VARIABLE)) return true;
- Token xsp;
- while (true) {
- xsp = jj_scanpos;
- if (jj_scan_token(1)) { jj_scanpos = xsp; break; }
- }
+ private boolean jj_3_10() {
+ if (jj_3R_161()) return true;
return false;
}
@@ -6091,13 +6060,23 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3R_235() {
- if (jj_scan_token(PARENT)) return true;
+ private boolean jj_3R_192() {
+ if (jj_scan_token(LBRACKET)) return true;
return false;
}
- private boolean jj_3R_234() {
- if (jj_scan_token(ANY)) return true;
+ private boolean jj_3R_158() {
+ if (jj_3R_161()) return true;
+ return false;
+ }
+
+ private boolean jj_3R_178() {
+ if (jj_scan_token(IDENT)) return true;
+ Token xsp;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_scan_token(1)) { jj_scanpos = xsp; break; }
+ }
return false;
}
@@ -6106,6 +6085,16 @@ LexicalUnitImpl result = null;
return false;
}
+ private boolean jj_3R_242() {
+ if (jj_scan_token(VARIABLE)) return true;
+ Token xsp;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_scan_token(1)) { jj_scanpos = xsp; break; }
+ }
+ return false;
+ }
+
private boolean jj_3R_217() {
if (jj_3R_240()) return true;
return false;
@@ -6129,6 +6118,21 @@ LexicalUnitImpl result = null;
return false;
}
+ private boolean jj_3R_216() {
+ if (jj_3R_239()) return true;
+ return false;
+ }
+
+ private boolean jj_3R_235() {
+ if (jj_scan_token(PARENT)) return true;
+ return false;
+ }
+
+ private boolean jj_3R_234() {
+ if (jj_scan_token(ANY)) return true;
+ return false;
+ }
+
private boolean jj_3R_247() {
if (jj_scan_token(IDENT)) return true;
return false;
@@ -6144,11 +6148,6 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3R_216() {
- if (jj_3R_239()) return true;
- return false;
- }
-
private boolean jj_3R_233() {
Token xsp;
if (jj_3R_243()) return true;
@@ -6294,11 +6293,24 @@ LexicalUnitImpl result = null;
return false;
}
+ private boolean jj_3R_238() {
+ if (jj_scan_token(DOT)) return true;
+ return false;
+ }
+
private boolean jj_3R_232() {
if (jj_scan_token(PRECEDES)) return true;
return false;
}
+ private boolean jj_3R_215() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_238()) jj_scanpos = xsp;
+ if (jj_scan_token(IDENT)) return true;
+ return false;
+ }
+
private boolean jj_3R_231() {
if (jj_scan_token(PLUS)) return true;
return false;
@@ -6319,6 +6331,11 @@ LexicalUnitImpl result = null;
return false;
}
+ private boolean jj_3R_214() {
+ if (jj_scan_token(STRING)) return true;
+ return false;
+ }
+
private boolean jj_3R_171() {
if (jj_scan_token(PRECEDES)) return true;
Token xsp;
@@ -6329,16 +6346,27 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3R_238() {
- if (jj_scan_token(DOT)) return true;
+ private boolean jj_3R_213() {
+ if (jj_3R_237()) return true;
return false;
}
- private boolean jj_3R_215() {
+ private boolean jj_3R_182() {
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_238()) jj_scanpos = xsp;
- if (jj_scan_token(IDENT)) return true;
+ if (jj_3R_214()) {
+ jj_scanpos = xsp;
+ if (jj_3R_215()) {
+ jj_scanpos = xsp;
+ if (jj_3R_216()) {
+ jj_scanpos = xsp;
+ if (jj_3R_217()) {
+ jj_scanpos = xsp;
+ if (jj_3R_218()) return true;
+ }
+ }
+ }
+ }
return false;
}
@@ -6381,37 +6409,23 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3R_214() {
- if (jj_scan_token(STRING)) return true;
+ private boolean jj_3R_212() {
+ if (jj_scan_token(DIMEN)) return true;
return false;
}
- private boolean jj_3R_213() {
- if (jj_3R_237()) return true;
+ private boolean jj_3R_211() {
+ if (jj_scan_token(KHZ)) return true;
return false;
}
- private boolean jj_3R_182() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_214()) {
- jj_scanpos = xsp;
- if (jj_3R_215()) {
- jj_scanpos = xsp;
- if (jj_3R_216()) {
- jj_scanpos = xsp;
- if (jj_3R_217()) {
- jj_scanpos = xsp;
- if (jj_3R_218()) return true;
- }
- }
- }
- }
+ private boolean jj_3R_210() {
+ if (jj_scan_token(HZ)) return true;
return false;
}
- private boolean jj_3R_212() {
- if (jj_scan_token(DIMEN)) return true;
+ private boolean jj_3R_209() {
+ if (jj_scan_token(MS)) return true;
return false;
}
@@ -6420,13 +6434,13 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3R_176() {
- if (jj_3R_191()) return true;
+ private boolean jj_3R_208() {
+ if (jj_scan_token(SECOND)) return true;
return false;
}
- private boolean jj_3R_211() {
- if (jj_scan_token(KHZ)) return true;
+ private boolean jj_3R_176() {
+ if (jj_3R_191()) return true;
return false;
}
@@ -6435,8 +6449,8 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3R_210() {
- if (jj_scan_token(HZ)) return true;
+ private boolean jj_3R_207() {
+ if (jj_scan_token(GRAD)) return true;
return false;
}
@@ -6450,18 +6464,18 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3R_209() {
- if (jj_scan_token(MS)) return true;
+ private boolean jj_3R_206() {
+ if (jj_scan_token(RAD)) return true;
return false;
}
- private boolean jj_3R_173() {
- if (jj_3R_188()) return true;
+ private boolean jj_3R_205() {
+ if (jj_scan_token(DEG)) return true;
return false;
}
- private boolean jj_3R_208() {
- if (jj_scan_token(SECOND)) return true;
+ private boolean jj_3R_173() {
+ if (jj_3R_188()) return true;
return false;
}
@@ -6489,13 +6503,13 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3R_207() {
- if (jj_scan_token(GRAD)) return true;
+ private boolean jj_3R_204() {
+ if (jj_scan_token(EXS)) return true;
return false;
}
- private boolean jj_3R_206() {
- if (jj_scan_token(RAD)) return true;
+ private boolean jj_3R_203() {
+ if (jj_scan_token(EMS)) return true;
return false;
}
@@ -6524,10 +6538,10 @@ LexicalUnitImpl result = null;
jj_la1_0 = new int[] {0x0,0xc02,0xc02,0x0,0xc00,0x2,0x2,0x2,0x0,0xe8000000,0xc00,0x2,0xc00,0x2,0x0,0x2,0x0,0x2,0x2,0x2,0xe9f45400,0xe9f45400,0x2,0x400000,0x2,0x2,0x2,0x2,0x0,0x0,0x2,0x0,0x800000,0x2,0x0,0x2,0x2,0x2,0x2,0x0,0x800000,0x2,0x0,0x2,0x1f45400,0x2,0x2,0x1100000,0x2,0x1100000,0x1100002,0x2,0x80080002,0x80080002,0x2,0x2,0x2,0x2,0x2,0xe8000000,0x0,0x0,0x0,0xe8000000,0x2,0x400000,0x2,0x2,0x88000000,0x88000000,0x88000000,0x88000000,0x88000000,0x88000000,0x88000000,0x88000000,0x88000000,0x88000000,0xe8000000,0x0,0x0,0x0,0x0,0x60000000,0x2,0x2,0xfc000,0x2,0x0,0x2,0xfc000,0x0,0x2,0x2,0x0,0x2,0x0,0x2,0x800000,0x27380002,0x2,0xe8000000,0x0,0xe8000000,0x2,0x0,0x2,0x27380002,0x0,0x2,0xe8000000,0x0,0xe8000000,0x2,0x27380002,0x2,0x2,0x2,0x0,0x2,0xe8000000,0x0,0x0,0xe8000000,0x2,0x2,0x400000,0x2,0x2,0x2,0x2,0x0,0x2,0xe8000000,0x0,0x0,0xe8000000,0x2,0x400000,0x2,0x2,0x2,0x400000,0x0,0x0,0x80300000,0x2,0x0,0x400000,0x2,0x80300000,0x2,0x0,0x2,0x0,0x2,0x800000,0x2,0x2,0x2,0x0,0x2,0x2,0x2,0x400000,0x2,0x2,0x2,0x2,0x2,0x0,0x2,0x2,0x2,0x400000,0x2,0x2,0x2,0x2,0x2,0x0,0x2,0x2,0x2,0x400000,0x2,0x2,0x0,0x2,0x2,0x2,0x800000,0x2,0x2,0x0,0x800000,0x2,0x0,0x2,0x2,0x0,0x2,0x0,0x800000,0x2,0x0,0x2,0x80301000,0x2,0x0,0x2,0x2,0x2,0x2,0x4400000,0x4400000,0x300000,0x80300000,0x300000,0x0,0x80000000,0x80000000,0x80300000,0x2,0x2,0x80300000,0x2,0xe8000000,0x2,0x2,0x2,0x0,0x800000,0x2,0x0,0x2,};
}
private static void jj_la1_init_1() {
- jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x283000c0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1c0,0x1c0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x100,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc2,0xc2,0x0,0x0,0x0,0x0,0x0,0xa82000c0,0x0,0x20000000,0x88200000,0xc0,0x0,0x0,0x0,0x0,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xc0,0x80,0x80,0x80,0x80,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3f,0x0,0x802000c0,0x80200000,0xc0,0x0,0x40000000,0x0,0x3f,0x0,0x0,0x802000c0,0x80200000,0xc0,0x0,0x3f,0x0,0x0,0x0,0x0,0x0,0x802000c0,0x200000,0x80000000,0xc0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x882000c0,0x200000,0x88000000,0xc0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x40,0x40,0x0,0x40,0x0,0x0,0x40,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x60000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,};
+ jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x283000c0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1c0,0x1c0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x100,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc2,0xc2,0x0,0x0,0x0,0x0,0x0,0xa82000c0,0x0,0x20000000,0x88200000,0xc0,0x0,0x0,0x0,0x0,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xc0,0x80,0x80,0x80,0x80,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3f,0x0,0x802000c0,0x80200000,0xc0,0x0,0x40000000,0x0,0x3f,0x0,0x0,0x802000c0,0x80200000,0xc0,0x0,0x3f,0x0,0x0,0x0,0x0,0x0,0x802000c0,0x200000,0x80000000,0xc0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x882000c0,0x200000,0x88000000,0xc0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x40,0x40,0x0,0x40,0x0,0x0,0x40,0x0,0x40,0x0,0x80,0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x60000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,};
}
private static void jj_la1_init_2() {
- jj_la1_2 = new int[] {0x80000000,0x0,0x0,0x20000000,0x0,0x0,0x0,0x0,0x400,0x50000440,0x0,0x0,0x0,0x0,0x220,0x0,0x40,0x0,0x0,0x0,0xf0000ae0,0xf0000ae0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0xe0000aa0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc0,0xc0,0x0,0x0,0x0,0x0,0x0,0x50000444,0x44,0x0,0x40000400,0x10000040,0x0,0x0,0x0,0x0,0x10000000,0x10000000,0x0,0x0,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000040,0x40,0x40,0x40,0x40,0x40,0x0,0x0,0x0,0x0,0x60,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x10,0x0,0x0,0x4c0,0x0,0x50000440,0x40000400,0x10000040,0x0,0x0,0x0,0x4c0,0x8,0x0,0x50000440,0x40000400,0x10000040,0x0,0x4c0,0x0,0x0,0x0,0x440,0x0,0x50000440,0x0,0x40000400,0x10000040,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x50000440,0x40000000,0x400,0x10000040,0x0,0x0,0x0,0x0,0x0,0x0,0x400,0x400,0x1ffffee0,0x0,0x0,0x0,0x0,0x1ffffee0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0x1ffffee0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1ffffee0,0x0,0xffff880,0x0,0x10000260,0x1ffffae0,0x0,0x0,0x1ffffee0,0x0,0x70000040,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,};
+ jj_la1_2 = new int[] {0x80000000,0x0,0x0,0x20000000,0x0,0x0,0x0,0x0,0x400,0x50000440,0x0,0x0,0x0,0x0,0x220,0x0,0x40,0x0,0x0,0x0,0xf0000ae0,0xf0000ae0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0xe0000aa0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc0,0xc0,0x0,0x0,0x0,0x0,0x0,0x50000444,0x44,0x0,0x40000400,0x10000040,0x0,0x0,0x0,0x0,0x10000000,0x10000000,0x0,0x0,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000040,0x40,0x40,0x40,0x40,0x40,0x0,0x0,0x0,0x0,0x60,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x10,0x0,0x0,0x4c0,0x0,0x50000440,0x40000400,0x10000040,0x0,0x0,0x0,0x4c0,0x8,0x0,0x50000440,0x40000400,0x10000040,0x0,0x4c0,0x0,0x0,0x0,0x440,0x0,0x50000440,0x0,0x40000400,0x10000040,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x50000440,0x40000000,0x400,0x10000040,0x0,0x0,0x0,0x0,0x0,0x0,0x400,0x400,0x1ffffee0,0x0,0x0,0x0,0x0,0x1ffffee0,0x0,0x0,0x0,0x440,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0x1ffffee0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1ffffee0,0x0,0xffff880,0x0,0x10000260,0x1ffffae0,0x0,0x0,0x1ffffee0,0x0,0x70000040,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,};
}
private static void jj_la1_init_3() {
jj_la1_3 = new int[] {0x0,0x4,0x4,0x0,0x4,0x0,0x0,0x0,0x0,0x3,0x4,0x0,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x6200f,0x6200f,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x6200f,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x20000,0x20000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x20000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x20000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x22000,0x0,0x0,0x0,0x0,0x22000,0x0,0x0,0x0,0x20000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x22000,0x0,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x22000,0x0,0x20000,0x0,0x2000,0x22000,0x0,0x0,0x22000,0x0,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,};
diff --git a/theme-compiler/src/com/vaadin/sass/parser/Parser.jj b/theme-compiler/src/com/vaadin/sass/parser/Parser.jj
index 92cb3e46c1..af53edb482 100644
--- a/theme-compiler/src/com/vaadin/sass/parser/Parser.jj
+++ b/theme-compiler/src/com/vaadin/sass/parser/Parser.jj
@@ -1576,12 +1576,18 @@ void includeDirective() :
{
<INCLUDE_SYM>
(<S>)*
- (name = property()
+ (name = property()|name = variableName(){ name = "$"+name;}|name = interpolation()
|(name = functionName()
args = argValuelist()) <RPARAN>)(";"(<S>)*)+
{documentHandler.includeDirective(name, args);}
}
+String interpolation() :
+{
+ Token n; } {
+ n = < INTERPOLATION >
+ {
+ return n.image; } }
void listModifyDirective() : {
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/BlockNode.java b/theme-compiler/src/com/vaadin/sass/tree/BlockNode.java
index 5a64a928db..07e4c69ed7 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/BlockNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/BlockNode.java
@@ -18,7 +18,11 @@ package com.vaadin.sass.tree;
import java.util.ArrayList;
-public class BlockNode extends Node implements IVariableNode, InterpolationNode {
+import com.vaadin.sass.ScssStylesheet;
+import com.vaadin.sass.visitor.BlockNodeHandler;
+import com.vaadin.sass.visitor.ParentSelectorHandler;
+
+public class BlockNode extends Node implements IVariableNode {
private static final long serialVersionUID = 5742962631468325048L;
@@ -94,25 +98,20 @@ public class BlockNode extends Node implements IVariableNode, InterpolationNode
return b.toString();
}
- @Override
- public void replaceInterpolation(String variableName, String variable) {
- if (selectorList == null || selectorList.isEmpty()) {
- return;
- }
-
- for (final String selector : new ArrayList<String>(selectorList)) {
- String interpolation = "#{" + variableName + "}";
- if (selector.contains(interpolation)) {
- String replace = selector.replace(interpolation, variable);
- selectorList.add(selectorList.indexOf(selector), replace);
- selectorList.remove(selector);
- }
- }
+ public void setParentNode(Node node) {
+ parentNode.removeChild(this);
+ node.appendChild(this);
}
@Override
- public boolean containsInterpolationVariable(String variable) {
- return getSelectors().contains(variable);
+ public void traverse() {
+ try {
+ ParentSelectorHandler.traverse(this);
+ BlockNodeHandler.traverse(this);
+ replaceVariables(ScssStylesheet.getVariables());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/CommentNode.java b/theme-compiler/src/com/vaadin/sass/tree/CommentNode.java
index 5fb438bb08..b867c5384b 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/CommentNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/CommentNode.java
@@ -35,4 +35,9 @@ public class CommentNode extends Node {
public String toString() {
return comment;
}
+
+ @Override
+ public void traverse() {
+ // Not used in CommentNode
+ }
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/ExtendNode.java b/theme-compiler/src/com/vaadin/sass/tree/ExtendNode.java
index 909e69e12f..b9bf5869d1 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/ExtendNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/ExtendNode.java
@@ -18,6 +18,8 @@ package com.vaadin.sass.tree;
import java.util.ArrayList;
+import com.vaadin.sass.visitor.ExtendNodeHandler;
+
public class ExtendNode extends Node implements IVariableNode {
private static final long serialVersionUID = 3301805078983796878L;
@@ -45,4 +47,14 @@ public class ExtendNode extends Node implements IVariableNode {
return b.toString();
}
+
+ @Override
+ public void traverse() {
+ try {
+ ExtendNodeHandler.traverse(this);
+ getParentNode().removeChild(this);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/FontFaceNode.java b/theme-compiler/src/com/vaadin/sass/tree/FontFaceNode.java
index 3dab4df773..9e3b24f8de 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/FontFaceNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/FontFaceNode.java
@@ -15,4 +15,9 @@ public class FontFaceNode extends Node {
return builder.toString();
}
+ @Override
+ public void traverse() {
+ // Not in use for FontFaceNode
+ }
+
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/ForNode.java b/theme-compiler/src/com/vaadin/sass/tree/ForNode.java
index 7c0239aa60..da0d784229 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/ForNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/ForNode.java
@@ -41,4 +41,9 @@ public class ForNode extends Node {
+ to + ", exclusive: " + exclusive + ", body" + body;
}
+ @Override
+ public void traverse() {
+
+ }
+
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/FunctionNode.java b/theme-compiler/src/com/vaadin/sass/tree/FunctionNode.java
index 6263d557b8..d81e4976e5 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/FunctionNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/FunctionNode.java
@@ -18,6 +18,8 @@ package com.vaadin.sass.tree;
import java.util.ArrayList;
+import com.vaadin.sass.ScssStylesheet;
+
public class FunctionNode extends Node implements IVariableNode {
private static final long serialVersionUID = -5383104165955523923L;
@@ -50,4 +52,9 @@ public class FunctionNode extends Node implements IVariableNode {
}
}
}
+
+ @Override
+ public void traverse() {
+ replaceVariables(ScssStylesheet.getVariables());
+ }
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/ImportNode.java b/theme-compiler/src/com/vaadin/sass/tree/ImportNode.java
index ac070d6ffc..9dd9c1b0d8 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/ImportNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/ImportNode.java
@@ -18,6 +18,9 @@ package com.vaadin.sass.tree;
import org.w3c.css.sac.SACMediaList;
+import com.vaadin.sass.ScssStylesheet;
+import com.vaadin.sass.visitor.ImportNodeHandler;
+
public class ImportNode extends Node {
private static final long serialVersionUID = 5671255892282668438L;
@@ -68,4 +71,10 @@ public class ImportNode extends Node {
public SACMediaList getMl() {
return ml;
}
+
+ @Override
+ public void traverse() {
+ // TODO shouldn't be reached with current setup, try anyway?
+ ImportNodeHandler.traverse((ScssStylesheet) getParentNode());
+ }
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/InterpolationNode.java b/theme-compiler/src/com/vaadin/sass/tree/InterpolationNode.java
deleted file mode 100644
index c998b60b52..0000000000
--- a/theme-compiler/src/com/vaadin/sass/tree/InterpolationNode.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.vaadin.sass.tree;
-
-public interface InterpolationNode {
- public void replaceInterpolation(String variableName, String variable);
-
- public boolean containsInterpolationVariable(String variable);
-}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java b/theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java
index d54f56f8a7..c571fde08e 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java
@@ -3,6 +3,7 @@ package com.vaadin.sass.tree;
import java.util.ArrayList;
import java.util.Arrays;
+import com.vaadin.sass.ScssStylesheet;
import com.vaadin.sass.parser.LexicalUnitImpl;
public abstract class ListModifyNode extends Node implements IVariableNode {
@@ -99,4 +100,11 @@ public abstract class ListModifyNode extends Node implements IVariableNode {
}
}
+ @Override
+ public void traverse() {
+ replaceVariables(ScssStylesheet.getVariables());
+ ScssStylesheet.addVariable(getModifiedList());
+ getParentNode().removeChild(this);
+ }
+
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java b/theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java
index 22fb216c9e..a72be7bc02 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java
@@ -2,8 +2,6 @@ package com.vaadin.sass.tree;
import java.util.ArrayList;
-import com.vaadin.sass.parser.LexicalUnitImpl;
-
public class ListRemoveNode extends ListModifyNode {
public ListRemoveNode(String variable, String list, String remove,
@@ -14,26 +12,9 @@ public class ListRemoveNode extends ListModifyNode {
}
- 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 : modify) {
- if (s.equals(string)) {
- return false;
- }
- }
- return true;
- }
-
@Override
protected void modifyList(ArrayList<String> newList) {
newList.removeAll(modify);
}
+
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/MediaNode.java b/theme-compiler/src/com/vaadin/sass/tree/MediaNode.java
index b312d53a00..e410e93e53 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/MediaNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/MediaNode.java
@@ -57,4 +57,9 @@ public class MediaNode extends Node {
return builder.toString();
}
+ @Override
+ public void traverse() {
+
+ }
+
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/MicrosoftRuleNode.java b/theme-compiler/src/com/vaadin/sass/tree/MicrosoftRuleNode.java
index cbd3b14289..ce2bdc8395 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/MicrosoftRuleNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/MicrosoftRuleNode.java
@@ -2,6 +2,8 @@ package com.vaadin.sass.tree;
import java.util.ArrayList;
+import com.vaadin.sass.ScssStylesheet;
+
public class MicrosoftRuleNode extends Node implements IVariableNode {
private final String name;
@@ -26,4 +28,9 @@ public class MicrosoftRuleNode extends Node implements IVariableNode {
public String toString() {
return name + ": " + value + ";";
}
+
+ @Override
+ public void traverse() {
+ replaceVariables(ScssStylesheet.getVariables());
+ }
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/MixinDefNode.java b/theme-compiler/src/com/vaadin/sass/tree/MixinDefNode.java
index 0cffbc3203..9f51a959b8 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/MixinDefNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/MixinDefNode.java
@@ -19,6 +19,7 @@ package com.vaadin.sass.tree;
import java.util.ArrayList;
import java.util.Collection;
+import com.vaadin.sass.ScssStylesheet;
import com.vaadin.sass.util.DeepCopy;
public class MixinDefNode extends Node implements IVariableNode {
@@ -73,4 +74,15 @@ public class MixinDefNode extends Node implements IVariableNode {
}
}
+ @Override
+ public void traverse() {
+ if (!arglist.isEmpty()) {
+ for (final VariableNode arg : arglist) {
+ if (arg.getExpr() != null) {
+ ScssStylesheet.addVariable(arg);
+ }
+ }
+ }
+ }
+
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/MixinNode.java b/theme-compiler/src/com/vaadin/sass/tree/MixinNode.java
index 205f20b500..e43be0488a 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/MixinNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/MixinNode.java
@@ -19,7 +19,9 @@ package com.vaadin.sass.tree;
import java.util.ArrayList;
import java.util.Collection;
+import com.vaadin.sass.ScssStylesheet;
import com.vaadin.sass.parser.LexicalUnitImpl;
+import com.vaadin.sass.visitor.MixinNodeHandler;
public class MixinNode extends Node implements IVariableNode {
private static final long serialVersionUID = 4725008226813110658L;
@@ -67,6 +69,27 @@ public class MixinNode extends Node implements IVariableNode {
arg.replaceValue(var.getExpr());
}
}
+
+ if (name.startsWith("$")) {
+ if (name.equals("$" + var.getName())) {
+ name = var.getExpr().toString();
+ }
+ } else if (name.startsWith("#{") && name.endsWith("}")) {
+ if (name.equals("#{$" + var.getName() + "}")) {
+ name = var.getExpr().toString();
+ }
+ }
+
+ }
+ }
+
+ @Override
+ public void traverse() {
+ try {
+ replaceVariables(ScssStylesheet.getVariables());
+ MixinNodeHandler.traverse(this);
+ } catch (Exception e) {
+ e.printStackTrace();
}
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/NestPropertiesNode.java b/theme-compiler/src/com/vaadin/sass/tree/NestPropertiesNode.java
index 27d3f5b23f..0b0dd90334 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/NestPropertiesNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/NestPropertiesNode.java
@@ -20,6 +20,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import com.vaadin.sass.visitor.NestedNodeHandler;
+
public class NestPropertiesNode extends Node implements IVariableNode {
private static final long serialVersionUID = 3671253315690598308L;
@@ -41,7 +43,8 @@ public class NestPropertiesNode extends Node implements IVariableNode {
public Collection<RuleNode> unNesting() {
List<RuleNode> result = new ArrayList<RuleNode>();
for (Node child : children) {
- result.add(createNewRuleNodeFromChild((RuleNode) child));
+ RuleNode createNewRuleNodeFromChild = createNewRuleNodeFromChild((RuleNode) child);
+ result.add(createNewRuleNodeFromChild);
}
return result;
}
@@ -63,4 +66,10 @@ public class NestPropertiesNode extends Node implements IVariableNode {
}
}
}
+
+ @Override
+ public void traverse() {
+ NestedNodeHandler.traverse(this);
+ }
+
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/Node.java b/theme-compiler/src/com/vaadin/sass/tree/Node.java
index 6e871df286..ccbd6d64da 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/Node.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/Node.java
@@ -24,28 +24,34 @@ public abstract class Node implements Serializable {
private static final long serialVersionUID = 5914711715839294816L;
protected ArrayList<Node> children;
- private String fileName;
- protected String rawString;
+ protected Node parentNode;
public Node() {
children = new ArrayList<Node>();
}
- public Node(String raw) {
- this();
- rawString = raw;
- }
-
public void appendAll(Collection<Node> nodes) {
if (nodes != null && !nodes.isEmpty()) {
children.addAll(nodes);
+
+ for (final Node n : nodes) {
+ if (n.getParentNode() != null) {
+ n.getParentNode().removeChild(n);
+ }
+ n.setParentNode(this);
+ }
+
}
}
public void appendChild(Node node) {
if (node != null) {
children.add(node);
+ if (node.getParentNode() != null) {
+ node.getParentNode().removeChild(node);
+ }
+ node.setParentNode(this);
}
}
@@ -54,6 +60,10 @@ public abstract class Node implements Serializable {
int index = children.indexOf(after);
if (index != -1) {
children.add(index + 1, node);
+ if (node.getParentNode() != null) {
+ node.getParentNode().removeChild(node);
+ }
+ node.setParentNode(this);
} else {
throw new NullPointerException("after-node was not found");
}
@@ -62,7 +72,10 @@ public abstract class Node implements Serializable {
public void removeChild(Node node) {
if (node != null) {
- children.remove(node);
+ boolean removed = children.remove(node);
+ if (removed) {
+ node.setParentNode(null);
+ }
}
}
@@ -78,21 +91,22 @@ public abstract class Node implements Serializable {
return !children.isEmpty();
}
- public void setFileName(String fileName) {
- this.fileName = fileName;
- }
-
- public String getFileName() {
- return fileName;
- }
-
@Override
public String toString() {
return "";
}
- public String getRawString() {
- return rawString;
+ /**
+ * Method for manipulating the data contained within the {@link Node}.
+ */
+ public abstract void traverse();
+
+ public Node getParentNode() {
+ return parentNode;
+ }
+
+ private void setParentNode(Node parentNode) {
+ this.parentNode = parentNode;
}
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/RuleNode.java b/theme-compiler/src/com/vaadin/sass/tree/RuleNode.java
index aad4509616..38c5b1cb4e 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/RuleNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/RuleNode.java
@@ -19,9 +19,10 @@ package com.vaadin.sass.tree;
import java.util.ArrayList;
import java.util.regex.Pattern;
+import com.vaadin.sass.ScssStylesheet;
import com.vaadin.sass.parser.LexicalUnitImpl;
-public class RuleNode extends Node implements IVariableNode, InterpolationNode {
+public class RuleNode extends Node implements IVariableNode {
private static final long serialVersionUID = 6653493127869037022L;
String variable;
@@ -83,36 +84,51 @@ public class RuleNode extends Node implements IVariableNode, InterpolationNode {
@Override
public void replaceVariables(ArrayList<VariableNode> variables) {
for (final VariableNode node : variables) {
+
+ String interpolation = "#{$" + node.getName() + "}";
+
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);
- }
+
+ 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();
}
+ param = param.getNextLexicalUnit();
}
}
}
+ } else if (value.getStringValue() != null
+ && value.getStringValue().contains(interpolation)) {
+ LexicalUnitImpl current = value;
+ while (current != null) {
+ if (current.getValue().toString().contains(interpolation)) {
+
+ current.setStringValue(current
+ .getValue()
+ .toString()
+ .replaceAll(Pattern.quote(interpolation),
+ node.getExpr().toString()));
+ }
+ current = current.getNextLexicalUnit();
+ }
} else {
LexicalUnitImpl current = value;
while (current != null) {
@@ -129,32 +145,7 @@ public class RuleNode extends Node implements IVariableNode, InterpolationNode {
}
@Override
- public void replaceInterpolation(String variableName, String variable) {
- if (this.variable.contains(variableName)) {
- this.variable = this.variable.replaceAll(variableName, variable);
- }
-
- if (value.toString().contains(variableName)) {
-
- LexicalUnitImpl current = value;
- while (current != null) {
- if (current.getValue().toString().contains(variableName)) {
- current.setStringValue(current
- .getValue()
- .toString()
- .replaceAll(
- Pattern.quote("#{" + variableName + "}"),
- variable));
- }
-
- current = value.getNextLexicalUnit();
- }
- }
- }
-
- @Override
- public boolean containsInterpolationVariable(String variable) {
- return value.toString().contains(variable)
- || this.variable.contains(variable);
+ public void traverse() {
+ replaceVariables(ScssStylesheet.getVariables());
}
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/SimpleNode.java b/theme-compiler/src/com/vaadin/sass/tree/SimpleNode.java
index 52329c1b14..adf1a3d15d 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/SimpleNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/SimpleNode.java
@@ -2,6 +2,8 @@ package com.vaadin.sass.tree;
import java.util.ArrayList;
+import com.vaadin.sass.ScssStylesheet;
+
/**
* A simple BlockNode where input text equals output. <b>Note : </b> ignores any
* possible children so only use it when you are sure no child nodes will be
@@ -33,4 +35,9 @@ public class SimpleNode extends Node implements IVariableNode {
}
}
}
+
+ @Override
+ public void traverse() {
+ replaceVariables(ScssStylesheet.getVariables());
+ }
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/VariableNode.java b/theme-compiler/src/com/vaadin/sass/tree/VariableNode.java
index 6ba27ebac5..3ea8379829 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/VariableNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/VariableNode.java
@@ -18,7 +18,9 @@ package com.vaadin.sass.tree;
import java.util.ArrayList;
+import com.vaadin.sass.ScssStylesheet;
import com.vaadin.sass.parser.LexicalUnitImpl;
+import com.vaadin.sass.visitor.VariableNodeHandler;
public class VariableNode extends Node implements IVariableNode {
private static final long serialVersionUID = 7003372557547748734L;
@@ -92,4 +94,10 @@ public class VariableNode extends Node implements IVariableNode {
unit = unit.getNextLexicalUnit();
}
}
+
+ @Override
+ public void traverse() {
+ replaceVariables(ScssStylesheet.getVariables());
+ VariableNodeHandler.traverse(this);
+ }
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/WhileNode.java b/theme-compiler/src/com/vaadin/sass/tree/WhileNode.java
index 465fec061d..4cd85a97a4 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/WhileNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/WhileNode.java
@@ -32,4 +32,9 @@ public class WhileNode extends Node {
return "While Node: { condition: " + condition + ", body:" + body + "}";
}
+ @Override
+ public void traverse() {
+
+ }
+
}
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 cb209273cb..4ab8486add 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/controldirective/EachDefNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/controldirective/EachDefNode.java
@@ -19,10 +19,12 @@ package com.vaadin.sass.tree.controldirective;
import java.util.ArrayList;
import java.util.List;
+import com.vaadin.sass.ScssStylesheet;
import com.vaadin.sass.parser.LexicalUnitImpl;
import com.vaadin.sass.tree.IVariableNode;
import com.vaadin.sass.tree.Node;
import com.vaadin.sass.tree.VariableNode;
+import com.vaadin.sass.visitor.EachNodeHandler;
public class EachDefNode extends Node implements IVariableNode {
private static final long serialVersionUID = 7943948981204906221L;
@@ -88,4 +90,10 @@ public class EachDefNode extends Node implements IVariableNode {
public String getListVariable() {
return listVariable;
}
+
+ @Override
+ public void traverse() {
+ replaceVariables(ScssStylesheet.getVariables());
+ EachNodeHandler.traverse(this);
+ }
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/controldirective/ElseNode.java b/theme-compiler/src/com/vaadin/sass/tree/controldirective/ElseNode.java
index 529ce4d76e..ecda69d601 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/controldirective/ElseNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/controldirective/ElseNode.java
@@ -9,4 +9,9 @@ public class ElseNode extends Node implements IfElseNode {
return null;
}
+ @Override
+ public void traverse() {
+
+ }
+
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/controldirective/IfElseDefNode.java b/theme-compiler/src/com/vaadin/sass/tree/controldirective/IfElseDefNode.java
index 5bd3ba526c..9a818f0a20 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/controldirective/IfElseDefNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/controldirective/IfElseDefNode.java
@@ -1,6 +1,7 @@
package com.vaadin.sass.tree.controldirective;
import com.vaadin.sass.tree.Node;
+import com.vaadin.sass.visitor.IfElseNodeHandler;
public class IfElseDefNode extends Node {
@@ -14,4 +15,17 @@ public class IfElseDefNode extends Node {
return b.toString();
}
+ public void traverse() {
+ try {
+
+ for (final Node child : children) {
+ child.traverse();
+ }
+
+ IfElseNodeHandler.traverse(this);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
}
diff --git a/theme-compiler/src/com/vaadin/sass/tree/controldirective/IfNode.java b/theme-compiler/src/com/vaadin/sass/tree/controldirective/IfNode.java
index 8de7ccf78a..cdaf1b0552 100644
--- a/theme-compiler/src/com/vaadin/sass/tree/controldirective/IfNode.java
+++ b/theme-compiler/src/com/vaadin/sass/tree/controldirective/IfNode.java
@@ -18,6 +18,7 @@ package com.vaadin.sass.tree.controldirective;
import java.util.ArrayList;
import java.util.regex.Pattern;
+import com.vaadin.sass.ScssStylesheet;
import com.vaadin.sass.tree.IVariableNode;
import com.vaadin.sass.tree.Node;
import com.vaadin.sass.tree.VariableNode;
@@ -46,11 +47,17 @@ public class IfNode extends Node implements IfElseNode, IVariableNode {
@Override
public void replaceVariables(ArrayList<VariableNode> variables) {
for (final VariableNode node : variables) {
- if (expression.contains("$" + node.getName())) {
- expression = expression.replaceAll(Pattern.quote("$"
- + node.getName()), node.getExpr().toString());
+ String variable = "$" + node.getName();
+ if (expression.contains(variable)) {
+ expression = expression.replaceAll(Pattern.quote(variable),
+ node.getExpr().toString());
}
}
}
+ @Override
+ public void traverse() {
+ replaceVariables(ScssStylesheet.getVariables());
+ }
+
} \ No newline at end of file
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/BlockNodeHandler.java b/theme-compiler/src/com/vaadin/sass/visitor/BlockNodeHandler.java
new file mode 100644
index 0000000000..efbfc4b8ff
--- /dev/null
+++ b/theme-compiler/src/com/vaadin/sass/visitor/BlockNodeHandler.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.sass.visitor;
+
+import java.util.ArrayList;
+
+import com.vaadin.sass.tree.BlockNode;
+import com.vaadin.sass.tree.Node;
+
+public class BlockNodeHandler {
+
+ public static void traverse(BlockNode node) {
+
+ Node parent = node.getParentNode();
+ if (node.getChildren().size() == 0) {
+ parent.removeChild(node);
+ while (parent != null && parent instanceof BlockNode
+ && parent.getChildren().size() == 0) {
+ Node temp = parent;
+ parent = parent.getParentNode();
+ parent.removeChild(temp);
+ }
+
+ return;
+ }
+
+ if (parent instanceof BlockNode) {
+ combineParentSelectorListToChild(node);
+ }
+ }
+
+ private static void combineParentSelectorListToChild(BlockNode node) {
+ ArrayList<String> newList = new ArrayList<String>();
+ ArrayList<String> parentSelectors = ((BlockNode) node.getParentNode())
+ .getSelectorList();
+ ArrayList<String> childSelectors = ((BlockNode) node).getSelectorList();
+ for (int i = 0; i < parentSelectors.size(); i++) {
+ String parentSelector = parentSelectors.get(i);
+ for (int j = 0; j < childSelectors.size(); j++) {
+ String childSelector = childSelectors.get(j);
+ newList.add(parentSelector + " " + childSelector);
+ }
+
+ }
+ node.setSelectorList(newList);
+ node.getParentNode().getParentNode()
+ .appendChild(node, node.getParentNode());
+ }
+}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/BlockVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/BlockVisitor.java
deleted file mode 100644
index 3cbf7e1f98..0000000000
--- a/theme-compiler/src/com/vaadin/sass/visitor/BlockVisitor.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.sass.visitor;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Set;
-
-import com.vaadin.sass.tree.BlockNode;
-import com.vaadin.sass.tree.Node;
-
-public class BlockVisitor implements Visitor {
-
- @Override
- public void traverse(Node node) {
- traverse(null, node);
- }
-
- private void traverse(Node parent, Node node) {
- Node after = node;
- Set<Node> toBeDeleted = new HashSet<Node>();
- for (int pos = 0; pos < node.getChildren().size(); pos++) {
- Node child = node.getChildren().get(pos);
-
- traverse(node, child);
-
- if (child instanceof BlockNode && node instanceof BlockNode
- && parent != null) {
- combineParentSelectorListToChild(node, child);
- toBeDeleted.add(child);
- parent.appendChild(child, after);
- after = child;
- } else if (child instanceof BlockNode
- && child.getChildren().size() == 0) {
- toBeDeleted.add(child);
- }
- }
- for (Node child : toBeDeleted) {
- node.removeChild(child);
- }
- }
-
- private void combineParentSelectorListToChild(Node parent, Node child) {
- if (parent instanceof BlockNode && child instanceof BlockNode) {
- ArrayList<String> newList = new ArrayList<String>();
- ArrayList<String> parentSelectors = ((BlockNode) parent)
- .getSelectorList();
- ArrayList<String> childSelectors = ((BlockNode) child)
- .getSelectorList();
- for (int i = 0; i < parentSelectors.size(); i++) {
- String parentSelector = parentSelectors.get(i);
- for (int j = 0; j < childSelectors.size(); j++) {
- String childSelector = childSelectors.get(j);
- newList.add(parentSelector + " " + childSelector);
- }
-
- }
- ((BlockNode) child).setSelectorList(newList);
- }
- }
-}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/EachNodeHandler.java b/theme-compiler/src/com/vaadin/sass/visitor/EachNodeHandler.java
new file mode 100644
index 0000000000..0eb86f3a80
--- /dev/null
+++ b/theme-compiler/src/com/vaadin/sass/visitor/EachNodeHandler.java
@@ -0,0 +1,57 @@
+package com.vaadin.sass.visitor;
+
+import java.util.ArrayList;
+
+import com.vaadin.sass.ScssStylesheet;
+import com.vaadin.sass.parser.LexicalUnitImpl;
+import com.vaadin.sass.tree.IVariableNode;
+import com.vaadin.sass.tree.Node;
+import com.vaadin.sass.tree.VariableNode;
+import com.vaadin.sass.tree.controldirective.EachDefNode;
+import com.vaadin.sass.util.DeepCopy;
+
+public class EachNodeHandler {
+
+ public static void traverse(EachDefNode node) {
+ replaceEachDefNode(node);
+ }
+
+ private static void replaceEachDefNode(EachDefNode defNode) {
+ Node last = defNode;
+
+ for (final String var : defNode.getVariables()) {
+ VariableNode varNode = new VariableNode(defNode.getVariableName()
+ .substring(1), LexicalUnitImpl.createIdent(var), false);
+ ArrayList<VariableNode> variables = new ArrayList<VariableNode>(
+ ScssStylesheet.getVariables());
+ variables.add(varNode);
+
+ for (final Node child : defNode.getChildren()) {
+
+ Node copy = (Node) DeepCopy.copy(child);
+
+ replaceInterpolation(copy, variables);
+
+ defNode.getParentNode().appendChild(copy, last);
+ last = copy;
+ }
+
+ }
+ defNode.setChildren(new ArrayList<Node>());
+ defNode.getParentNode().removeChild(defNode);
+ }
+
+ private static void replaceInterpolation(Node copy,
+ ArrayList<VariableNode> variables) {
+ if (copy instanceof IVariableNode) {
+ IVariableNode n = (IVariableNode) copy;
+ n.replaceVariables(variables);
+ }
+
+ for (Node c : copy.getChildren()) {
+ replaceInterpolation(c, variables);
+ }
+
+ }
+
+}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/EachVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/EachVisitor.java
deleted file mode 100644
index de58947982..0000000000
--- a/theme-compiler/src/com/vaadin/sass/visitor/EachVisitor.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package com.vaadin.sass.visitor;
-
-import java.util.HashMap;
-import java.util.Map.Entry;
-
-import com.vaadin.sass.tree.BlockNode;
-import com.vaadin.sass.tree.Node;
-import com.vaadin.sass.tree.RuleNode;
-import com.vaadin.sass.tree.controldirective.EachDefNode;
-import com.vaadin.sass.util.DeepCopy;
-
-public class EachVisitor implements Visitor {
-
- HashMap<EachDefNode, Node> controlDefs = new HashMap<EachDefNode, Node>();
- private Node rootNode;
-
- @Override
- public void traverse(Node node) throws Exception {
- this.rootNode = node;
-
- findDefNodes(null, node);
-
- replaceControlNodes();
-
- }
-
- private void findDefNodes(Node parent, Node node) {
- for (Node child : node.getChildren()) {
- findDefNodes(node, child);
- }
- if (node instanceof EachDefNode) {
- controlDefs.put((EachDefNode) node, parent);
- }
- }
-
- private void replaceControlNodes() {
- for (final Entry<EachDefNode, Node> entry : controlDefs.entrySet()) {
- replaceEachDefNode(entry.getKey(), entry.getValue());
- }
- }
-
- private void replaceEachDefNode(EachDefNode defNode, Node parent) {
- Node last = defNode;
- for (final Node child : defNode.getChildren()) {
- if (child instanceof BlockNode) {
- BlockNode iNode = (BlockNode) child;
- String interpolation = "#{" + defNode.getVariableName() + "}";
- if (iNode.containsInterpolationVariable(interpolation)) {
- for (final String variable : defNode.getVariables()) {
- BlockNode copy = (BlockNode) DeepCopy.copy(child);
- copy.replaceInterpolation(defNode.getVariableName(),
- variable);
-
- for (final Node blockChild : copy.getChildren()) {
- if (blockChild instanceof RuleNode) {
- ((RuleNode) blockChild).replaceInterpolation(
- defNode.getVariableName(), variable);
- }
- }
-
- parent.appendChild(copy, last);
- last = copy;
- }
- }
- }
-
- last = child;
- }
- parent.removeChild(defNode);
- }
-
-}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/ExtendVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/ExtendNodeHandler.java
index 23519b6e69..0e05781072 100644
--- a/theme-compiler/src/com/vaadin/sass/visitor/ExtendVisitor.java
+++ b/theme-compiler/src/com/vaadin/sass/visitor/ExtendNodeHandler.java
@@ -22,21 +22,20 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import com.vaadin.sass.ScssStylesheet;
import com.vaadin.sass.tree.BlockNode;
import com.vaadin.sass.tree.ExtendNode;
import com.vaadin.sass.tree.Node;
-public class ExtendVisitor implements Visitor {
- private Map<String, List<ArrayList<String>>> extendsMap = new HashMap<String, List<ArrayList<String>>>();
+public class ExtendNodeHandler {
+ private static Map<String, List<ArrayList<String>>> extendsMap = new HashMap<String, List<ArrayList<String>>>();
- @Override
- public void traverse(Node node) throws Exception {
+ public static void traverse(ExtendNode node) throws Exception {
buildExtendsMap(node);
- modifyTree(node);
+ modifyTree(ScssStylesheet.get());
}
- @SuppressWarnings("unchecked")
- private void modifyTree(Node node) throws Exception {
+ private static void modifyTree(Node node) throws Exception {
for (Node child : node.getChildren()) {
if (child instanceof BlockNode) {
BlockNode blockNode = (BlockNode) child;
@@ -62,42 +61,22 @@ public class ExtendVisitor implements Visitor {
}
}
}
- } else {
- buildExtendsMap(child);
}
}
}
- private void buildExtendsMap(Node node) {
- if (node instanceof BlockNode) {
- BlockNode blockNode = (BlockNode) node;
- for (Node child : new ArrayList<Node>(node.getChildren())) {
- if (child instanceof ExtendNode) {
- ExtendNode extendNode = (ExtendNode) child;
-
- String extendedString = extendNode.getListAsString();
- if (extendsMap.get(extendedString) == null) {
- extendsMap.put(extendedString,
- new ArrayList<ArrayList<String>>());
- }
- extendsMap.get(extendedString).add(
- blockNode.getSelectorList());
- node.removeChild(child);
- } else {
- buildExtendsMap(child);
- }
- }
- } else {
- for (Node child : node.getChildren()) {
- buildExtendsMap(child);
- }
+ private static void buildExtendsMap(ExtendNode node) {
+ String extendedString = node.getListAsString();
+ if (extendsMap.get(extendedString) == null) {
+ extendsMap.put(extendedString, new ArrayList<ArrayList<String>>());
}
-
+ extendsMap.get(extendedString).add(
+ ((BlockNode) node.getParentNode()).getSelectorList());
}
- private void addAdditionalSelectorListToBlockNode(BlockNode blockNode,
- ArrayList<String> list, String selectorString) {
+ private static void addAdditionalSelectorListToBlockNode(
+ BlockNode blockNode, ArrayList<String> list, String selectorString) {
if (list != null) {
for (int i = 0; i < list.size(); i++) {
if (selectorString == null) {
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/IfElseNodeHandler.java b/theme-compiler/src/com/vaadin/sass/visitor/IfElseNodeHandler.java
new file mode 100644
index 0000000000..593f22a631
--- /dev/null
+++ b/theme-compiler/src/com/vaadin/sass/visitor/IfElseNodeHandler.java
@@ -0,0 +1,102 @@
+package com.vaadin.sass.visitor;
+
+import java.util.ArrayList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.jexl2.Expression;
+import org.apache.commons.jexl2.JexlEngine;
+import org.apache.commons.jexl2.JexlException;
+import org.w3c.flute.parser.ParseException;
+
+import com.vaadin.sass.tree.Node;
+import com.vaadin.sass.tree.controldirective.ElseNode;
+import com.vaadin.sass.tree.controldirective.IfElseDefNode;
+import com.vaadin.sass.tree.controldirective.IfElseNode;
+import com.vaadin.sass.tree.controldirective.IfNode;
+
+public class IfElseNodeHandler {
+
+ private static final JexlEngine evaluator = new JexlEngine();
+ private static final Pattern pattern = Pattern
+ .compile("[a-zA-Z0-9]*[a-zA-Z]+[a-zA-Z0-9]*");
+
+ public static void traverse(IfElseDefNode node) throws Exception {
+
+ for (final Node child : node.getChildren()) {
+ if (child instanceof IfNode) {
+ try {
+ String expression = ((IfElseNode) child).getExpression();
+ // We need to add ' ' for strings in the expression for
+ // jexl to understand that is should do a string
+ // comparison
+ expression = replaceStrings(expression);
+ Expression e = evaluator.createExpression(expression);
+ try {
+ Object eval = e.evaluate(null);
+
+ Boolean result = false;
+ if (eval instanceof Boolean) {
+ result = (Boolean) eval;
+ } else if (eval instanceof String) {
+ result = Boolean.valueOf((String) eval);
+ }
+
+ if (result) {
+ replaceDefNodeWithCorrectChild(node,
+ node.getParentNode(), child);
+ break;
+ }
+ } catch (ClassCastException ex) {
+ throw new ParseException(
+ "Invalid @if/@else in scss file, not a boolean expression : "
+ + child.toString());
+ } catch (NullPointerException ex) {
+ throw new ParseException(
+ "Invalid @if/@else in scss file, not a boolean expression : "
+ + child.toString());
+ }
+ } catch (JexlException e) {
+ throw new ParseException(
+ "Invalid @if/@else in scss file for "
+ + child.toString());
+ }
+ } else {
+ if (!(child instanceof ElseNode)
+ && node.getChildren().indexOf(child) == node
+ .getChildren().size() - 1) {
+ throw new ParseException(
+ "Invalid @if/@else in scss file for " + node);
+ } else {
+ replaceDefNodeWithCorrectChild(node, node.getParentNode(),
+ child);
+ break;
+ }
+ }
+ }
+
+ node.getParentNode().removeChild(node);
+ }
+
+ private static String replaceStrings(String expression) {
+ expression = expression.replaceAll("\"", "");
+ Matcher m = pattern.matcher(expression);
+ StringBuffer b = new StringBuffer();
+ while (m.find()) {
+ String group = m.group();
+ m.appendReplacement(b, "'" + group + "'");
+ }
+ m.appendTail(b);
+ if (b.length() != 0) {
+ return b.toString();
+ }
+ return expression;
+ }
+
+ private static void replaceDefNodeWithCorrectChild(IfElseDefNode defNode,
+ Node parent, final Node child) {
+ for (final Node n : new ArrayList<Node>(child.getChildren())) {
+ parent.appendChild(n, defNode);
+ }
+ }
+}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/IfElseVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/IfElseVisitor.java
deleted file mode 100644
index 2cffb890ee..0000000000
--- a/theme-compiler/src/com/vaadin/sass/visitor/IfElseVisitor.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package com.vaadin.sass.visitor;
-
-import java.util.HashMap;
-import java.util.Map.Entry;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.commons.jexl2.Expression;
-import org.apache.commons.jexl2.JexlEngine;
-import org.apache.commons.jexl2.JexlException;
-import org.w3c.flute.parser.ParseException;
-
-import com.vaadin.sass.tree.Node;
-import com.vaadin.sass.tree.controldirective.ElseNode;
-import com.vaadin.sass.tree.controldirective.IfElseDefNode;
-import com.vaadin.sass.tree.controldirective.IfElseNode;
-import com.vaadin.sass.tree.controldirective.IfNode;
-
-public class IfElseVisitor implements Visitor {
-
- private HashMap<Node, IfElseDefNode> controlDefs = new HashMap<Node, IfElseDefNode>();
-
- private static final JexlEngine evaluator = new JexlEngine();
- private static final Pattern pattern = Pattern
- .compile("[a-zA-Z0-9]*[a-zA-Z]+[a-zA-Z0-9]*");
-
- @Override
- public void traverse(Node node) throws Exception {
- addControlDefs(node, node);
-
- for (final Entry<Node, IfElseDefNode> entry : controlDefs.entrySet()) {
- IfElseDefNode defNode = entry.getValue();
- Node parent = entry.getKey();
- for (final Node child : defNode.getChildren()) {
- if (child instanceof IfNode) {
- try {
- String expression = ((IfElseNode) child)
- .getExpression();
- // We need to add ' ' for strings in the expression for
- // jexl to understand that is should do a string
- // comparison
- expression = replaceStrings(expression);
- Expression e = evaluator.createExpression(expression);
- try {
- Object eval = e.evaluate(null);
-
- Boolean result = false;
- if (eval instanceof Boolean) {
- result = (Boolean) eval;
- } else if (eval instanceof String) {
- result = Boolean.valueOf((String) eval);
- }
-
- if (result) {
- replaceDefNodeWithCorrectChild(defNode, parent,
- child);
- break;
- }
- System.out.println();
- } catch (ClassCastException ex) {
- throw new ParseException(
- "Invalid @if/@else in scss file, not a boolean expression : "
- + child.toString());
- } catch (NullPointerException ex) {
- throw new ParseException(
- "Invalid @if/@else in scss file, not a boolean expression : "
- + child.toString());
- }
- } catch (JexlException e) {
- throw new ParseException(
- "Invalid @if/@else in scss file for "
- + child.toString());
- }
- } else {
- if (!(child instanceof ElseNode)
- && defNode.getChildren().indexOf(child) == defNode
- .getChildren().size() - 1) {
- throw new ParseException(
- "Invalid @if/@else in scss file for " + defNode);
- } else {
- replaceDefNodeWithCorrectChild(defNode, parent, child);
- break;
- }
- }
- }
-
- parent.removeChild(defNode);
- }
-
- }
-
- private String replaceStrings(String expression) {
- expression = expression.replaceAll("\"", "");
- Matcher m = pattern.matcher(expression);
- StringBuffer b = new StringBuffer();
- while (m.find()) {
- String group = m.group();
- m.appendReplacement(b, "'" + group + "'");
- }
- m.appendTail(b);
- if (b.length() != 0) {
- return b.toString();
- }
- return expression;
- }
-
- private void replaceDefNodeWithCorrectChild(IfElseDefNode defNode,
- Node parent, final Node child) {
- for (final Node n : child.getChildren()) {
- parent.appendChild(n, defNode);
- }
- }
-
- private void addControlDefs(Node current, Node node) {
- for (Node child : current.getChildren()) {
- addControlDefs(node, child);
- if (child instanceof IfElseDefNode) {
- controlDefs.put(current, (IfElseDefNode) child);
- }
- }
- }
-}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/ImportVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/ImportNodeHandler.java
index bda040be39..f2fb128128 100644
--- a/theme-compiler/src/com/vaadin/sass/visitor/ImportVisitor.java
+++ b/theme-compiler/src/com/vaadin/sass/visitor/ImportNodeHandler.java
@@ -31,17 +31,15 @@ import com.vaadin.sass.tree.Node;
import com.vaadin.sass.tree.RuleNode;
import com.vaadin.sass.util.StringUtil;
-public class ImportVisitor implements Visitor {
+public class ImportNodeHandler {
- @Override
- public void traverse(Node node) {
- for (Node child : new ArrayList<Node>(node.getChildren())) {
- if (child instanceof ImportNode) {
- ImportNode importNode = (ImportNode) child;
+ public static void traverse(ScssStylesheet node) {
+ ArrayList<Node> c = new ArrayList<Node>(node.getChildren());
+ for (Node n : c) {
+ if (n instanceof ImportNode) {
+ ImportNode importNode = (ImportNode) n;
if (!importNode.isPureCssImport()) {
-
try {
-
StringBuilder filePathBuilder = new StringBuilder(
node.getFileName());
filePathBuilder.append(File.separatorChar).append(
@@ -57,16 +55,20 @@ public class ImportVisitor implements Visitor {
}
if (imported == null) {
throw new FileNotFoundException(importNode.getUri()
- + " (parent: " + node.getFileName() + ")");
+ + " (parent: "
+ + ScssStylesheet.get().getFileName() + ")");
}
traverse(imported);
+
String prefix = getUrlPrefix(importNode.getUri());
if (prefix != null) {
updateUrlInImportedSheet(imported, prefix);
}
+
Node pre = importNode;
- for (Node importedChild : imported.getChildren()) {
+ for (Node importedChild : new ArrayList<Node>(
+ imported.getChildren())) {
node.appendChild(importedChild, pre);
pre = importedChild;
}
@@ -81,7 +83,7 @@ public class ImportVisitor implements Visitor {
}
}
- private String getUrlPrefix(String url) {
+ private static String getUrlPrefix(String url) {
if (url == null) {
return null;
}
@@ -92,7 +94,7 @@ public class ImportVisitor implements Visitor {
return url.substring(0, pos + 1);
}
- private void updateUrlInImportedSheet(Node node, String prefix) {
+ private static void updateUrlInImportedSheet(Node node, String prefix) {
for (Node child : node.getChildren()) {
if (child instanceof RuleNode) {
LexicalUnit value = ((RuleNode) child).getValue();
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/ListModifyVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/ListModifyVisitor.java
deleted file mode 100644
index 3edb599a07..0000000000
--- a/theme-compiler/src/com/vaadin/sass/visitor/ListModifyVisitor.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.vaadin.sass.visitor;
-
-import java.util.ArrayList;
-
-import com.vaadin.sass.tree.ListModifyNode;
-import com.vaadin.sass.tree.Node;
-
-public class ListModifyVisitor implements Visitor {
-
- @Override
- public void traverse(Node node) throws Exception {
- for (final Node child : new ArrayList<Node>(node.getChildren())) {
- removeNodes(child, node);
- }
- }
-
- private void removeNodes(Node child, Node parent) {
- for (final Node c : new ArrayList<Node>(child.getChildren())) {
- removeNodes(c, child);
- }
-
- if (child instanceof ListModifyNode) {
- parent.removeChild(child);
- }
-
- }
-}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/MixinVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/MixinNodeHandler.java
index fecc717437..3c31ee1073 100644
--- a/theme-compiler/src/com/vaadin/sass/visitor/MixinVisitor.java
+++ b/theme-compiler/src/com/vaadin/sass/visitor/MixinNodeHandler.java
@@ -17,9 +17,8 @@
package com.vaadin.sass.visitor;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
+import com.vaadin.sass.ScssStylesheet;
import com.vaadin.sass.parser.LexicalUnitImpl;
import com.vaadin.sass.tree.IVariableNode;
import com.vaadin.sass.tree.MixinDefNode;
@@ -28,57 +27,35 @@ import com.vaadin.sass.tree.Node;
import com.vaadin.sass.tree.VariableNode;
import com.vaadin.sass.util.DeepCopy;
-public class MixinVisitor implements Visitor {
- Map<String, MixinDefNode> mixinDefs = new HashMap<String, MixinDefNode>();
-
- @Override
- public void traverse(Node node) throws Exception {
- // create mixin map.
- for (Node child : node.getChildren()) {
- if (child instanceof MixinDefNode) {
- mixinDefs.put(((MixinDefNode) child).getName(),
- (MixinDefNode) child);
- }
- }
+public class MixinNodeHandler {
+ public static void traverse(MixinNode node) throws Exception {
replaceMixins(node);
-
- // delete MixinDefNode
- for (Node child : new ArrayList<Node>(node.getChildren())) {
- if (child instanceof MixinDefNode) {
- node.removeChild(child);
- }
- }
-
}
- private void replaceMixins(Node node) throws Exception {
- for (Node child : new ArrayList<Node>(node.getChildren())) {
- replaceMixins(child);
- if (child instanceof MixinNode) {
- MixinNode mixinNode = (MixinNode) child;
- MixinDefNode mixinDef = mixinDefs.get(mixinNode.getName());
- if (mixinDef == null) {
- throw new Exception("Mixin Definition: "
- + mixinNode.getName() + " not found");
- }
- replaceMixinNode(node, mixinNode, mixinDef);
- }
+ private static void replaceMixins(MixinNode node) throws Exception {
+ MixinDefNode mixinDef = ScssStylesheet.getMixinDefinition(node
+ .getName());
+ if (mixinDef == null) {
+ throw new Exception("Mixin Definition: " + node.getName()
+ + " not found");
}
+ replaceMixinNode(node, mixinDef);
}
- private void replaceMixinNode(Node current, MixinNode mixinNode,
+ private static void replaceMixinNode(MixinNode mixinNode,
MixinDefNode mixinDef) {
Node pre = mixinNode;
+
+ MixinDefNode defClone = (MixinDefNode) DeepCopy.copy(mixinDef);
+
if (mixinDef.getArglist().isEmpty()) {
- for (Node child : mixinDef.getChildren()) {
- current.appendChild(child, pre);
+ for (Node child : new ArrayList<Node>(defClone.getChildren())) {
+ mixinNode.getParentNode().appendChild(child, pre);
pre = child;
}
} else {
- MixinDefNode defClone = (MixinDefNode) DeepCopy.copy(mixinDef);
-
replacePossibleArguments(mixinNode, defClone);
Node previous = mixinNode;
@@ -88,14 +65,15 @@ public class MixinVisitor implements Visitor {
replaceChildVariables(defClone, clone);
- current.appendChild(clone, previous);
+ mixinNode.getParentNode().appendChild(clone, previous);
previous = clone;
}
}
- current.removeChild(mixinNode);
+
+ mixinNode.getParentNode().removeChild(mixinNode);
}
/**
@@ -106,7 +84,8 @@ public class MixinVisitor implements Visitor {
* @param mixinNode
* @param def
*/
- private void replacePossibleArguments(MixinNode mixinNode, MixinDefNode def) {
+ private static void replacePossibleArguments(MixinNode mixinNode,
+ MixinDefNode def) {
if (mixinNode.getArglist().size() > 0) {
ArrayList<VariableNode> remainingNodes = new ArrayList<VariableNode>(
@@ -140,7 +119,7 @@ public class MixinVisitor implements Visitor {
}
- private void replaceChildVariables(MixinDefNode mixinDef, Node node) {
+ private static void replaceChildVariables(MixinDefNode mixinDef, Node node) {
for (final Node child : node.getChildren()) {
replaceChildVariables(mixinDef, child);
}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/NestPropertiesVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/NestedNodeHandler.java
index 82fbef42ef..bb094885f0 100644
--- a/theme-compiler/src/com/vaadin/sass/visitor/NestPropertiesVisitor.java
+++ b/theme-compiler/src/com/vaadin/sass/visitor/NestedNodeHandler.java
@@ -16,28 +16,18 @@
package com.vaadin.sass.visitor;
-import java.util.ArrayList;
-
import com.vaadin.sass.tree.NestPropertiesNode;
import com.vaadin.sass.tree.Node;
import com.vaadin.sass.tree.RuleNode;
-public class NestPropertiesVisitor implements Visitor {
+public class NestedNodeHandler {
- @Override
- public void traverse(Node node) {
- for (Node child : new ArrayList<Node>(node.getChildren())) {
- if (child instanceof NestPropertiesNode) {
- Node previous = child;
- for (RuleNode unNested : ((NestPropertiesNode) child)
- .unNesting()) {
- node.appendChild(unNested, previous);
- previous = unNested;
- node.removeChild(child);
- }
- } else {
- traverse(child);
- }
+ public static void traverse(NestPropertiesNode node) {
+ Node previous = node;
+ for (RuleNode unNested : node.unNesting()) {
+ node.getParentNode().appendChild(unNested, previous);
+ previous = unNested;
}
+ node.getParentNode().removeChild(node);
}
}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/ParentSelectorHandler.java b/theme-compiler/src/com/vaadin/sass/visitor/ParentSelectorHandler.java
new file mode 100644
index 0000000000..77e0bba10b
--- /dev/null
+++ b/theme-compiler/src/com/vaadin/sass/visitor/ParentSelectorHandler.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.sass.visitor;
+
+import java.util.ArrayList;
+
+import com.google.gwt.dev.util.collect.HashMap;
+import com.vaadin.sass.tree.BlockNode;
+import com.vaadin.sass.tree.Node;
+
+public class ParentSelectorHandler {
+
+ private static HashMap<Node, Node> parentSelectors = new HashMap<Node, Node>();
+
+ public static void traverse(BlockNode block) throws Exception {
+ Node parentNode = block.getParentNode();
+ if (parentNode instanceof BlockNode) {
+ boolean isParentSelector = false;
+ ArrayList<String> newList = new ArrayList<String>(block
+ .getSelectorList().size());
+ BlockNode parentBlock = (BlockNode) parentNode;
+ for (final String s : block.getSelectorList()) {
+
+ if (s.startsWith("&") || s.endsWith("&")) {
+ for (final String parentSelector : parentBlock
+ .getSelectorList()) {
+ newList.add(s.replace("&", parentSelector));
+ isParentSelector = true;
+ }
+
+ }
+ }
+
+ if (isParentSelector) {
+ block.setSelectorList(newList);
+ Node oldparent = block.getParentNode();
+ if (parentSelectors.containsKey(block.getParentNode())) {
+ block.getParentNode()
+ .getParentNode()
+ .appendChild(block,
+ parentSelectors.get(block.getParentNode()));
+ } else {
+ block.getParentNode().getParentNode()
+ .appendChild(block, block.getParentNode());
+ }
+
+ parentSelectors.put(oldparent, block);
+ }
+ }
+ }
+
+ public static void clear() {
+ parentSelectors.clear();
+ }
+}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/ParentSelectorVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/ParentSelectorVisitor.java
deleted file mode 100644
index f515d63e96..0000000000
--- a/theme-compiler/src/com/vaadin/sass/visitor/ParentSelectorVisitor.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.sass.visitor;
-
-import java.util.ArrayList;
-
-import com.vaadin.sass.tree.BlockNode;
-import com.vaadin.sass.tree.Node;
-
-public class ParentSelectorVisitor implements Visitor {
-
- @Override
- public void traverse(Node node) throws Exception {
- for (Node child : new ArrayList<Node>(node.getChildren())) {
- if (child instanceof BlockNode) {
- traverse(node, (BlockNode) child);
- }
- }
- }
-
- private void traverse(Node parent, BlockNode block) throws Exception {
- Node pre = block;
- for (Node child : new ArrayList<Node>(block.getChildren())) {
- if (child instanceof BlockNode) {
- BlockNode blockChild = (BlockNode) child;
- traverse(block, blockChild);
- for (final String s : blockChild.getSelectorList()) {
-
- if (s.contains("&")) {
- parent.appendChild(child, pre);
- pre = child;
- block.removeChild(child);
-
- ArrayList<String> newList = new ArrayList<String>(block
- .getSelectorList().size());
- for (final String parentSelector : block
- .getSelectorList()) {
- newList.add(s.replace("&", parentSelector));
- }
- blockChild.setSelectorList(newList);
- }
- }
- }
- }
- }
-}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/VariableNodeHandler.java b/theme-compiler/src/com/vaadin/sass/visitor/VariableNodeHandler.java
new file mode 100644
index 0000000000..3ea26433e2
--- /dev/null
+++ b/theme-compiler/src/com/vaadin/sass/visitor/VariableNodeHandler.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.sass.visitor;
+
+import com.vaadin.sass.ScssStylesheet;
+import com.vaadin.sass.tree.VariableNode;
+
+public class VariableNodeHandler {
+
+ public static void traverse(VariableNode node) {
+ if (ScssStylesheet.getVariable(node.getName()) == null
+ || !node.isGuarded()) {
+ ScssStylesheet.addVariable(node);
+ }
+ node.getParentNode().removeChild(node);
+ }
+
+}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/VariableVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/VariableVisitor.java
deleted file mode 100644
index c8e28cd9e3..0000000000
--- a/theme-compiler/src/com/vaadin/sass/visitor/VariableVisitor.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.sass.visitor;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import com.vaadin.sass.tree.IVariableNode;
-import com.vaadin.sass.tree.ListModifyNode;
-import com.vaadin.sass.tree.Node;
-import com.vaadin.sass.tree.VariableNode;
-
-public class VariableVisitor implements Visitor {
-
- private final HashMap<String, VariableNode> variables = new HashMap<String, VariableNode>();
-
- @Override
- public void traverse(Node node) {
-
- replaceVariables(node, node.getChildren());
-
- removeVariableNodes(node, node);
- }
-
- private void removeVariableNodes(Node parent, Node node) {
- for (final Node child : new ArrayList<Node>(node.getChildren())) {
- removeVariableNodes(node, child);
- }
- if (node instanceof VariableNode) {
- for (final Node child : node.getChildren()) {
- parent.appendChild(child, node);
- }
- parent.removeChild(node);
- }
- }
-
- private void replaceVariables(Node n, ArrayList<Node> children) {
-
- ArrayList<VariableNode> variables = new ArrayList<VariableNode>(
- this.variables.values());
-
- for (Node node : children) {
-
- if (node instanceof IVariableNode) {
- ((IVariableNode) node)
- .replaceVariables(new ArrayList<VariableNode>(
- this.variables.values()));
- }
-
- if (node instanceof VariableNode) {
- VariableNode variableNode = (VariableNode) node;
- if (this.variables.containsKey(variableNode.getName())
- && variableNode.isGuarded()) {
- continue;
- }
- this.variables.put(variableNode.getName(), variableNode);
- } else if (node instanceof ListModifyNode) {
-
- ListModifyNode modify = (ListModifyNode) node;
-
- String variable = modify.getNewVariable().substring(1);
-
- try {
- VariableNode modifiedList = modify.getModifiedList();
-
- this.variables.put(variable, modifiedList);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- replaceVariables(node, node.getChildren());
- }
-
- for (final VariableNode v : variables) {
- this.variables.put(v.getName(), v);
- }
- }
-
-}