com.vaadin.sass.internal.parser
Class Interpolation

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

public class Interpolation
extends Object
implements SassListItem, Serializable

Interpolation represents a single instance of interpolation. The string representation of an Interpolation object is "#{}" (without quotes) where is the textual representation of the expression of the interpolation. An Interpolation object is evaluated by calling replaceInterpolation(). The result of the evaluation is the value of the expression, a SassListItem. If the result is a single textual value with quotation marks, the quotation marks are removed from the result. Variables should be replaced with their values and functions and expressions evaluated before calling replaceInterpolation().

Author:
Vaadin
See Also:
Serialized Form

Constructor Summary
Interpolation(SassListItem expression, int line, int column)
           
 
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.
 boolean containsVariable()
          Checks whether this item contains a variable.
 boolean equals(Object o)
          Returns true if this and o are equal interpolation objects.
 Interpolation evaluateFunctionsAndExpressions(ScssContext context, boolean evaluateArithmetics)
          Evaluates the arithmetic expressions and functions of this item without modifying this item.
 int getColumnNumber()
           
 LexicalUnitImpl getContainedValue()
           
 int getLineNumber()
           
 int hashCode()
           
 String printState()
          Returns a string representation of this item.
 SassListItem replaceInterpolation()
          Returns the value of the expression, with quotation marks removed if the value is a single textual value.
 Interpolation replaceVariables(ScssContext context)
          Returns a new item that is otherwise equal to this one but all occurrences of variables have been replaced by the values in the current variable scope.
 String toString()
           
 String unquotedString()
          Returns a string representation of this item with surrounding quotation marks of the same type (" or ') removed.
 Interpolation updateUrl(String prefix)
          Returns a new item that is obtained from this by updating all url's 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, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Interpolation

public Interpolation(SassListItem expression,
                     int line,
                     int column)
Method Detail

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

evaluateFunctionsAndExpressions

public Interpolation evaluateFunctionsAndExpressions(ScssContext context,
                                                     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:
context - the compilation context in which to evaluate functions, variables etc.
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 Interpolation replaceVariables(ScssContext context)
Description copied from interface: SassListItem
Returns a new item that is otherwise equal to this one but all occurrences of variables have been replaced by the values in the current variable scope. Does not modify this item.

Specified by:
replaceVariables in interface SassListItem
Parameters:
context - the compilation context in which to evaluate functions, variables etc.
Returns:
A SassListItem where all occurrences of variables have been replaced by their values.

updateUrl

public Interpolation updateUrl(String prefix)
Description copied from interface: SassListItem
Returns a new item that is obtained from this by updating all url's by, e.g., adding the prefix to an url not starting with slash "/" and not containing the symbol ":". Does not modify this item.

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

replaceInterpolation

public SassListItem replaceInterpolation()
Returns the value of the expression, with quotation marks removed if the value is a single textual value. Before this method the methods replaceVariables and evaluateFunctionsAndExpressions should be called to determine the evaluated value of the expression.

Returns:
The value of the evaluated expression, a SassListItem.

containsVariable

public boolean containsVariable()
Description copied from interface: SassListItem
Checks whether this item contains a variable. This method is used to avoid the evaluation of expressions when unset variables remain. That situation can happen as a result of calling replaceVariables for the children of a @mixin node. The replaceVariables method in MixinNodeHandler then replaces the variables corresponding to the parameter list of the @mixin but other variables remain unset until the node is traversed again. The evaluation of interpolation and expressions should then be deferred until all variables of the SassListItem have a value.

Specified by:
containsVariable in interface SassListItem
Returns:
Whether this expression contains variables.

equals

public boolean equals(Object o)
Returns true if this and o are equal interpolation objects. Two interpolation objects are considered to be equal if their expressions are equal. For comparing the results of the interpolation instead of the expressions, the objects should be expanded to SassListitems using replaceInterpolation() after replacing all variables occurring in the interpolation objects.

Overrides:
equals in class Object
Returns:

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 2013–2015 Vaadin. All rights reserved.