Browse Source

Remove theme-compiler and replace with external vaadin-sass-compiler

* Moves CompileTheme from the theme-compiler to buildhelpers
* Refactors CompileTheme to get the Vaadin version on the command line
  instead of using the Version class found in vaadin-shared
* Refactors build scripts to pass the version number on the command line
  when running CompileTheme
* Removes the theme-compiler module/project/whatchamacallit
* Replaces the theme-compiler dependency with vaadin-sass-compiler 0.9.0
  from maven

Change-Id: I4f98d15b60e18a826bf264eb55d12b3e736e8e54
tags/7.2.0.beta1
Jonatan Kronqvist 10 years ago
parent
commit
353a1a1c30
100 changed files with 41 additions and 25352 deletions
  1. 8
    4
      WebContent/release-notes.html
  2. 0
    2
      all/ivy.xml
  3. 1
    1
      build.properties
  4. 5
    4
      build/ide.xml
  5. 7
    0
      buildhelpers/ivy.xml
  6. 11
    8
      buildhelpers/src/com/vaadin/buildhelpers/CompileTheme.java
  7. 2
    2
      client-compiler/ivy.xml
  8. 1
    1
      common.xml
  9. 0
    2
      ivysettings.xml
  10. 6
    4
      server/ivy.xml
  11. 0
    11
      theme-compiler/README
  12. 0
    15
      theme-compiler/apache2header.txt
  13. 0
    83
      theme-compiler/build.xml
  14. 0
    57
      theme-compiler/ivy.xml
  15. 0
    52
      theme-compiler/src/com/vaadin/sass/CustomConsoleHandler.java
  16. 0
    72
      theme-compiler/src/com/vaadin/sass/SassCompiler.java
  17. 0
    487
      theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java
  18. 0
    140
      theme-compiler/src/com/vaadin/sass/internal/expression/ArithmeticExpressionEvaluator.java
  19. 0
    46
      theme-compiler/src/com/vaadin/sass/internal/expression/BinaryExpression.java
  20. 0
    70
      theme-compiler/src/com/vaadin/sass/internal/expression/BinaryOperator.java
  21. 0
    21
      theme-compiler/src/com/vaadin/sass/internal/expression/Parentheses.java
  22. 0
    42
      theme-compiler/src/com/vaadin/sass/internal/expression/exception/ArithmeticException.java
  23. 0
    29
      theme-compiler/src/com/vaadin/sass/internal/expression/exception/IncompatibleUnitsException.java
  24. 0
    104
      theme-compiler/src/com/vaadin/sass/internal/handler/SCSSDocumentHandler.java
  25. 0
    398
      theme-compiler/src/com/vaadin/sass/internal/handler/SCSSDocumentHandlerImpl.java
  26. 0
    56
      theme-compiler/src/com/vaadin/sass/internal/handler/SCSSErrorHandler.java
  27. 0
    130
      theme-compiler/src/com/vaadin/sass/internal/parser/CharStream.java
  28. 0
    370
      theme-compiler/src/com/vaadin/sass/internal/parser/Generic_CharStream.java
  29. 0
    39
      theme-compiler/src/com/vaadin/sass/internal/parser/JumpException.java
  30. 0
    888
      theme-compiler/src/com/vaadin/sass/internal/parser/LexicalUnitImpl.java
  31. 0
    154
      theme-compiler/src/com/vaadin/sass/internal/parser/LocatorImpl.java
  32. 0
    100
      theme-compiler/src/com/vaadin/sass/internal/parser/MediaListImpl.java
  33. 0
    203
      theme-compiler/src/com/vaadin/sass/internal/parser/ParseException.java
  34. 0
    7887
      theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java
  35. 0
    3139
      theme-compiler/src/com/vaadin/sass/internal/parser/Parser.jj
  36. 0
    392
      theme-compiler/src/com/vaadin/sass/internal/parser/ParserConstants.java
  37. 0
    5000
      theme-compiler/src/com/vaadin/sass/internal/parser/ParserTokenManager.java
  38. 0
    40
      theme-compiler/src/com/vaadin/sass/internal/parser/SCSSLexicalUnit.java
  39. 0
    34
      theme-compiler/src/com/vaadin/sass/internal/parser/SCSSParseException.java
  40. 0
    77
      theme-compiler/src/com/vaadin/sass/internal/parser/SelectorListImpl.java
  41. 0
    69
      theme-compiler/src/com/vaadin/sass/internal/parser/Selectors.java
  42. 0
    41
      theme-compiler/src/com/vaadin/sass/internal/parser/ThrowedParseException.java
  43. 0
    146
      theme-compiler/src/com/vaadin/sass/internal/parser/Token.java
  44. 0
    162
      theme-compiler/src/com/vaadin/sass/internal/parser/TokenMgrError.java
  45. 0
    41
      theme-compiler/src/com/vaadin/sass/internal/parser/function/AbsFunctionGenerator.java
  46. 0
    41
      theme-compiler/src/com/vaadin/sass/internal/parser/function/CeilFunctionGenerator.java
  47. 0
    40
      theme-compiler/src/com/vaadin/sass/internal/parser/function/DarkenFunctionGenerator.java
  48. 0
    48
      theme-compiler/src/com/vaadin/sass/internal/parser/function/DefaultFunctionGenerator.java
  49. 0
    42
      theme-compiler/src/com/vaadin/sass/internal/parser/function/FloorFunctionGenerator.java
  50. 0
    40
      theme-compiler/src/com/vaadin/sass/internal/parser/function/LightenFunctionGenerator.java
  51. 0
    41
      theme-compiler/src/com/vaadin/sass/internal/parser/function/RoundFunctionGenerator.java
  52. 0
    57
      theme-compiler/src/com/vaadin/sass/internal/parser/function/SCSSFunctionGenerator.java
  53. 0
    200
      theme-compiler/src/com/vaadin/sass/internal/resolver/AbstractResolver.java
  54. 0
    52
      theme-compiler/src/com/vaadin/sass/internal/resolver/ClassloaderResolver.java
  55. 0
    77
      theme-compiler/src/com/vaadin/sass/internal/resolver/FilesystemResolver.java
  56. 0
    39
      theme-compiler/src/com/vaadin/sass/internal/resolver/ScssStylesheetResolver.java
  57. 0
    43
      theme-compiler/src/com/vaadin/sass/internal/selector/CompositeSelector.java
  58. 0
    340
      theme-compiler/src/com/vaadin/sass/internal/selector/SelectorUtil.java
  59. 0
    128
      theme-compiler/src/com/vaadin/sass/internal/tree/BlockNode.java
  60. 0
    48
      theme-compiler/src/com/vaadin/sass/internal/tree/CommentNode.java
  61. 0
    33
      theme-compiler/src/com/vaadin/sass/internal/tree/ContentNode.java
  62. 0
    68
      theme-compiler/src/com/vaadin/sass/internal/tree/ExtendNode.java
  63. 0
    47
      theme-compiler/src/com/vaadin/sass/internal/tree/FontFaceNode.java
  64. 0
    49
      theme-compiler/src/com/vaadin/sass/internal/tree/ForNode.java
  65. 0
    63
      theme-compiler/src/com/vaadin/sass/internal/tree/FunctionNode.java
  66. 0
    24
      theme-compiler/src/com/vaadin/sass/internal/tree/IVariableNode.java
  67. 0
    85
      theme-compiler/src/com/vaadin/sass/internal/tree/ImportNode.java
  68. 0
    51
      theme-compiler/src/com/vaadin/sass/internal/tree/KeyframeSelectorNode.java
  69. 0
    72
      theme-compiler/src/com/vaadin/sass/internal/tree/KeyframesNode.java
  70. 0
    34
      theme-compiler/src/com/vaadin/sass/internal/tree/ListAppendNode.java
  71. 0
    43
      theme-compiler/src/com/vaadin/sass/internal/tree/ListContainsNode.java
  72. 0
    131
      theme-compiler/src/com/vaadin/sass/internal/tree/ListModifyNode.java
  73. 0
    35
      theme-compiler/src/com/vaadin/sass/internal/tree/ListRemoveNode.java
  74. 0
    82
      theme-compiler/src/com/vaadin/sass/internal/tree/MediaNode.java
  75. 0
    57
      theme-compiler/src/com/vaadin/sass/internal/tree/MicrosoftRuleNode.java
  76. 0
    122
      theme-compiler/src/com/vaadin/sass/internal/tree/MixinDefNode.java
  77. 0
    134
      theme-compiler/src/com/vaadin/sass/internal/tree/MixinNode.java
  78. 0
    84
      theme-compiler/src/com/vaadin/sass/internal/tree/NestPropertiesNode.java
  79. 0
    184
      theme-compiler/src/com/vaadin/sass/internal/tree/Node.java
  80. 0
    175
      theme-compiler/src/com/vaadin/sass/internal/tree/RuleNode.java
  81. 0
    64
      theme-compiler/src/com/vaadin/sass/internal/tree/SimpleNode.java
  82. 0
    131
      theme-compiler/src/com/vaadin/sass/internal/tree/VariableNode.java
  83. 0
    40
      theme-compiler/src/com/vaadin/sass/internal/tree/WhileNode.java
  84. 0
    104
      theme-compiler/src/com/vaadin/sass/internal/tree/controldirective/EachDefNode.java
  85. 0
    32
      theme-compiler/src/com/vaadin/sass/internal/tree/controldirective/ElseNode.java
  86. 0
    60
      theme-compiler/src/com/vaadin/sass/internal/tree/controldirective/IfElseDefNode.java
  87. 0
    22
      theme-compiler/src/com/vaadin/sass/internal/tree/controldirective/IfElseNode.java
  88. 0
    62
      theme-compiler/src/com/vaadin/sass/internal/tree/controldirective/IfNode.java
  89. 0
    22
      theme-compiler/src/com/vaadin/sass/internal/util/Clonable.java
  90. 0
    309
      theme-compiler/src/com/vaadin/sass/internal/util/ColorUtil.java
  91. 0
    89
      theme-compiler/src/com/vaadin/sass/internal/util/DeepCopy.java
  92. 0
    82
      theme-compiler/src/com/vaadin/sass/internal/util/FastByteArrayInputStream.java
  93. 0
    103
      theme-compiler/src/com/vaadin/sass/internal/util/FastByteArrayOutputStream.java
  94. 0
    237
      theme-compiler/src/com/vaadin/sass/internal/util/StringUtil.java
  95. 0
    112
      theme-compiler/src/com/vaadin/sass/internal/visitor/BlockNodeHandler.java
  96. 0
    72
      theme-compiler/src/com/vaadin/sass/internal/visitor/EachNodeHandler.java
  97. 0
    130
      theme-compiler/src/com/vaadin/sass/internal/visitor/ExtendNodeHandler.java
  98. 0
    117
      theme-compiler/src/com/vaadin/sass/internal/visitor/IfElseNodeHandler.java
  99. 0
    132
      theme-compiler/src/com/vaadin/sass/internal/visitor/ImportNodeHandler.java
  100. 0
    0
      theme-compiler/src/com/vaadin/sass/internal/visitor/MixinNodeHandler.java

+ 8
- 4
WebContent/release-notes.html View File

@@ -298,8 +298,7 @@
<li>Shared library (<tt>vaadin-shared</tt>) for both
server- and client-side libraries
</li>
<li>Built-in themes (<tt>vaadin-themes</tt>) and the
theme compiler (<tt>vaadin-theme-compiler</tt>)
<li>Built-in themes (<tt>vaadin-themes</tt>)
</li>
<li>Dependency libraries provided under the <tt>lib/</tt>
folder
@@ -322,8 +321,6 @@
<tt>vaadin-client-compiled</tt>
,
<tt>vaadin-shared</tt>
,
<tt>vaadin-theme-compiler</tt>
, and
<tt>vaadin-themes</tt>
from the main folder and the dependencies from the
@@ -337,6 +334,13 @@
components.)
</p>

<h4 id="package.updates">Updates to the Packaging</h4>
<p>
Since Vaadin 7.2.0, the old vaadin-theme-compiler has been moved into
a separate project and renamed to vaadin-sass-compiler. It is now included
along with the other 3rd party dependencies in the ZIP package.
</p>

<p>
For pure client-side development, you only need the
<tt>vaadin-client</tt>

+ 0
- 2
all/ivy.xml View File

@@ -26,8 +26,6 @@
rev="${vaadin.version}" />
<dependency org="com.vaadin" name="vaadin-client-compiler"
rev="${vaadin.version}" />
<dependency org="com.vaadin" name="vaadin-theme-compiler"
rev="${vaadin.version}" />
<dependency org="com.vaadin" name="vaadin-themes"
rev="${vaadin.version}" />
<dependency org="com.vaadin" name="vaadin-client-compiled"

+ 1
- 1
build.properties View File

@@ -5,4 +5,4 @@ vaadin.vendor=Vaadin Ltd
vaadin.url=http://vaadin.com
vaadin.java.version=1.6
vaadin.version=0.0.0.unversioned-development-build
vaadin.sass.version=0.9.0

+ 5
- 4
build/ide.xml View File

@@ -23,8 +23,8 @@
<ivy:cachepath pathid="shared.deps" conf="ide" />
<ivy:resolve log="download-only" file="uitest/ivy.xml" conf="ide" />
<ivy:cachepath pathid="uitest.deps" conf="ide" />
<ivy:resolve log="download-only" file="theme-compiler/ivy.xml" conf="ide" />
<ivy:cachepath pathid="theme-compiler.deps" conf="ide" />
<ivy:resolve log="download-only" file="buildhelpers/ivy.xml" />
<ivy:cachepath pathid="buildhelpers.deps" />

<path id="classpath">
<path location="bin" />
@@ -36,12 +36,11 @@
<path location="${gwt.dev.super.src}" />
<path location="${gwt.dev.src}" />
<path refid="client-compiler.deps" />
<path refid="theme-compiler.deps" />
<path refid="server.deps" />
<path refid="shared.deps" />
<path refid="uitest.deps" />
<path refid="client.deps" />
<path location="theme-compiler/src" />
<path refid="buildhelpers.deps" />
<path location="server/src" />
<path location="shared/src" />
<path location="uitest/src" />
@@ -76,6 +75,8 @@
<arg value="${theme}" />
<arg value="--theme-folder" />
<arg value="WebContent/VAADIN/themes" />
<arg value="--version" />
<arg value="${vaadin.version}" />
</java>

</target>

+ 7
- 0
buildhelpers/ivy.xml View File

@@ -29,6 +29,13 @@
</publications>
<dependencies>
<dependency org="commons-io" name="commons-io" rev="2.2" />
<dependency org="commons-cli" name="commons-cli" rev="1.2" />
<dependency org="com.vaadin" name="vaadin-sass-compiler"
rev="${vaadin.sass.version}" />

<!-- Internally used, for now -->
<dependency org="com.carrotsearch" name="smartsprites"
rev="0.2.10" />
</dependencies>

</ivy-module>

theme-compiler/src/com/vaadin/buildhelpers/CompileTheme.java → buildhelpers/src/com/vaadin/buildhelpers/CompileTheme.java View File

@@ -29,7 +29,6 @@ import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.shared.Version;

/**
* Helper to combine css divided into separate per component dirs into one to
@@ -47,9 +46,12 @@ public class CompileTheme {
options.addOption("t", "theme", true, "the theme to compile");
options.addOption("f", "theme-folder", true,
"the folder containing the theme");
options.addOption("v", "version", true,
"the Vaadin version to compile for");
CommandLineParser parser = new PosixParser();
CommandLine params = parser.parse(options, args);
if (!params.hasOption("theme") || !params.hasOption("theme-folder")) {
if (!params.hasOption("theme") || !params.hasOption("theme-folder")
|| !params.hasOption("version")) {
// automatically generate the help statement
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(CompileTheme.class.getName(), options);
@@ -57,11 +59,11 @@ public class CompileTheme {
}
String themeName = params.getOptionValue("theme");
String themeFolder = params.getOptionValue("theme-folder");
String version = params.getOptionValue("version");

// Regular theme
try {
processSassTheme(themeFolder, themeName, "styles",
Version.getFullVersion());
processSassTheme(themeFolder, themeName, "styles", version);
System.out.println("Compiling theme " + themeName
+ " styles successful");
} catch (Exception e) {
@@ -71,8 +73,7 @@ public class CompileTheme {
}
// Legacy theme w/o .themename{} wrapping
try {
processSassTheme(themeFolder, themeName, "legacy-styles",
Version.getFullVersion());
processSassTheme(themeFolder, themeName, "legacy-styles", version);
System.out.println("Compiling theme " + themeName
+ " legacy-styles successful");
} catch (Exception e) {
@@ -101,13 +102,15 @@ public class CompileTheme {
+ " not found");
}
scss.compile();
String filteredScss = scss.printState().replace("@version@", version);

BufferedWriter out = new BufferedWriter(new FileWriter(stylesCssName));
out.write(cssHeader.toString());
out.write(scss.printState().replace("@version@", version));
out.write(filteredScss);
out.close();

System.out.println("Compiled CSS to " + stylesCssName + " ("
+ scss.printState().length() + " bytes)");
+ filteredScss.length() + " bytes)");

createSprites(themeFolder, themeName);
File oldCss = new File(stylesCssName);

+ 2
- 2
client-compiler/ivy.xml View File

@@ -25,8 +25,8 @@
rev="${vaadin.version}" conf="build" />
<dependency org="com.vaadin" name="vaadin-client"
rev="${vaadin.version}" conf="build" />
<dependency org="com.vaadin" name="vaadin-theme-compiler"
rev="${vaadin.version}" conf="build" />
<dependency org="com.vaadin" name="vaadin-sass-compiler"
rev="${vaadin.sass.version}" conf="build,ide->default" />

<dependency org="commons-collections" name="commons-collections"
rev="3.1" conf="build,ide -> default" />

+ 1
- 1
common.xml View File

@@ -9,7 +9,7 @@
<property name="gwt.basedir" location="${vaadin.basedir}/../gwt" />
<property file="${vaadin.basedir}/build.properties" />

<property name="modules.to.publish.to.maven" value="shared,server,client,client-compiler,client-compiled,theme-compiler,themes,push" />
<property name="modules.to.publish.to.maven" value="shared,server,client,client-compiler,client-compiled,themes,push" />
<property name="modules.to.publish.to.download" value="${modules.to.publish.to.maven},all" />

<ivy:settings file="${vaadin.basedir}/ivysettings.xml" />

+ 0
- 2
ivysettings.xml View File

@@ -39,8 +39,6 @@
resolver="build-temp" />
<module organisation="com.vaadin" name="vaadin-client-compiled"
resolver="build-temp" />
<module organisation="com.vaadin" name="vaadin-theme-compiler"
resolver="build-temp" />
<module organisation="com.vaadin" name="vaadin-themes"
resolver="build-temp" />
<module organisation="com.vaadin" name="vaadin-push"

+ 6
- 4
server/ivy.xml View File

@@ -42,16 +42,18 @@
<dependency org="javax.validation" name="validation-api"
rev="1.0.0.GA" conf="build-provided,ide,test -> default" />

<!-- Sass compiler -->
<dependency org="com.vaadin" name="vaadin-sass-compiler"
rev="${vaadin.sass.version}" conf="build,ide,test->default">
<exclude type="pom" conf="test" />
</dependency>

<!-- LIBRARY DEPENDENCIES (compile time) -->
<!-- Project modules -->
<dependency org="com.vaadin" name="vaadin-shared"
rev="${vaadin.version}" conf="build,test->build">
<exclude type="pom" conf="test" />
</dependency>
<dependency org="com.vaadin" name="vaadin-theme-compiler"
rev="${vaadin.version}" conf="build,test->build">
<exclude type="pom" conf="test" />
</dependency>
<dependency org="com.vaadin" name="vaadin-push" rev="${vaadin.version}"
conf="build-provided,test->build">
<exclude type="pom" conf="test" />

+ 0
- 11
theme-compiler/README View File

@@ -1,11 +0,0 @@
This project compiles SCSS into CSS.
It parses the SCSS into a tree.

Classes
=======
SassCompiler: This is the main class that can be run from command line. First parameter is for a scss file to be compiled. Second parameter is optional and is a reference to a file where you want the compiled css. If file doesn't exist, it will be deleted. If file exists, it will be deleted and recreated. If second argument is left out, the css will be printed into standard out.
ScssStylesheet: When Scss/Css is parsed in, it will be represented in memory as this file. Reference is got through static get(File file) where file is input.
Parser: A JavaCC compiled java class that parses the input and notifies the DocumentHandler on what nodes it encounters.
Parser.jj: Source for the Parser class.
SCSSDocumentHandlerImpl: Class that takes in calls from parser and creates nodes into ScssStylesheet based on those calls.
Node package: All the nodes representing the Scss/Css in tree format

+ 0
- 15
theme-compiler/apache2header.txt View File

@@ -1,15 +0,0 @@
/*
* Copyright 2000-2013 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.
*/

+ 0
- 83
theme-compiler/build.xml View File

@@ -1,83 +0,0 @@
<?xml version="1.0"?>

<project name="vaadin-theme-compiler" basedir="." default="publish-local" xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:antcontrib="antlib:net.sf.antcontrib">
<description>
Compiles build helpers used when building other modules.
</description>
<include file="../common.xml" as="common" />
<include file="../build.xml" as="vaadin" />
<include file="../gwt-files.xml" as="gwtfiles" />

<!-- global properties -->
<property name="module.name" value="vaadin-theme-compiler" />
<property name="module.symbolic" value="com.vaadin.theme-compiler" />
<property name="result.dir" value="result" />
<property name="parser.src.dir" value="src/com/vaadin/sass/internal/parser" />
<property name="generate.dir" value="${result.dir}/generated/${parser.src.dir}" />
<property name="header.file" location="apache2header.txt" />

<path id="classpath.compile.custom">
</path>
<path id="classpath.test.custom" />

<property name="classes.exclude" value="**/*.properties"/>
<property name="extra.classes" value="${classes.exclude}"/>

<target name="parser">
<!-- Copy javacc-5.0.jar to ${result.dir}/javacc/javacc.jar as the
javacc task requires the jar to be named javacc.jar -->
<property name="javacc.home" location="${result.dir}/javacc" />
<ivy:retrieve organisation="net.java.dev.javacc" module="javacc" revision="5.0" inline="true" type="jar" pattern="${javacc.home}/[artifact].[ext]" />
<delete dir="${generate.dir}" />
<mkdir dir="${generate.dir}" />
<!-- Generate new parser files in another directory, this ensure
they are always generated -->
<copy file="${parser.src.dir}/Parser.jj" todir="${generate.dir}" />
<javacc target="${generate.dir}/Parser.jj" javacchome="${javacc.home}">
</javacc>
<!-- Add headers to the generated files and copy back to src -->
<antcontrib:foreach target="prepend.generated.file.header" param="path">
<path>
<fileset dir="${generate.dir}" includes="*.java" excludes="ParseException.java" />
</path>
</antcontrib:foreach>
</target>

<target name="prepend.generated.file.header">
<basename property="file" file="${path}" />
<concat destfile="${parser.src.dir}/${file}">
<header filtering="no" trimleading="no" file="${header.file}" />
<path path="${generate.dir}/${file}" />
</concat>
</target>

<target name="jar" depends="parser">
<antcall target="common.jar">
<param name="import-package" value="org.apache.commons.jexl2;version=&quot;2.1.1&quot;,org.w3c.css.sac;version=&quot;1.3&quot;,org.w3c.flute.parser;version=&quot;1.3.0.gg2&quot;,org.w3c.flute.parser.selectors;version=&quot;1.3.0.gg2&quot;,org.w3c.flute.util;version=&quot;1.3.0.gg2&quot;" />
<reference torefid="extra.jar.includes" refid="empty.reference" />
</antcall>
</target>
<target name="publish-local" depends="jar">
<antcall target="common.sources.jar">
<reference torefid="extra.jar.includes" refid="empty.reference" />
</antcall>
<antcall target="common.javadoc.jar" />

<antcall target="common.publish-local" />
</target>

<target name="clean">
<antcall target="common.clean" />
</target>

<target name="checkstyle">
<antcall target="common.checkstyle">
<param name="cs.src" location="src" />
</antcall>
</target>

<target name="test" depends="checkstyle">
<antcall target="common.test.run" />
</target>

</project>

+ 0
- 57
theme-compiler/ivy.xml View File

@@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"
xmlns:m="http://ant.apache.org/ivy/maven">

<info organisation="com.vaadin" module="vaadin-theme-compiler"
revision="${vaadin.version}" />

<configurations>
<conf name="build" />
<conf name="build-provided" />
<conf name="ide" visibility="private" />
<conf name="test" />
</configurations>
<publications>
<artifact type="jar" ext="jar" />
<artifact type="pom" ext="pom" />
<artifact type="source" ext="jar" m:classifier="sources" />
<artifact type="javadoc" ext="jar" m:classifier="javadoc" />
</publications>
<dependencies defaultconf="*->default">
<!-- LIBRARY DEPENDENCIES (compile time) -->
<!-- Project modules -->
<dependency org="com.vaadin" name="vaadin-shared"
rev="${vaadin.version}" conf="build,test->build" >
<exclude type="pom" conf="test" />
</dependency>

<!-- Required build libs -->
<dependency org="org.apache.commons" name="commons-jexl"
rev="2.1.1" conf="build,ide,test->default" />
<dependency org="org.w3c.css" name="sac" rev="1.3"
conf="build,ide,test->default" />
<dependency org="net.sourceforge.cssparser" name="cssparser"
rev="0.9.5" conf="build,ide,test->default" />
<dependency org="commons-cli" name="commons-cli" rev="1.2"
conf="build,ide,test->default" />

<!-- Provided build libs -->
<dependency org="javax.servlet" name="servlet-api"
rev="2.4" conf="build-provided->default" />

<!-- Testing libs -->
<dependency org="junit" name="junit" rev="4.11"
conf="ide,test -> default" />
<dependency org="org.jsoup" name="jsoup" rev="1.6.3"
conf="ide,test -> default" />

<!-- Internally used, for now -->
<dependency org="com.carrotsearch" name="smartsprites"
rev="0.2.10" />
<!-- Use the same commons-io as the rest of the project -->
<override org="commons-io" module="commons-io" rev="2.2" />
</dependencies>

</ivy-module>

+ 0
- 52
theme-compiler/src/com/vaadin/sass/CustomConsoleHandler.java View File

@@ -1,52 +0,0 @@
/*
* Copyright 2000-2013 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;

import java.io.PrintStream;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.LogRecord;

/**
*
* @since
* @author Vaadin Ltd
*/
public class CustomConsoleHandler extends ConsoleHandler {

private ConsoleHandler stdoutHandler;

public CustomConsoleHandler() {
PrintStream err = System.err;
/*
* ConsoleHandler uses System.err to output all messages. Replace
* System.err temporary to construct ConsoleHandler and set it back
* after construction.
*/
System.setErr(System.out);
stdoutHandler = new ConsoleHandler();
System.setErr(err);
}

@Override
public void publish(LogRecord record) {
if (!Level.SEVERE.equals(record.getLevel())) {
stdoutHandler.publish(record);
} else {
super.publish(record);
}
}
}

+ 0
- 72
theme-compiler/src/com/vaadin/sass/SassCompiler.java View File

@@ -1,72 +0,0 @@
/*
* Copyright 2000-2013 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;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import com.vaadin.sass.internal.ScssStylesheet;

public class SassCompiler {

public static void main(String[] args) throws Exception {
String input = null;
String output = null;
if (args.length < 1 || args.length > 2) {
System.out
.println("usage: SassCompile <scss file to compile> <css file to write>");
return;
}

File in = new File(args[0]);
if (!in.canRead()) {
System.err.println(in.getCanonicalPath() + " could not be read!");
return;
}
input = in.getCanonicalPath();

if (args.length == 2) {
output = args[1];
}

// You can set the resolver; if none is set, VaadinResolver will be used
// ScssStylesheet.setStylesheetResolvers(new VaadinResolver());

ScssStylesheet scss = ScssStylesheet.get(input);
if (scss == null) {
System.err.println("The scss file " + input
+ " could not be found.");
return;
}

scss.compile();
if (output == null) {
System.out.println(scss.printState());
} else {
writeFile(output, scss.printState());
}
}

public static void writeFile(String filename, String output)
throws IOException {
File file = new File(filename);
FileWriter writer = new FileWriter(file);
writer.write(output);
writer.close();
}
}

+ 0
- 487
theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java View File

@@ -1,487 +0,0 @@
/*
* Copyright 2000-2013 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.internal;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.logging.LogManager;
import java.util.logging.Logger;

import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.InputSource;

import com.vaadin.buildhelpers.CompileTheme;
import com.vaadin.sass.internal.handler.SCSSDocumentHandler;
import com.vaadin.sass.internal.handler.SCSSDocumentHandlerImpl;
import com.vaadin.sass.internal.handler.SCSSErrorHandler;
import com.vaadin.sass.internal.parser.ParseException;
import com.vaadin.sass.internal.parser.Parser;
import com.vaadin.sass.internal.parser.SCSSParseException;
import com.vaadin.sass.internal.resolver.ClassloaderResolver;
import com.vaadin.sass.internal.resolver.FilesystemResolver;
import com.vaadin.sass.internal.resolver.ScssStylesheetResolver;
import com.vaadin.sass.internal.tree.BlockNode;
import com.vaadin.sass.internal.tree.MixinDefNode;
import com.vaadin.sass.internal.tree.Node;
import com.vaadin.sass.internal.tree.VariableNode;
import com.vaadin.sass.internal.tree.controldirective.IfElseDefNode;
import com.vaadin.sass.internal.visitor.ExtendNodeHandler;
import com.vaadin.sass.internal.visitor.ImportNodeHandler;

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 static HashMap<Node, Node> lastNodeAdded = new HashMap<Node, Node>();

private File file;

private String charset;

private List<ScssStylesheetResolver> resolvers = new ArrayList<ScssStylesheetResolver>();

/**
* Read in a file SCSS and parse it into a ScssStylesheet
*
* @param file
* @throws IOException
*/
public ScssStylesheet() {
super();
}

