Class SearchTerminals<T extends JobParameters>

All Implemented Interfaces:
Activatable, ActivatableLifecycleUser<T>, LifecycleUser<T>

public class SearchTerminals<T extends JobParameters> extends ConfigurableTransformation<T>
This phase finds targets in specified target token types (usually identifiers) and triggers their handlers. The behavior of the targets can be customized with the various available core targets. By default, an exact string match of the text in the terminal node and the needle search string is required. However, this behavior can be configured. If something other than terminals should be searched, simply extend the walk phase yourself and do something when it visits the parse context of interest. (meaning without using this class as it's specifically for visiting terminals)
  • Field Details

    • IDENTIFIER

      public static final int IDENTIFIER
      The identifier token type.
      See Also:
    • ANY_TYPE

      public static final int ANY_TYPE
      The token type that matches any terminal token.
      See Also:
    • targetsDirect

      protected Collection<HandlerTarget<T extends JobParameters>> targetsDirect
      The defalt collection of targets that is added onto when adding targets individually. This field is not used if the getter method or the configuration property is overwritten.
  • Constructor Details

    • SearchTerminals

      public SearchTerminals()
  • Method Details

    • findNeedle

      protected boolean findNeedle(String content, HandlerTarget<T> target)
      Checks if the given content contains a needle. This should be overwritten if the matching should be done differently, like using regex or case-insensitive matching.
      Parameters:
      content - The content to search in
      target - The target being searched for
      Returns:
      If the target was found in the content
    • addTarget

      public SearchTerminals<T> addTarget(HandlerTarget<T> target)
      Adds a target for processing.
      Parameters:
      target - The target to add to the collection of targets
      Returns:
      This object
    • addReplacement

      public SearchTerminals<T> addReplacement(String needle, String newContent, Function<io.github.douira.glsl_transformer.GLSLParser,ExtendedContext> parseMethod)
      Adds a replacement target that replaces matching terminal nodes with new nodes parsed from the given string using a specified parser method.
      Parameters:
      needle - The needle (search string)
      newContent - The new content to parse into a node
      parseMethod - The parser method to create the new node with
      Returns:
      This object
    • addReplacementExpression

      public SearchTerminals<T> addReplacementExpression(String needle, String expressionContent)
      Adds a replacement target that replaces matching terminal nodes with new expression nodes parsed from the given string.
      Parameters:
      needle - The needle (search string)
      expressionContent - The new content to parse into an expression
      Returns:
      This object
    • addReplacementTerminal

      public SearchTerminals<T> addReplacementTerminal(String needle, String terminalContent)
      Adds a replacement target that replaces matching terminal nodes with new unparsed string nodes.
      Parameters:
      needle - The needle (search string)
      terminalContent - The new terminal content to insert as a string node
      Returns:
      This object
    • getTerminalTokenType

      protected int getTerminalTokenType()
      Gets the value of a configuration property. This method should not be called by subclasses, only implemented in case a custom value generation is needed.
      Returns:
      The configuration property value
    • getRequireFullMatch

      protected boolean getRequireFullMatch()
      Gets the value of a configuration property. This method should not be called by subclasses, only implemented in case a custom value generation is needed.
      Returns:
      The configuration property value
    • getTargets

      protected Collection<HandlerTarget<T>> getTargets()
      Gets the value of a configuration property. This method should not be called by subclasses, only implemented in case a custom value generation is needed.
      Returns:
      The configuration property value
    • terminalTokenType

      public SearchTerminals<T> terminalTokenType(int terminalTokenType)
      Sets the terminal token type to match the target's needles against. The available tokens are static int fields on GLSLLexer.
      Parameters:
      terminalTokenType - The terminal token type to match targets on
      Returns:
      This object
    • requireFullMatch

      public SearchTerminals<T> requireFullMatch(boolean requireFullMatch)
      Sets if the search should be done exactly or also larger strings that contain the needle are allowed. True by default.
      Parameters:
      requireFullMatch - If the whole token must match the target's needle
      Returns:
      This object
    • targets

      public SearchTerminals<T> targets(Collection<HandlerTarget<T>> targets)
      Sets the collection of targets to act on.
      Parameters:
      targets - The targets to act on
      Returns:
      This object
    • singleTarget

      public SearchTerminals<T> singleTarget(HandlerTarget<T> target)
      Sets the single target to act on. No other targets will be considered.
      Parameters:
      target - The target to act on
      Returns:
      This object
    • terminalTokenType

      public SearchTerminals<T> terminalTokenType(Supplier<Integer> terminalTokenType)
      Sets the supplier for a configuration property.
      Parameters:
      terminalTokenType - The value supplier
      Returns:
      This object
    • requireFullMatch

      public SearchTerminals<T> requireFullMatch(Supplier<Boolean> requireFullMatch)
      Sets the supplier for a configuration property.
      Parameters:
      requireFullMatch - The value supplier
      Returns:
      This object
    • targets

      public SearchTerminals<T> targets(Supplier<Collection<HandlerTarget<T>>> targets)
      Sets the supplier for a configuration property.
      Parameters:
      targets - The value supplier
      Returns:
      This object
    • terminalTokenType

      public SearchTerminals<T> terminalTokenType(CachePolicy newPolicy)
      Changes the cache policy of a configuration property.
      Parameters:
      newPolicy - The new cache policy
      Returns:
      This object
    • requireFullMatch

      public SearchTerminals<T> requireFullMatch(CachePolicy newPolicy)
      Changes the cache policy of a configuration property.
      Parameters:
      newPolicy - The new cache policy
      Returns:
      This object
    • targets

      public SearchTerminals<T> targets(CachePolicy newPolicy)
      Changes the cache policy of a configuration property.
      Parameters:
      newPolicy - The new cache policy
      Returns:
      This object
    • terminalTokenType

      protected final int terminalTokenType()
      Returns the proper value of a configuration property.
      Returns:
      The configuration property value
    • requireFullMatch

      protected final boolean requireFullMatch()
      Returns the proper value of a configuration property.
      Returns:
      The configuration property value
    • targets

      protected final Collection<HandlerTarget<T>> targets()
      Returns the proper value of a configuration property.
      Returns:
      The configuration property value