com.vaadin.sass.internal.parser.function
Class AbstractFunctionGenerator

java.lang.Object
  extended by com.vaadin.sass.internal.parser.function.AbstractFunctionGenerator
All Implemented Interfaces:
SCSSFunctionGenerator
Direct Known Subclasses:
AbstractSingleParameterFunctionGenerator, AdjustColorFunctionGenerator, AlphaFunctionGenerator, ColorComponentFunctionGenerator, DarkenFunctionGenerator, LightenFunctionGenerator, ListFunctionGenerator, ListIndexFunctionGenerator, ListLengthFunctionGenerator, ListNthFunctionGenerator, MinMaxFunctionGenerator, MixFunctionGenerator, RectFunctionGenerator, RGBFunctionGenerator, SaturationModificationFunctionGenerator, TransparencyModificationFunctionGenerator, TypeOfFunctionGenerator

public abstract class AbstractFunctionGenerator
extends Object
implements SCSSFunctionGenerator

AbstractFunctionGenerator is an abstract base class for implementing built-in Sass functions. It is assumed that all functions implemented by a subclass of AbstractFunctionGenerator have the same formal argument list, i.e. they have the same number of arguments and the arguments of the different functions have the same names.

Author:
Vaadin

Constructor Summary
AbstractFunctionGenerator(FormalArgumentList arguments, String... functionNames)
           
 
Method Summary
protected  boolean checkForUnsetParameters()
          Returns true if this function should ensure that all parameters have been set.
 SassListItem compute(ScssContext context, LexicalUnitImpl function)
          Computes the value of the function.
protected abstract  SassListItem computeForArgumentList(LexicalUnitImpl function, FormalArgumentList actualArguments)
          Computes the value of the function with the given argument list.
protected static FormalArgumentList createArgumentList(String[] argumentNames, boolean hasVariableArguments)
          Creates a new FormalArgumentList with no default values, i.e.
protected static FormalArgumentList createArgumentList(String[] argumentNames, SassListItem[] defaultValues)
          Creates a new FormalArgumentList without variable arguments.
protected static FormalArgumentList createArgumentList(String[] argumentNames, SassListItem[] defaultValues, boolean hasVariableArguments)
          Creates a formal argument list with the given argument names and default values.
protected  FormalArgumentList getArguments()
           
 String[] getFunctionNames()
          Returns function names handled by this generator.
protected static SassListItem getParam(FormalArgumentList args, int index)
          Returns the value of the argument at the given index.
protected static SassListItem getParam(FormalArgumentList args, String name)
          Returns the value of the argument with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractFunctionGenerator

public AbstractFunctionGenerator(FormalArgumentList arguments,
                                 String... functionNames)
Method Detail

getFunctionNames

public String[] getFunctionNames()
Description copied from interface: SCSSFunctionGenerator
Returns function names handled by this generator. Default generator returns null and is used if there is no dedicated generator for given function.

Specified by:
getFunctionNames in interface SCSSFunctionGenerator
Returns:

getArguments

protected FormalArgumentList getArguments()

compute

public SassListItem compute(ScssContext context,
                            LexicalUnitImpl function)
Description copied from interface: SCSSFunctionGenerator
Computes the value of the function. The parameters should be evaluated before this method is called. Both the input and the output of the method should be separate from any chain of lexical units.

Specified by:
compute in interface SCSSFunctionGenerator
Parameters:
context - current compilation context
function - Function lexical unit to print its state
Returns:
SassListItem the value of the function

computeForArgumentList

protected abstract SassListItem computeForArgumentList(LexicalUnitImpl function,
                                                       FormalArgumentList actualArguments)
Computes the value of the function with the given argument list. This method is called by compute(), which also forms the parameter list actualArguments by replacing the formal arguments of the function with their actual values.

Parameters:
function - The function to be evaluated. The function object can be used to determine which function to evaluate when a function generator implements several Sass functions. It is also used to obtain line and column numbers for error messages.
actualArguments - The argument list of the function, obtained by replacing all formal arguments with the corresponding values of the actual argument list of the function.
Returns:
The value of the function.

checkForUnsetParameters

protected boolean checkForUnsetParameters()
Returns true if this function should ensure that all parameters have been set. This is the most common use case. The value false can be used for built-in functions that have optional parameters without a default value.

Returns:
whether this function requires that all its parameters have a value.

createArgumentList

protected static FormalArgumentList createArgumentList(String[] argumentNames,
                                                       SassListItem[] defaultValues,
                                                       boolean hasVariableArguments)
Creates a formal argument list with the given argument names and default values. The arrays argumentNames and defaultValues should have an equal number of elements.

Parameters:
argumentNames - The names of the arguments.
defaultValues - The default values of the arguments.
hasVariableArguments - True, if the function supports variable arguments, false otherwise.
Returns:
A FormalArgumentList.

createArgumentList

protected static FormalArgumentList createArgumentList(String[] argumentNames,
                                                       SassListItem[] defaultValues)
Creates a new FormalArgumentList without variable arguments.

Parameters:
argumentNames - The names of the arguments.
defaultValues - The default values of the arguments.
Returns:
A FormalArgumentList.

createArgumentList

protected static FormalArgumentList createArgumentList(String[] argumentNames,
                                                       boolean hasVariableArguments)
Creates a new FormalArgumentList with no default values, i.e. all default values are null.

Parameters:
argumentNames - The names of the arguments.
hasVariableArguments - True, if the function supports variable arguments, false otherwise.
Returns:
A FormalArgumentList.

getParam

protected static SassListItem getParam(FormalArgumentList args,
                                       String name)
Returns the value of the argument with the given name.

Parameters:
args - The argument list.
name - The name of the argument.
Returns:
The value of the argument whose name corresponds to the parameter name.

getParam

protected static SassListItem getParam(FormalArgumentList args,
                                       int index)
Returns the value of the argument at the given index.

Parameters:
args - The argument list.
index - The position of the argument in the argument list.
Returns:
The value of the argument at position index in the argument list args.


Copyright © 2013–2015 Vaadin. All rights reserved.