/**
* Main entry point for the SASS compiler. Takes in a file and builds up a
* ScssStylesheet tree out of it. Calling compile() on it will transform
* SASS into CSS. Calling printState() will print out the SCSS/CSS.
*
* @param identifier
* The file path. If null then null is returned.
* @return
* @throws CSSException
* @throws IOException
*/
public static ScssStylesheet get(String identifier) throws CSSException,
IOException {
return get(identifier, null);
}

/**
* Main entry point for the SASS compiler. Takes in a file and an optional
* parent style sheet, then builds up a ScssStylesheet tree out of it.
* Calling compile() on it will transform SASS into CSS. Calling
* printState() will print out the SCSS/CSS.
*
* @param identifier
* The file path. If null then null is returned.
* @param parentStylesheet
* Style sheet from which to inherit resolvers and encoding. May
* be null.
* @return
* @throws CSSException
* @throws IOException
*/
public static ScssStylesheet get(String identifier,
ScssStylesheet parentStylesheet) throws CSSException, IOException {
return get(identifier, parentStylesheet, new SCSSDocumentHandlerImpl(),
new SCSSErrorHandler());
}

/**
* Main entry point for the SASS compiler. Takes in a file, an optional
* parent stylesheet, and document and error handlers. Then builds up a
* ScssStylesheet tree out of it. Calling compile() on it will transform
* SASS into CSS. Calling printState() will print out the SCSS/CSS.
*
* @param identifier
* The file path. If null then null is returned.
* @param parentStylesheet
* Style sheet from which to inherit resolvers and encoding. May
* be null.
* @param documentHandler
* Instance of document handler. May not be null.
* @param errorHandler
* Instance of error handler. May not be null.
* @return
* @throws CSSException
* @throws IOException
*/
public static ScssStylesheet get(String identifier,
ScssStylesheet parentStylesheet,
SCSSDocumentHandler documentHandler, SCSSErrorHandler errorHandler)
throws CSSException, IOException {
/*
* The encoding to be used is passed through "encoding" parameter. the
* imported children scss node will have the same encoding as their
* parent, ultimately the root scss file. The root scss node has this
* "encoding" parameter to be null. Its encoding is determined by the
*
* @charset declaration, the default one is ASCII.
*/

if (identifier == null) {
return null;
}

// FIXME Is this actually intended? /John 1.3.2013
File file = new File(identifier);
file = file.getCanonicalFile();

ScssStylesheet stylesheet = documentHandler.getStyleSheet();
if (parentStylesheet == null) {
// Use default resolvers
stylesheet.addResolver(new FilesystemResolver());
stylesheet.addResolver(new ClassloaderResolver());
} else {
// Use parent resolvers
stylesheet.setResolvers(parentStylesheet.getResolvers());
}
InputSource source = stylesheet.resolveStylesheet(identifier,
parentStylesheet);
if (source == null) {
return null;
}
if (parentStylesheet != null) {
source.setEncoding(parentStylesheet.getCharset());
}

Parser parser = new Parser();
parser.setErrorHandler(errorHandler);
parser.setDocumentHandler(documentHandler);

try {
parser.parseStyleSheet(source);
} catch (ParseException e) {
// catch ParseException, re-throw a SCSSParseException which has
// file name info.
throw new SCSSParseException(e, identifier);
}

stylesheet.setCharset(parser.getInputSource().getEncoding());
return stylesheet;
}

public InputSource resolveStylesheet(String identifier,
ScssStylesheet parentStylesheet) {
for (ScssStylesheetResolver resolver : getResolvers()) {
InputSource source = resolver.resolve(parentStylesheet, identifier);
if (source != null) {
File f = new File(source.getURI());
setFile(f);
return source;
}
}

return null;
}

/**
* Retrieves a list of resolvers to use when resolving imports
*
* @since 7.2
* @return the resolvers used to resolving imports
*/
public List<ScssStylesheetResolver> getResolvers() {
return Collections.unmodifiableList(resolvers);
}

/**
* Sets the list of resolvers to use when resolving imports
*
* @since 7.2
* @param resolvers
* the resolvers to set
*/
public void setResolvers(List<ScssStylesheetResolver> resolvers) {
this.resolvers = new ArrayList<ScssStylesheetResolver>(resolvers);
}

/**
* Adds the given resolver to the resolver list
*
* @since 7.2
* @param resolver
* The resolver to add
*/
public void addResolver(ScssStylesheetResolver resolver) {
resolvers.add(resolver);
}

/**
* Applies all the visitors and compiles SCSS into Css.
*
* @throws Exception
*/
public void compile() throws Exception {
mainStyleSheet = this;
mixinDefs.clear();
variables.clear();
ifElseDefNodes.clear();
lastNodeAdded.clear();
ExtendNodeHandler.clear();
importOtherFiles(this);
populateDefinitions(this);
traverse(this);
removeEmptyBlocks(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);
}

}

/**
* Prints out the current state of the node tree. Will return SCSS before
* compile and CSS after.
*
* For now this is an own method with it's own implementation that most node
* types will implement themselves.
*/
@Override
public String printState() {
return buildString(PRINT_STRATEGY);
}

@Override
public String toString() {
return "Stylesheet node [" + buildString(TO_STRING_STRATEGY) + "]";
}

public void addChild(int index, VariableNode node) {
if (node != null) {
children.add(index, node);
}
}

public static ScssStylesheet get() {
return mainStyleSheet;
}

@Override
public void traverse() {
// Not used for ScssStylesheet
}

/**
* Traverses a node and its children recursively, calling all the
* appropriate handlers via {@link Node#traverse()}.
*
* The node itself may be removed during the traversal and replaced with
* other nodes at the same position or later on the child list of its
* parent.
*
* @param node
* node to traverse
* @return true if the node was removed (and possibly replaced by others),
* false if not
*/
public boolean traverse(Node node) {
Node originalParent = node.getParentNode();

node.traverse();

Map<String, VariableNode> variableScope = openVariableScope();

// the size of the child list may change on each iteration: current node
// may get deleted and possibly other nodes have been inserted where it
// was or after that position
for (int i = 0; i < node.getChildren().size(); i++) {
Node current = node.getChildren().get(i);
if (traverse(current)) {
// current has been removed
--i;
}
}

closeVariableScope(variableScope);

// clean up insert point so that processing of the next block will
// insert after that block
lastNodeAdded.remove(originalParent);

// has the node been removed from its parent?
if (originalParent != null) {
boolean removed = !originalParent.getChildren().contains(node);
return removed;
} else {
return false;
}
}

/**
* Start a new scope for variables. Any variables set or modified after
* opening a new scope are only valid until the scope is closed, at which
* time they are replaced with their old values.
*
* @return old scope to give to a paired {@link #closeVariableScope(Map)}
* call at the end of the scope (unmodifiable map).
*/
public static Map<String, VariableNode> openVariableScope() {
@SuppressWarnings("unchecked")
HashMap<String, VariableNode> variableScope = (HashMap<String, VariableNode>) variables
.clone();
return Collections.unmodifiableMap(variableScope);
}

/**
* End a scope for variables, replacing all active variables with those from
* the original scope (obtained from {@link #openVariableScope()}).
*
* @param originalScope
* original scope
*/
public static void closeVariableScope(
Map<String, VariableNode> originalScope) {
variables.clear();
variables.putAll(originalScope);
}

public void removeEmptyBlocks(Node node) {
// depth first for avoiding re-checking parents of removed nodes
for (Node child : new ArrayList<Node>(node.getChildren())) {
removeEmptyBlocks(child);
}
Node parent = node.getParentNode();
if (node instanceof BlockNode && node.getChildren().isEmpty()
&& parent != null) {
// remove empty block
parent.removeChild(node);
}
}

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 setFile(File file) {
this.file = file;
}

/**
* Returns the directory containing this style sheet
*
* @since 7.2
* @return The directory containing this style sheet
*/
public String getDirectory() {
return file.getParent();
}

/**
* Returns the full file name for this style sheet
*
* @since 7.2
* @return The full file name for this style sheet
*/
public String getFileName() {
return file.getPath();
}

public static HashMap<Node, Node> getLastNodeAdded() {
return lastNodeAdded;
}

public static final void warning(String msg) {
Logger.getLogger(ScssStylesheet.class.getName()).warning(msg);
}

public String getCharset() {
return charset;
}

public void setCharset(String charset) {
this.charset = charset;
}

private String buildString(BuildStringStrategy strategy) {
StringBuilder string = new StringBuilder("");
String delimeter = "\n\n";
// add charset declaration, if it is not default "ASCII".
if (!"ASCII".equals(getCharset())) {
string.append("@charset \"").append(getCharset()).append("\";")
.append(delimeter);
}
if (children.size() > 0) {
string.append(strategy.build(children.get(0)));
}
if (children.size() > 1) {
for (int i = 1; i < children.size(); i++) {
String childString = strategy.build(children.get(i));
if (childString != null) {
string.append(delimeter).append(childString);
}
}
}
String output = string.toString();
return output;
}

static {
String logFile = System.getProperty("java.util.logging.config.file");
if (logFile == null) {
try {
LogManager.getLogManager().readConfiguration(
CompileTheme.class
.getResourceAsStream("/logging.properties"));
} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

}

+ 0
- 140
theme-compiler/src/com/vaadin/sass/internal/expression/ArithmeticExpressionEvaluator.java View File

@@ -1,140 +0,0 @@
/*
* Copyright 2000-2013 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.internal.expression;

import static com.vaadin.sass.internal.parser.SCSSLexicalUnit.SCSS_VARIABLE;

import java.util.Stack;

import com.vaadin.sass.internal.expression.exception.ArithmeticException;
import com.vaadin.sass.internal.parser.LexicalUnitImpl;
import com.vaadin.sass.internal.parser.SCSSLexicalUnit;

public class ArithmeticExpressionEvaluator {
private static ArithmeticExpressionEvaluator instance;

public static ArithmeticExpressionEvaluator get() {
if (instance == null) {
instance = new ArithmeticExpressionEvaluator();
}
return instance;
}

private void createNewOperand(BinaryOperator operator,
Stack<Object> operands) {
Object rightOperand = operands.pop();
operands.push(new BinaryExpression(operands.pop(), operator,
rightOperand));
}

public boolean containsArithmeticalOperator(LexicalUnitImpl term) {
LexicalUnitImpl current = term;
while (current != null) {
for (BinaryOperator operator : BinaryOperator.values()) {
/*
* '/' is treated as an arithmetical operator when one of its
* operands is Variable, or there is another binary operator.
* Otherwise, '/' is treated as a CSS operator.
*/
if (current.getLexicalUnitType() == operator.type) {
if (current.getLexicalUnitType() != BinaryOperator.DIV.type) {
return true;
} else {
if (current.getPreviousLexicalUnit()
.getLexicalUnitType() == SCSS_VARIABLE
|| current.getNextLexicalUnit()
.getLexicalUnitType() == SCSS_VARIABLE) {
return true;
}
}
}
}
current = current.getNextLexicalUnit();
}
return false;
}

private Object createExpression(LexicalUnitImpl term) {
LexicalUnitImpl current = term;
boolean afterOperand = false;
Stack<Object> operands = new Stack<Object>();
Stack<Object> operators = new Stack<Object>();
inputTermLoop: while (current != null) {
if (afterOperand) {
if (current.getLexicalUnitType() == SCSSLexicalUnit.SCSS_OPERATOR_RIGHT_PAREN) {
Object operator = null;
while (!operators.isEmpty()
&& ((operator = operators.pop()) != Parentheses.LEFT)) {
createNewOperand((BinaryOperator) operator, operands);
}
current = current.getNextLexicalUnit();
continue;
}
afterOperand = false;
for (BinaryOperator operator : BinaryOperator.values()) {
if (current.getLexicalUnitType() == operator.type) {
while (!operators.isEmpty()
&& (operators.peek() != Parentheses.LEFT)
&& (((BinaryOperator) operators.peek()).precedence >= operator.precedence)) {
createNewOperand((BinaryOperator) operators.pop(),
operands);
}
operators.push(operator);

current = current.getNextLexicalUnit();
continue inputTermLoop;
}
}
throw new ArithmeticException("Illegal arithmetic expression",
term);
}
if (current.getLexicalUnitType() == SCSSLexicalUnit.SCSS_OPERATOR_LEFT_PAREN) {
operators.push(Parentheses.LEFT);
current = current.getNextLexicalUnit();
continue;
}
afterOperand = true;

operands.push(current);
current = current.getNextLexicalUnit();
}

while (!operators.isEmpty()) {
Object operator = operators.pop();
if (operator == Parentheses.LEFT) {
throw new ArithmeticException("Unexpected \"(\" found", term);
}
createNewOperand((BinaryOperator) operator, operands);
}
Object expression = operands.pop();
if (!operands.isEmpty()) {
LexicalUnitImpl operand = (LexicalUnitImpl) operands.peek();
throw new ArithmeticException("Unexpected operand "
+ operand.toString() + " found", term);
}
return expression;
}

public LexicalUnitImpl evaluate(LexicalUnitImpl term) {
Object result = ArithmeticExpressionEvaluator.get().createExpression(
term);
if (result instanceof BinaryExpression) {
return ((BinaryExpression) result).eval();
}
return term;
}
}

+ 0
- 46
theme-compiler/src/com/vaadin/sass/internal/expression/BinaryExpression.java View File

@@ -1,46 +0,0 @@
/*
* Copyright 2000-2013 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.internal.expression;

import com.vaadin.sass.internal.parser.LexicalUnitImpl;

public class BinaryExpression {
public Object leftOperand = null;
public BinaryOperator operator = null;
public Object rightOperand = null;

public BinaryExpression(Object leftOperand, BinaryOperator operator,
Object rightOperand) {
this.leftOperand = leftOperand;
this.operator = operator;
this.rightOperand = rightOperand;
}

public LexicalUnitImpl eval() {
LexicalUnitImpl leftValue = (leftOperand instanceof BinaryExpression) ? ((BinaryExpression) leftOperand)
.eval() : (LexicalUnitImpl) leftOperand;
LexicalUnitImpl rightValue = (rightOperand instanceof BinaryExpression) ? ((BinaryExpression) rightOperand)
.eval() : (LexicalUnitImpl) rightOperand;
return operator.eval(leftValue, rightValue);
}

@Override
public String toString() {
return "(" + leftOperand + " " + operator.type + " " + rightOperand
+ ")";
}
}

+ 0
- 70
theme-compiler/src/com/vaadin/sass/internal/expression/BinaryOperator.java View File

@@ -1,70 +0,0 @@
/*
* Copyright 2000-2013 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.internal.expression;

import org.w3c.css.sac.LexicalUnit;

import com.vaadin.sass.internal.parser.LexicalUnitImpl;

public enum BinaryOperator {
ADD(LexicalUnit.SAC_OPERATOR_PLUS, 1) {
@Override
public LexicalUnitImpl eval(LexicalUnitImpl leftValue,
LexicalUnitImpl rightValue) {
return leftValue.add(rightValue);
}
},
MINUS(LexicalUnit.SAC_OPERATOR_MINUS, 1) {
@Override
public LexicalUnitImpl eval(LexicalUnitImpl leftValue,
LexicalUnitImpl rightValue) {
return leftValue.minus(rightValue);
}
},
MUL(LexicalUnit.SAC_OPERATOR_MULTIPLY, 2) {
@Override
public LexicalUnitImpl eval(LexicalUnitImpl leftValue,
LexicalUnitImpl rightValue) {
return leftValue.multiply(rightValue);
}
},
DIV(LexicalUnit.SAC_OPERATOR_SLASH, 2) {
@Override
public LexicalUnitImpl eval(LexicalUnitImpl leftValue,
LexicalUnitImpl rightValue) {
return leftValue.divide(rightValue);
}
},
MOD(LexicalUnit.SAC_OPERATOR_MOD, 2) {
@Override
public LexicalUnitImpl eval(LexicalUnitImpl leftValue,
LexicalUnitImpl rightValue) {
return leftValue.modulo(rightValue);
}
};

public final short type;
public final int precedence;

BinaryOperator(short type, int precedence) {
this.type = type;
this.precedence = precedence;
}

public abstract LexicalUnitImpl eval(LexicalUnitImpl leftValue,
LexicalUnitImpl rightValue);
}

+ 0
- 21
theme-compiler/src/com/vaadin/sass/internal/expression/Parentheses.java View File

@@ -1,21 +0,0 @@
/*
* Copyright 2000-2013 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.internal.expression;

public enum Parentheses {
LEFT, RIGHT
}

+ 0
- 42
theme-compiler/src/com/vaadin/sass/internal/expression/exception/ArithmeticException.java View File

@@ -1,42 +0,0 @@
/*
* Copyright 2000-2013 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.internal.expression.exception;

import com.vaadin.sass.internal.parser.LexicalUnitImpl;

public class ArithmeticException extends RuntimeException {
public ArithmeticException(String errorMsg) {
super(errorMsg);
}

public ArithmeticException(String error, LexicalUnitImpl term) {
super(buildMessage(error, term));
}

private static String buildMessage(String message, LexicalUnitImpl term) {
StringBuilder builder = new StringBuilder(message);

builder.append(": \"");
builder.append(term.toString());
builder.append("\" [");
builder.append(term.getLineNumber());
builder.append(",");
builder.append(term.getColumnNumber());
builder.append("]");

return builder.toString();
}
}

+ 0
- 29
theme-compiler/src/com/vaadin/sass/internal/expression/exception/IncompatibleUnitsException.java View File

@@ -1,29 +0,0 @@
/*
* Copyright 2000-2013 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.internal.expression.exception;

public class IncompatibleUnitsException extends ArithmeticException {
public IncompatibleUnitsException(String errorExpr) {
super(getErrorMsg(errorExpr));
}

private static String getErrorMsg(String errorExpr) {
StringBuilder builder = new StringBuilder();
builder.append("Incompatible units found in: ");
builder.append("'").append(errorExpr).append("'");
return builder.toString();
}
}

+ 0
- 104
theme-compiler/src/com/vaadin/sass/internal/handler/SCSSDocumentHandler.java View File

@@ -1,104 +0,0 @@
/*
* Copyright 2000-2013 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.internal.handler;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.DocumentHandler;
import org.w3c.css.sac.SACMediaList;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.parser.LexicalUnitImpl;
import com.vaadin.sass.internal.tree.ForNode;
import com.vaadin.sass.internal.tree.VariableNode;
import com.vaadin.sass.internal.tree.WhileNode;
import com.vaadin.sass.internal.tree.controldirective.EachDefNode;

public interface SCSSDocumentHandler extends DocumentHandler {
ScssStylesheet getStyleSheet();

void variable(String name, LexicalUnitImpl value, boolean guarded);

void startMixinDirective(String name, Collection<VariableNode> args);

void endMixinDirective(String name, Collection<VariableNode> args);

void debugDirective();

ForNode forDirective(String var, String from, String to, boolean exclusive,
String body);

WhileNode whileDirective(String condition, String body);

void startNestedProperties(String name);

void endNestedProperties(String name);

void importStyle(String uri, SACMediaList media, boolean isURL);

void property(String name, LexicalUnitImpl value, boolean important,
String comment);

EachDefNode startEachDirective(String variable, ArrayList<String> list);

void endEachDirective();

void startIfElseDirective();

void endIfElseDirective();

void ifDirective(String evaluator);

void elseDirective();

void startSelector(ArrayList<String> selectors) throws CSSException;

void endSelector() throws CSSException;

void extendDirective(ArrayList<String> list);

void microsoftDirective(String name, String value);

EachDefNode startEachDirective(String var, String listVariable);

void removeDirective(String variable, String list, String remove,
String separator);

void appendDirective(String variable, String list, String remove,
String separator);

void containsDirective(String variable, String list, String contains,
String separator);

void startKeyFrames(String keyframeName, String animationname);

void endKeyFrames();

void startKeyframeSelector(String selector);

void endKeyframeSelector();

void contentDirective();

void startInclude(String name, List<LexicalUnitImpl> args);

void endInclude();

}

+ 0
- 398
theme-compiler/src/com/vaadin/sass/internal/handler/SCSSDocumentHandlerImpl.java View File

@@ -1,398 +0,0 @@
/*
* Copyright 2000-2013 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.internal.handler;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.InputSource;
import org.w3c.css.sac.LexicalUnit;
import org.w3c.css.sac.SACMediaList;
import org.w3c.css.sac.SelectorList;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.parser.LexicalUnitImpl;
import com.vaadin.sass.internal.tree.BlockNode;
import com.vaadin.sass.internal.tree.CommentNode;
import com.vaadin.sass.internal.tree.ContentNode;
import com.vaadin.sass.internal.tree.ExtendNode;
import com.vaadin.sass.internal.tree.FontFaceNode;
import com.vaadin.sass.internal.tree.ForNode;
import com.vaadin.sass.internal.tree.ImportNode;
import com.vaadin.sass.internal.tree.KeyframeSelectorNode;
import com.vaadin.sass.internal.tree.KeyframesNode;
import com.vaadin.sass.internal.tree.ListAppendNode;
import com.vaadin.sass.internal.tree.ListContainsNode;
import com.vaadin.sass.internal.tree.ListRemoveNode;
import com.vaadin.sass.internal.tree.MediaNode;
import com.vaadin.sass.internal.tree.MicrosoftRuleNode;
import com.vaadin.sass.internal.tree.MixinDefNode;
import com.vaadin.sass.internal.tree.MixinNode;
import com.vaadin.sass.internal.tree.NestPropertiesNode;
import com.vaadin.sass.internal.tree.Node;
import com.vaadin.sass.internal.tree.RuleNode;
import com.vaadin.sass.internal.tree.SimpleNode;
import com.vaadin.sass.internal.tree.VariableNode;
import com.vaadin.sass.internal.tree.WhileNode;
import com.vaadin.sass.internal.tree.controldirective.EachDefNode;
import com.vaadin.sass.internal.tree.controldirective.ElseNode;
import com.vaadin.sass.internal.tree.controldirective.IfElseDefNode;
import com.vaadin.sass.internal.tree.controldirective.IfNode;

public class SCSSDocumentHandlerImpl implements SCSSDocumentHandler {

private final ScssStylesheet styleSheet;
Stack<Node> nodeStack = new Stack<Node>();

public SCSSDocumentHandlerImpl() {
this(new ScssStylesheet());
}

public SCSSDocumentHandlerImpl(ScssStylesheet styleSheet) {
this.styleSheet = styleSheet;
nodeStack.push(styleSheet);
}

@Override
public ScssStylesheet getStyleSheet() {
return styleSheet;
}

@Override
public void startDocument(InputSource source) throws CSSException {
nodeStack.push(styleSheet);
}

@Override
public void endDocument(InputSource source) throws CSSException {
}

@Override
public void variable(String name, LexicalUnitImpl value, boolean guarded) {
VariableNode node = new VariableNode(name, value, guarded);
nodeStack.peek().appendChild(node);
}

@Override
public void debugDirective() {
}

@Override
public ForNode forDirective(String var, String from, String to,
boolean exclusive, String body) {
ForNode node = new ForNode(var, from, to, exclusive, body);
log(node);
return node;
}

@Override
public EachDefNode startEachDirective(String var, ArrayList<String> list) {
EachDefNode node = new EachDefNode(var, list);
nodeStack.peek().appendChild(node);
nodeStack.push(node);
return node;
}

@Override
public EachDefNode startEachDirective(String var, String listVariable) {
EachDefNode node = new EachDefNode(var, listVariable);
nodeStack.peek().appendChild(node);
nodeStack.push(node);
return node;
}

@Override
public void endEachDirective() {
nodeStack.pop();
}

@Override
public WhileNode whileDirective(String condition, String body) {
WhileNode node = new WhileNode(condition, body);
log(node);
return node;
}

@Override
public void comment(String text) throws CSSException {
CommentNode node = new CommentNode(text);
nodeStack.peek().appendChild(node);
}

@Override
public void ignorableAtRule(String atRule) throws CSSException {
log("ignorableAtRule(String atRule): " + atRule);
}

@Override
public void namespaceDeclaration(String prefix, String uri)
throws CSSException {
log("namespaceDeclaration(String prefix, String uri): " + prefix + ", "
+ uri);
}

@Override
public void importStyle(String uri, SACMediaList media,
String defaultNamespaceURI) throws CSSException {
}

@Override
public void startMedia(SACMediaList media) throws CSSException {
MediaNode node = new MediaNode(media);
nodeStack.peek().appendChild(node);
nodeStack.push(node);
}

@Override
public void endMedia(SACMediaList media) throws CSSException {
nodeStack.pop();
}

@Override
public void startPage(String name, String pseudo_page) throws CSSException {
log("startPage(String name, String pseudo_page): " + name + ", "
+ pseudo_page);
}

@Override
public void endPage(String name, String pseudo_page) throws CSSException {
log("endPage(String name, String pseudo_page): " + name + ", "
+ pseudo_page);
}

@Override
public void startFontFace() throws CSSException {
FontFaceNode node = new FontFaceNode();
nodeStack.peek().appendChild(node);
nodeStack.push(node);
}

@Override
public void endFontFace() throws CSSException {
nodeStack.pop();
}

@Override
public void startSelector(ArrayList<String> selectors) throws CSSException {
BlockNode node = new BlockNode(selectors);
nodeStack.peek().appendChild(node);
nodeStack.push(node);
}

@Override
public void endSelector() throws CSSException {
nodeStack.pop();
}

@Override
public void property(String name, LexicalUnit value, boolean important)
throws CSSException {
property(name, (LexicalUnitImpl) value, important, null);
}

@Override
public void property(String name, LexicalUnitImpl value, boolean important,
String comment) {
RuleNode node = new RuleNode(name, value, important, comment);
nodeStack.peek().appendChild(node);
}

@Override
public void extendDirective(ArrayList<String> list) {
ExtendNode node = new ExtendNode(list);
nodeStack.peek().appendChild(node);
}

@Override
public void startNestedProperties(String name) {
NestPropertiesNode node = new NestPropertiesNode(name);
nodeStack.peek().appendChild(node);
nodeStack.push(node);
}

@Override
public void endNestedProperties(String name) {
nodeStack.pop();
}

@Override
public void startMixinDirective(String name, Collection<VariableNode> args) {
MixinDefNode node = new MixinDefNode(name.trim(), args);
nodeStack.peek().appendChild(node);
nodeStack.push(node);
}

@Override
public void endMixinDirective(String name, Collection<VariableNode> args) {
nodeStack.pop();
}

@Override
public void importStyle(String uri, SACMediaList media, boolean isURL) {
ImportNode node = new ImportNode(uri, media, isURL);
nodeStack.peek().appendChild(node);
}

@Override
public void startIfElseDirective() {
final IfElseDefNode node = new IfElseDefNode();
nodeStack.peek().appendChild(node);
nodeStack.push(node);
}

@Override
public void ifDirective(String evaluator) {
if (nodeStack.peek() instanceof IfNode) {
nodeStack.pop();
}
IfNode node = new IfNode(evaluator);
nodeStack.peek().appendChild(node);
nodeStack.push(node);
}

@Override
public void elseDirective() {
if (nodeStack.peek() instanceof IfNode) {
nodeStack.pop();
}
ElseNode node = new ElseNode();
nodeStack.peek().appendChild(node);
nodeStack.push(node);
}

@Override
public void endIfElseDirective() {
if ((nodeStack.peek() instanceof ElseNode)
|| (nodeStack.peek() instanceof IfNode)) {
nodeStack.pop();
}
nodeStack.pop();
}

@Override
public void microsoftDirective(String name, String value) {
MicrosoftRuleNode node = new MicrosoftRuleNode(name, value);
nodeStack.peek().appendChild(node);
}

// rule that is passed to the output as-is (except variable value
// substitution) - no children
public void unrecognizedRule(String text) {
SimpleNode node = new SimpleNode(text);
nodeStack.peek().appendChild(node);
}

@Override
public void endSelector(SelectorList arg0) throws CSSException {
// TODO Auto-generated method stub

}

@Override
public void startSelector(SelectorList arg0) throws CSSException {
// TODO Auto-generated method stub

}

@Override
public void removeDirective(String variable, String list, String remove,
String separator) {
ListRemoveNode node = new ListRemoveNode(variable, list, remove,
separator);
nodeStack.peek().appendChild(node);
}

@Override
public void appendDirective(String variable, String list, String append,
String separator) {
ListAppendNode node = new ListAppendNode(variable, list, append,
separator);
nodeStack.peek().appendChild(node);
}

@Override
public void containsDirective(String variable, String list,
String contains, String separator) {
ListContainsNode node = new ListContainsNode(variable, list, contains,
separator);
nodeStack.peek().appendChild(node);
}

@Override
public void startKeyFrames(String keyframeName, String animationName) {
KeyframesNode node = new KeyframesNode(keyframeName, animationName);
nodeStack.peek().appendChild(node);
nodeStack.push(node);

}

@Override
public void endKeyFrames() {
nodeStack.pop();

}

@Override
public void startKeyframeSelector(String selector) {
KeyframeSelectorNode node = new KeyframeSelectorNode(selector);
nodeStack.peek().appendChild(node);
nodeStack.push(node);

}

@Override
public void endKeyframeSelector() {
nodeStack.pop();
}

@Override
public void contentDirective() {
ContentNode node = new ContentNode();
nodeStack.peek().appendChild(node);
}

@Override
public void startInclude(String name, List<LexicalUnitImpl> args) {
MixinNode node = new MixinNode(name, args);
nodeStack.peek().appendChild(node);
nodeStack.push(node);

}

@Override
public void endInclude() {
nodeStack.pop();
}

private void log(Object object) {
if (object != null) {
log(object.toString());
} else {
log(null);
}
}

private void log(String msg) {
Logger.getLogger(SCSSDocumentHandlerImpl.class.getName()).log(
Level.INFO, msg);
}
}

+ 0
- 56
theme-compiler/src/com/vaadin/sass/internal/handler/SCSSErrorHandler.java View File

@@ -1,56 +0,0 @@
/*
* Copyright 2000-2013 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.internal.handler;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.CSSParseException;
import org.w3c.css.sac.ErrorHandler;

public class SCSSErrorHandler implements ErrorHandler {

public SCSSErrorHandler() {
}

@Override
public void error(CSSParseException arg0) throws CSSException {
log("Error when parsing file \n" + arg0.getURI() + " on line "
+ arg0.getLineNumber() + ", column " + arg0.getColumnNumber());
log(arg0.getMessage() + "\n");
}

@Override
public void fatalError(CSSParseException arg0) throws CSSException {
log("FATAL Error when parsing file \n" + arg0.getURI() + " on line "
+ arg0.getLineNumber() + ", column " + arg0.getColumnNumber());
log(arg0.getMessage() + "\n");
}

@Override
public void warning(CSSParseException arg0) throws CSSException {
log("Warning when parsing file \n" + arg0.getURI() + " on line "
+ arg0.getLineNumber() + ", column " + arg0.getColumnNumber());
log(arg0.getMessage() + "\n");
}

private void log(String msg) {
Logger.getLogger(SCSSDocumentHandlerImpl.class.getName()).log(
Level.SEVERE, msg);
}

}

+ 0
- 130
theme-compiler/src/com/vaadin/sass/internal/parser/CharStream.java View File

@@ -1,130 +0,0 @@
/*
* Copyright 2000-2013 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.
*/
/* Generated By:JavaCC: Do not edit this line. CharStream.java Version 5.0 */
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package com.vaadin.sass.internal.parser;

