com.vaadin.sass.internal.parser
Class SassExpression

java.lang.Object
  extended by com.vaadin.sass.internal.parser.SassExpression
All Implemented Interfaces:
SassListItem, Serializable

public class SassExpression
extends Object
implements SassListItem, Serializable

SassExpressions are used for representing and evaluating arithmetic expressions.

Author:
Vaadin
See Also:
Serialized Form

Method Summary
 String buildString(Node.BuildStringStrategy strategy)
          Return a string representation of this item using the given strategy of converting items to strings.
 boolean containsArithmeticalOperator()
          Checks whether the item contains an arithmetic expression.
static SassListItem createExpression(List<SassListItem> items)
          Creates a new expression containing the elements of the parameter items but with trailing whitespace items eliminated.
 SassListItem evaluateFunctionsAndExpressions(boolean evaluateArithmetics)
          Evaluates the arithmetic expressions and functions of this item without modifying this item.
 int getColumnNumber()
           
 LexicalUnitImpl getContainedValue()
           
 int getLineNumber()
           
static int getNextNonspaceIndex(List<SassListItem> list, int startIndex)
          Returns the index of the next non-whitespace item in list, starting from startIndex (inclusive).
static boolean isWhitespace(SassListItem unit)
           
 String printState()
          Returns a string representation of this item.
 SassExpression replaceVariables(Collection<VariableNode> variables)
          Returns a new item that is otherwise equal to this one but all occurrences of the given variables have been replaced by the values given in the VariableNodes.
 String toString()
           
 String unquotedString()
          Returns a string representation of this item with surrounding quotation marks of the same type (" or ') removed.
 void updateUrl(String prefix)
          Updates all url's of this item by, e.g., adding the prefix to an url not starting with slash "/" and not containing the symbol ":".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

createExpression

public static SassListItem createExpression(List<SassListItem> items)
Creates a new expression containing the elements of the parameter items but with trailing whitespace items eliminated. If items contains only one element excluding the trailing whitespace, returns the only contained element. Otherwise returns a SassExpression.

Parameters:
items - A list of SassListItems.
Returns:
A SassExpression corresponding to items. If there is only one item after the removal of whitespace, returns that item instead of a SassExpression.

getLineNumber

public int getLineNumber()
Specified by:
getLineNumber in interface SassListItem

getColumnNumber

public int getColumnNumber()
Specified by:
getColumnNumber in interface SassListItem

containsArithmeticalOperator

public boolean containsArithmeticalOperator()
Description copied from interface: SassListItem
Checks whether the item contains an arithmetic expression.

Specified by:
containsArithmeticalOperator in interface SassListItem

getNextNonspaceIndex

public static int getNextNonspaceIndex(List<SassListItem> list,
                                       int startIndex)
Returns the index of the next non-whitespace item in list, starting from startIndex (inclusive). If there are no non-whitespace items in list[startIndex...list.size() - 1], returns list.size().

Parameters:
list - A list.
startIndex - The first index included in the search.
Returns:
The smallest index i such that i >= startIndex && list.get(i) does not represent whitespace. If no such index exists, returns list.size().

evaluateFunctionsAndExpressions

public SassListItem evaluateFunctionsAndExpressions(boolean evaluateArithmetics)
Description copied from interface: SassListItem
Evaluates the arithmetic expressions and functions of this item without modifying this item.

Specified by:
evaluateFunctionsAndExpressions in interface SassListItem
Parameters:
evaluateArithmetics - True indicates that the arithmetic expressions in this item should be evaluated. This parameter is used to handle the case where the operator '/' should not be interpreted as an arithmetic operation. The arithmetic expressions occurring in the parameter lists of functions will be evaluated even if evaluateArithmetics is false.
Returns:
For single values, the result of the arithmetic expression or function. For a list, a copy of the list where the arithmetic expressions and functions have been replaced with their evaluated values.

replaceVariables

public SassExpression replaceVariables(Collection<VariableNode> variables)
Description copied from interface: SassListItem
Returns a new item that is otherwise equal to this one but all occurrences of the given variables have been replaced by the values given in the VariableNodes. Does not modify this item.

Specified by:
replaceVariables in interface SassListItem
Returns:
A SassListItem where all occurrences of variables have been replaced by their values.

updateUrl

public void updateUrl(String prefix)
Description copied from interface: SassListItem
Updates all url's of this item by, e.g., adding the prefix to an url not starting with slash "/" and not containing the symbol ":". This is a mutating method, i.e. it modifies the contents of the current object.

Specified by:
updateUrl in interface SassListItem
Parameters:
prefix - The prefix to be added.

printState

public String printState()
Description copied from interface: SassListItem
Returns a string representation of this item. See LexicalUnitImpl.printState(). For a list, the string representation contains the list items separated with the separator character of the list. No parentheses appear in the string representation of a list, for valid CSS output.

Specified by:
printState in interface SassListItem
Returns:
A string representation of this item.

buildString

public String buildString(Node.BuildStringStrategy strategy)
Description copied from interface: SassListItem
Return a string representation of this item using the given strategy of converting items to strings. See LexicalUnitImpl#buildString(BuildStringStrategy).

Specified by:
buildString in interface SassListItem
Parameters:
strategy - Specifies how an item is converted to a string. The strategy may use the toString- and printState-methods.
Returns:
A string representation of this string.

toString

public String toString()
Overrides:
toString in class Object

unquotedString

public String unquotedString()
Description copied from interface: SassListItem
Returns a string representation of this item with surrounding quotation marks of the same type (" or ') removed. Quotation marks are only removed from a single item or a list containing a single element and only one pair of quotation marks is removed.

Specified by:
unquotedString in interface SassListItem
Returns:
An unquoted string representation of this item.

getContainedValue

public LexicalUnitImpl getContainedValue()
Specified by:
getContainedValue in interface SassListItem

isWhitespace

public static boolean isWhitespace(SassListItem unit)


Copyright © 2013–2014 Vaadin. All rights reserved.