Class SearchTerminals<T>

java.lang.Object
io.github.douira.glsl_transformer.GLSLParserBaseListener
All Implemented Interfaces:
io.github.douira.glsl_transformer.GLSLParserListener, CollectorChild<T>, ParseTreeListener

public class SearchTerminals<T> extends WalkPhase<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 classes. 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.
  • Nested Class Summary

    Nested classes/interfaces inherited from class io.github.douira.glsl_transformer.transform.TransformationPhase

    TransformationPhase.InjectionPoint
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    A constant for easy access to the identifier token type.
    protected final Collection<HandlerTarget<T>>
    The list of targets to process for each targeted context.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new empty identifier search with a hash set.
    SearchTerminals(int terminalTokenType, HandlerTarget<T> target)
    Creates a new target search phase with only a single target.
    SearchTerminals(int terminalTokenType, Collection<HandlerTarget<T>> targets)
    Creates a new target search phase with the given targets.
    Creates a new identifier search phase with only a single target.
    Creates a new identifier search phase with with given targets.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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.
    void
    addReplacementExpression(String needle, String expressionContent)
    Adds a replacement target that replaces matching terminal nodes with new expression nodes parsed from the given string.
    void
    addReplacementTerminal(String needle, String terminalContent)
    Adds a replacement target that replaces matching terminal nodes with new unparsed string nodes.
    void
    Adds a target for processing.
    void
    Makes this search phase not use exact matching.
    protected boolean
    findNeedle(String content, HandlerTarget<T> target)
    Checks if the given content contains a needle.
    void
    setTerminalTokenType(int terminalTokenType)
    Sets the terminal token type.
    void
     
    static <T> SearchTerminals<T>
    withReplacement(String needle, String newContent, Function<io.github.douira.glsl_transformer.GLSLParser,ExtendedContext> parseMethod)
    Creates a new identifier replacement transformation with a replacement target that replaces matching terminal nodes with new nodes parsed from the given string using a specified parser method.
    static <T> SearchTerminals<T>
    withReplacementExpression(String needle, String expressionContent)
    Creates a new identifier replacement transformation with a replacement target that replaces matching terminal nodes with new expression nodes parsed from the given string.
    static <T> SearchTerminals<T>
    withReplacementTerminal(String needle, String terminalContent)
    Creates a new identifier replacement transformation with a replacement target that replaces matching terminal nodes with new unparsed string nodes.

    Methods inherited from class io.github.douira.glsl_transformer.transform.WalkPhase

    afterWalk, beforeWalk, checkBeforeWalk, isActiveAfterWalk, isActiveAtWalk, isActiveBeforeWalk, runAfterWalk

    Methods inherited from class io.github.douira.glsl_transformer.GLSLParserBaseListener

    enterAdditiveExpression, enterAndExpression, enterArraySpecifier, enterAssignmentExpression, enterAssignmentOperator, enterAttribute, enterBuiltinTypeSpecifierFixed, enterBuiltinTypeSpecifierParseable, enterCallParameterList, enterCaseLabel, enterCompoundStatement, enterCondition, enterConditionalExpression, enterConstantExpression, enterDeclaration, enterDeclarationMember, enterDeclarationMemberList, enterDeclarationStatement, enterDemoteStatement, enterDoWhileStatement, enterEmptyStatement, enterEqualityExpression, enterEveryRule, enterExclusiveOrExpression, enterExpression, enterExpressionStatement, enterExtensionState, enterExtensionStatement, enterExternalDeclaration, enterForStatement, enterFullySpecifiedType, enterFunctionCall, enterFunctionDefinition, enterFunctionHeader, enterFunctionIdentifier, enterFunctionParameterList, enterFunctionPrototype, enterInclusiveOrExpression, enterInitDeclaratorList, enterInitializer, enterInterpolationQualifier, enterInvariantQualifier, enterJumpStatement, enterLayoutDefaults, enterLayoutModes, enterLayoutQualifier, enterLayoutQualifierId, enterLogicalAndExpression, enterLogicalOrExpression, enterLogicalXorExpression, enterMethodCall, enterMultiplicativeExpression, enterParameterDeclaration, enterParameterDeclarator, enterPostfixExpression, enterPragmaStatement, enterPreciseQualifier, enterPrecisionQualifier, enterPrimaryExpression, enterRelationalExpression, enterSelectionStatement, enterShiftExpression, enterSimpleStatement, enterSingleAttribute, enterStatement, enterStorageQualifier, enterStructDeclaration, enterStructDeclarationList, enterStructDeclarator, enterStructDeclaratorList, enterStructSpecifier, enterSwitchStatement, enterTranslationUnit, enterTypeNameList, enterTypeQualifier, enterTypeSpecifier, enterTypeSpecifierNonarray, enterUnaryExpression, enterUnaryOperator, enterVariableIdentifier, enterVersionStatement, enterWhileStatement, exitAdditiveExpression, exitAndExpression, exitArraySpecifier, exitAssignmentExpression, exitAssignmentOperator, exitAttribute, exitBuiltinTypeSpecifierFixed, exitBuiltinTypeSpecifierParseable, exitCallParameterList, exitCaseLabel, exitCompoundStatement, exitCondition, exitConditionalExpression, exitConstantExpression, exitDeclaration, exitDeclarationMember, exitDeclarationMemberList, exitDeclarationStatement, exitDemoteStatement, exitDoWhileStatement, exitEmptyStatement, exitEqualityExpression, exitEveryRule, exitExclusiveOrExpression, exitExpression, exitExpressionStatement, exitExtensionState, exitExtensionStatement, exitExternalDeclaration, exitForStatement, exitFullySpecifiedType, exitFunctionCall, exitFunctionDefinition, exitFunctionHeader, exitFunctionIdentifier, exitFunctionParameterList, exitFunctionPrototype, exitInclusiveOrExpression, exitInitDeclaratorList, exitInitializer, exitInterpolationQualifier, exitInvariantQualifier, exitJumpStatement, exitLayoutDefaults, exitLayoutModes, exitLayoutQualifier, exitLayoutQualifierId, exitLogicalAndExpression, exitLogicalOrExpression, exitLogicalXorExpression, exitMethodCall, exitMultiplicativeExpression, exitParameterDeclaration, exitParameterDeclarator, exitPostfixExpression, exitPragmaStatement, exitPreciseQualifier, exitPrecisionQualifier, exitPrimaryExpression, exitRelationalExpression, exitSelectionStatement, exitShiftExpression, exitSimpleStatement, exitSingleAttribute, exitStatement, exitStorageQualifier, exitStructDeclaration, exitStructDeclarationList, exitStructDeclarator, exitStructDeclaratorList, exitStructSpecifier, exitSwitchStatement, exitTranslationUnit, exitTypeNameList, exitTypeQualifier, exitTypeSpecifier, exitTypeSpecifierNonarray, exitUnaryExpression, exitUnaryOperator, exitVariableIdentifier, exitVersionStatement, exitWhileStatement, visitErrorNode

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.github.douira.glsl_transformer.transform.CollectorChild

    getJobParameters, getLexer, getParser, getRootNode
  • Field Details

    • IDENTIFIER

      public static final int IDENTIFIER
      A constant for easy access to the identifier token type.
      See Also:
    • targets

      protected final Collection<HandlerTarget<T>> targets
      The list of targets to process for each targeted context.
  • Constructor Details

    • SearchTerminals

      public SearchTerminals(int terminalTokenType, Collection<HandlerTarget<T>> targets)
      Creates a new target search phase with the given targets.
      Parameters:
      terminalTokenType - The type of the tokens to search in
      targets - The targets to search for
    • SearchTerminals

      public SearchTerminals(int terminalTokenType, HandlerTarget<T> target)
      Creates a new target search phase with only a single target.
      Parameters:
      terminalTokenType - The type of the token to search in
      target - The target to search for
    • SearchTerminals

      public SearchTerminals(Collection<HandlerTarget<T>> targets)
      Creates a new identifier search phase with with given targets.
      Parameters:
      targets - The targets to search for in identifiers
    • SearchTerminals

      public SearchTerminals(HandlerTarget<T> target)
      Creates a new identifier search phase with only a single target.
      Parameters:
      target - The target to search for in identifiers
    • SearchTerminals

      public SearchTerminals()
      Creates a new empty identifier search with a hash set.
  • Method Details

    • visitTerminal

      public void visitTerminal(TerminalNode node)
      Specified by:
      visitTerminal in interface ParseTreeListener
      Overrides:
      visitTerminal in class io.github.douira.glsl_transformer.GLSLParserBaseListener
    • allowInexactMatches

      public void allowInexactMatches()
      Makes this search phase not use exact matching.
    • setTerminalTokenType

      public void setTerminalTokenType(int terminalTokenType)
      Sets the terminal token type. Use IDENTIFIER to search for identifiers.
      Parameters:
      terminalTokenType - The terminal token type
    • addTarget

      public void addTarget(HandlerTarget<T> target)
      Adds a target for processing.
      Parameters:
      target - The target to add to the collection of targets
    • 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
    • addReplacement

      public void 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
    • addReplacementExpression

      public void 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
    • addReplacementTerminal

      public void 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
    • withReplacement

      public static <T> SearchTerminals<T> withReplacement(String needle, String newContent, Function<io.github.douira.glsl_transformer.GLSLParser,ExtendedContext> parseMethod)
      Creates a new identifier replacement transformation with a replacement target that replaces matching terminal nodes with new nodes parsed from the given string using a specified parser method.
      Type Parameters:
      T - The job parameter type
      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:
      The configured identifier replacement transformation
      See Also:
    • withReplacementExpression

      public static <T> SearchTerminals<T> withReplacementExpression(String needle, String expressionContent)
      Creates a new identifier replacement transformation with a replacement target that replaces matching terminal nodes with new expression nodes parsed from the given string.
      Type Parameters:
      T - The job parameter type
      Parameters:
      needle - The needle (search string)
      expressionContent - The new content to parse into an expression
      Returns:
      The configured identifier replacement transformation
    • withReplacementTerminal

      public static <T> SearchTerminals<T> withReplacementTerminal(String needle, String terminalContent)
      Creates a new identifier replacement transformation with a replacement target that replaces matching terminal nodes with new unparsed string nodes.
      Type Parameters:
      T - The job parameter type
      Parameters:
      needle - The needle (search string)
      terminalContent - The new terminal content to insert as a string node
      Returns:
      The configured identifier replacement transformation