/**
* This interface describes a character stream that maintains line and
* column number positions of the characters. It also has the capability
* to backup the stream to some extent. An implementation of this
* interface is used in the TokenManager implementation generated by
* JavaCCParser.
*
* All the methods except backup can be implemented in any fashion. backup
* needs to be implemented correctly for the correct operation of the lexer.
* Rest of the methods are all used to get information like line number,
* column number and the String that constitutes a token and are not used
* by the lexer. Hence their implementation won't affect the generated lexer's
* operation.
*/

public
interface CharStream {

/**
* Returns the next character from the selected input. The method
* of selecting the input is the responsibility of the class
* implementing this interface. Can throw any java.io.IOException.
*/
char readChar() throws java.io.IOException;

@Deprecated
/**
* Returns the column position of the character last read.
* @deprecated
* @see #getEndColumn
*/
int getColumn();

@Deprecated
/**
* Returns the line number of the character last read.
* @deprecated
* @see #getEndLine
*/
int getLine();

/**
* Returns the column number of the last character for current token (being
* matched after the last call to BeginTOken).
*/
int getEndColumn();

/**
* Returns the line number of the last character for current token (being
* matched after the last call to BeginTOken).
*/
int getEndLine();

/**
* Returns the column number of the first character for current token (being
* matched after the last call to BeginTOken).
*/
int getBeginColumn();

/**
* Returns the line number of the first character for current token (being
* matched after the last call to BeginTOken).
*/
int getBeginLine();

/**
* Backs up the input stream by amount steps. Lexer calls this method if it
* had already read some characters, but could not use them to match a
* (longer) token. So, they will be used again as the prefix of the next
* token and it is the implemetation's responsibility to do this right.
*/
void backup(int amount);

/**
* Returns the next character that marks the beginning of the next token.
* All characters must remain in the buffer between two successive calls
* to this method to implement backup correctly.
*/
char BeginToken() throws java.io.IOException;

/**
* Returns a string made up of characters from the marked token beginning
* to the current buffer position. Implementations have the choice of returning
* anything that they want to. For example, for efficiency, one might decide
* to just return null, which is a valid implementation.
*/
String GetImage();

/**
* Returns an array of characters that make up the suffix of length 'len' for
* the currently matched token. This is used to build up the matched string
* for use in actions in the case of MORE. A simple and inefficient
* implementation of this is as follows :
*
* {
* String t = GetImage();
* return t.substring(t.length() - len, t.length()).toCharArray();
* }
*/
char[] GetSuffix(int len);

/**
* The lexer calls this function to indicate that it is done with the stream
* and hence implementations can free any resources held by this class.
* Again, the body of this function can be just empty and it will not
* affect the lexer's operation.
*/
void Done();

}
/* JavaCC - OriginalChecksum=18aae0a549695f0fec96a11297b442bb (do not edit this line) */

+ 0
- 370
theme-compiler/src/com/vaadin/sass/internal/parser/Generic_CharStream.java View File

@@ -1,370 +0,0 @@
/*
* Copyright 2000-2013 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.
*/
/* Generated By:JavaCC: Do not edit this line. Generic_CharStream.java Version 0.7pre6 */
package com.vaadin.sass.internal.parser;

/**
* An implementation of interface CharStream, where the stream is assumed to
* contain only ASCII characters (without unicode processing).
*/

public final class Generic_CharStream implements CharStream
{
public static final boolean staticFlag = false;
int bufsize;
int available;
int tokenBegin;
public int bufpos = -1;
private int bufline[];
private int bufcolumn[];

private int column = 0;
private int line = 1;

private boolean prevCharIsCR = false;
private boolean prevCharIsLF = false;

private java.io.Reader reader;

private char[] buffer;
private int maxNextCharInd = 0;
private int inBuf = 0;

private final void ExpandBuff(boolean wrapAround)
{
char[] newbuffer = new char[bufsize + 2048];
int newbufline[] = new int[bufsize + 2048];
int newbufcolumn[] = new int[bufsize + 2048];

try
{
if (wrapAround)
{
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
System.arraycopy(buffer, 0, newbuffer,
bufsize - tokenBegin, bufpos);
buffer = newbuffer;

System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
bufline = newbufline;

System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
bufcolumn = newbufcolumn;

maxNextCharInd = (bufpos += (bufsize - tokenBegin));
}
else
{
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
buffer = newbuffer;

System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
bufline = newbufline;

System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
bufcolumn = newbufcolumn;

maxNextCharInd = (bufpos -= tokenBegin);
}
}
catch (Throwable t)
{
throw new Error(t.getMessage());
}


bufsize += 2048;
available = bufsize;
tokenBegin = 0;
}

private final void FillBuff() throws java.io.IOException
{
if (maxNextCharInd == available)
{
if (available == bufsize)
{
if (tokenBegin > 2048)
{
bufpos = maxNextCharInd = 0;
available = tokenBegin;
}
else if (tokenBegin < 0)
bufpos = maxNextCharInd = 0;
else
ExpandBuff(false);
}
else if (available > tokenBegin)
available = bufsize;
else if ((tokenBegin - available) < 2048)
ExpandBuff(true);
else
available = tokenBegin;
}

int i;
try {
if ((i = reader.read(buffer, maxNextCharInd,
available - maxNextCharInd)) == -1)
{
reader.close();
throw new java.io.IOException();
}
else
maxNextCharInd += i;
return;
}
catch(java.io.IOException e) {
--bufpos;
backup(0);
if (tokenBegin == -1)
tokenBegin = bufpos;
throw e;
}
}

public final char BeginToken() throws java.io.IOException
{
tokenBegin = -1;
char c = readChar();
tokenBegin = bufpos;

return c;
}

private final void UpdateLineColumn(char c)
{
column++;

if (prevCharIsLF)
{
prevCharIsLF = false;
line += (column = 1);
}
else if (prevCharIsCR)
{
prevCharIsCR = false;
if (c == '\n')
{
prevCharIsLF = true;
}
else
line += (column = 1);
}

switch (c)
{
case '\r' :
prevCharIsCR = true;
break;
case '\n' :
prevCharIsLF = true;
break;
case '\t' :
column--;
column += (8 - (column & 07));
break;
default :
break;
}

bufline[bufpos] = line;
bufcolumn[bufpos] = column;
}

public final char readChar() throws java.io.IOException
{
if (inBuf > 0)
{
--inBuf;
return (char)((char)0xff & buffer[(bufpos == bufsize - 1) ? (bufpos = 0) : ++bufpos]);
}

if (++bufpos >= maxNextCharInd)
FillBuff();

char c = (char)((char)0xff & buffer[bufpos]);

UpdateLineColumn(c);
return (c);
}

/**
* @deprecated
* @see #getEndColumn
*/

public final int getColumn() {
return bufcolumn[bufpos];
}

/**
* @deprecated
* @see #getEndLine
*/

public final int getLine() {
return bufline[bufpos];
}

public final int getEndColumn() {
return bufcolumn[bufpos];
}

public final int getEndLine() {
return bufline[bufpos];
}

public final int getBeginColumn() {
return bufcolumn[tokenBegin];
}

public final int getBeginLine() {
return bufline[tokenBegin];
}

public final void backup(int amount) {

inBuf += amount;
if ((bufpos -= amount) < 0)
bufpos += bufsize;
}

public Generic_CharStream(java.io.Reader dstream, int startline,
int startcolumn, int buffersize)
{
reader = dstream;
line = startline;
column = startcolumn - 1;

available = bufsize = buffersize;
buffer = new char[buffersize];
bufline = new int[buffersize];
bufcolumn = new int[buffersize];
}

public Generic_CharStream(java.io.Reader dstream, int startline,
int startcolumn)
{
this(dstream, startline, startcolumn, 4096);
}
public void ReInit(java.io.Reader dstream, int startline,
int startcolumn, int buffersize)
{
reader = dstream;
line = startline;
column = startcolumn - 1;

if (buffer == null || buffersize != buffer.length)
{
available = bufsize = buffersize;
buffer = new char[buffersize];
bufline = new int[buffersize];
bufcolumn = new int[buffersize];
}
prevCharIsLF = prevCharIsCR = false;
tokenBegin = inBuf = maxNextCharInd = 0;
bufpos = -1;
}

public void ReInit(java.io.Reader dstream, int startline,
int startcolumn)
{
ReInit(dstream, startline, startcolumn, 4096);
}

public final String GetImage()
{
if (bufpos >= tokenBegin)
return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
else
return new String(buffer, tokenBegin, bufsize - tokenBegin) +
new String(buffer, 0, bufpos + 1);
}

public final char[] GetSuffix(int len)
{
char[] ret = new char[len];

if ((bufpos + 1) >= len)
System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
else
{
System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
len - bufpos - 1);
System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
}
return ret;
}

public void Done()
{
buffer = null;
bufline = null;
bufcolumn = null;
}

/**
* Method to adjust line and column numbers for the start of a token.<BR>
*/
public void adjustBeginLineColumn(int newLine, int newCol)
{
int start = tokenBegin;
int len;

if (bufpos >= tokenBegin)
{
len = bufpos - tokenBegin + inBuf + 1;
}
else
{
len = bufsize - tokenBegin + bufpos + 1 + inBuf;
}

int i = 0, j = 0, k = 0;
int nextColDiff = 0, columnDiff = 0;

while (i < len &&
bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
{
bufline[j] = newLine;
nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
bufcolumn[j] = newCol + columnDiff;
columnDiff = nextColDiff;
i++;
}

if (i < len)
{
bufline[j] = newLine++;
bufcolumn[j] = newCol + columnDiff;

while (i++ < len)
{
if (bufline[j = start % bufsize] != bufline[++start % bufsize])
bufline[j] = newLine++;
else
bufline[j] = newLine;
}
}

line = bufline[j];
column = bufcolumn[j];
}

}

+ 0
- 39
theme-compiler/src/com/vaadin/sass/internal/parser/JumpException.java View File

@@ -1,39 +0,0 @@
/*
* Copyright 2000-2013 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.
*/
/*
* (c) COPYRIGHT 1999 World Wide Web Consortium
* (Massachusetts Institute of Technology, Institut National de Recherche
* en Informatique et en Automatique, Keio University).
* All Rights Reserved. http://www.w3.org/Consortium/Legal/
*
* $Id: JumpException.java,v 1.1 1999/06/09 15:21:33 plehegar Exp $
*/
package com.vaadin.sass.internal.parser;

/**
* @version $Revision: 1.1 $
* @author Philippe Le Hegaret
*/
public class JumpException extends RuntimeException {
private static final long serialVersionUID = -2010286909393046205L;

/**
* Creates a new JumpException
*/
public JumpException() {
}

}

+ 0
- 888
theme-compiler/src/com/vaadin/sass/internal/parser/LexicalUnitImpl.java View File

@@ -1,888 +0,0 @@
/*
* Copyright 2000-2013 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.
*/
/*
* Copyright (c) 1999 World Wide Web Consortium
* (Massachusetts Institute of Technology, Institut National de Recherche
* en Informatique et en Automatique, Keio University).
* All Rights Reserved. http://www.w3.org/Consortium/Legal/
*
* $Id: LexicalUnitImpl.java,v 1.3 2000/02/15 02:08:19 plehegar Exp $
*/
package com.vaadin.sass.internal.parser;

import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.w3c.css.sac.LexicalUnit;

import com.vaadin.sass.internal.expression.exception.IncompatibleUnitsException;
import com.vaadin.sass.internal.parser.function.AbsFunctionGenerator;
import com.vaadin.sass.internal.parser.function.CeilFunctionGenerator;
import com.vaadin.sass.internal.parser.function.DarkenFunctionGenerator;
import com.vaadin.sass.internal.parser.function.DefaultFunctionGenerator;
import com.vaadin.sass.internal.parser.function.FloorFunctionGenerator;
import com.vaadin.sass.internal.parser.function.LightenFunctionGenerator;
import com.vaadin.sass.internal.parser.function.RoundFunctionGenerator;
import com.vaadin.sass.internal.parser.function.SCSSFunctionGenerator;
import com.vaadin.sass.internal.tree.Node;
import com.vaadin.sass.internal.tree.Node.BuildStringStrategy;
import com.vaadin.sass.internal.util.DeepCopy;

/**
* @version $Revision: 1.3 $
* @author Philippe Le Hegaret
*
* @modified Sebastian Nyholm @ Vaadin Ltd
*/
public class LexicalUnitImpl implements LexicalUnit, SCSSLexicalUnit,
Serializable {
private static final long serialVersionUID = -6649833716809789399L;

private static int PRECISION = 100000;
private static int PERC_PRECISION_FACTOR = 100 * PRECISION;

LexicalUnitImpl prev;
LexicalUnitImpl next;

short type;
int line;
int column;

int i;
float f;
short dimension;
String sdimension;
String s;
String fname;
LexicalUnitImpl params;

LexicalUnitImpl(short type, int line, int column, LexicalUnitImpl p) {
if (p != null) {
prev = p;
p.next = this;
}
this.line = line;
this.column = column - 1;
this.type = type;
}

LexicalUnitImpl(int line, int column, LexicalUnitImpl previous, int i) {
this(SAC_INTEGER, line, column, previous);
this.i = i;
f = i;
}

LexicalUnitImpl(int line, int column, LexicalUnitImpl previous,
short dimension, String sdimension, float f) {
this(dimension, line, column, previous);
this.f = f;
i = (int) f;
this.dimension = dimension;
this.sdimension = sdimension;
}

LexicalUnitImpl(int line, int column, LexicalUnitImpl previous, short type,
String s) {
this(type, line, column, previous);
this.s = s;
}

LexicalUnitImpl(short type, int line, int column, LexicalUnitImpl previous,
String fname, LexicalUnitImpl params) {
this(type, line, column, previous);
this.fname = fname;
this.params = params;
}

public int getLineNumber() {
return line;
}

public int getColumnNumber() {
return column;
}

@Override
public short getLexicalUnitType() {
return type;
}

public void setLexicalUnitType(short type) {
this.type = type;
}

public void getLexicalUnitType(short type) {
this.type = type;
}

@Override
public LexicalUnitImpl getNextLexicalUnit() {
return next;
}

public void setNextLexicalUnit(LexicalUnitImpl n) {
next = n;
}

@Override
public LexicalUnitImpl getPreviousLexicalUnit() {
return prev;
}

public void setPrevLexicalUnit(LexicalUnitImpl n) {
prev = n;
}

@Override
public int getIntegerValue() {
return i;
}

void setIntegerValue(int i) {
this.i = i;
f = i;
}

@Override
public float getFloatValue() {
return f;
}

/**
* Returns the float value as a string unless the value is an integer. In
* that case returns the integer value as a string.
*
* @return a string representing the value, either with or without decimals
*/
public String getFloatOrInteger() {
float f = getFloatValue();
int i = (int) f;
if ((i) == f) {
return i + "";
} else {
return f + "";
}
}

public void setFloatValue(float f) {
this.f = f;
i = (int) f;
}

@Override
public String getDimensionUnitText() {
switch (type) {
case SAC_PERCENTAGE:
return "%";
case SAC_EM:
return "em";
case SCSSLexicalUnit.SAC_LEM:
return "lem";
case SCSSLexicalUnit.SAC_REM:
return "rem";
case SAC_EX:
return "ex";
case SAC_PIXEL:
return "px";
case SAC_CENTIMETER:
return "cm";
case SAC_MILLIMETER:
return "mm";
case SAC_INCH:
return "in";
case SAC_POINT:
return "pt";
case SAC_PICA:
return "pc";
case SAC_DEGREE:
return "deg";
case SAC_RADIAN:
return "rad";
case SAC_GRADIAN:
return "grad";
case SAC_MILLISECOND:
return "ms";
case SAC_SECOND:
return "s";
case SAC_HERTZ:
return "Hz";
case SAC_KILOHERTZ:
return "kHz";
case SAC_DIMENSION:
return sdimension;
default:
throw new IllegalStateException("invalid dimension " + type);
}
}

@Override
public String getStringValue() {
return s;
}

public void setStringValue(String str) {
s = str;
}

@Override
public String getFunctionName() {
return fname;
}

@Override
public LexicalUnitImpl getParameters() {
return params;
}

@Override
public LexicalUnitImpl getSubValues() {
return params;
}

/**
* Prints out the current state of the node tree. Will return SCSS before
* compile and CSS after.
*
* Result value could be null.
*
* @since 7.2
* @return State as a string
*/
public String printState() {
return buildString(Node.PRINT_STRATEGY);
}

@Override
public String toString() {
String result = simpleAsString();
if (result == null) {
return "Lexical unit node [" + buildString(Node.TO_STRING_STRATEGY)
+ "]";
} else {
return result;
}
}

// A helper method for sass interpolation
public String unquotedString() {
String result = printState();
if (result.length() >= 2
&& ((result.charAt(0) == '"' && result
.charAt(result.length() - 1) == '"') || (result
.charAt(0) == '\'' && result
.charAt(result.length() - 1) == '\''))) {
result = result.substring(1, result.length() - 1);
}
return result;
}

@Override
public LexicalUnitImpl divide(LexicalUnitImpl denominator) {
if (denominator.getLexicalUnitType() != SAC_INTEGER
&& denominator.getLexicalUnitType() != SAC_REAL
&& getLexicalUnitType() != denominator.getLexicalUnitType()) {
throw new IncompatibleUnitsException(printState());
}
setFloatValue(getFloatValue() / denominator.getFloatValue());
if (getLexicalUnitType() == denominator.getLexicalUnitType()) {
setLexicalUnitType(SAC_REAL);
}
setNextLexicalUnit(denominator.getNextLexicalUnit());
return this;
}

@Override
public LexicalUnitImpl add(LexicalUnitImpl another) {
checkAndSetUnit(another);
setFloatValue(getFloatValue() + another.getFloatValue());
return this;
}

@Override
public LexicalUnitImpl minus(LexicalUnitImpl another) {
checkAndSetUnit(another);
setFloatValue(getFloatValue() - another.getFloatValue());
return this;
}

@Override
public LexicalUnitImpl multiply(LexicalUnitImpl another) {
checkAndSetUnit(another);
setFloatValue(getFloatValue() * another.getIntegerValue());
return this;
}

protected void checkAndSetUnit(LexicalUnitImpl another) {
if (getLexicalUnitType() != SAC_INTEGER
&& getLexicalUnitType() != SAC_REAL
&& another.getLexicalUnitType() != SAC_INTEGER
&& another.getLexicalUnitType() != SAC_REAL
&& getLexicalUnitType() != another.getLexicalUnitType()) {
throw new IncompatibleUnitsException(printState());
}
if (another.getLexicalUnitType() != SAC_INTEGER
&& another.getLexicalUnitType() != SAC_REAL) {
setLexicalUnitType(another.getLexicalUnitType());
}
setNextLexicalUnit(another.getNextLexicalUnit());
}

@Override
public LexicalUnitImpl modulo(LexicalUnitImpl another) {
if (getLexicalUnitType() != another.getLexicalUnitType()) {
throw new IncompatibleUnitsException(printState());
}
setIntegerValue(getIntegerValue() % another.getIntegerValue());
setNextLexicalUnit(another.getNextLexicalUnit());
return this;
}

public void replaceValue(LexicalUnitImpl another) {
// shouldn't modify 'another' directly, should only modify its copy.
LexicalUnitImpl deepCopyAnother = (LexicalUnitImpl) DeepCopy
.copy(another);
type = deepCopyAnother.getLexicalUnitType();
i = deepCopyAnother.getIntegerValue();
f = deepCopyAnother.getFloatValue();
s = deepCopyAnother.getStringValue();
fname = deepCopyAnother.getFunctionName();
prev = deepCopyAnother.getPreviousLexicalUnit();
dimension = deepCopyAnother.getDimension();
sdimension = deepCopyAnother.getSdimension();
params = deepCopyAnother.getParameters();

LexicalUnitImpl finalNextInAnother = deepCopyAnother;
while (finalNextInAnother.getNextLexicalUnit() != null) {
finalNextInAnother = finalNextInAnother.getNextLexicalUnit();
}

finalNextInAnother.setNextLexicalUnit(next);
next = deepCopyAnother.next;
}

public void setParameters(LexicalUnitImpl params) {
this.params = params;
}

public short getDimension() {
return dimension;
}

public String getSdimension() {
return sdimension;
}

// here some useful function for creation
public static LexicalUnitImpl createVariable(int line, int column,
LexicalUnitImpl previous, String name) {
return new LexicalUnitImpl(line, column, previous, SCSS_VARIABLE, name);
}

public static LexicalUnitImpl createNull(int line, int column,
LexicalUnitImpl previous) {
return new LexicalUnitImpl(line, column, previous, SCSS_NULL, "null");
}

public static LexicalUnitImpl createNumber(int line, int column,
LexicalUnitImpl previous, float v) {
int i = (int) v;
if (v == i) {
return new LexicalUnitImpl(line, column, previous, i);
} else {
return new LexicalUnitImpl(line, column, previous, SAC_REAL, "", v);
}
}

public static LexicalUnitImpl createInteger(int line, int column,
LexicalUnitImpl previous, int i) {
return new LexicalUnitImpl(line, column, previous, i);
}

public static LexicalUnitImpl createPercentage(int line, int column,
LexicalUnitImpl previous, float v) {
return new LexicalUnitImpl(line, column, previous, SAC_PERCENTAGE,
null, v);
}

static LexicalUnitImpl createEMS(int line, int column,
LexicalUnitImpl previous, float v) {
return new LexicalUnitImpl(line, column, previous, SAC_EM, null, v);
}

static LexicalUnitImpl createLEM(int line, int column,
LexicalUnitImpl previous, float v) {
return new LexicalUnitImpl(line, column, previous,
SCSSLexicalUnit.SAC_LEM, null, v);
}

static LexicalUnitImpl createREM(int line, int column,
LexicalUnitImpl previous, float v) {
return new LexicalUnitImpl(line, column, previous,
SCSSLexicalUnit.SAC_REM, null, v);
}

static LexicalUnitImpl createEXS(int line, int column,
LexicalUnitImpl previous, float v) {
return new LexicalUnitImpl(line, column, previous, SAC_EX, null, v);
}

public static LexicalUnitImpl createPX(int line, int column,
LexicalUnitImpl previous, float v) {
return new LexicalUnitImpl(line, column, previous, SAC_PIXEL, null, v);
}

public static LexicalUnitImpl createCM(int line, int column,
LexicalUnitImpl previous, float v) {
return new LexicalUnitImpl(line, column, previous, SAC_CENTIMETER,
null, v);
}

static LexicalUnitImpl createMM(int line, int column,
LexicalUnitImpl previous, float v) {
return new LexicalUnitImpl(line, column, previous, SAC_MILLIMETER,
null, v);
}

static LexicalUnitImpl createIN(int line, int column,
LexicalUnitImpl previous, float v) {
return new LexicalUnitImpl(line, column, previous, SAC_INCH, null, v);
}

static LexicalUnitImpl createPT(int line, int column,
LexicalUnitImpl previous, float v) {
return new LexicalUnitImpl(line, column, previous, SAC_POINT, null, v);
}

static LexicalUnitImpl createPC(int line, int column,
LexicalUnitImpl previous, float v) {
return new LexicalUnitImpl(line, column, previous, SAC_PICA, null, v);
}

static LexicalUnitImpl createDEG(int line, int column,
LexicalUnitImpl previous, float v) {
return new LexicalUnitImpl(line, column, previous, SAC_DEGREE, null, v);
}

static LexicalUnitImpl createRAD(int line, int column,
LexicalUnitImpl previous, float v) {
return new LexicalUnitImpl(line, column, previous, SAC_RADIAN, null, v);
}

static LexicalUnitImpl createGRAD(int line, int column,
LexicalUnitImpl previous, float v) {
return new LexicalUnitImpl(line, column, previous, SAC_GRADIAN, null, v);
}

static LexicalUnitImpl createMS(int line, int column,
LexicalUnitImpl previous, float v) {
if (v < 0) {
throw new ParseException("Time values may not be negative");
}
return new LexicalUnitImpl(line, column, previous, SAC_MILLISECOND,
null, v);
}

static LexicalUnitImpl createS(int line, int column,
LexicalUnitImpl previous, float v) {
if (v < 0) {
throw new ParseException("Time values may not be negative");
}
return new LexicalUnitImpl(line, column, previous, SAC_SECOND, null, v);
}

static LexicalUnitImpl createHZ(int line, int column,
LexicalUnitImpl previous, float v) {
if (v < 0) {
throw new ParseException("Frequency values may not be negative");
}
return new LexicalUnitImpl(line, column, previous, SAC_HERTZ, null, v);
}

static LexicalUnitImpl createKHZ(int line, int column,
LexicalUnitImpl previous, float v) {
if (v < 0) {
throw new ParseException("Frequency values may not be negative");
}
return new LexicalUnitImpl(line, column, previous, SAC_KILOHERTZ, null,
v);
}

static LexicalUnitImpl createDimen(int line, int column,
LexicalUnitImpl previous, float v, String s) {
return new LexicalUnitImpl(line, column, previous, SAC_DIMENSION, s, v);
}

static LexicalUnitImpl createInherit(int line, int column,
LexicalUnitImpl previous) {
return new LexicalUnitImpl(line, column, previous, SAC_INHERIT,
"inherit");
}

public static LexicalUnitImpl createIdent(int line, int column,
LexicalUnitImpl previous, String s) {
return new LexicalUnitImpl(line, column, previous, SAC_IDENT, s);
}

public static LexicalUnitImpl createString(String s) {
return new LexicalUnitImpl(0, 0, null, SAC_STRING_VALUE, s);
}

static LexicalUnitImpl createString(int line, int column,
LexicalUnitImpl previous, String s) {
return new LexicalUnitImpl(line, column, previous, SAC_STRING_VALUE, s);
}

static LexicalUnitImpl createURL(int line, int column,
LexicalUnitImpl previous, String s) {
return new LexicalUnitImpl(line, column, previous, SAC_URI, s);
}

static LexicalUnitImpl createAttr(int line, int column,
LexicalUnitImpl previous, String s) {
return new LexicalUnitImpl(line, column, previous, SAC_ATTR, s);
}

static LexicalUnitImpl createCounter(int line, int column,
LexicalUnitImpl previous, LexicalUnit params) {
return new LexicalUnitImpl(SAC_COUNTER_FUNCTION, line, column,
previous, "counter", (LexicalUnitImpl) params);
}

public static LexicalUnitImpl createCounters(int line, int column,
LexicalUnitImpl previous, LexicalUnit params) {
return new LexicalUnitImpl(SAC_COUNTERS_FUNCTION, line, column,
previous, "counters", (LexicalUnitImpl) params);
}

public static LexicalUnitImpl createRGBColor(int line, int column,
LexicalUnitImpl previous, LexicalUnit params) {
return new LexicalUnitImpl(SAC_RGBCOLOR, line, column, previous, "rgb",
(LexicalUnitImpl) params);
}

public static LexicalUnitImpl createRect(int line, int column,
LexicalUnitImpl previous, LexicalUnit params) {
return new LexicalUnitImpl(SAC_RECT_FUNCTION, line, column, previous,
"rect", (LexicalUnitImpl) params);
}

public static LexicalUnitImpl createFunction(int line, int column,
LexicalUnitImpl previous, String fname, LexicalUnit params) {
return new LexicalUnitImpl(SAC_FUNCTION, line, column, previous, fname,
(LexicalUnitImpl) params);
}

public static LexicalUnitImpl createUnicodeRange(int line, int column,
LexicalUnit previous, LexicalUnit params) {
// @@ return new LexicalUnitImpl(line, column, previous, null,
// SAC_UNICODERANGE, params);
return null;
}

public static LexicalUnitImpl createComma(int line, int column,
LexicalUnitImpl previous) {
return new LexicalUnitImpl(SAC_OPERATOR_COMMA, line, column, previous);
}

public static LexicalUnitImpl createSlash(int line, int column,
LexicalUnitImpl previous) {
return new LexicalUnitImpl(SAC_OPERATOR_SLASH, line, column, previous);
}

public static LexicalUnitImpl createAdd(int line, int column,
LexicalUnitImpl previous) {
return new LexicalUnitImpl(SAC_OPERATOR_PLUS, line, column, previous);
}

public static LexicalUnitImpl createMinus(int line, int column,
LexicalUnitImpl previous) {
return new LexicalUnitImpl(SAC_OPERATOR_MINUS, line, column, previous);
}

public static LexicalUnitImpl createMultiply(int line, int column,
LexicalUnitImpl previous) {
return new LexicalUnitImpl(SAC_OPERATOR_MULTIPLY, line, column,
previous);
}

public static LexicalUnitImpl createModulo(int line, int column,
LexicalUnitImpl previous) {
return new LexicalUnitImpl(SAC_OPERATOR_MOD, line, column, previous);
}

public static LexicalUnitImpl createLeftParenthesis(int line, int column,
LexicalUnitImpl previous) {
return new LexicalUnitImpl(SCSS_OPERATOR_LEFT_PAREN, line, column,
previous);
}

public static LexicalUnitImpl createRightParenthesis(int line, int column,
LexicalUnitImpl previous) {
return new LexicalUnitImpl(SCSS_OPERATOR_LEFT_PAREN, line, column,
previous);
}

/**
* Tries to return the value for this {@link LexicalUnitImpl} without
* considering any related units.
*
* @return
*/
public Object getValue() {
if (s != null) {
return s;
} else if (i != -1) {
return i;
} else if (f != -1) {
return f;
} else {
return null;
}
}

public String getValueAsString() {
Object value = getValue();
if (value == null) {
return null;
} else {
return value.toString();
}
}

public void setFunctionName(String functionName) {
fname = functionName;
}

public static LexicalUnitImpl createIdent(String s) {
return new LexicalUnitImpl(0, 0, null, SAC_IDENT, s);
}

public static void replaceValues(LexicalUnitImpl unit,
LexicalUnitImpl replaceWith) {
unit.setLexicalUnitType(replaceWith.getLexicalUnitType());
unit.setStringValue(replaceWith.getStringValue());
unit.setFloatValue(replaceWith.getFloatValue());
unit.setIntegerValue(replaceWith.getIntegerValue());
unit.setFunctionName(replaceWith.getFunctionName());

if (replaceWith.getParameters() != null) {
unit.setParameters(replaceWith.getParameters());
}

}

private static SCSSFunctionGenerator getGenerator(String funcName) {
SCSSFunctionGenerator serializer = SERIALIZERS.get(funcName);
if (serializer == null) {
return DEFAULT_SERIALIZER;
} else {
return serializer;
}
}

private static List<SCSSFunctionGenerator> initSerializers() {
List<SCSSFunctionGenerator> list = new LinkedList<SCSSFunctionGenerator>();
list.add(new AbsFunctionGenerator());
list.add(new CeilFunctionGenerator());
list.add(new DarkenFunctionGenerator());
list.add(new FloorFunctionGenerator());
list.add(new LightenFunctionGenerator());
list.add(new RoundFunctionGenerator());
list.add(new PercentageFunctionGenerator());
return list;
}

private static class PercentageFunctionGenerator implements
SCSSFunctionGenerator {

@Override
public String getFunctionName() {
return "percentage";
}

@Override
public String printState(LexicalUnitImpl function,
BuildStringStrategy strategy) {
StringBuilder builder = new StringBuilder();
LexicalUnitImpl firstParam = function.getParameters();
float value = firstParam.getFloatValue();
value *= PERC_PRECISION_FACTOR;
int intValue = Math.round(value);
value = ((float) intValue) / PRECISION;

int resultIntValue = (int) value;

firstParam.type = SAC_PERCENTAGE;

if (intValue == resultIntValue * PRECISION) {
builder.append(resultIntValue);
firstParam.setIntegerValue(resultIntValue);
} else {
builder.append(value);
firstParam.setFloatValue(value);
}

firstParam.setStringValue(builder.append('%').toString());

return strategy.build(firstParam);
}

}

private static final Map<String, SCSSFunctionGenerator> SERIALIZERS = new HashMap<String, SCSSFunctionGenerator>();

private static final SCSSFunctionGenerator DEFAULT_SERIALIZER = new DefaultFunctionGenerator();

private String simpleAsString() {
short type = getLexicalUnitType();
String text = null;
switch (type) {
case SCSS_VARIABLE:
text = "$" + s;
break;
case SCSS_NULL:
text = "";
break;
case LexicalUnit.SAC_OPERATOR_COMMA:
text = ",";
break;
case LexicalUnit.SAC_OPERATOR_PLUS:
text = "+";
break;
case LexicalUnit.SAC_OPERATOR_MINUS:
text = "-";
break;
case LexicalUnit.SAC_OPERATOR_MULTIPLY:
text = "*";
break;
case LexicalUnit.SAC_OPERATOR_SLASH:
text = "/";
break;
case LexicalUnit.SAC_OPERATOR_MOD:
text = "%";
break;
case LexicalUnit.SAC_OPERATOR_EXP:
text = "^";
break;
case LexicalUnit.SAC_OPERATOR_LT:
text = "<";
break;
case LexicalUnit.SAC_OPERATOR_GT:
text = ">";
break;
case LexicalUnit.SAC_OPERATOR_LE:
text = "<=";
break;
case LexicalUnit.SAC_OPERATOR_GE:
text = "=>";
break;
case LexicalUnit.SAC_OPERATOR_TILDE:
text = "~";
break;
case LexicalUnit.SAC_INHERIT:
text = "inherit";
break;
case LexicalUnit.SAC_INTEGER:
text = Integer.toString(getIntegerValue(), 10);
break;
case LexicalUnit.SAC_REAL:
text = getFloatOrInteger();
break;
case LexicalUnit.SAC_EM:
case SCSSLexicalUnit.SAC_LEM:
case SCSSLexicalUnit.SAC_REM:
case LexicalUnit.SAC_EX:
case LexicalUnit.SAC_PIXEL:
case LexicalUnit.SAC_INCH:
case LexicalUnit.SAC_CENTIMETER:
case LexicalUnit.SAC_MILLIMETER:
case LexicalUnit.SAC_POINT:
case LexicalUnit.SAC_PICA:
case LexicalUnit.SAC_PERCENTAGE:
case LexicalUnit.SAC_DEGREE:
case LexicalUnit.SAC_GRADIAN:
case LexicalUnit.SAC_RADIAN:
case LexicalUnit.SAC_MILLISECOND:
case LexicalUnit.SAC_SECOND:
case LexicalUnit.SAC_HERTZ:
case LexicalUnit.SAC_KILOHERTZ:
case LexicalUnit.SAC_DIMENSION:
text = getFloatOrInteger() + getDimensionUnitText();
break;
}
return text;
}

private String buildString(BuildStringStrategy strategy) {
short type = getLexicalUnitType();
String text = simpleAsString();
if (text == null) {
switch (type) {
case LexicalUnit.SAC_URI:
text = "url(" + getStringValue() + ")";
break;
case LexicalUnit.SAC_RGBCOLOR:
case LexicalUnit.SAC_COUNTER_FUNCTION:
case LexicalUnit.SAC_COUNTERS_FUNCTION:
case LexicalUnit.SAC_RECT_FUNCTION:
case LexicalUnit.SAC_FUNCTION:
text = buildFunctionString(strategy);
break;
case LexicalUnit.SAC_IDENT:
text = getStringValue();
break;
case LexicalUnit.SAC_STRING_VALUE:
// @@SEEME. not exact
text = "\"" + getStringValue() + "\"";
break;
case LexicalUnit.SAC_ATTR:
text = "attr(" + getStringValue() + ")";
break;
case LexicalUnit.SAC_UNICODERANGE:
text = "@@TODO";
break;
case LexicalUnit.SAC_SUB_EXPRESSION:
text = strategy.build(getSubValues());
break;
default:
text = "@unknown";
break;
}
}
if (getNextLexicalUnit() != null) {
if (getNextLexicalUnit().getLexicalUnitType() == SAC_OPERATOR_COMMA) {
return text + strategy.build(getNextLexicalUnit());
}
return text + ' ' + strategy.build(getNextLexicalUnit());
} else {
return text;
}
}

private String buildFunctionString(BuildStringStrategy strategy) {
SCSSFunctionGenerator generator = getGenerator(getFunctionName());
return generator.printState(this, strategy);
}

static {
for (SCSSFunctionGenerator serializer : initSerializers()) {
SERIALIZERS.put(serializer.getFunctionName(), serializer);
}
}
}

