Class ResolveCustomFunctionNodesForChunks<T>

All Implemented Interfaces:
AtRuleHandler, CssCompilerPass, CssTreeVisitor

public class ResolveCustomFunctionNodesForChunks<T> extends ResolveCustomFunctionNodes
This compiler pass evaluates CssCustomFunctionNode instances only when they have no references as arguments. Otherwise, it creates a new definition for the function call even if it's already a definition. At the end, the main tree is free of function calls; all the new definitions are collected in a map of ConstantDefinitions per chunk; there are no nested calls.
  • Field Details

    • DEF_PREFIX

      public static final String DEF_PREFIX
      The prefix for definitions of calls with references
      See Also:
  • Constructor Details

    • ResolveCustomFunctionNodesForChunks

      public ResolveCustomFunctionNodesForChunks(MutatingVisitController visitController, ErrorManager errorManager, Map<String,GssFunction> functionMap, boolean allowUnknownFunctions, Set<String> allowedNonStandardFunctions, com.google.common.base.Function<T,String> nextUniqueSuffix)
      Constructs the pass.
      Parameters:
      visitController - the visit controller
      errorManager - the error manager
      functionMap - the map from function names to resolve to GSS functions
      allowUnknownFunctions - whether to allow unknown function calls, leaving them as is, instead of reporting an error
      nextUniqueSuffix - a function from a chunk to a globally unique suffix
  • Method Details

    • evaluateFunction

      protected List<CssValueNode> evaluateFunction(CssCustomFunctionNode node, GssFunction function, List<CssValueNode> arguments, ErrorManager errorManager) throws GssFunctionException
      Description copied from class: ResolveCustomFunctionNodes
      Evaluates the given function node.

      Subclasses may sublcass this method to change the evaluation process in some circumstances.

      Overrides:
      evaluateFunction in class ResolveCustomFunctionNodes
      Parameters:
      node - the function node to evaluate
      function - the GSS function matching this node
      arguments - the arguments of this node
      errorManager - the error manager passed into the GSS function call
      Returns:
      the result of the evaluation as a list of value nodes
      Throws:
      GssFunctionException - if the function call is invalid
    • getConstantDefinitions

      public Map<T,ConstantDefinitions> getConstantDefinitions()
      Gets the constant definitions for the replaced calls with references. Chunks which have no such calls are not in the map.
      Returns:
      A map of constant definitions per chunk