+ 0
- 154
theme-compiler/src/com/vaadin/sass/internal/parser/LocatorImpl.java View File

@@ -1,154 +0,0 @@
/*
* Copyright 2000-2013 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.
*/
/*
* Copyright (c) 1999 World Wide Web Consortium
* (Massachusetts Institute of Technology, Institut National de Recherche
* en Informatique et en Automatique, Keio University).
* All Rights Reserved. http://www.w3.org/Consortium/Legal/
*
* $Id: LocatorImpl.java,v 1.2 2000/02/14 16:59:06 plehegar Exp $
*/
package com.vaadin.sass.internal.parser;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.w3c.css.sac.Locator;

import com.vaadin.sass.internal.handler.SCSSDocumentHandlerImpl;

/**
* @version $Revision: 1.2 $
* @author Philippe Le Hegaret
*/
public class LocatorImpl implements Locator {

// W3C DEBUG mode
private static boolean W3CDebug;
static {
try {
W3CDebug = (Boolean.getBoolean("debug")
|| Boolean
.getBoolean("org.w3c.flute.parser.LocatorImpl.debug")
|| Boolean.getBoolean("org.w3c.flute.parser.debug")
|| Boolean.getBoolean("org.w3c.flute.debug")
|| Boolean.getBoolean("org.w3c.debug") || Boolean
.getBoolean("org.debug"));
} catch (Exception e) {
// nothing
}
}

String uri;
int line;
int column;

@Override
public String getURI() {
return uri;
}

@Override
public int getLineNumber() {
return line;
}

@Override
public int getColumnNumber() {
return column;
}

/**
* Creates a new LocatorImpl
*/
public LocatorImpl(Parser p) {
if (W3CDebug) {
log("LocatorImpl::newLocator(" + p + ");");
}
uri = p.source.getURI();
line = p.token.beginLine;
column = p.token.beginColumn;
}

/**
* Reinitializes a LocatorImpl
*/
public LocatorImpl(Parser p, Token tok) {
if (W3CDebug) {
log("LocatorImpl::newLocator(" + p + ", " + tok + ");");
}
uri = p.source.getURI();
line = tok.beginLine;
column = tok.beginColumn;
}

/**
* Reinitializes a LocatorImpl
*/
public LocatorImpl(Parser p, int line, int column) {
if (W3CDebug) {
log("LocatorImpl::newLocator(" + p + ", " + line + ", " + column
+ ");");
}
uri = p.source.getURI();
this.line = line;
this.column = column;
}

/**
* Reinitializes a LocatorImpl
*/
public LocatorImpl reInit(Parser p) {
if (W3CDebug) {
log("LocatorImpl::reInit(" + p + ");");
}
uri = p.source.getURI();
line = p.token.beginLine;
column = p.token.beginColumn;
return this;
}

/**
* Reinitializes a LocatorImpl
*/
public LocatorImpl reInit(Parser p, Token tok) {
if (W3CDebug) {
log("LocatorImpl::reInit(" + p + ", " + tok + ");");
}
uri = p.source.getURI();
line = tok.beginLine;
column = tok.beginColumn;
return this;
}

/**
* Reinitializes a LocatorImpl
*/
public LocatorImpl reInit(Parser p, int line, int column) {
if (W3CDebug) {
log("LocatorImpl::reInit(" + p + ", " + line + ", " + column + ");");
}
uri = p.source.getURI();
this.line = line;
this.column = column;
return this;
}

private void log(String msg) {
Logger.getLogger(SCSSDocumentHandlerImpl.class.getName()).log(
Level.SEVERE, msg);
}
}

+ 0
- 100
theme-compiler/src/com/vaadin/sass/internal/parser/MediaListImpl.java View File

@@ -1,100 +0,0 @@
/*
* Copyright 2000-2013 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.
*/
/*
* (c) COPYRIGHT 1999 World Wide Web Consortium
* (Massachusetts Institute of Technology, Institut National de Recherche
* en Informatique et en Automatique, Keio University).
* All Rights Reserved. http://www.w3.org/Consortium/Legal/
*
* $Id: MediaListImpl.java,v 1.4 2000/04/26 13:40:19 plehegar Exp $
*/
package com.vaadin.sass.internal.parser;

import java.io.Serializable;

import org.w3c.css.sac.SACMediaList;

/**
* @version $Revision: 1.4 $
* @author Philippe Le Hegaret
*/
public class MediaListImpl implements SACMediaList, Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;
String[] array = new String[10];
int current;

@Override
public int getLength() {
return current;
}

@Override
public String item(int index) {
if ((index < 0) || (index >= current)) {
return null;
}
return array[index];
}

void addItem(String medium) {
if (medium.equals("all")) {
array[0] = "all";
current = 1;
return;
}
for (int i = 0; i < current; i++) {
if (medium.equals(array[i])) {
return;
}
}
if (current == array.length) {
String[] old = array;
array = new String[current + current];
System.arraycopy(old, 0, array, 0, current);
}
array[current++] = medium;
}

/**
* Returns a string representation of this object.
*/
@Override
public String toString() {
switch (current) {
case 0:
return "";
case 1:
return array[0];
default:
boolean not_done = true;
int i = 0;
StringBuffer buf = new StringBuffer(50);
do {
buf.append(array[i++]);
if (i == current) {
not_done = false;
} else {
buf.append(", ");
}
} while (not_done);
return buf.toString();
}
}
}

+ 0
- 203
theme-compiler/src/com/vaadin/sass/internal/parser/ParseException.java View File

@@ -1,203 +0,0 @@
/*
* Copyright 2000-2013 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.
*/
/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 0.7pre6 */
package com.vaadin.sass.internal.parser;

import org.w3c.css.sac.CSSException;

/**
* This exception is thrown when parse errors are encountered. You can
* explicitly create objects of this exception type by calling the method
* generateParseException in the generated parser.
*
* You can modify this class to customize your error reporting mechanisms so
* long as you retain the public fields.
*/
public class ParseException extends CSSException {
private static final long serialVersionUID = -8556588037264585977L;

/**
* This constructor is used by the method "generateParseException" in the
* generated parser. Calling this constructor generates a new object of this
* type with the fields "currentToken", "expectedTokenSequences", and
* "tokenImage" set. The boolean flag "specialConstructor" is also set to
* true to indicate that this constructor was used to create this object.
* This constructor calls its super class with the empty string to force the
* "toString" method of parent class "Throwable" to print the error message
* in the form: ParseException: <result of getMessage>
*/
public ParseException(Token currentTokenVal,
int[][] expectedTokenSequencesVal, String[] tokenImageVal) {
super("");
specialConstructor = true;
currentToken = currentTokenVal;
expectedTokenSequences = expectedTokenSequencesVal;
tokenImage = tokenImageVal;
}

/**
* The following constructors are for use by you for whatever purpose you
* can think of. Constructing the exception in this manner makes the
* exception behave in the normal way - i.e., as documented in the class
* "Throwable". The fields "errorToken", "expectedTokenSequences", and
* "tokenImage" do not contain relevant information. The JavaCC generated
* code does not use these constructors.
*/

public ParseException() {
super();
specialConstructor = false;
}

public ParseException(String message) {
super(message);
specialConstructor = false;
}

/**
* This variable determines which constructor was used to create this object
* and thereby affects the semantics of the "getMessage" method (see below).
*/
protected boolean specialConstructor;

/**
* This is the last token that has been consumed successfully. If this
* object has been created due to a parse error, the token followng this
* token will (therefore) be the first error token.
*/
public Token currentToken;

/**
* Each entry in this array is an array of integers. Each array of integers
* represents a sequence of tokens (by their ordinal values) that is
* expected at this point of the parse.
*/
public int[][] expectedTokenSequences;

/**
* This is a reference to the "tokenImage" array of the generated parser
* within which the parse error occurred. This array is defined in the
* generated ...Constants interface.
*/
public String[] tokenImage;

/**
* This method has the standard behavior when this object has been created
* using the standard constructors. Otherwise, it uses "currentToken" and
* "expectedTokenSequences" to generate a parse error message and returns
* it. If this object has been created due to a parse error, and you do not
* catch it (it gets thrown from the parser), then this method is called
* during the printing of the final stack trace, and hence the correct error
* message gets displayed.
*/
@Override
public String getMessage() {
if (!specialConstructor) {
return super.getMessage();
}
String expected = "";
int maxSize = 0;
for (int i = 0; i < expectedTokenSequences.length; i++) {
if (maxSize < expectedTokenSequences[i].length) {
maxSize = expectedTokenSequences[i].length;
}
for (int j = 0; j < expectedTokenSequences[i].length; j++) {
expected += tokenImage[expectedTokenSequences[i][j]] + " ";
}
if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
expected += "...";
}
expected += eol + " ";
}
String retval = "Encountered \"";
Token tok = currentToken.next;
for (int i = 0; i < maxSize; i++) {
if (i != 0) {
retval += " ";
}
if (tok.kind == 0) {
retval += tokenImage[0];
break;
}
retval += add_escapes(tok.image);
tok = tok.next;
}
retval += "\" at line " + currentToken.next.beginLine + ", column "
+ currentToken.next.beginColumn + "." + eol;
if (expectedTokenSequences.length == 1) {
retval += "Was expecting:" + eol + " ";
} else {
retval += "Was expecting one of:" + eol + " ";
}
retval += expected;
return retval;
}

/**
* The end of line string for this machine.
*/
protected String eol = System.getProperty("line.separator", "\n");

/**
* Used to convert raw characters to their escaped version when these raw
* version cannot be used as part of an ASCII string literal.
*/
protected String add_escapes(String str) {
StringBuffer retval = new StringBuffer();
char ch;
for (int i = 0; i < str.length(); i++) {
switch (str.charAt(i)) {
case 0:
continue;
case '\b':
retval.append("\\b");
continue;
case '\t':
retval.append("\\t");
continue;
case '\n':
retval.append("\\n");
continue;
case '\f':
retval.append("\\f");
continue;
case '\r':
retval.append("\\r");
continue;
case '\"':
retval.append("\\\"");
continue;
case '\'':
retval.append("\\\'");
continue;
case '\\':
retval.append("\\\\");
continue;
default:
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
String s = "0000" + Integer.toString(ch, 16);
retval.append("\\u"
+ s.substring(s.length() - 4, s.length()));
} else {
retval.append(ch);
}
continue;
}
}
return retval.toString();
}

}

+ 0
- 7887
theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java
File diff suppressed because it is too large
View File


+ 0
- 3139
theme-compiler/src/com/vaadin/sass/internal/parser/Parser.jj
File diff suppressed because it is too large
View File


+ 0
- 392
theme-compiler/src/com/vaadin/sass/internal/parser/ParserConstants.java View File

@@ -1,392 +0,0 @@
/*
* Copyright 2000-2013 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.
*/
/* Generated By:JavaCC: Do not edit this line. ParserConstants.java */
package com.vaadin.sass.internal.parser;


/**
* Token literal values and constants.
* Generated by org.javacc.parser.OtherFilesGen#start()
*/
public interface ParserConstants {

/** End of File. */
int EOF = 0;
/** RegularExpression Id. */
int S = 1;
/** RegularExpression Id. */
int SINGLE_LINE_COMMENT = 2;
/** RegularExpression Id. */
int FORMAL_COMMENT = 5;
/** RegularExpression Id. */
int MULTI_LINE_COMMENT = 6;
/** RegularExpression Id. */
int CDO = 8;
/** RegularExpression Id. */
int CDC = 9;
/** RegularExpression Id. */
int LBRACE = 10;
/** RegularExpression Id. */
int RBRACE = 11;
/** RegularExpression Id. */
int DASHMATCH = 12;
/** RegularExpression Id. */
int CARETMATCH = 13;
/** RegularExpression Id. */
int DOLLARMATCH = 14;
/** RegularExpression Id. */
int STARMATCH = 15;
/** RegularExpression Id. */
int INCLUDES = 16;
/** RegularExpression Id. */
int EQ = 17;
/** RegularExpression Id. */
int PLUS = 18;
/** RegularExpression Id. */
int MINUS = 19;
/** RegularExpression Id. */
int COMMA = 20;
/** RegularExpression Id. */
int SEMICOLON = 21;
/** RegularExpression Id. */
int PRECEDES = 22;
/** RegularExpression Id. */
int SIBLING = 23;
/** RegularExpression Id. */
int SUCCEEDS = 24;
/** RegularExpression Id. */
int DIV = 25;
/** RegularExpression Id. */
int LBRACKET = 26;
/** RegularExpression Id. */
int RBRACKET = 27;
/** RegularExpression Id. */
int ANY = 28;
/** RegularExpression Id. */
int MOD = 29;
/** RegularExpression Id. */
int PARENT = 30;
/** RegularExpression Id. */
int DOT = 31;
/** RegularExpression Id. */
int LPARAN = 32;
/** RegularExpression Id. */
int RPARAN = 33;
/** RegularExpression Id. */
int COMPARE = 34;
/** RegularExpression Id. */
int OR = 35;
/** RegularExpression Id. */
int AND = 36;
/** RegularExpression Id. */
int NOT_EQ = 37;
/** RegularExpression Id. */
int COLON = 38;
/** RegularExpression Id. */
int INTERPOLATION = 39;
/** RegularExpression Id. */
int NONASCII = 40;
/** RegularExpression Id. */
int H = 41;
/** RegularExpression Id. */
int UNICODE = 42;
/** RegularExpression Id. */
int ESCAPE = 43;
/** RegularExpression Id. */
int NMSTART = 44;
/** RegularExpression Id. */
int NMCHAR = 45;
/** RegularExpression Id. */
int STRINGCHAR = 46;
/** RegularExpression Id. */
int D = 47;
/** RegularExpression Id. */
int NAME = 48;
/** RegularExpression Id. */
int TO = 49;
/** RegularExpression Id. */
int THROUGH = 50;
/** RegularExpression Id. */
int EACH_IN = 51;
/** RegularExpression Id. */
int FROM = 52;
/** RegularExpression Id. */
int MIXIN_SYM = 53;
/** RegularExpression Id. */
int INCLUDE_SYM = 54;
/** RegularExpression Id. */
int FUNCTION_SYM = 55;
/** RegularExpression Id. */
int RETURN_SYM = 56;
/** RegularExpression Id. */
int DEBUG_SYM = 57;
/** RegularExpression Id. */
int WARN_SYM = 58;
/** RegularExpression Id. */
int FOR_SYM = 59;
/** RegularExpression Id. */
int EACH_SYM = 60;
/** RegularExpression Id. */
int WHILE_SYM = 61;
/** RegularExpression Id. */
int IF_SYM = 62;
/** RegularExpression Id. */
int ELSE_SYM = 63;
/** RegularExpression Id. */
int EXTEND_SYM = 64;
/** RegularExpression Id. */
int MOZ_DOCUMENT_SYM = 65;
/** RegularExpression Id. */
int SUPPORTS_SYM = 66;
/** RegularExpression Id. */
int CONTENT_SYM = 67;
/** RegularExpression Id. */
int MICROSOFT_RULE = 68;
/** RegularExpression Id. */
int IF = 69;
/** RegularExpression Id. */
int GUARDED_SYM = 70;
/** RegularExpression Id. */
int STRING = 71;
/** RegularExpression Id. */
int IDENT = 72;
/** RegularExpression Id. */
int NUMBER = 73;
/** RegularExpression Id. */
int _URL = 74;
/** RegularExpression Id. */
int URL = 75;
/** RegularExpression Id. */
int VARIABLE = 76;
/** RegularExpression Id. */
int PERCENTAGE = 77;
/** RegularExpression Id. */
int PT = 78;
/** RegularExpression Id. */
int MM = 79;
/** RegularExpression Id. */
int CM = 80;
/** RegularExpression Id. */
int PC = 81;
/** RegularExpression Id. */
int IN = 82;
/** RegularExpression Id. */
int PX = 83;
/** RegularExpression Id. */
int EMS = 84;
/** RegularExpression Id. */
int LEM = 85;
/** RegularExpression Id. */
int REM = 86;
/** RegularExpression Id. */
int EXS = 87;
/** RegularExpression Id. */
int DEG = 88;
/** RegularExpression Id. */
int RAD = 89;
/** RegularExpression Id. */
int GRAD = 90;
/** RegularExpression Id. */
int MS = 91;
/** RegularExpression Id. */
int SECOND = 92;
/** RegularExpression Id. */
int HZ = 93;
/** RegularExpression Id. */
int KHZ = 94;
/** RegularExpression Id. */
int DIMEN = 95;
/** RegularExpression Id. */
int HASH = 96;
/** RegularExpression Id. */
int IMPORT_SYM = 97;
/** RegularExpression Id. */
int MEDIA_SYM = 98;
/** RegularExpression Id. */
int CHARSET_SYM = 99;
/** RegularExpression Id. */
int PAGE_SYM = 100;
/** RegularExpression Id. */
int FONT_FACE_SYM = 101;
/** RegularExpression Id. */
int KEY_FRAME_SYM = 102;
/** RegularExpression Id. */
int ATKEYWORD = 103;
/** RegularExpression Id. */
int IMPORTANT_SYM = 104;
/** RegularExpression Id. */
int RANGE0 = 105;
/** RegularExpression Id. */
int RANGE1 = 106;
/** RegularExpression Id. */
int RANGE2 = 107;
/** RegularExpression Id. */
int RANGE3 = 108;
/** RegularExpression Id. */
int RANGE4 = 109;
/** RegularExpression Id. */
int RANGE5 = 110;
/** RegularExpression Id. */
int RANGE6 = 111;
/** RegularExpression Id. */
int RANGE = 112;
/** RegularExpression Id. */
int UNI = 113;
/** RegularExpression Id. */
int UNICODERANGE = 114;
/** RegularExpression Id. */
int REMOVE = 115;
/** RegularExpression Id. */
int APPEND = 116;
/** RegularExpression Id. */
int CONTAINS = 117;
/** RegularExpression Id. */
int FUNCTION = 118;
/** RegularExpression Id. */
int UNKNOWN = 119;

/** Lexical state. */
int DEFAULT = 0;
/** Lexical state. */
int IN_FORMAL_COMMENT = 1;
/** Lexical state. */
int IN_MULTI_LINE_COMMENT = 2;

/** Literal token values. */
String[] tokenImage = {
"<EOF>",
"<S>",
"<SINGLE_LINE_COMMENT>",
"<token of kind 3>",
"\"/*\"",
"\"*/\"",
"\"*/\"",
"<token of kind 7>",
"\"<!--\"",
"\"-->\"",
"\"{\"",
"\"}\"",
"\"|=\"",
"\"^=\"",
"\"$=\"",
"\"*=\"",
"\"~=\"",
"\"=\"",
"\"+\"",
"\"-\"",
"\",\"",
"\";\"",
"\">\"",
"\"~\"",
"\"<\"",
"\"/\"",
"\"[\"",
"\"]\"",
"\"*\"",
"\"%\"",
"\"&\"",
"\".\"",
"\"(\"",
"\")\"",
"\"==\"",
"\"||\"",
"\"&&\"",
"\"!=\"",
"\":\"",
"<INTERPOLATION>",
"<NONASCII>",
"<H>",
"<UNICODE>",
"<ESCAPE>",
"<NMSTART>",
"<NMCHAR>",
"<STRINGCHAR>",
"<D>",
"<NAME>",
"\"to\"",
"\"through\"",
"\"in\"",
"\"from\"",
"\"@mixin\"",
"\"@include\"",
"\"@function\"",
"\"@return\"",
"\"@debug\"",
"\"@warn\"",
"\"@for\"",
"\"@each\"",
"\"@while\"",
"\"@if\"",
"\"@else\"",
"\"@extend\"",
"\"@-moz-document\"",
"\"@supports\"",
"\"@content\"",
"<MICROSOFT_RULE>",
"\"if\"",
"<GUARDED_SYM>",
"<STRING>",
"<IDENT>",
"<NUMBER>",
"<_URL>",
"<URL>",
"<VARIABLE>",
"<PERCENTAGE>",
"<PT>",
"<MM>",
"<CM>",
"<PC>",
"<IN>",
"<PX>",
"<EMS>",
"<LEM>",
"<REM>",
"<EXS>",
"<DEG>",
"<RAD>",
"<GRAD>",
"<MS>",
"<SECOND>",
"<HZ>",
"<KHZ>",
"<DIMEN>",
"<HASH>",
"\"@import\"",
"\"@media\"",
"\"@charset\"",
"\"@page\"",
"\"@font-face\"",
"<KEY_FRAME_SYM>",
"<ATKEYWORD>",
"<IMPORTANT_SYM>",
"<RANGE0>",
"<RANGE1>",
"<RANGE2>",
"<RANGE3>",
"<RANGE4>",
"<RANGE5>",
"<RANGE6>",
"<RANGE>",
"<UNI>",
"<UNICODERANGE>",
"<REMOVE>",
"<APPEND>",
"<CONTAINS>",
"<FUNCTION>",
"<UNKNOWN>",
};

}

+ 0
- 5000
theme-compiler/src/com/vaadin/sass/internal/parser/ParserTokenManager.java
File diff suppressed because it is too large
View File


+ 0
- 40
theme-compiler/src/com/vaadin/sass/internal/parser/SCSSLexicalUnit.java View File

@@ -1,40 +0,0 @@
/*
* Copyright 2000-2013 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.internal.parser;

import org.w3c.css.sac.LexicalUnit;

public interface SCSSLexicalUnit extends LexicalUnit {
static final short SCSS_VARIABLE = 100;
static final short SCSS_OPERATOR_LEFT_PAREN = 101;
static final short SCSS_OPERATOR_RIGHT_PAREN = 102;

static final short SCSS_NULL = 110;

static final short SAC_LEM = 200;
static final short SAC_REM = 201;

LexicalUnitImpl divide(LexicalUnitImpl denominator);

LexicalUnitImpl add(LexicalUnitImpl another);

LexicalUnitImpl minus(LexicalUnitImpl another);

LexicalUnitImpl multiply(LexicalUnitImpl another);

LexicalUnitImpl modulo(LexicalUnitImpl another);

}

+ 0
- 34
theme-compiler/src/com/vaadin/sass/internal/parser/SCSSParseException.java View File

@@ -1,34 +0,0 @@
/*
* Copyright 2000-2013 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.internal.parser;

public class SCSSParseException extends ParseException {
private ParseException parseException;
private String fileName;

public SCSSParseException(ParseException parseException, String fileName) {
this.parseException = parseException;
this.fileName = fileName;
}

@Override
public String getMessage() {
StringBuilder builder = new StringBuilder();
builder.append("Error when parsing file ").append(fileName)
.append("\n").append(parseException.getMessage());
return builder.toString();
}
}

+ 0
- 77
theme-compiler/src/com/vaadin/sass/internal/parser/SelectorListImpl.java View File

@@ -1,77 +0,0 @@
/*
* Copyright 2000-2013 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.
*/
/*
* Copyright (c) 1999 World Wide Web Consortium,
* (Massachusetts Institute of Technology, Institut National de
* Recherche en Informatique et en Automatique, Keio University). All
* Rights Reserved. This program is distributed under the W3C's Software
* Intellectual Property License. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE.
* See W3C License http://www.w3.org/Consortium/Legal/ for more details.
*
* $Id: SelectorListImpl.java,v 1.1 2000/08/07 01:16:21 plehegar Exp $
*/
package com.vaadin.sass.internal.parser;

import org.w3c.css.sac.Selector;
import org.w3c.css.sac.SelectorList;

/**
* @version $Revision: 1.1 $
* @author Philippe Le Hegaret
*/
public class SelectorListImpl implements SelectorList {

Selector[] selectors = new Selector[5];
int current;

@Override
public Selector item(int index) {
if ((index < 0) || (index >= current)) {
return null;
}
return selectors[index];
}

public Selector itemSelector(int index) {
if ((index < 0) || (index >= current)) {
return null;
}
return selectors[index];
}

@Override
public int getLength() {
return current;
}

public void addSelector(Selector selector) {
if (current == selectors.length) {
Selector[] old = selectors;
selectors = new Selector[old.length + old.length];
System.arraycopy(old, 0, selectors, 0, old.length);
}
selectors[current++] = selector;
}

public void replaceSelector(int index, Selector selector) {
if ((index >= 0) && (index < current)) {
selectors[index] = selector;
}
}
}

+ 0
- 69
theme-compiler/src/com/vaadin/sass/internal/parser/Selectors.java View File

@@ -1,69 +0,0 @@
/*
* Copyright 2000-2013 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.
*/
/*
* Copyright (c) 1999 World Wide Web Consortium,
* (Massachusetts Institute of Technology, Institut National de
* Recherche en Informatique et en Automatique, Keio University). All
* Rights Reserved. This program is distributed under the W3C's Software
* Intellectual Property License. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE.
* See W3C License http://www.w3.org/Consortium/Legal/ for more details.
*
* $Id: Selectors.java,v 1.1 2000/02/14 16:58:31 plehegar Exp $
*/
package com.vaadin.sass.internal.parser;

import org.w3c.css.sac.SelectorList;
import org.w3c.css.sac.Selector;

/**
* @version $Revision: 1.1 $
* @author Philippe Le Hegaret
*/
class Selectors implements SelectorList {

Selector[] selectors = new Selector[5];
int current;

public Selector item(int index) {
if ((index < 0) || (index >= current)) {
return null;
}
return selectors[index];
}

public Selector itemSelector(int index) {
if ((index < 0) || (index >= current)) {
return null;
}
return selectors[index];
}

public int getLength() {
return current;
}

void addSelector(Selector selector) {
if (current == selectors.length) {
Selector[] old = selectors;
selectors = new Selector[old.length + old.length];
System.arraycopy(old, 0, selectors, 0, old.length);
}
selectors[current++] = selector;
}
}

+ 0
- 41
theme-compiler/src/com/vaadin/sass/internal/parser/ThrowedParseException.java View File

@@ -1,41 +0,0 @@
/*
* Copyright 2000-2013 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.
*/
/*
* (c) COPYRIGHT 1999 World Wide Web Consortium
* (Massachusetts Institute of Technology, Institut National de Recherche
* en Informatique et en Automatique, Keio University).
* All Rights Reserved. http://www.w3.org/Consortium/Legal/
*
* $Id: ThrowedParseException.java,v 1.1 1999/06/09 15:21:33 plehegar Exp $
*/
package com.vaadin.sass.internal.parser;

/**
* @version $Revision: 1.1 $
* @author Philippe Le Hegaret
*/
class ThrowedParseException extends RuntimeException {
private static final long serialVersionUID = -7926371344505913546L;

ParseException e;

/**
* Creates a new ThrowedParseException
*/
ThrowedParseException(ParseException e) {
this.e = e;
}
}

+ 0
- 146
theme-compiler/src/com/vaadin/sass/internal/parser/Token.java View File

@@ -1,146 +0,0 @@
/*
* Copyright 2000-2013 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.
*/
/* Generated By:JavaCC: Do not edit this line. Token.java Version 5.0 */
/* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COL=null,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package com.vaadin.sass.internal.parser;

/**
* Describes the input token stream.
*/

public class Token implements java.io.Serializable {

/**
* The version identifier for this Serializable class.
* Increment only if the <i>serialized</i> form of the
* class changes.
*/
private static final long serialVersionUID = 1L;

/**
* An integer that describes the kind of this token. This numbering
* system is determined by JavaCCParser, and a table of these numbers is
* stored in the file ...Constants.java.
*/
public int kind;

/** The line number of the first character of this Token. */
public int beginLine;
/** The column number of the first character of this Token. */
public int beginColumn;
/** The line number of the last character of this Token. */
public int endLine;
/** The column number of the last character of this Token. */
public int endColumn;

/**
* The string image of the token.
*/
public String image;

/**
* A reference to the next regular (non-special) token from the input
* stream. If this is the last token from the input stream, or if the
* token manager has not read tokens beyond this one, this field is
* set to null. This is true only if this token is also a regular
* token. Otherwise, see below for a description of the contents of
* this field.
*/
public Token next;

/**
* This field is used to access special tokens that occur prior to this
* token, but after the immediately preceding regular (non-special) token.
* If there are no such special tokens, this field is set to null.
* When there are more than one such special token, this field refers
* to the last of these special tokens, which in turn refers to the next
* previous special token through its specialToken field, and so on
* until the first special token (whose specialToken field is null).
* The next fields of special tokens refer to other special tokens that
* immediately follow it (without an intervening regular token). If there
* is no such token, this field is null.
*/
public Token specialToken;

/**
* An optional attribute value of the Token.
* Tokens which are not used as syntactic sugar will often contain
* meaningful values that will be used later on by the compiler or
* interpreter. This attribute value is often different from the image.
* Any subclass of Token that actually wants to return a non-null value can
* override this method as appropriate.
*/
public Object getValue() {
return null;
}

/**
* No-argument constructor
*/
public Token() {}

/**
* Constructs a new token for the specified Image.
*/
public Token(int kind)
{
this(kind, null);
}

/**
* Constructs a new token for the specified Image and Kind.
*/
public Token(int kind, String image)
{
this.kind = kind;
this.image = image;
}

/**
* Returns the image.
*/
public String toString()
{
return image;
}

/**
* Returns a new Token object, by default. However, if you want, you
* can create and return subclass objects based on the value of ofKind.
* Simply add the cases to the switch for all those special cases.
* For example, if you have a subclass of Token called IDToken that
* you want to create if ofKind is ID, simply add something like :
*
* case MyParserConstants.ID : return new IDToken(ofKind, image);
*
* to the following switch statement. Then you can cast matchedToken
* variable to the appropriate type and use sit in your lexical actions.
*/
public static Token newToken(int ofKind, String image)
{
switch(ofKind)
{
default : return new Token(ofKind, image);
}
}

public static Token newToken(int ofKind)
{
return newToken(ofKind, null);
}

}
/* JavaCC - OriginalChecksum=8b653fc6be4ca9bd10137ee3ad4c32c4 (do not edit this line) */

+ 0
- 162
theme-compiler/src/com/vaadin/sass/internal/parser/TokenMgrError.java View File

@@ -1,162 +0,0 @@
/*
* Copyright 2000-2013 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.
*/
/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */
/* JavaCCOptions: */
package com.vaadin.sass.internal.parser;

/** Token Manager Error. */
public class TokenMgrError extends Error
{

/**
* The version identifier for this Serializable class.
* Increment only if the <i>serialized</i> form of the
* class changes.
*/
private static final long serialVersionUID = 1L;

/*
* Ordinals for various reasons why an Error of this type can be thrown.
*/

/**
* Lexical error occurred.
*/
static final int LEXICAL_ERROR = 0;

/**
* An attempt was made to create a second instance of a static token manager.
*/
static final int STATIC_LEXER_ERROR = 1;

/**
* Tried to change to an invalid lexical state.
*/
static final int INVALID_LEXICAL_STATE = 2;

/**
* Detected (and bailed out of) an infinite loop in the token manager.
*/
static final int LOOP_DETECTED = 3;

/**
* Indicates the reason why the exception is thrown. It will have
* one of the above 4 values.
*/
int errorCode;

/**
* Replaces unprintable characters by their escaped (or unicode escaped)
* equivalents in the given string
*/
protected static final String addEscapes(String str) {
StringBuffer retval = new StringBuffer();
char ch;
for (int i = 0; i < str.length(); i++) {
switch (str.charAt(i))
{
case 0 :
continue;
case '\b':
retval.append("\\b");
continue;
case '\t':
retval.append("\\t");
continue;
case '\n':
retval.append("\\n");
continue;
case '\f':
retval.append("\\f");
continue;
case '\r':
retval.append("\\r");
continue;
case '\"':
retval.append("\\\"");
continue;
case '\'':
retval.append("\\\'");
continue;
case '\\':
retval.append("\\\\");
continue;
default:
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
String s = "0000" + Integer.toString(ch, 16);
retval.append("\\u" + s.substring(s.length() - 4, s.length()));
} else {
retval.append(ch);
}
continue;
}
}
return retval.toString();
}

/**
* Returns a detailed message for the Error when it is thrown by the
* token manager to indicate a lexical error.
* Parameters :
* EOFSeen : indicates if EOF caused the lexical error
* curLexState : lexical state in which this error occurred
* errorLine : line number when the error occurred
* errorColumn : column number when the error occurred
* errorAfter : prefix that was seen before this error occurred
* curchar : the offending character
* Note: You can customize the lexical error message by modifying this method.
*/
protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
return("Lexical error at line " +
errorLine + ", column " +
errorColumn + ". Encountered: " +
(EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
"after : \"" + addEscapes(errorAfter) + "\"");
}

/**
* You can also modify the body of this method to customize your error messages.
* For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
* of end-users concern, so you can return something like :
*
* "Internal Error : Please file a bug report .... "
*
* from this method for such cases in the release version of your parser.
*/
public String getMessage() {
return super.getMessage();
}

/*
* Constructors of various flavors follow.
*/

/** No arg constructor. */
public TokenMgrError() {
}

/** Constructor with message and reason. */
public TokenMgrError(String message, int reason) {
super(message);
errorCode = reason;
}

/** Full Constructor. */
public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
}
}
/* JavaCC - OriginalChecksum=525946b34c715198d7c29f668b049f5d (do not edit this line) */

+ 0
- 41
theme-compiler/src/com/vaadin/sass/internal/parser/function/AbsFunctionGenerator.java View File

@@ -1,41 +0,0 @@
/*
* Copyright 2000-2013 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.internal.parser.function;

import com.vaadin.sass.internal.parser.LexicalUnitImpl;
import com.vaadin.sass.internal.tree.Node.BuildStringStrategy;

/**
*
* @since 7.2
* @author Vaadin Ltd
*/
public class AbsFunctionGenerator implements SCSSFunctionGenerator {

@Override
public String getFunctionName() {
return "abs";
}

@Override
public String printState(LexicalUnitImpl function,
BuildStringStrategy strategy) {
LexicalUnitImpl firstParam = function.getParameters();
firstParam.setFloatValue(Math.abs(firstParam.getFloatValue()));
return strategy.build(firstParam);
}

}

+ 0
- 41
theme-compiler/src/com/vaadin/sass/internal/parser/function/CeilFunctionGenerator.java View File

@@ -1,41 +0,0 @@
/*
* Copyright 2000-2013 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.internal.parser.function;

import com.vaadin.sass.internal.parser.LexicalUnitImpl;
import com.vaadin.sass.internal.tree.Node.BuildStringStrategy;

/**
*
* @since 7.2
* @author Vaadin Ltd
*/
public class CeilFunctionGenerator implements SCSSFunctionGenerator {

@Override
public String getFunctionName() {
return "ceil";
}

@Override
public String printState(LexicalUnitImpl function,
BuildStringStrategy strategy) {
LexicalUnitImpl firstParam = function.getParameters();
firstParam.setFloatValue((float) Math.ceil(firstParam.getFloatValue()));
return strategy.build(firstParam);
}

}

+ 0
- 40
theme-compiler/src/com/vaadin/sass/internal/parser/function/DarkenFunctionGenerator.java View File

@@ -1,40 +0,0 @@
/*
* Copyright 2000-2013 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.internal.parser.function;

import com.vaadin.sass.internal.parser.LexicalUnitImpl;
import com.vaadin.sass.internal.tree.Node.BuildStringStrategy;
import com.vaadin.sass.internal.util.ColorUtil;

/**
*
* @since 7.2
* @author Vaadin Ltd
*/
public class DarkenFunctionGenerator implements SCSSFunctionGenerator {

@Override
public String getFunctionName() {
return "darken";
}

@Override
public String printState(LexicalUnitImpl function,
BuildStringStrategy strategy) {
LexicalUnitImpl dark = ColorUtil.darken(function);
return strategy.build(dark);
}
}

+ 0
- 48
theme-compiler/src/com/vaadin/sass/internal/parser/function/DefaultFunctionGenerator.java View File

@@ -1,48 +0,0 @@
/*
* Copyright 2000-2013 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.internal.parser.function;

import com.vaadin.sass.internal.parser.LexicalUnitImpl;
import com.vaadin.sass.internal.tree.Node.BuildStringStrategy;

/**
*
* @since 7.2
* @author Vaadin Ltd
*/
public class DefaultFunctionGenerator implements SCSSFunctionGenerator {

@Override
public String getFunctionName() {
return null;
}

@Override
public String printState(LexicalUnitImpl function,
BuildStringStrategy strategy) {
StringBuilder builder = new StringBuilder(function.getFunctionName());
return builder.append('(').append(printParameters(function, strategy))
.append(')').toString();
}

private String printParameters(LexicalUnitImpl function,
BuildStringStrategy strategy) {
if (function.getParameters() == null) {
return null;
}
return strategy.build(function.getParameters());
}
}

+ 0
- 42
theme-compiler/src/com/vaadin/sass/internal/parser/function/FloorFunctionGenerator.java View File

@@ -1,42 +0,0 @@
/*
* Copyright 2000-2013 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.internal.parser.function;

import com.vaadin.sass.internal.parser.LexicalUnitImpl;
import com.vaadin.sass.internal.tree.Node.BuildStringStrategy;

/**
*
* @since 7.2
* @author Vaadin Ltd
*/
public class FloorFunctionGenerator implements SCSSFunctionGenerator {

@Override
public String getFunctionName() {
return "floor";
}

@Override
public String printState(LexicalUnitImpl function,
BuildStringStrategy strategy) {
LexicalUnitImpl firstParam = function.getParameters();
firstParam
.setFloatValue((float) Math.floor(firstParam.getFloatValue()));
return strategy.build(firstParam);
}

}

+ 0
- 40
theme-compiler/src/com/vaadin/sass/internal/parser/function/LightenFunctionGenerator.java View File

@@ -1,40 +0,0 @@
/*
* Copyright 2000-2013 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.internal.parser.function;

import com.vaadin.sass.internal.parser.LexicalUnitImpl;
import com.vaadin.sass.internal.tree.Node.BuildStringStrategy;
import com.vaadin.sass.internal.util.ColorUtil;

/**
*
* @since 7.2
* @author Vaadin Ltd
*/
public class LightenFunctionGenerator implements SCSSFunctionGenerator {

@Override
public String getFunctionName() {
return "lighten";
}

@Override
public String printState(LexicalUnitImpl function,
BuildStringStrategy strategy) {
return strategy.build(ColorUtil.lighten(function));
}

}

+ 0
- 41
theme-compiler/src/com/vaadin/sass/internal/parser/function/RoundFunctionGenerator.java View File

@@ -1,41 +0,0 @@
/*
* Copyright 2000-2013 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.internal.parser.function;

import com.vaadin.sass.internal.parser.LexicalUnitImpl;
import com.vaadin.sass.internal.tree.Node.BuildStringStrategy;

/**
*
* @since 7.2
* @author Vaadin Ltd
*/
public class RoundFunctionGenerator implements SCSSFunctionGenerator {

@Override
public String getFunctionName() {
return "round";
}

@Override
public String printState(LexicalUnitImpl function,
BuildStringStrategy strategy) {
LexicalUnitImpl firstParam = function.getParameters();
firstParam.setFloatValue(Math.round(firstParam.getFloatValue()));
return strategy.build(firstParam);
}

}

+ 0
- 57
theme-compiler/src/com/vaadin/sass/internal/parser/function/SCSSFunctionGenerator.java View File

@@ -1,57 +0,0 @@
/*
* Copyright 2000-2013 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.internal.parser.function;

import com.vaadin.sass.internal.parser.LexicalUnitImpl;
import com.vaadin.sass.internal.tree.Node.BuildStringStrategy;

/**
* Generator class is used to handle SCSS functions. Generator is applied to the
* function lexical unit if its method {@link #getFunctionName()} returns name
* of the function.
*
* If there are no dedicated generator for the function then default generator
* is used.
*
* @since 7.2
* @author Vaadin Ltd
*/
public interface SCSSFunctionGenerator {

/**
* Returns function name handled by this generator. Default generator
* returns <code>null</code> and is used if there is no dedicated generator
* for given function.
*
* @since 7.2
* @return
*/
String getFunctionName();

/**
* Prints out the current state of the function. State is SCSS content of
* the function before compilation and compiled CSS content after
* compilation.
*
* @since 7.2
* @param function
* Function lexical unit to print its state
* @param strategy
* Strategy to build string from nodes
* @return String state representation of the function
*/
String printState(LexicalUnitImpl function, BuildStringStrategy strategy);
}

+ 0
- 200
theme-compiler/src/com/vaadin/sass/internal/resolver/AbstractResolver.java View File

@@ -1,200 +0,0 @@
/*
* Copyright 2000-2013 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.internal.resolver;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

import org.w3c.css.sac.InputSource;

import com.vaadin.sass.internal.ScssStylesheet;

/**
* Base class for resolvers. Implements functionality for locating paths which
* an import can be relative to and helpers for extracting path information from
* the identifier.
*
* @since 7.2
* @author Vaadin Ltd
*/
public abstract class AbstractResolver implements ScssStylesheetResolver,
Serializable {
/*
* (non-Javadoc)
*
* @see
* com.vaadin.sass.internal.resolver.ScssStylesheetResolver#resolve(java
* .lang.String)
*/
@Override
public InputSource resolve(ScssStylesheet parentStylesheet,
String identifier) {
// Remove a possible ".scss" suffix
identifier = identifier.replaceFirst(".scss$", "");

List<String> potentialParentPaths = getPotentialParentPaths(
parentStylesheet, identifier);

// remove path from identifier as it has already been added to the
// parent path
if (identifier.contains("/")) {
identifier = identifier.substring(identifier.lastIndexOf("/") + 1);
}

for (String path : potentialParentPaths) {
InputSource source = normalizeAndResolve(path + "/" + identifier);

if (source != null) {
return source;
}

// Try to find partial import (_identifier.scss)
source = normalizeAndResolve(path + "/_" + identifier);

if (source != null) {
return source;
}

}

return normalizeAndResolve(identifier);
}

/**
* Retrieves the parent paths which should be used while resolving relative
* identifiers. By default uses the parent stylesheet location and a
* possible absolute path in the identifier.
*
* @param parentStylesheet
* The parent stylesheet or null if there is no parent
* @param identifier
* The identifier to be resolved
* @return a list of paths in which to look for the relative import
*/
protected List<String> getPotentialParentPaths(
ScssStylesheet parentStylesheet, String identifier) {
List<String> potentialParents = new ArrayList<String>();
if (parentStylesheet != null) {
potentialParents.add(extractFullPath(
parentStylesheet.getDirectory(), identifier));
}

// Identifier can be a full path so extract the path part also as a
// potential parent
if (identifier.contains("/")) {
potentialParents.add(extractFullPath("", identifier));
}

return potentialParents;

}

/**
* Extracts the full path from the path combined with the identifier
*
* @param path
* The base path
* @param identifier
* The identifier which may contain a path part, separated by "/"
* from the real identifier
* @return a normalized version of the path where identifier does not
* contain any directory information
*/
protected String extractFullPath(String path, String identifier) {
int lastSlashPosition = identifier.lastIndexOf("/");
if (lastSlashPosition == -1) {
return path;
}
String identifierPath = identifier.substring(0, lastSlashPosition);
if ("".equals(path)) {
return identifierPath;
} else {
return path + "/" + identifierPath;
}
}

/**
* Resolves the normalized version of the given identifier
*
* @param identifier
* The identifier to resolve
* @return An input source if the resolver found one or null otherwise
*/
protected InputSource normalizeAndResolve(String identifier) {
String normalized = normalize(identifier);
return resolveNormalized(normalized);
}

/**
* Resolves the identifier after it has been normalized using
* {@link #normalize(String)}.
*
* @param identifier
* The normalized identifier
* @return an InputSource if the resolver found a source or null otherwise
*/
protected abstract InputSource resolveNormalized(String identifier);

/**
* Normalizes "." and ".." from the path string where parent path segments
* can be removed. Preserve leading "..". Also ensure / is used instead of \
* in all places.
*
* @param path
* A relative or absolute file path
* @return The normalized path
*/
protected String normalize(String path) {

// Ensure only "/" is used, also in Windows
path = path.replace(File.separatorChar, '/');

// Split into segments
String[] segments = path.split("/");
Stack<String> result = new Stack<String>();

// Replace '.' and '..' segments
for (int i = 0; i < segments.length; i++) {
if (segments[i].equals(".")) {
// Segments marked '.' are ignored

} else if (segments[i].equals("..") && !result.isEmpty()
&& !result.lastElement().equals("..")) {
// If segment is ".." then remove the previous iff the previous
// element is not a ".." and the result stack is not empty
result.pop();
} else {
// Other segments are just added to the stack
result.push(segments[i]);
}
}

// Reconstruct path
StringBuilder pathBuilder = new StringBuilder();
for (int i = 0; i < result.size(); i++) {
if (i > 0) {
pathBuilder.append("/");
}
pathBuilder.append(result.get(i));
}
return pathBuilder.toString();
}

}

+ 0
- 52
theme-compiler/src/com/vaadin/sass/internal/resolver/ClassloaderResolver.java View File

@@ -1,52 +0,0 @@
/*
* Copyright 2000-2013 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.internal.resolver;

import java.io.InputStream;

import org.w3c.css.sac.InputSource;

public class ClassloaderResolver extends AbstractResolver {

@Override
public InputSource resolveNormalized(String identifier) {
String fileName = identifier;
if (!fileName.endsWith(".css")) {
fileName += ".scss";
}

// Filename should be a relative path starting with VAADIN/...
int vaadinIdx = fileName.lastIndexOf("VAADIN/");
if (vaadinIdx > -1) {
fileName = fileName.substring(vaadinIdx);
}

// Can the classloader find it?
InputStream is = getClass().getClassLoader().getResourceAsStream(
fileName);
if (is != null) {
InputSource source = new InputSource();
source.setByteStream(is);
source.setURI(fileName);
return source;

} else {
return null;
}

}

}

+ 0
- 77
theme-compiler/src/com/vaadin/sass/internal/resolver/FilesystemResolver.java View File

@@ -1,77 +0,0 @@
/*
* Copyright 2000-2013 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.internal.resolver;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;

import org.w3c.css.sac.InputSource;

import com.vaadin.sass.internal.ScssStylesheet;

public class FilesystemResolver extends AbstractResolver {

private String[] customPaths = null;

public FilesystemResolver(String... customPaths) {
this.customPaths = customPaths;
}

/*
* (non-Javadoc)
*
* @see
* com.vaadin.sass.internal.resolver.AbstractResolver#getPotentialPaths(
* com.vaadin.sass.internal.ScssStylesheet, java.lang.String)
*/
@Override
protected List<String> getPotentialParentPaths(
ScssStylesheet parentStyleSheet, String identifier) {
List<String> potentialPaths = super.getPotentialParentPaths(
parentStyleSheet, identifier);
if (customPaths != null) {
for (String path : customPaths) {
potentialPaths.add(extractFullPath(path, identifier));
}
}

return potentialPaths;
}

@Override
public InputSource resolveNormalized(String identifier) {
String fileName = identifier;
if (!fileName.endsWith(".css")) {
fileName += ".scss";
}

try {
InputStream is = new FileInputStream(fileName);
InputSource source = new InputSource();
source.setByteStream(is);
source.setURI(fileName);
return source;

} catch (FileNotFoundException e) {
// not found, try something else
return null;
}

}

}

+ 0
- 39
theme-compiler/src/com/vaadin/sass/internal/resolver/ScssStylesheetResolver.java View File

@@ -1,39 +0,0 @@
/*
* Copyright 2000-2013 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.internal.resolver;

import org.w3c.css.sac.InputSource;

import com.vaadin.sass.internal.ScssStylesheet;

public interface ScssStylesheetResolver {
/**
* Called with the "identifier" of a stylesheet that the resolver should try
* to find. The identifier is basically a filename, like "runo.scss" or
* "addon/styles.scss", but might exclude ".scss". The resolver must
* {@link InputSource#setURI(String)} to the final location where the
* stylesheet was found, e.g "runo.scss" might result in a URI like
* "VAADIN/themes/runo/runo.scss".
*
* @param parentStylesheet
* The parent style sheet
* @param identifier
* used fo find stylesheet
* @return InputSource for stylesheet (with URI set) or null if not found
*/
public InputSource resolve(ScssStylesheet parentStylesheet,
String identifier);
}

+ 0
- 43
theme-compiler/src/com/vaadin/sass/internal/selector/CompositeSelector.java View File

@@ -1,43 +0,0 @@
/*
* Copyright 2000-2013 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.internal.selector;

import org.w3c.css.sac.Selector;

public class CompositeSelector implements Selector {
public static final short SCSS_COMPOSITE_SELECTOR = 100;
private Selector first;
private Selector second;

public CompositeSelector(Selector first, Selector second) {
this.first = first;
this.second = second;
}

public Selector getFirst() {
return first;
}

public Selector getSecond() {
return second;
}

@Override
public short getSelectorType() {
return SCSS_COMPOSITE_SELECTOR;
}
}

+ 0
- 340
theme-compiler/src/com/vaadin/sass/internal/selector/SelectorUtil.java View File

@@ -1,340 +0,0 @@
/*
* Copyright 2000-2013 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.internal.selector;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.w3c.css.sac.CombinatorCondition;
import org.w3c.css.sac.Condition;
import org.w3c.css.sac.ConditionFactory;
import org.w3c.css.sac.ConditionalSelector;
import org.w3c.css.sac.DescendantSelector;
import org.w3c.css.sac.ElementSelector;
import org.w3c.css.sac.Selector;
import org.w3c.css.sac.SelectorFactory;
import org.w3c.css.sac.SelectorList;
import org.w3c.css.sac.SiblingSelector;
import org.w3c.css.sac.SimpleSelector;
import org.w3c.flute.parser.selectors.AndConditionImpl;
import org.w3c.flute.parser.selectors.AttributeConditionImpl;
import org.w3c.flute.parser.selectors.ChildSelectorImpl;
import org.w3c.flute.parser.selectors.ClassConditionImpl;
import org.w3c.flute.parser.selectors.ConditionFactoryImpl;
import org.w3c.flute.parser.selectors.DirectAdjacentSelectorImpl;
import org.w3c.flute.parser.selectors.ElementSelectorImpl;
import org.w3c.flute.parser.selectors.IdConditionImpl;
import org.w3c.flute.parser.selectors.PseudoClassConditionImpl;
import org.w3c.flute.parser.selectors.PseudoElementSelectorImpl;
import org.w3c.flute.parser.selectors.SelectorFactoryImpl;

import com.vaadin.sass.internal.parser.SelectorListImpl;

public class SelectorUtil {

public static String toString(CompositeSelector compositeSelector) {
StringBuilder builder = new StringBuilder();
if (compositeSelector != null) {
if (compositeSelector.getFirst() != null) {
builder.append(toString(compositeSelector.getFirst())).append(
" ");
}
if (compositeSelector.getSecond() != null) {
builder.append(toString(compositeSelector.getSecond()));
}
}
return builder.toString();
}

public static String toString(SelectorList selectorList) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < selectorList.getLength(); i++) {
String selectorString = toString(selectorList.item(i));
stringBuilder.append(selectorString);
if (selectorList.getLength() > i + 1) {
stringBuilder.append(", ");
}
}
return stringBuilder.toString();
}

public static String toString(Selector selector) {
if (selector == null) {
return "";
}
if (selector.getSelectorType() == Selector.SAC_CONDITIONAL_SELECTOR) {
StringBuilder stringBuilder = new StringBuilder();
ConditionalSelector conditionalSelector = (ConditionalSelector) selector;
String simpleSelectorString = toString(conditionalSelector
.getSimpleSelector());
if (simpleSelectorString != null) {
stringBuilder.append(simpleSelectorString);
}
String conditionString = getConditionString(conditionalSelector
.getCondition());
stringBuilder.append(conditionString);
return stringBuilder.toString();
} else if (selector.getSelectorType() == Selector.SAC_DESCENDANT_SELECTOR) {
return getDecendantSelectorString((DescendantSelector) selector,
" ");
} else if (selector.getSelectorType() == Selector.SAC_CHILD_SELECTOR) {
DescendantSelector childSelector = (DescendantSelector) selector;
String seperator = " > ";
if (childSelector.getSimpleSelector() instanceof PseudoElementSelectorImpl) {
seperator = "::";
}
return getDecendantSelectorString((DescendantSelector) selector,
seperator);
} else if (selector.getSelectorType() == Selector.SAC_ELEMENT_NODE_SELECTOR) {
ElementSelectorImpl elementSelector = (ElementSelectorImpl) selector;
return elementSelector.getLocalName() == null ? ""
: elementSelector.getLocalName();
} else if (selector.getSelectorType() == Selector.SAC_DIRECT_ADJACENT_SELECTOR) {
DirectAdjacentSelectorImpl directAdjacentSelector = (DirectAdjacentSelectorImpl) selector;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder
.append(toString(directAdjacentSelector.getSelector()));
stringBuilder.append(" + ");
stringBuilder.append(toString(directAdjacentSelector
.getSiblingSelector()));
return stringBuilder.toString();
} else if (selector.getSelectorType() == Selector.SAC_PSEUDO_ELEMENT_SELECTOR) {
PseudoElementSelectorImpl pseudoElementSelectorImpl = (PseudoElementSelectorImpl) selector;
return pseudoElementSelectorImpl.getLocalName();
} else if (selector.getSelectorType() == CompositeSelector.SCSS_COMPOSITE_SELECTOR) {
return toString((CompositeSelector) selector);
} else {
log("SU !Unknown selector type, type: "
+ selector.getSelectorType() + ", " + selector.toString());
}
return "";
}

private static String getDecendantSelectorString(
DescendantSelector selector, String separator) {
StringBuilder stringBuilder = new StringBuilder();
String ancestor = toString(selector.getAncestorSelector());
String simpleSelector = toString(selector.getSimpleSelector());
stringBuilder.append(ancestor);
stringBuilder.append(separator);
stringBuilder.append(simpleSelector);
return stringBuilder.toString();
}

private static String getConditionString(Condition condition) {
short conditionType = condition.getConditionType();
if (conditionType == Condition.SAC_CLASS_CONDITION) {
ClassConditionImpl classCondition = (ClassConditionImpl) condition;
return "." + classCondition.getValue();
} else if (conditionType == Condition.SAC_ID_CONDITION) {
IdConditionImpl idCondition = (IdConditionImpl) condition;
return "#" + idCondition.getValue();
} else if (conditionType == Condition.SAC_AND_CONDITION) {
AndConditionImpl andCondition = (AndConditionImpl) condition;
return getConditionString(andCondition.getFirstCondition())
+ getConditionString(andCondition.getSecondCondition());
} else if (conditionType == Condition.SAC_ATTRIBUTE_CONDITION) {
AttributeConditionImpl attributeCondition = (AttributeConditionImpl) condition;
StringBuilder string = new StringBuilder();
string.append('[');
string.append(attributeCondition.getLocalName());
String value = attributeCondition.getValue();
if ("true".equals(value) || "false".equals(value)) {
string.append("=").append(value).append(']');
} else {
string.append("=\"");
string.append(attributeCondition.getValue());
string.append("\"]");
}
return string.toString();
} else if (conditionType == Condition.SAC_PSEUDO_CLASS_CONDITION) {
PseudoClassConditionImpl pseudoClassCondition = (PseudoClassConditionImpl) condition;
return ":" + pseudoClassCondition.getValue();
} else {
log("CU !condition type not identified, type: " + conditionType
+ ", " + condition.toString());
return "";
}
}

public static boolean hasParentSelector(SelectorList selectorList) {
String selectorString = toString(selectorList);
return selectorString.contains("&");
}

public static SelectorList createNewSelectorListFromAnOldOneWithSomPartReplaced(
SelectorList oldList, String toBeReplacedSelectorName,
SelectorList candidateSelectorList) throws Exception {
if (candidateSelectorList.getLength() != 1) {
throw new Exception("Candidate selector should not be a list");
}
if (!(candidateSelectorList.item(0) instanceof SimpleSelector)) {
throw new Exception(
"Candidate selector should only be a SimpleSelector");
}
SelectorListImpl newSelectorList = new SelectorListImpl();
SimpleSelector candidateSelector = (SimpleSelector) candidateSelectorList
.item(0);
for (int i = 0; i < oldList.getLength(); i++) {
Selector selector = oldList.item(i);
newSelectorList.addSelector(createSelectorWithSomePartReplaced(
selector, toBeReplacedSelectorName, candidateSelector));
}
return newSelectorList;
}

private static Selector createSelectorWithSomePartReplaced(
Selector selector, String toBeReplacedSelectorName,
SimpleSelector candidateSelector) {
if (!toString(selector).contains(toBeReplacedSelectorName)) {
return selector;
}
SelectorFactory factory = new SelectorFactoryImpl();
if (selector instanceof SimpleSelector) {
return createSimpleSelectorWithSomePartReplaced(
(SimpleSelector) selector, toBeReplacedSelectorName,
candidateSelector);
} else if (selector instanceof DescendantSelector) {
DescendantSelector descendantSelector = (DescendantSelector) selector;
Selector ancestor = descendantSelector.getAncestorSelector();
SimpleSelector simpleSelector = descendantSelector
.getSimpleSelector();
return factory.createDescendantSelector(
createSelectorWithSomePartReplaced(ancestor,
toBeReplacedSelectorName, candidateSelector),
createSimpleSelectorWithSomePartReplaced(simpleSelector,
toBeReplacedSelectorName, candidateSelector));
} else if (selector instanceof DirectAdjacentSelectorImpl) {
SiblingSelector siblingSelector = (SiblingSelector) selector;
Selector ancestor = siblingSelector.getSelector();
SimpleSelector simpleSelector = siblingSelector
.getSiblingSelector();
return factory.createDirectAdjacentSelector(
Selector.SAC_DIRECT_ADJACENT_SELECTOR, ancestor,
simpleSelector);
} else if (selector instanceof CompositeSelector) {
CompositeSelector compositeSelector = (CompositeSelector) selector;
Selector first = compositeSelector.getFirst();
Selector second = compositeSelector.getSecond();
return new CompositeSelector(createSelectorWithSomePartReplaced(
first, toBeReplacedSelectorName, candidateSelector),
createSelectorWithSomePartReplaced(second,
toBeReplacedSelectorName, candidateSelector));
}
return null;
}

private static SimpleSelector createSimpleSelectorWithSomePartReplaced(
SimpleSelector simpleSelector, String toBeReplacedSelectorName,
SimpleSelector candidateSelector) {
if (simpleSelector == null
|| !toString(simpleSelector).contains(toBeReplacedSelectorName)) {
return simpleSelector;
}
if (simpleSelector instanceof ElementSelector
&& candidateSelector instanceof ElementSelector) {
return candidateSelector;
}
if (simpleSelector instanceof ConditionalSelector) {
return createConditionSelectorWithSomePartReplaced(
(ConditionalSelector) simpleSelector,
toBeReplacedSelectorName, candidateSelector);
}
return simpleSelector;
}

private static ConditionalSelector createConditionSelectorWithSomePartReplaced(
ConditionalSelector oldConditionSelector,
String toBeReplacedSelectorName, SimpleSelector candidateSelector) {
if (oldConditionSelector == null
|| !toString(oldConditionSelector).contains(
toBeReplacedSelectorName)) {
return oldConditionSelector;
}
SelectorFactory selectorFactory = new SelectorFactoryImpl();
if (candidateSelector instanceof ElementSelector) {
return selectorFactory.createConditionalSelector(candidateSelector,
oldConditionSelector.getCondition());
}
if (candidateSelector instanceof ConditionalSelector) {
// TODO some cases not covered.
ConditionalSelector candidateConditionSelector = (ConditionalSelector) candidateSelector;
Condition newCondition = createConditionWithSomePartReplaced(
oldConditionSelector.getCondition(),
toBeReplacedSelectorName,
candidateConditionSelector.getCondition());
return selectorFactory.createConditionalSelector(
oldConditionSelector.getSimpleSelector(), newCondition);
}
return oldConditionSelector;
}

private static Condition createConditionWithSomePartReplaced(
Condition oldCondition, String toBeReplaced, Condition candidate) {
if (oldCondition == null
|| !getConditionString(oldCondition).contains(toBeReplaced)) {
return oldCondition;
}
if (oldCondition.getConditionType() == Condition.SAC_AND_CONDITION) {
ConditionFactory conditionFactory = new ConditionFactoryImpl();
CombinatorCondition oldCombinatorCondition = (CombinatorCondition) oldCondition;
Condition newFirstCondition = createConditionWithSomePartReplaced(
oldCombinatorCondition.getFirstCondition(), toBeReplaced,
candidate);
Condition newSecondCondition = createConditionWithSomePartReplaced(
oldCombinatorCondition.getSecondCondition(), toBeReplaced,
candidate);
return conditionFactory.createAndCondition(newFirstCondition,
newSecondCondition);
} else {
return candidate;
}
}

public static boolean equals(Selector one, Selector another) {
return one == null ? another == null : toString(one).equals(
toString(another));
}

public static Selector createSelectorAndreplaceSelectorVariableWithValue(
Selector selector, String variable, String value) throws Exception {

SelectorFactoryImpl factory = new SelectorFactoryImpl();

ElementSelector es = factory.createElementSelector(
null,
((ElementSelector) selector).getLocalName().replaceAll(
variable, value));

if (selector instanceof ConditionalSelector) {
return factory.createConditionalSelector(es,
((ConditionalSelector) selector).getCondition());
} else if (selector instanceof DescendantSelector) {
return factory.createDescendantSelector(es,
((DescendantSelector) selector).getSimpleSelector());
} else if (selector instanceof ChildSelectorImpl) {
return factory.createChildSelector(es,
((DescendantSelector) selector).getSimpleSelector());
} else {
throw new Exception("Invalid selector type");
}
}

private static void log(String msg) {
Logger.getLogger(SelectorUtil.class.getName()).log(Level.INFO, msg);
}
}

+ 0
- 128
theme-compiler/src/com/vaadin/sass/internal/tree/BlockNode.java View File

@@ -1,128 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.visitor.BlockNodeHandler;

public class BlockNode extends Node implements IVariableNode {

private static final long serialVersionUID = 5742962631468325048L;

ArrayList<String> selectorList;

public BlockNode(ArrayList<String> selectorList) {
this.selectorList = selectorList;
}

public ArrayList<String> getSelectorList() {
return selectorList;
}

public void setSelectorList(ArrayList<String> selectorList) {
this.selectorList = selectorList;
}

public String buildString(boolean indent) {
return buildString(indent, PRINT_STRATEGY);
}

@Override
public String printState() {
return buildString(false);
}

@Override
public String toString() {
return "BlockNode [" + buildString(true, TO_STRING_STRATEGY) + "]";
}

@Override
public void replaceVariables(ArrayList<VariableNode> variables) {

if (selectorList == null || selectorList.isEmpty()) {
return;
}

for (final VariableNode var : variables) {
for (final String selector : new ArrayList<String>(selectorList)) {
String interpolation = "#{$" + var.getName() + "}";
if (selector.contains(interpolation)) {
String replace = selector.replace(interpolation, var
.getExpr().unquotedString());

selectorList.add(selectorList.indexOf(selector), replace);
selectorList.remove(selector);
}
}
}
}

public String getSelectors() {
StringBuilder b = new StringBuilder();
for (final String s : selectorList) {
b.append(s);
}

return b.toString();
}

public void setParentNode(Node node) {
parentNode.removeChild(this);
node.appendChild(this);
}

@Override
public void traverse() {
try {
BlockNodeHandler.traverse(this);
replaceVariables(ScssStylesheet.getVariables());
} catch (Exception e) {
Logger.getLogger(BlockNode.class.getName()).log(Level.SEVERE, null,
e);
}
}

private String buildString(boolean indent, BuildStringStrategy strategy) {
StringBuilder string = new StringBuilder();
int i = 0;
for (final String s : selectorList) {
string.append(s);
if (i != selectorList.size() - 1) {
string.append(", ");
}
i++;
}
string.append(" {\n");
for (Node child : children) {
if (indent) {
string.append("\t");
}
string.append("\t" + strategy.build(child) + "\n");
}
if (indent) {
string.append("\t");
}
string.append("}");
return string.toString();
}

}

+ 0
- 48
theme-compiler/src/com/vaadin/sass/internal/tree/CommentNode.java View File

@@ -1,48 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

public class CommentNode extends Node {
private String comment;

public CommentNode(String comment) {
this.comment = comment;
}

public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}

@Override
public String printState() {
return comment;
}

@Override
public String toString() {
return "Comment node [" + comment + "]";
}

@Override
public void traverse() {
// Not used in CommentNode
}
}

+ 0
- 33
theme-compiler/src/com/vaadin/sass/internal/tree/ContentNode.java View File

@@ -1,33 +0,0 @@
/*
* Copyright 2000-2013 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.
*/

/**
* ContentNode represents a {@literal @}content in a SCSS tree.
*/
package com.vaadin.sass.internal.tree;

public class ContentNode extends Node {

@Override
public void traverse() {
/*
* ContentNode is basically just a placeholder for some content which
* will be included. So for traverse of this node, it does nothing. it
* will be replaced when traversing MixinDefNode which contains it.
*/
}

}

+ 0
- 68
theme-compiler/src/com/vaadin/sass/internal/tree/ExtendNode.java View File

@@ -1,68 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.vaadin.sass.internal.visitor.ExtendNodeHandler;

public class ExtendNode extends Node implements IVariableNode {
private static final long serialVersionUID = 3301805078983796878L;

ArrayList<String> list;

public ExtendNode(ArrayList<String> list) {
super();
this.list = list;
}

public ArrayList<String> getList() {
return list;
}

@Override
public void replaceVariables(ArrayList<VariableNode> variables) {

}

@Override
public String toString() {
return "Extend node [" + getListAsString() + "]";
}

public String getListAsString() {
StringBuilder b = new StringBuilder();
for (final String s : list) {
b.append(s);
}

return b.toString();
}

@Override
public void traverse() {
try {
ExtendNodeHandler.traverse(this);
getParentNode().removeChild(this);
} catch (Exception e) {
Logger.getLogger(ExtendNode.class.getName()).log(Level.SEVERE,
null, e);
}
}
}

+ 0
- 47
theme-compiler/src/com/vaadin/sass/internal/tree/FontFaceNode.java View File

@@ -1,47 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

public class FontFaceNode extends Node {

@Override
public String printState() {
return buildString(PRINT_STRATEGY);
}

@Override
public String toString() {
return "FontFace node [" + buildString(TO_STRING_STRATEGY) + "]";
}

@Override
public void traverse() {
// Not in use for FontFaceNode
}

private String buildString(BuildStringStrategy strategy) {
StringBuilder builder = new StringBuilder();
builder.append("@font-face {\n");

for (final Node child : children) {
builder.append("\t" + strategy.build(child) + "\n");
}

builder.append("}");
return builder.toString();
}

}

+ 0
- 49
theme-compiler/src/com/vaadin/sass/internal/tree/ForNode.java View File

@@ -1,49 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

public class ForNode extends Node {
private static final long serialVersionUID = -1159180539216623335L;

String var;
String from;
String to;
boolean exclusive;
String body;

public ForNode(String var, String from, String to, boolean exclusive,
String body) {
super();
this.var = var;
this.from = from;
this.to = to;
this.exclusive = exclusive;
this.body = body;
}

@Override
public String toString() {
return "For Node: " + "{variable: " + var + ", from:" + from + ", to: "
+ to + ", exclusive: " + exclusive + ", body" + body;
}

@Override
public void traverse() {

}

}

+ 0
- 63
theme-compiler/src/com/vaadin/sass/internal/tree/FunctionNode.java View File

@@ -1,63 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import java.util.ArrayList;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.util.StringUtil;

public class FunctionNode extends Node implements IVariableNode {
private static final long serialVersionUID = -5383104165955523923L;

private String name;
private String args;
private String body;

public FunctionNode(String name) {
super();
this.name = name;
}

public FunctionNode(String name, String args, String body) {
this.name = name;
this.args = args;
this.body = body;
}

@Override
public String toString() {
return "Function Node: {name: " + name + ", args: " + args + ", body: "
+ body + "}";
}

@Override
public void replaceVariables(ArrayList<VariableNode> variables) {
for (final VariableNode node : variables) {
if (StringUtil.containsVariable(args, node.getName())) {
args = StringUtil.replaceVariable(args, node.getName(), node
.getExpr().printState());
}
}
}

@Override
public void traverse() {
replaceVariables(ScssStylesheet.getVariables());
}

}

+ 0
- 24
theme-compiler/src/com/vaadin/sass/internal/tree/IVariableNode.java View File

@@ -1,24 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import java.util.ArrayList;

public interface IVariableNode {

public void replaceVariables(ArrayList<VariableNode> variables);

}

+ 0
- 85
theme-compiler/src/com/vaadin/sass/internal/tree/ImportNode.java View File

@@ -1,85 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import org.w3c.css.sac.SACMediaList;

import com.vaadin.sass.internal.visitor.ImportNodeHandler;

public class ImportNode extends Node {
private static final long serialVersionUID = 5671255892282668438L;

private String uri;
private SACMediaList ml;
private boolean isURL;

public ImportNode(String uri, SACMediaList ml, boolean isURL) {
super();
this.uri = uri;
this.ml = ml;
this.isURL = isURL;
}

public boolean isPureCssImport() {
return (isURL || uri.endsWith(".css") || uri.startsWith("http://") || hasMediaQueries());
}

private boolean hasMediaQueries() {
return (ml != null && ml.getLength() >= 1 && !"all".equals(ml.item(0)));
}

@Override
public String printState() {
StringBuilder builder = new StringBuilder("@import ");
if (isURL) {
builder.append("url(").append(uri).append(")");
} else {
builder.append("\"").append(uri).append("\"");
}
if (hasMediaQueries()) {
for (int i = 0; i < ml.getLength(); i++) {
builder.append(" ").append(ml.item(i));
}
}
builder.append(";");
return builder.toString();
}

@Override
public String toString() {
return "Import node [" + printState() + "]";
}

public String getUri() {
return uri;
}

public void setUri(String uri) {
this.uri = uri;
}

public SACMediaList getMl() {
return ml;
}

@Override
public void traverse() {
// nested imports
ImportNodeHandler.traverse(getParentNode());
}

}

+ 0
- 51
theme-compiler/src/com/vaadin/sass/internal/tree/KeyframeSelectorNode.java View File

@@ -1,51 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

public class KeyframeSelectorNode extends Node {
private String selector;

public KeyframeSelectorNode(String selector) {
this.selector = selector;
}

@Override
public String printState() {
return buildString(PRINT_STRATEGY);
}

@Override
public String toString() {
return "Key frame selector node [" + buildString(TO_STRING_STRATEGY)
+ "]";
}

@Override
public void traverse() {

}

public String buildString(BuildStringStrategy strategy) {
StringBuilder string = new StringBuilder();
string.append(selector).append(" {\n");
for (Node child : children) {
string.append("\t\t").append(strategy.build(child)).append("\n");
}
string.append("\t}");
return string.toString();
}
}

+ 0
- 72
theme-compiler/src/com/vaadin/sass/internal/tree/KeyframesNode.java View File

@@ -1,72 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import java.util.ArrayList;
import java.util.regex.Pattern;

import com.vaadin.sass.internal.ScssStylesheet;

public class KeyframesNode extends Node implements IVariableNode {
private String keyframeName;
private String animationName;

public KeyframesNode(String keyframeName, String animationName) {
this.keyframeName = keyframeName;
this.animationName = animationName;
}

@Override
public String printState() {
return buildString(PRINT_STRATEGY);
}

@Override
public String toString() {
return "Key frames node [" + buildString(TO_STRING_STRATEGY) + "]";
}

@Override
public void traverse() {
replaceVariables(ScssStylesheet.getVariables());
}

@Override
public void replaceVariables(ArrayList<VariableNode> variables) {
for (final VariableNode node : variables) {
String interpolation = "#{$" + node.getName() + "}";
if (animationName != null && animationName.contains(interpolation)) {
if (animationName.contains(interpolation)) {
animationName = animationName.replaceAll(Pattern
.quote(interpolation), node.getExpr()
.unquotedString());
}
}
}
}

private String buildString(BuildStringStrategy strategy) {
StringBuilder string = new StringBuilder();
string.append(keyframeName).append(" ").append(animationName)
.append(" {\n");
for (Node child : children) {
string.append("\t\t").append(strategy.build(child)).append("\n");
}
string.append("\t}");
return string.toString();
}
}

+ 0
- 34
theme-compiler/src/com/vaadin/sass/internal/tree/ListAppendNode.java View File

@@ -1,34 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import java.util.ArrayList;

public class ListAppendNode extends ListModifyNode {

public ListAppendNode(String variable, String list, String append,
String separator) {
this.variable = variable;
checkSeparator(separator, list);
populateList(list, append);
}

@Override
protected void modifyList(ArrayList<String> newList) {
newList.addAll(modify);
}

}

+ 0
- 43
theme-compiler/src/com/vaadin/sass/internal/tree/ListContainsNode.java View File

@@ -1,43 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import java.util.ArrayList;

import com.vaadin.sass.internal.parser.LexicalUnitImpl;

public class ListContainsNode extends ListModifyNode {

public ListContainsNode(String variable, String list, String contains,
String separator) {
this.variable = variable;
checkSeparator(separator, list);
populateList(list, contains);
}

@Override
protected void modifyList(ArrayList<String> newList) {
// Does not actually modify the list
}

@Override
public VariableNode getModifiedList() {
String contains = "" + list.containsAll(modify);
VariableNode node = new VariableNode(variable.substring(1),
LexicalUnitImpl.createString(contains), false);
return node;
}
}

+ 0
- 131
theme-compiler/src/com/vaadin/sass/internal/tree/ListModifyNode.java View File

@@ -1,131 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import java.util.ArrayList;
import java.util.Arrays;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.parser.LexicalUnitImpl;

public abstract class ListModifyNode extends Node implements IVariableNode {

protected ArrayList<String> list;
protected ArrayList<String> modify;
protected String separator = " ";
protected String variable;

public String getNewVariable() {
return variable;
}

@Override
public String toString() {
return "List append node [var = " + variable + " , list =" + list
+ ", separator =" + separator + ", modify =" + modify + "]";
}

public VariableNode getModifiedList() {
final ArrayList<String> newList = new ArrayList<String>(list);
modifyList(newList);

LexicalUnitImpl unit = null;
if (newList.size() > 0) {
unit = LexicalUnitImpl.createIdent(newList.get(0));
LexicalUnitImpl last = unit;
for (int i = 1; i < newList.size(); i++) {
LexicalUnitImpl current = LexicalUnitImpl.createIdent(newList
.get(i));
last.setNextLexicalUnit(current);
last = current;
}

}
VariableNode node = new VariableNode(variable.substring(1), unit, false);
return node;
}

protected abstract void modifyList(ArrayList<String> newList);

protected void checkSeparator(String separator, String list) {
String lowerCase = "";
if (separator == null
|| (lowerCase = separator.toLowerCase()).equals("auto")) {
if (list.contains(",")) {
this.separator = ",";
}
} else if (lowerCase.equals("comma")) {
this.separator = ",";
} else if (lowerCase.equals("space")) {
this.separator = " ";
}
}

protected void populateList(String list, String modify) {
this.list = new ArrayList<String>(Arrays.asList(list.split(separator)));
this.modify = new ArrayList<String>(Arrays.asList(modify
.split(separator)));
}

@Override
public void replaceVariables(ArrayList<VariableNode> variables) {
for (final String listVar : new ArrayList<String>(list)) {
replacePossibleVariable(variables, listVar, list);
}

for (final String listVar : new ArrayList<String>(modify)) {
replacePossibleVariable(variables, listVar, modify);
}

}

private void replacePossibleVariable(ArrayList<VariableNode> variables,
final String listVar, ArrayList<String> list) {
if (listVar.startsWith("$")) {

for (final VariableNode var : variables) {

if (var.getName().equals(listVar.substring(1))) {

String[] split = null;
if (var.getExpr().printState().contains(",")) {
split = var.getExpr().printState().split(",");
} else {
split = var.getExpr().printState().split(" ");
}
int i = list.indexOf(listVar);
for (final String s : split) {
list.add(i, s.trim());
i++;
}

list.remove(listVar);
break;

}
}

}
}

@Override
public void traverse() {
replaceVariables(ScssStylesheet.getVariables());
ScssStylesheet.addVariable(getModifiedList());
getParentNode().removeChild(this);
}

}

+ 0
- 35
theme-compiler/src/com/vaadin/sass/internal/tree/ListRemoveNode.java View File

@@ -1,35 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import java.util.ArrayList;

public class ListRemoveNode extends ListModifyNode {

public ListRemoveNode(String variable, String list, String remove,
String separator) {
this.variable = variable;
checkSeparator(separator, list);
populateList(list, remove);

}

@Override
protected void modifyList(ArrayList<String> newList) {
newList.removeAll(modify);
}

}

+ 0
- 82
theme-compiler/src/com/vaadin/sass/internal/tree/MediaNode.java View File

@@ -1,82 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import org.w3c.css.sac.SACMediaList;

public class MediaNode extends Node {
private static final long serialVersionUID = 2502097081457509523L;

SACMediaList media;

public MediaNode(SACMediaList media) {
super();
this.media = media;
}

public SACMediaList getMedia() {
return media;
}

public void setMedia(SACMediaList media) {
this.media = media;
}

@Override
public String printState() {
return buildString(PRINT_STRATEGY, true);
}

@Override
public String toString() {
return buildString(TO_STRING_STRATEGY, true);
}

@Override
public void traverse() {

}

private String buildString(BuildStringStrategy strategy, boolean indent) {
StringBuilder builder = new StringBuilder("@media ");
if (media != null) {
for (int i = 0; i < media.getLength(); i++) {
if (i > 0) {
builder.append(", ");
}
builder.append(media.item(i));
}
}
builder.append(" {\n");
for (Node child : children) {
builder.append('\t');
if (child instanceof BlockNode) {
if (PRINT_STRATEGY.equals(strategy)) {
builder.append(((BlockNode) child).buildString(indent));
} else {
builder.append(strategy.build(child));

}
} else {
builder.append(strategy.build(child));
}
builder.append('\n');
}
builder.append("}");
return builder.toString();
}
}

+ 0
- 57
theme-compiler/src/com/vaadin/sass/internal/tree/MicrosoftRuleNode.java View File

@@ -1,57 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import java.util.ArrayList;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.util.StringUtil;

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 (StringUtil.containsVariable(value, var.getName())) {
value = StringUtil.replaceVariable(value, var.getName(), var
.getExpr().printState());
}
}
}

@Override
public String printState() {
return name + ": " + value + ";";
}

@Override
public String toString() {
return "MicrosoftRule node [" + printState() + "]";
}

@Override
public void traverse() {
replaceVariables(ScssStylesheet.getVariables());
}
}

+ 0
- 122
theme-compiler/src/com/vaadin/sass/internal/tree/MixinDefNode.java View File

@@ -1,122 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import java.util.ArrayList;
import java.util.Collection;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.util.DeepCopy;

public class MixinDefNode extends Node implements IVariableNode {
private static final long serialVersionUID = 5469294053247343948L;

private String name;
private ArrayList<VariableNode> arglist;
private String body;

public MixinDefNode(String name, Collection<VariableNode> args) {
super();
this.name = name;
arglist = new ArrayList<VariableNode>();
if (args != null && !args.isEmpty()) {
arglist.addAll(args);
}
}

@Override
public String toString() {
return "Mixin Definition Node: {name: " + name + ", args: "
+ arglist.size() + ", body: " + body + "}";
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public ArrayList<VariableNode> getArglist() {
return arglist;
}

public void setArglist(ArrayList<VariableNode> arglist) {
this.arglist = arglist;
}

@Override
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())
&& arg.getExpr() == null) {
arglist.add(arglist.indexOf(arg),
(VariableNode) DeepCopy.copy(var));
arglist.remove(arg);
}
}
}
}

@Override
public void traverse() {
if (!arglist.isEmpty()) {
for (final VariableNode arg : arglist) {
if (arg.getExpr() != null) {
ScssStylesheet.addVariable(arg);
}
}
}
}

/**
* This should only happen on a cloned MixinDefNode, since it changes the
* Node itself.
*
* @param mixinNode
* @return
*/
public MixinDefNode replaceContentDirective(MixinNode mixinNode) {
return findAndReplaceContentNodeInChildren(this, mixinNode);
}

private MixinDefNode findAndReplaceContentNodeInChildren(Node node,
MixinNode mixinNode) {
ContentNode contentNode = null;
for (Node child : new ArrayList<Node>(node.getChildren())) {
if (child instanceof ContentNode) {
contentNode = (ContentNode) child;
replaceContentNode(contentNode, mixinNode);
} else {
findAndReplaceContentNodeInChildren(child, mixinNode);
}
}
return this;
}

public MixinDefNode replaceContentNode(ContentNode contentNode,
MixinNode mixinNode) {
if (contentNode != null) {
contentNode.getParentNode().appendChildrenAfter(
DeepCopy.copy(mixinNode.getChildren()), contentNode);
contentNode.getParentNode().removeChild(contentNode);
}
return this;
}
}

+ 0
- 134
theme-compiler/src/com/vaadin/sass/internal/tree/MixinNode.java View File

@@ -1,134 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.parser.LexicalUnitImpl;
import com.vaadin.sass.internal.visitor.MixinNodeHandler;

public class MixinNode extends Node implements IVariableNode {
private static final long serialVersionUID = 4725008226813110658L;

private String name;
private ArrayList<LexicalUnitImpl> arglist;

public MixinNode(String name) {
this.name = name;
arglist = new ArrayList<LexicalUnitImpl>();
}

public MixinNode(String name, Collection<LexicalUnitImpl> args) {
this(name);
if (args != null && !args.isEmpty()) {
arglist.addAll(args);
}
}

@Override
public String printState() {
return "name: " + name + " args: " + arglist;
}

@Override
public String toString() {
return "Mixin node [" + printState() + "]";
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public ArrayList<LexicalUnitImpl> getArglist() {
return arglist;
}

public void setArglist(ArrayList<LexicalUnitImpl> arglist) {
this.arglist = arglist;
}

/**
* Replace variable references with their values in the mixin argument list.
*/
@Override
public void replaceVariables(ArrayList<VariableNode> variables) {
for (final VariableNode var : variables) {
for (final LexicalUnitImpl arg : new ArrayList<LexicalUnitImpl>(
arglist)) {
LexicalUnitImpl unit = arg;
// only perform replace in the value if separate argument
// name
// and value
if (unit.getNextLexicalUnit() != null) {
unit = unit.getNextLexicalUnit();
}
if (unit.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE
&& unit.getStringValue().equals(var.getName())) {
unit.replaceValue(var.getExpr());
}
}

if (name.startsWith("$")) {
if (name.equals("$" + var.getName())) {
name = var.getExpr().printState();
}
} else if (name.startsWith("#{") && name.endsWith("}")) {
if (name.equals("#{$" + var.getName() + "}")) {
name = var.getExpr().printState();
}
}
}
}

protected void replaceVariablesForChildren() {
for (Node child : getChildren()) {
if (child instanceof IVariableNode) {
((IVariableNode) child).replaceVariables(ScssStylesheet
.getVariables());
}
}
}

@Override
public void traverse() {
try {
// limit variable scope to the mixin
Map<String, VariableNode> variableScope = ScssStylesheet
.openVariableScope();

replaceVariables(ScssStylesheet.getVariables());
replaceVariablesForChildren();
MixinNodeHandler.traverse(this);

ScssStylesheet.closeVariableScope(variableScope);

} catch (Exception e) {
Logger.getLogger(MixinNode.class.getName()).log(Level.SEVERE, null,
e);
}
}

}

+ 0
- 84
theme-compiler/src/com/vaadin/sass/internal/tree/NestPropertiesNode.java View File

@@ -1,84 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.vaadin.sass.internal.visitor.NestedNodeHandler;

public class NestPropertiesNode extends Node implements IVariableNode {
private static final long serialVersionUID = 3671253315690598308L;

public NestPropertiesNode(String name) {
super();
this.name = name;
}

private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return "Nest properties node [ name = " + name + " ]";
}

public Collection<RuleNode> unNesting() {
List<RuleNode> result = new ArrayList<RuleNode>();
for (Node child : children) {
RuleNode createNewRuleNodeFromChild = createNewRuleNodeFromChild((RuleNode) child);
result.add(createNewRuleNodeFromChild);
}
return result;
}

public RuleNode createNewRuleNodeFromChild(RuleNode child) {
StringBuilder builder = new StringBuilder(name);
builder.append("-").append(child.getVariable());
RuleNode newRuleNode = new RuleNode(builder.toString(),
child.getValue(), child.isImportant(), null);
return newRuleNode;
}

@Override
public void replaceVariables(ArrayList<VariableNode> variables) {
for (Node child : getChildren()) {
if (child instanceof RuleNode) {
((RuleNode) child).replaceVariables(variables);
}
}
}

@Override
public void traverse() {
NestedNodeHandler.traverse(this);
}

@Override
public String printState() {
return null;
}

}

+ 0
- 184
theme-compiler/src/com/vaadin/sass/internal/tree/Node.java View File

@@ -1,184 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

import com.vaadin.sass.internal.parser.LexicalUnitImpl;

public abstract class Node implements Serializable {

public static BuildStringStrategy PRINT_STRATEGY = new PrintStrategy();

public static BuildStringStrategy TO_STRING_STRATEGY = new ToStringStrategy();

private static final long serialVersionUID = 5914711715839294816L;

protected ArrayList<Node> children;

protected Node parentNode;

public Node() {
children = new ArrayList<Node>();
}

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 appendChildrenAfter(Collection<Node> childrenNodes, Node after) {
if (childrenNodes != null && !childrenNodes.isEmpty()) {
int index = children.indexOf(after);
if (index != -1) {
children.addAll(index, childrenNodes);
for (final Node child : childrenNodes) {
if (child.getParentNode() != null) {
child.getParentNode().removeChild(child);
}
child.setParentNode(this);
}
} else {
throw new NullPointerException("after-node was not found");
}
}
}

public void appendChild(Node node) {
if (node != null) {
children.add(node);
if (node.getParentNode() != null) {
node.getParentNode().removeChild(node);
}
node.setParentNode(this);
}
}

public void appendChild(Node node, Node after) {
if (node != null) {
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");
}
}
}

public void removeChild(Node node) {
if (node != null) {
boolean removed = children.remove(node);
if (removed) {
node.setParentNode(null);
}
}
}

public ArrayList<Node> getChildren() {
return children;
}

public void setChildren(ArrayList<Node> children) {
this.children = children;
}

public boolean hasChildren() {
return !children.isEmpty();
}

/**
* Method for manipulating the data contained within the {@link Node}.
*
* Traversing a node is allowed to modify the node, replace it with one or
* more nodes at the same or later position in its parent and modify the
* children of the node, but not modify or remove preceding nodes in its
* parent.
*/
public abstract void traverse();

/**
* Prints out the current state of the node tree. Will return SCSS before
* compile and CSS after.
*
* Result value could be null.
*
* @since 7.2
* @return State as a string
*/
public String printState() {
return null;
}

public Node getParentNode() {
return parentNode;
}

private void setParentNode(Node parentNode) {
this.parentNode = parentNode;
}

public static interface BuildStringStrategy {

String build(Node node);

String build(LexicalUnitImpl unit);
}

public static class PrintStrategy implements BuildStringStrategy {

@Override
public String build(Node node) {
return node.printState();
}

@Override
public String build(LexicalUnitImpl unit) {
return unit.printState();
}

}

public static class ToStringStrategy implements BuildStringStrategy {

@Override
public String build(Node node) {
return node.toString();
}

@Override
public String build(LexicalUnitImpl unit) {
return unit.toString();
}

}

}

+ 0
- 175
theme-compiler/src/com/vaadin/sass/internal/tree/RuleNode.java View File

@@ -1,175 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import java.util.ArrayList;
import java.util.regex.Pattern;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.expression.ArithmeticExpressionEvaluator;
import com.vaadin.sass.internal.parser.LexicalUnitImpl;
import com.vaadin.sass.internal.util.StringUtil;

public class RuleNode extends Node implements IVariableNode {
private static final long serialVersionUID = 6653493127869037022L;

String variable;
LexicalUnitImpl value;
String comment;
private boolean important;

public RuleNode(String variable, LexicalUnitImpl value, boolean important,
String comment) {
this.variable = variable;
this.value = value;
this.important = important;
this.comment = comment;
}

public String getVariable() {
return variable;
}

public void setVariable(String variable) {
this.variable = variable;
}

public LexicalUnitImpl getValue() {
return value;
}

public void setValue(LexicalUnitImpl value) {
this.value = value;
}

@Override
public String printState() {
return buildString(PRINT_STRATEGY);
}

@Override
public String toString() {
return "Rule node [" + buildString(TO_STRING_STRATEGY) + "]";
}

public boolean isImportant() {
return important;
}

public void setImportant(boolean important) {
this.important = important;
}

public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}

@Override
public void replaceVariables(ArrayList<VariableNode> variables) {
for (final VariableNode node : variables) {

String interpolation = "#{$" + node.getName() + "}";

if (variable != null && variable.contains(interpolation)) {
variable = variable.replaceAll(Pattern.quote(interpolation),
node.getExpr().unquotedString());

}

if (value.getLexicalUnitType() == LexicalUnitImpl.SAC_FUNCTION) {

if (value.getParameters() != null) {
if (StringUtil.containsVariable(value.getParameters()
.printState(), node.getName())) {
LexicalUnitImpl param = value.getParameters();
while (param != null) {
if (param.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE
&& param.getValueAsString().equals(
node.getName())) {
param.replaceValue(node.getExpr());
}
param = param.getNextLexicalUnit();
}
}
}
} else if (value.getStringValue() != null
&& value.getStringValue().contains(interpolation)) {
LexicalUnitImpl current = value;
while (current != null) {
if (current.getValueAsString().contains(interpolation)) {

current.setStringValue(current.getValueAsString()
.replaceAll(Pattern.quote(interpolation),
node.getExpr().unquotedString()));
}
current = current.getNextLexicalUnit();
}
} else {
LexicalUnitImpl current = value;
while (current != null) {
if (current.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE
&& current.getValueAsString()
.equals(node.getName())) {

current.replaceValue(node.getExpr());
}
current = current.getNextLexicalUnit();
}
}
}
}

@Override
public void traverse() {
/*
* "replaceVariables(ScssStylesheet.getVariables());" seems duplicated
* and can be extracted out of if, but it is not.
* containsArithmeticalOperator must be called before replaceVariables.
* Because for the "/" operator, it needs to see if its predecessor or
* successor is a Variable or not, to determine it is an arithmetic
* operator.
*/
if (ArithmeticExpressionEvaluator.get().containsArithmeticalOperator(
value)) {
replaceVariables(ScssStylesheet.getVariables());
value = ArithmeticExpressionEvaluator.get().evaluate(value);
} else {
replaceVariables(ScssStylesheet.getVariables());
}
}

private String buildString(BuildStringStrategy strategy) {
String stringValue = strategy.build(value)
+ (important ? " !important" : "");
StringBuilder builder = new StringBuilder();
if (!"".equals(stringValue.trim())) {
builder.append(variable);
builder.append(": ");
builder.append(stringValue);
builder.append(';');
}

if (comment != null) {
builder.append(comment);
}
return builder.toString();
}
}

+ 0
- 64
theme-compiler/src/com/vaadin/sass/internal/tree/SimpleNode.java View File

@@ -1,64 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import java.util.ArrayList;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.util.StringUtil;

/**
* 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
* applied.
*
* @author Sebastian Nyholm @ Vaadin Ltd
*
*/
public class SimpleNode extends Node implements IVariableNode {

private String text;

public SimpleNode(String text) {
this.text = text;

}

@Override
public String printState() {
return text;
}

@Override
public String toString() {
return printState();
}

@Override
public void replaceVariables(ArrayList<VariableNode> variables) {
for (final VariableNode node : variables) {
if (StringUtil.containsVariable(text, node.getName())) {
text = StringUtil.replaceVariable(text, node.getName(), node
.getExpr().printState());
}
}
}

@Override
public void traverse() {
replaceVariables(ScssStylesheet.getVariables());
}
}

+ 0
- 131
theme-compiler/src/com/vaadin/sass/internal/tree/VariableNode.java View File

@@ -1,131 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

import java.util.ArrayList;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.expression.ArithmeticExpressionEvaluator;
import com.vaadin.sass.internal.parser.LexicalUnitImpl;
import com.vaadin.sass.internal.util.StringUtil;
import com.vaadin.sass.internal.visitor.VariableNodeHandler;

public class VariableNode extends Node implements IVariableNode {
private static final long serialVersionUID = 7003372557547748734L;

private String name;
private LexicalUnitImpl expr;
private boolean guarded;

public VariableNode(String name, LexicalUnitImpl expr, boolean guarded) {
super();
this.name = name;
this.expr = expr;
this.guarded = guarded;
}

public LexicalUnitImpl getExpr() {
return expr;
}

public void setExpr(LexicalUnitImpl expr) {
this.expr = expr;
}

public void setName(String name) {
this.name = name;
}

public String getName() {
return name;
}

public boolean isGuarded() {
return guarded;
}

@Override
public String printState() {
return buildString(PRINT_STRATEGY);
}

@Override
public String toString() {
return "Variable node [" + buildString(TO_STRING_STRATEGY) + "]";
}

public void setGuarded(boolean guarded) {
this.guarded = guarded;
}

@Override
public void replaceVariables(ArrayList<VariableNode> variables) {
for (final VariableNode node : variables) {
if (!equals(node)) {

if (StringUtil.containsVariable(expr.printState(),
node.getName())) {
if (expr.getParameters() != null
&& StringUtil.containsVariable(expr.getParameters()
.printState(), node.getName())) {
replaceValues(expr.getParameters(), node);
} else if (expr.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE) {
replaceValues(expr, node);
}
}
}
}
}

private void replaceValues(LexicalUnitImpl unit, VariableNode node) {
while (unit != null) {

if (unit.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE
&& unit.getValueAsString().equals(node.getName())) {
LexicalUnitImpl.replaceValues(unit, node.getExpr());
}

unit = unit.getNextLexicalUnit();
}
}

@Override
public void traverse() {
/*
* "replaceVariables(ScssStylesheet.getVariables());" seems duplicated
* and can be extracted out of if, but it is not.
* containsArithmeticalOperator must be called before replaceVariables.
* Because for the "/" operator, it needs to see if its predecessor or
* successor is a Variable or not, to determine it is an arithmetic
* operator.
*/
if (ArithmeticExpressionEvaluator.get().containsArithmeticalOperator(
expr)) {
replaceVariables(ScssStylesheet.getVariables());
expr = ArithmeticExpressionEvaluator.get().evaluate(expr);
} else {
replaceVariables(ScssStylesheet.getVariables());
}
VariableNodeHandler.traverse(this);
}

private String buildString(BuildStringStrategy strategy) {
StringBuilder builder = new StringBuilder("$");
builder.append(name).append(": ").append(strategy.build(expr));
return builder.toString();
}
}

+ 0
- 40
theme-compiler/src/com/vaadin/sass/internal/tree/WhileNode.java View File

@@ -1,40 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree;

public class WhileNode extends Node {
private static final long serialVersionUID = 7593896018196027279L;

private String condition;
private String body;

public WhileNode(String condition, String body) {
this.condition = condition;
this.body = body;
}

@Override
public String toString() {
return "While Node: { condition: " + condition + ", body:" + body + "}";
}

@Override
public void traverse() {

}

}

+ 0
- 104
theme-compiler/src/com/vaadin/sass/internal/tree/controldirective/EachDefNode.java View File

@@ -1,104 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree.controldirective;

import java.util.ArrayList;
import java.util.List;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.parser.LexicalUnitImpl;
import com.vaadin.sass.internal.tree.IVariableNode;
import com.vaadin.sass.internal.tree.Node;
import com.vaadin.sass.internal.tree.VariableNode;
import com.vaadin.sass.internal.visitor.EachNodeHandler;

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;
}

public String getVariableName() {
return var;
}

@Override
public String toString() {
if (hasListVariable()) {
return "Each Definition Node: {variable : " + var + ", "
+ "listVariable : " + listVariable + "}";
} else {
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 = var.getExpr();
list = new ArrayList<String>();

while (current != null) {
if (current.getValue() != null
&& current.getLexicalUnitType() != LexicalUnitImpl.SAC_OPERATOR_COMMA) {
list.add(current.getValueAsString());
}
current = current.getNextLexicalUnit();
}
listVariable = null;
break;
}
}

}
}

public String getListVariable() {
return listVariable;
}

@Override
public void traverse() {
replaceVariables(ScssStylesheet.getVariables());
EachNodeHandler.traverse(this);
}
}

+ 0
- 32
theme-compiler/src/com/vaadin/sass/internal/tree/controldirective/ElseNode.java View File

@@ -1,32 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree.controldirective;

import com.vaadin.sass.internal.tree.Node;

public class ElseNode extends Node implements IfElseNode {

@Override
public String getExpression() {
return null;
}

@Override
public void traverse() {

}

}

+ 0
- 60
theme-compiler/src/com/vaadin/sass/internal/tree/controldirective/IfElseDefNode.java View File

@@ -1,60 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree.controldirective;

import java.util.logging.Level;
import java.util.logging.Logger;

import com.vaadin.sass.internal.tree.Node;
import com.vaadin.sass.internal.visitor.IfElseNodeHandler;

public class IfElseDefNode extends Node {

@Override
public String printState() {
return buildString(PRINT_STRATEGY);
}

@Override
public String toString() {
return "IfElseDef node [" + buildString(TO_STRING_STRATEGY) + "]";
}

@Override
public void traverse() {
try {

for (final Node child : children) {
child.traverse();
}

IfElseNodeHandler.traverse(this);
} catch (Exception e) {
Logger.getLogger(IfElseDefNode.class.getName()).log(Level.SEVERE,
null, e);
}
}

private String buildString(BuildStringStrategy strategy) {
StringBuilder b = new StringBuilder();
for (final Node child : getChildren()) {
b.append(strategy.build(child));
b.append("\n");
}
return b.toString();
}

}

+ 0
- 22
theme-compiler/src/com/vaadin/sass/internal/tree/controldirective/IfElseNode.java View File

@@ -1,22 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree.controldirective;

public interface IfElseNode {

String getExpression();

}

+ 0
- 62
theme-compiler/src/com/vaadin/sass/internal/tree/controldirective/IfNode.java View File

@@ -1,62 +0,0 @@
/*
* Copyright 2000-2013 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.internal.tree.controldirective;

import java.util.ArrayList;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.tree.IVariableNode;
import com.vaadin.sass.internal.tree.Node;
import com.vaadin.sass.internal.tree.VariableNode;
import com.vaadin.sass.internal.util.StringUtil;

public class IfNode extends Node implements IfElseNode, IVariableNode {
private String expression;

public IfNode(String expression) {
this.expression = expression;
}

@Override
public String getExpression() {
if (expression != null) {
return expression.trim();
} else {
return "false";
}
}

@Override
public String toString() {
return "@if " + expression;
}

@Override
public void replaceVariables(ArrayList<VariableNode> variables) {
for (final VariableNode node : variables) {
if (StringUtil.containsVariable(expression, node.getName())) {
expression = StringUtil.replaceVariable(expression,
node.getName(), node.getExpr().printState());
}
}
}

@Override
public void traverse() {
replaceVariables(ScssStylesheet.getVariables());
}

}

+ 0
- 22
theme-compiler/src/com/vaadin/sass/internal/util/Clonable.java View File

@@ -1,22 +0,0 @@
/*
* Copyright 2000-2013 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.internal.util;

public interface Clonable {

public Object clone() throws CloneNotSupportedException;

}

+ 0
- 309
theme-compiler/src/com/vaadin/sass/internal/util/ColorUtil.java View File

@@ -1,309 +0,0 @@
/*
* Copyright 2000-2013 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.internal.util;

import org.w3c.css.sac.LexicalUnit;

import com.vaadin.sass.internal.parser.LexicalUnitImpl;

public class ColorUtil {
public static LexicalUnitImpl hexColorToHsl(LexicalUnitImpl hexColor) {
String s = hexColor.getStringValue().substring(1);
int r = 0, g = 0, b = 0;
if (s.length() == 3) {
String sh = s.substring(0, 1);
r = Integer.parseInt(sh + sh, 16);
sh = s.substring(1, 2);
g = Integer.parseInt(sh + sh, 16);
sh = s.substring(2, 3);
b = Integer.parseInt(sh + sh, 16);
} else if (s.length() == 6) {
r = Integer.parseInt(s.substring(0, 2), 16);
g = Integer.parseInt(s.substring(2, 4), 16);
b = Integer.parseInt(s.substring(4, 6), 16);
}
int hsl[] = calculateHsl(r, g, b);

LexicalUnitImpl hslParams = createHslParameters(hsl[0], hsl[1], hsl[2],
hexColor.getLineNumber(), hexColor.getColumnNumber(),
hexColor.getPreviousLexicalUnit());

return LexicalUnitImpl.createFunction(hexColor.getLineNumber(),
hexColor.getColumnNumber(), hexColor.getPreviousLexicalUnit(),
"hsl", hslParams);
}

public static LexicalUnitImpl hslToHexColor(LexicalUnitImpl hsl, int lengh) {
int[] rgb = calculateRgb(hsl);
StringBuilder builder = new StringBuilder("#");
for (int i = 0; i < 3; i++) {
String color = Integer.toHexString(rgb[i]);
if (lengh == 6) {
if (color.length() == 1) {
color = "0" + color;
}
}
if (lengh == 3) {
color = color.substring(0, 1);
}
builder.append(color);
}
return LexicalUnitImpl.createIdent(hsl.getLineNumber(),
hsl.getColumnNumber(), hsl.getPreviousLexicalUnit(),
builder.toString());
}

private static int[] calculateRgb(LexicalUnitImpl hsl) {
LexicalUnitImpl hslParam = hsl.getParameters();
LexicalUnitImpl hue = null;
LexicalUnitImpl saturation = null;
LexicalUnitImpl lightness = null;
int i = 0;
while (i < 5) {
switch (i) {
case 0:
hue = hslParam;
break;
case 2:
saturation = hslParam;
break;
case 4:
lightness = hslParam;
break;
case 1:
case 3:
break;
}
hslParam = hslParam.getNextLexicalUnit();
i++;
}
float h = ((hue.getIntegerValue() % 360) + 360) % 360 / 360f;
float s = saturation.getFloatValue() / 100;
float l = lightness.getFloatValue() / 100;
float m2, m1;
int[] rgb = new int[3];
m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
m1 = l * 2 - m2;
rgb[0] = Math.round(hueToRgb(m1, m2, h + 1f / 3) * 255);
rgb[1] = Math.round(hueToRgb(m1, m2, h) * 255);
rgb[2] = Math.round(hueToRgb(m1, m2, h - 1f / 3) * 255);
return rgb;
}

public static LexicalUnitImpl rgbToHsl(LexicalUnitImpl rgb) {
LexicalUnitImpl rgbParam = rgb.getParameters();
LexicalUnitImpl red = null;
LexicalUnitImpl green = null;
LexicalUnitImpl blue = null;
int i = 0;
while (i < 5) {
switch (i) {
case 0:
red = rgbParam;
break;
case 2:
green = rgbParam;
break;
case 4:
blue = rgbParam;
break;
case 1:
case 3:
break;
}
rgbParam = rgbParam.getNextLexicalUnit();
i++;
}

int hsl[] = calculateHsl(red.getIntegerValue(),
green.getIntegerValue(), blue.getIntegerValue());

rgbParam = rgb.getParameters();

LexicalUnitImpl hslParams = createHslParameters(hsl[0], hsl[1], hsl[2],
rgbParam.getLineNumber(), rgbParam.getColumnNumber(),
rgbParam.getPreviousLexicalUnit());

return LexicalUnitImpl.createFunction(rgb.getLineNumber(),
rgb.getColumnNumber(), rgb.getPreviousLexicalUnit(), "hsl",
hslParams);
}

private static int[] calculateHsl(int red, int green, int blue) {
int[] hsl = new int[3];

float r = red / 255f;
float g = green / 255f;
float b = blue / 255f;

float max = Math.max(Math.max(r, g), b);
float min = Math.min(Math.min(r, g), b);
float d = max - min;

float h = 0f, s = 0f, l = 0f;

if (max == min) {
h = 0;
}
if (max == r) {
h = 60 * (g - b) / d;
} else if (max == g) {
h = 60 * (b - r) / d + 120;
} else if (max == b) {
h = 60 * (r - g) / d + 240;
}

l = (max + min) / 2f;

if (max == min) {
s = 0;
} else if (l < 0.5) {
s = d / (2 * l);
} else {
s = d / (2 - 2 * l);
}

hsl[0] = Math.round(h % 360);
hsl[1] = Math.round(s * 100);
hsl[2] = Math.round(l * 100);

return hsl;
}

public static LexicalUnitImpl hslToRgb(LexicalUnitImpl hsl) {
int[] rgb = calculateRgb(hsl);
LexicalUnitImpl hslParam = hsl.getParameters();
LexicalUnitImpl rgbParams = createRgbParameters(rgb[0], rgb[1], rgb[2],
hslParam.getLineNumber(), hslParam.getColumnNumber(),
hslParam.getPreviousLexicalUnit());

return LexicalUnitImpl.createFunction(hsl.getLineNumber(),
hsl.getColumnNumber(), hsl.getPreviousLexicalUnit(), "rgb",
rgbParams);
}

private static float hueToRgb(float m1, float m2, float h) {
if (h < 0) {
h = h + 1;
}
if (h > 1) {
h = h - 1;
}
if (h * 6 < 1) {
return m1 + (m2 - m1) * h * 6;
}
if (h * 2 < 1) {
return m2;
}
if (h * 3 < 2) {
return m1 + (m2 - m1) * (2f / 3 - h) * 6;
}
return m1;
}

private static LexicalUnitImpl createRgbParameters(int r, int g, int b,
int ln, int cn, LexicalUnitImpl prev) {
LexicalUnitImpl red = LexicalUnitImpl.createInteger(ln, cn, prev, r);
LexicalUnitImpl firstComma = LexicalUnitImpl.createComma(ln, cn, red);
LexicalUnitImpl green = LexicalUnitImpl.createInteger(ln, cn,
firstComma, g);
LexicalUnitImpl secondComma = LexicalUnitImpl
.createComma(ln, cn, green);
LexicalUnitImpl.createInteger(ln, cn, secondComma, b);
return red;
}

private static LexicalUnitImpl createHslParameters(int h, int s, int l,
int ln, int cn, LexicalUnitImpl prev) {
LexicalUnitImpl hue = LexicalUnitImpl.createInteger(ln, cn, prev, h);
LexicalUnitImpl firstComma = LexicalUnitImpl.createComma(ln, cn, hue);
LexicalUnitImpl saturation = LexicalUnitImpl.createPercentage(ln, cn,
firstComma, s);
LexicalUnitImpl secondComma = LexicalUnitImpl.createComma(ln, cn,
saturation);
LexicalUnitImpl.createPercentage(ln, cn, secondComma, l);
return hue;
}

public static LexicalUnitImpl darken(LexicalUnitImpl darkenFunc) {
LexicalUnitImpl color = darkenFunc.getParameters();
float amount = getAmountValue(color);
LexicalUnitImpl pre = darkenFunc.getPreviousLexicalUnit();

return adjust(color, amount, ColorOperation.Darken, pre);
}

private static LexicalUnitImpl adjust(LexicalUnitImpl color,
float amountByPercent, ColorOperation op, LexicalUnitImpl pre) {
if (color.getLexicalUnitType() == LexicalUnit.SAC_FUNCTION) {
LexicalUnit funcParam = color.getParameters();
if ("hsl".equals(color.getFunctionName())) {
LexicalUnit lightness = funcParam;
for (int index = 0; index < 4; index++) {
lightness = lightness.getNextLexicalUnit();
}
float newValue = 0f;
if (op == ColorOperation.Darken) {
newValue = lightness.getFloatValue() - amountByPercent;
newValue = newValue < 0 ? 0 : newValue;
} else if (op == ColorOperation.Lighten) {
newValue = lightness.getFloatValue() + amountByPercent;
newValue = newValue > 100 ? 100 : newValue;
}
((LexicalUnitImpl) lightness).setFloatValue(newValue);
return LexicalUnitImpl.createFunction(color.getLineNumber(),
color.getColumnNumber(), pre, color.getFunctionName(),
funcParam);
}

} else if (color.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
if (color.getStringValue().startsWith("#")) {
return hslToHexColor(
adjust(hexColorToHsl(color), amountByPercent, op, pre),
color.getStringValue().substring(1).length());
}
} else if (color.getLexicalUnitType() == LexicalUnit.SAC_RGBCOLOR) {
LexicalUnitImpl hsl = rgbToHsl(color);
LexicalUnitImpl hslAfterDarken = adjust(hsl, amountByPercent, op,
pre);
return hslToRgb(hslAfterDarken);
}
return color;
}

public static LexicalUnitImpl lighten(LexicalUnitImpl lightenFunc) {
LexicalUnitImpl color = lightenFunc.getParameters();
float amount = getAmountValue(color);
LexicalUnitImpl pre = lightenFunc.getPreviousLexicalUnit();

return adjust(color, amount, ColorOperation.Lighten, pre);
}

private static float getAmountValue(LexicalUnitImpl color) {
LexicalUnit next = color.getNextLexicalUnit();
float amount = 10f;
if (next != null && next.getNextLexicalUnit() != null) {
next = next.getNextLexicalUnit();
amount = next.getFloatValue();
}
return amount;
}

enum ColorOperation {
Darken, Lighten
}
}

+ 0
- 89
theme-compiler/src/com/vaadin/sass/internal/util/DeepCopy.java View File

@@ -1,89 +0,0 @@
/*
* Copyright 2000-2013 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.internal.util;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Utility for making deep copies (vs. clone()'s shallow copies) of objects.
* Objects are first serialized and then deserialized. Error checking is fairly
* minimal in this implementation. If an object is encountered that cannot be
* serialized (or that references an object that cannot be serialized) an error
* is printed to the logger and null is returned. Depending on your specific
* application, it might make more sense to have copy(...) re-throw the
* exception.
*/
public class DeepCopy {

/**
* Returns a copy of the object, or null if the object cannot be serialized.
*/
public static Object copy(Object orig) {

Object obj = null;
if (!(orig instanceof Clonable)) {
try {
// Write the object out to a byte array
FastByteArrayOutputStream fbos = new FastByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(fbos);
out.writeObject(orig);
out.flush();
out.close();

// Retrieve an input stream from the byte array and read
// a copy of the object back in.
ObjectInputStream in = new ObjectInputStream(
fbos.getInputStream());
obj = in.readObject();
in.close();
} catch (IOException e) {
log(e);
} catch (ClassNotFoundException cnfe) {
log(cnfe);
}
return obj;
} else {
try {
obj = ((Clonable) orig).clone();
} catch (ClassCastException e2) {
// Can't clone, return obj as null
} catch (CloneNotSupportedException e2) {
// Can't clone, return obj as null
}
return obj;
}
}

public static <T> Collection<T> copy(Collection<T> objects) {
List<T> copies = new LinkedList<T>();
for (T object : objects) {
copies.add((T) copy(object));
}
return copies;
}

private static void log(Throwable e) {
Logger.getLogger(DeepCopy.class.getName()).log(Level.SEVERE, null, e);
}
}

+ 0
- 82
theme-compiler/src/com/vaadin/sass/internal/util/FastByteArrayInputStream.java View File

@@ -1,82 +0,0 @@
/*
* Copyright 2000-2013 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.internal.util;

import java.io.InputStream;

/**
* ByteArrayInputStream implementation that does not synchronize methods.
*/
public class FastByteArrayInputStream extends InputStream {
/**
* Our byte buffer
*/
protected byte[] buf = null;

/**
* Number of bytes that we can read from the buffer
*/
protected int count = 0;

/**
* Number of bytes that have been read from the buffer
*/
protected int pos = 0;

public FastByteArrayInputStream(byte[] buf, int count) {
this.buf = buf;
this.count = count;
}

@Override
public final int available() {
return count - pos;
}

@Override
public final int read() {
return (pos < count) ? (buf[pos++] & 0xff) : -1;
}

@Override
public final int read(byte[] b, int off, int len) {
if (pos >= count) {
return -1;
}

if ((pos + len) > count) {
len = (count - pos);
}

System.arraycopy(buf, pos, b, off, len);
pos += len;
return len;
}

@Override
public final long skip(long n) {
if ((pos + n) > count) {
n = count - pos;
}
if (n < 0) {
return 0;
}
pos += n;
return n;
}

}

+ 0
- 103
theme-compiler/src/com/vaadin/sass/internal/util/FastByteArrayOutputStream.java View File

@@ -1,103 +0,0 @@
/*
* Copyright 2000-2013 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.internal.util;

import java.io.InputStream;
import java.io.OutputStream;

/**
* ByteArrayOutputStream implementation that doesn't synchronize methods and
* doesn't copy the data on toByteArray().
*/
public class FastByteArrayOutputStream extends OutputStream {
/**
* Buffer and size
*/
protected byte[] buf = null;
protected int size = 0;

/**
* Constructs a stream with buffer capacity size 5K
*/
public FastByteArrayOutputStream() {
this(5 * 1024);
}

/**
* Constructs a stream with the given initial size
*/
public FastByteArrayOutputStream(int initSize) {
size = 0;
buf = new byte[initSize];
}

/**
* Ensures that we have a large enough buffer for the given size.
*/
private void verifyBufferSize(int sz) {
if (sz > buf.length) {
byte[] old = buf;
buf = new byte[Math.max(sz, 2 * buf.length)];
System.arraycopy(old, 0, buf, 0, old.length);
old = null;
}
}

public int getSize() {
return size;
}

/**
* Returns the byte array containing the written data. Note that this array
* will almost always be larger than the amount of data actually written.
*/
public byte[] getByteArray() {
return buf;
}

@Override
public final void write(byte b[]) {
verifyBufferSize(size + b.length);
System.arraycopy(b, 0, buf, size, b.length);
size += b.length;
}

@Override
public final void write(byte b[], int off, int len) {
verifyBufferSize(size + len);
System.arraycopy(b, off, buf, size, len);
size += len;
}

@Override
public final void write(int b) {
verifyBufferSize(size + 1);
buf[size++] = (byte) b;
}

public void reset() {
size = 0;
}

/**
* Returns a ByteArrayInputStream for reading back the written data
*/
public InputStream getInputStream() {
return new FastByteArrayInputStream(buf, size);
}

}

+ 0
- 237
theme-compiler/src/com/vaadin/sass/internal/util/StringUtil.java View File

@@ -1,237 +0,0 @@
/*
* Copyright 2000-2013 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.internal.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil {
private static final String FOLDER_SEPARATOR = "/"; // folder separator

private static final String WINDOWS_FOLDER_SEPARATOR = "\\"; // Windows
// folder
// separator

private static final String TOP_PATH = ".."; // top folder

private static final String CURRENT_PATH = "."; // current folder

public static String cleanPath(String path) {
String pathToUse = replace(path, WINDOWS_FOLDER_SEPARATOR,
FOLDER_SEPARATOR);
String[] pathArray = delimitedListToStringArray(pathToUse,
FOLDER_SEPARATOR);
List pathElements = new LinkedList();
int tops = 0;
for (int i = pathArray.length - 1; i >= 0; i--) {
if (CURRENT_PATH.equals(pathArray[i])) {
// do nothing
} else if (TOP_PATH.equals(pathArray[i])) {
tops++;
} else {
if (tops > 0) {
tops--;
} else {
pathElements.add(0, pathArray[i]);
}
}
}
for (int i = 0; i < tops; i++) {
pathElements.add(0, TOP_PATH);
}
return collectionToDelimitedString(pathElements, FOLDER_SEPARATOR);
}

public static String replace(String inString, String oldPattern,
String newPattern) {
if (inString == null) {
return null;
}
if (oldPattern == null || newPattern == null) {
return inString;
}

StringBuffer sbuf = new StringBuffer();
// output StringBuffer we'll build up
int pos = 0; // our position in the old string
int index = inString.indexOf(oldPattern);
// the index of an occurrence we've found, or -1
int patLen = oldPattern.length();
while (index >= 0) {
sbuf.append(inString.substring(pos, index));
sbuf.append(newPattern);
pos = index + patLen;
index = inString.indexOf(oldPattern, pos);
}
sbuf.append(inString.substring(pos));

// remember to append any characters to the right of a match
return sbuf.toString();
}

public static String[] delimitedListToStringArray(String str,
String delimiter) {
if (str == null) {
return new String[0];
}
if (delimiter == null) {
return new String[] { str };
}

List result = new ArrayList();
int pos = 0;
int delPos = 0;
while ((delPos = str.indexOf(delimiter, pos)) != -1) {
result.add(str.substring(pos, delPos));
pos = delPos + delimiter.length();
}
if (str.length() > 0 && pos <= str.length()) {
// Add rest of String, but not in case of empty input.
result.add(str.substring(pos));
}

return (String[]) result.toArray(new String[result.size()]);
}

public static String collectionToDelimitedString(Collection coll,
String delim, String prefix, String suffix) {
if (coll == null) {
return "";
}

StringBuffer sb = new StringBuffer();
Iterator it = coll.iterator();
int i = 0;
while (it.hasNext()) {
if (i > 0) {
sb.append(delim);
}
sb.append(prefix).append(it.next()).append(suffix);
i++;
}
return sb.toString();
}

public static String collectionToDelimitedString(Collection coll,
String delim) {
return collectionToDelimitedString(coll, delim, "", "");
}

/**
* Check if a String contains a SCSS variable, using whole word match.
*
* @param text
* text to be checked
* @Param varName SCSS variable name to be checked. (Without '$' sign)
* @return true if the text contains the SCSS variable, false if not
*/
public static boolean containsVariable(String text, String varName) {
return containsSubString(text, "$" + varName);
}

/**
* Replace the SCSS variable in a String to its corresponding value, using
* whole word match.
*
* @param text
* text which contains the SCSS variable
* @param varName
* SCSS variable name (Without '$' sign)
* @param value
* the value of the SCSS variable
* @return the String after replacing
*/
public static String replaceVariable(String text, String varName,
String value) {
return replaceSubString(text, "$" + varName, value);
}

/**
* Check if a String contains a sub string, using whole word match.
*
* @param text
* text to be checked
* @Param sub Sub String to be checked.
* @return true if the text contains the sub string, false if not
*/
public static boolean containsSubString(String text, String sub) {
StringBuilder builder = new StringBuilder();
// (?![\\w-]) means lookahead, the next one shouldn't be a word
// character nor a dash.
builder.append("(?<![\\w-])").append(Pattern.quote(sub))
.append("(?![\\w-])");
Pattern pattern = Pattern.compile(builder.toString());
Matcher matcher = pattern.matcher(text);
return matcher.find();
}

/**
* Replace the sub string in a String to a value, using whole word match.
*
* @param text
* text which contains the sub string
* @param sub
* the sub string
* @param value
* the new value
* @return the String after replacing
*/
public static String replaceSubString(String text, String sub, String value) {
StringBuilder builder = new StringBuilder();
// (?![\\w-]) means lookahead, the next one shouldn't be a word
// character nor a dash.
builder.append("(?<![\\w-])").append(Pattern.quote(sub))
.append("(?![\\w-])");
return text.replaceAll(builder.toString(), value);
}

/**
* Remove duplicated sub string in a String given a splitter. Can be used to
* removed duplicated selectors, e.g., in ".error.error", one duplicated
* ".error" can be removed.
*
* @param motherString
* string which may contains duplicated sub strings
* @param splitter
* the splitter splits the mother string to sub strings
* @return the mother string with duplicated sub strings removed
*/
public static String removeDuplicatedSubString(String motherString,
String splitter) {
List<String> subStrings = Arrays.asList(motherString.split(Pattern
.quote(splitter)));
LinkedHashSet<String> uniqueSubStrings = new LinkedHashSet<String>(
subStrings);
StringBuilder builder = new StringBuilder();
int count = 0;
for (String uniqueSubString : uniqueSubStrings) {
count++;
builder.append(uniqueSubString);
if (count < uniqueSubStrings.size()) {
builder.append(splitter);
}
}
return builder.toString();
}
}

+ 0
- 112
theme-compiler/src/com/vaadin/sass/internal/visitor/BlockNodeHandler.java View File

@@ -1,112 +0,0 @@
/*
* Copyright 2000-2013 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.internal.visitor;

import java.util.ArrayList;
import java.util.HashMap;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.tree.BlockNode;
import com.vaadin.sass.internal.tree.Node;

/**
* Handle nesting of blocks by moving child blocks to their parent, updating
* their selector lists while doing so. Also parent selectors (&amp;) are
* handled here.
*
* Sample SASS code (from www.sass-lang.com):
*
* <pre>
* table.hl {
* margin: 2em 0;
* td.ln {
* text-align: right;
* }
* }
* </pre>
*
* Note that nested properties are handled by {@link NestedNodeHandler}, not
* here.
*/
public class BlockNodeHandler {

public static void traverse(BlockNode node) {

if (node.getChildren().size() == 0) {
// empty blocks are removed later
return;
}

Node parent = node.getParentNode();

if (parent instanceof BlockNode) {
combineParentSelectorListToChild(node);

} else if (node.getSelectors().contains("&")) {
ScssStylesheet.warning("Base-level rule contains"
+ " the parent-selector-referencing character '&';"
+ " the character will be removed:\n" + node);
removeParentReference(node);
}
}

/**
* Goes through the selector list of the given BlockNode and removes the '&'
* character from the selectors.
*
* @param node
*/
private static void removeParentReference(BlockNode node) {
ArrayList<String> newList = new ArrayList<String>();
for (String childSelector : node.getSelectorList()) {
// remove parent selector
if (childSelector.contains("&")) {
newList.add(childSelector.replace("&", ""));
} else {
newList.add(childSelector);
}
}
node.setSelectorList(newList);
}

private static void combineParentSelectorListToChild(BlockNode node) {
ArrayList<String> newList = new ArrayList<String>();
BlockNode parentBlock = (BlockNode) node.getParentNode();
for (String parentSelector : parentBlock.getSelectorList()) {
for (String childSelector : node.getSelectorList()) {
// handle parent selector
if (childSelector.contains("&")) {
newList.add(childSelector.replace("&", parentSelector));
} else {
newList.add(parentSelector + " " + childSelector);
}
}
}
node.setSelectorList(newList);
Node oldParent = node.getParentNode();

HashMap<Node, Node> lastNodeAdded = ScssStylesheet.getLastNodeAdded();
Node lastAdded = lastNodeAdded.get(oldParent.getParentNode());
if (lastAdded == null) {
lastAdded = oldParent;
}

oldParent.getParentNode().appendChild(node, lastAdded);

lastNodeAdded.put(oldParent.getParentNode(), node);
}
}

+ 0
- 72
theme-compiler/src/com/vaadin/sass/internal/visitor/EachNodeHandler.java View File

@@ -1,72 +0,0 @@
/*
* Copyright 2000-2013 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.internal.visitor;

import java.util.ArrayList;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.parser.LexicalUnitImpl;
import com.vaadin.sass.internal.tree.IVariableNode;
import com.vaadin.sass.internal.tree.Node;
import com.vaadin.sass.internal.tree.VariableNode;
import com.vaadin.sass.internal.tree.controldirective.EachDefNode;
import com.vaadin.sass.internal.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);
}

}

}

+ 0
- 130
theme-compiler/src/com/vaadin/sass/internal/visitor/ExtendNodeHandler.java View File

@@ -1,130 +0,0 @@
/*
* Copyright 2000-2013 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.internal.visitor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.tree.BlockNode;
import com.vaadin.sass.internal.tree.ExtendNode;
import com.vaadin.sass.internal.tree.Node;
import com.vaadin.sass.internal.util.StringUtil;

public class ExtendNodeHandler {
private static Map<String, List<ArrayList<String>>> extendsMap = new HashMap<String, List<ArrayList<String>>>();

public static void traverse(ExtendNode node) throws Exception {
buildExtendsMap(node);
modifyTree(ScssStylesheet.get());
}

public static void clear() {
if (extendsMap != null) {
extendsMap.clear();
}
}

private static void modifyTree(Node node) throws Exception {
for (Node child : node.getChildren()) {
if (child instanceof BlockNode) {
BlockNode blockNode = (BlockNode) child;
String selectorString = blockNode.getSelectors();
if (extendsMap.get(selectorString) != null) {
for (ArrayList<String> sList : extendsMap
.get(selectorString)) {
ArrayList<String> clone = (ArrayList<String>) sList
.clone();
addAdditionalSelectorListToBlockNode(blockNode, clone,
null);
}
} else {
for (Entry<String, List<ArrayList<String>>> entry : extendsMap
.entrySet()) {
if (StringUtil.containsSubString(selectorString,
entry.getKey())) {
for (ArrayList<String> sList : entry.getValue()) {
ArrayList<String> clone = (ArrayList<String>) sList
.clone();
addAdditionalSelectorListToBlockNode(blockNode,
clone, entry.getKey());
}
}
}
}
}
}

}

private static void buildExtendsMap(ExtendNode node) {
String extendedString = node.getListAsString();
if (extendsMap.get(extendedString) == null) {
extendsMap.put(extendedString, new ArrayList<ArrayList<String>>());
}
// prevent a selector extends itself, e.g. .test{ @extend .test}
String parentSelectorString = ((BlockNode) node.getParentNode())
.getSelectors();
if (!parentSelectorString.equals(extendedString)) {
extendsMap.get(extendedString).add(
((BlockNode) node.getParentNode()).getSelectorList());
}
}

private static void addAdditionalSelectorListToBlockNode(
BlockNode blockNode, ArrayList<String> extendingSelectors,
String extendedSelector) {
if (extendingSelectors != null) {
for (String extendingSelector : extendingSelectors) {
if (extendedSelector == null) {
blockNode.getSelectorList().add(extendingSelector);
} else {
ArrayList<String> newTags = new ArrayList<String>();
for (final String selectorString : blockNode
.getSelectorList()) {
if (StringUtil.containsSubString(selectorString,
extendedSelector)) {
String newTag = generateExtendingSelectors(
selectorString, extendedSelector,
extendingSelector);
// prevent adding duplicated selector list
if (!blockNode.getSelectorList().contains(newTag)
&& !newTags.contains(newTag)) {
newTags.add(newTag);
}
}
}
blockNode.getSelectorList().addAll(newTags);
}
}
}
}

private static String generateExtendingSelectors(String selectorString,
String extendedSelector, String extendingSelector) {
String result = StringUtil.replaceSubString(selectorString,
extendedSelector, extendingSelector);
// remove duplicated class selectors.
if (result.startsWith(".")) {
result = StringUtil.removeDuplicatedSubString(result, ".");
}
return result;
}
}

+ 0
- 117
theme-compiler/src/com/vaadin/sass/internal/visitor/IfElseNodeHandler.java View File

@@ -1,117 +0,0 @@
/*
* Copyright 2000-2013 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.internal.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.internal.tree.Node;
import com.vaadin.sass.internal.tree.controldirective.ElseNode;
import com.vaadin.sass.internal.tree.controldirective.IfElseDefNode;
import com.vaadin.sass.internal.tree.controldirective.IfElseNode;
import com.vaadin.sass.internal.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);
}
}
}

+ 0
- 132
theme-compiler/src/com/vaadin/sass/internal/visitor/ImportNodeHandler.java View File

@@ -1,132 +0,0 @@
/*
* Copyright 2000-2013 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.internal.visitor;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.LexicalUnit;

import com.vaadin.sass.internal.ScssStylesheet;
import com.vaadin.sass.internal.parser.LexicalUnitImpl;
import com.vaadin.sass.internal.parser.ParseException;
import com.vaadin.sass.internal.tree.ImportNode;
import com.vaadin.sass.internal.tree.Node;
import com.vaadin.sass.internal.tree.RuleNode;
import com.vaadin.sass.internal.util.StringUtil;

public class ImportNodeHandler {

public static void traverse(Node node) {
ScssStylesheet styleSheet = null;
if (node instanceof ScssStylesheet) {
styleSheet = (ScssStylesheet) node;
} else {
// iterate to parents of node, find ScssStylesheet
Node parent = node.getParentNode();
while (parent != null && !(parent instanceof ScssStylesheet)) {
parent = parent.getParentNode();
}
if (parent instanceof ScssStylesheet) {
styleSheet = (ScssStylesheet) parent;
}
}
if (styleSheet == null) {
throw new ParseException("Nested import in an invalid context");
}
ArrayList<Node> c = new ArrayList<Node>(node.getChildren());
for (Node n : c) {
if (n instanceof ImportNode) {
ImportNode importNode = (ImportNode) n;
if (!importNode.isPureCssImport()) {
try {
// set parent's charset to imported node.
ScssStylesheet imported = ScssStylesheet.get(
importNode.getUri(), styleSheet);
if (imported == null) {
throw new FileNotFoundException("Import '"
+ importNode.getUri() + "' in '"
+ styleSheet.getFileName()
+ "' could not be found");
}

traverse(imported);

String prefix = getUrlPrefix(importNode.getUri());
if (prefix != null) {
updateUrlInImportedSheet(imported, prefix);
}

node.appendChildrenAfter(
new ArrayList<Node>(imported.getChildren()),
importNode);
node.removeChild(importNode);
} catch (CSSException e) {
Logger.getLogger(ImportNodeHandler.class.getName())
.log(Level.SEVERE, null, e);
} catch (IOException e) {
Logger.getLogger(ImportNodeHandler.class.getName())
.log(Level.SEVERE, null, e);
}
} else {
if (styleSheet != node) {
throw new ParseException(
"CSS imports can only be used at the top level, not as nested imports. Within style rules, use SCSS imports.");
}
}
}
}
}

private static String getUrlPrefix(String url) {
if (url == null) {
return null;
}
int pos = url.lastIndexOf('/');
if (pos == -1) {
return null;
}
return url.substring(0, pos + 1);
}

private static void updateUrlInImportedSheet(Node node, String prefix) {
for (Node child : node.getChildren()) {
if (child instanceof RuleNode) {
LexicalUnit value = ((RuleNode) child).getValue();
while (value != null) {
if (value.getLexicalUnitType() == LexicalUnit.SAC_URI) {
String path = value.getStringValue()
.replaceAll("^\"|\"$", "")
.replaceAll("^'|'$", "");
if (!path.startsWith("/") && !path.contains(":")) {
path = prefix + path;
path = StringUtil.cleanPath(path);
((LexicalUnitImpl) value).setStringValue(path);
}
}
value = value.getNextLexicalUnit();
}

}
updateUrlInImportedSheet(child, prefix);
}
}
}

+ 0
- 0
theme-compiler/src/com/vaadin/sass/internal/visitor/MixinNodeHandler.java View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save