Class SearchTerminalsImpl<T extends JobParameters>

java.lang.Object
io.github.douira.glsl_transformer.GLSLParserBaseListener
All Implemented Interfaces:
io.github.douira.glsl_transformer.GLSLParserListener, LifecycleUser<T>, PartialParseTreeListener, ParseTreeListener
Direct Known Subclasses:
SearchTerminalsDynamic

public class SearchTerminalsImpl<T extends JobParameters> extends SearchTerminals<T>
This implementation of the search terminals transformation phase uses static fields to return the targets and the terminal token type.
  • 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
    The list of targets to process for each targeted context.

    Fields inherited from class io.github.douira.glsl_transformer.core.SearchTerminals

    ANY_TYPE, IDENTIFIER
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new empty identifier search with a hash set.
    SearchTerminalsImpl(int terminalTokenType)
    Creates a new target search phase with only the terminal token type given.
    SearchTerminalsImpl(int terminalTokenType, HandlerTarget<T> target)
    Creates a new target search phase with only a single target.
    SearchTerminalsImpl(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.
    Returns the collection of targets to search for.
    protected int
    Returns the terminal token type to match the target's needles against.
    void
    setTerminalTokenType(int terminalTokenType)
    Sets the terminal token type.
    static <T extends JobParameters>
    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 extends JobParameters>
    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 extends JobParameters>
    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.core.SearchTerminals

    allowInexactMatches, findNeedle, visitTerminal

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

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

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

    enterAdditiveExpression, enterArrayAccessExpression, enterArraySpecifier, enterArraySpecifierSegment, enterAssignmentExpression, enterAtomicUnitType, enterAttribute, enterBitwiseAndExpression, enterBitwiseExclusiveOrExpression, enterBitwiseInclusiveOrExpression, enterBooleanType, enterBooleanVectorType, enterBreakStatement, enterBuiltinType, enterCallParameterList, enterCompoundStatement, enterConditionalExpression, enterContinueStatement, enterDeclarationMember, enterDeclarationStatement, enterDefaultCaseLabel, enterDemoteStatement, enterDiscardStatement, enterDoWhileStatement, enterEmptyDeclaration, enterEmptyStatement, enterEqualityExpression, enterEveryRule, enterExpressionStatement, enterExtensionStatement, enterExternalDeclaration, enterFloatMatrixType, enterFloatType, enterFloatVectorType, enterForStatement, enterFullySpecifiedType, enterFunctionCall, enterFunctionCallExpression, enterFunctionDeclaration, enterFunctionDefinition, enterFunctionHeader, enterFunctionIdentifier, enterFunctionParameterList, enterFunctionPrototype, enterGroupingExpression, enterImageType, enterInitDeclaratorList, enterInitializer, enterIntegerType, enterIntegerVectorType, enterInterfaceBlockDeclaration, enterInterpolationQualifier, enterInvariantQualifier, enterIterationCondition, enterLayoutDefaults, enterLayoutQualifier, enterLiteralExpression, enterLogicalAndExpression, enterLogicalExclusiveOrExpression, enterLogicalInclusiveOrExpression, enterMemberAccessExpression, enterMethodCall, enterMethodCallExpression, enterMultiplicativeExpression, enterNamedLayoutQualifier, enterParameterDeclaration, enterParameterDeclarator, enterPostfixExpression, enterPragmaStatement, enterPreciseQualifier, enterPrecisionDeclaration, enterPrecisionQualifier, enterPrefixExpression, enterReferencedType, enterReferenceExpression, enterRelationalExpression, enterReturnStatement, enterSamplerType, enterSelectionStatement, enterSequenceExpression, enterSharedLayoutQualifier, enterShiftExpression, enterSingleAttribute, enterStatement, enterStorageQualifier, enterStructBody, enterStructDeclarator, enterStructMember, enterStructSpecifier, enterStructSpecifierType, enterSwitchStatement, enterTranslationUnit, enterTypeAndInitDeclaration, enterTypeNameList, enterTypeQualifier, enterTypeSpecifier, enterValuedCaseLabel, enterVariableDeclaration, enterVariableIdentifier, enterVersionStatement, enterVoidType, enterWhileStatement, exitAdditiveExpression, exitArrayAccessExpression, exitArraySpecifier, exitArraySpecifierSegment, exitAssignmentExpression, exitAtomicUnitType, exitAttribute, exitBitwiseAndExpression, exitBitwiseExclusiveOrExpression, exitBitwiseInclusiveOrExpression, exitBooleanType, exitBooleanVectorType, exitBreakStatement, exitBuiltinType, exitCallParameterList, exitCompoundStatement, exitConditionalExpression, exitContinueStatement, exitDeclarationMember, exitDeclarationStatement, exitDefaultCaseLabel, exitDemoteStatement, exitDiscardStatement, exitDoWhileStatement, exitEmptyDeclaration, exitEmptyStatement, exitEqualityExpression, exitEveryRule, exitExpressionStatement, exitExtensionStatement, exitExternalDeclaration, exitFloatMatrixType, exitFloatType, exitFloatVectorType, exitForStatement, exitFullySpecifiedType, exitFunctionCall, exitFunctionCallExpression, exitFunctionDeclaration, exitFunctionDefinition, exitFunctionHeader, exitFunctionIdentifier, exitFunctionParameterList, exitFunctionPrototype, exitGroupingExpression, exitImageType, exitInitDeclaratorList, exitInitializer, exitIntegerType, exitIntegerVectorType, exitInterfaceBlockDeclaration, exitInterpolationQualifier, exitInvariantQualifier, exitIterationCondition, exitLayoutDefaults, exitLayoutQualifier, exitLiteralExpression, exitLogicalAndExpression, exitLogicalExclusiveOrExpression, exitLogicalInclusiveOrExpression, exitMemberAccessExpression, exitMethodCall, exitMethodCallExpression, exitMultiplicativeExpression, exitNamedLayoutQualifier, exitParameterDeclaration, exitParameterDeclarator, exitPostfixExpression, exitPragmaStatement, exitPreciseQualifier, exitPrecisionDeclaration, exitPrecisionQualifier, exitPrefixExpression, exitReferencedType, exitReferenceExpression, exitRelationalExpression, exitReturnStatement, exitSamplerType, exitSelectionStatement, exitSequenceExpression, exitSharedLayoutQualifier, exitShiftExpression, exitSingleAttribute, exitStatement, exitStorageQualifier, exitStructBody, exitStructDeclarator, exitStructMember, exitStructSpecifier, exitStructSpecifierType, exitSwitchStatement, exitTranslationUnit, exitTypeAndInitDeclaration, exitTypeNameList, exitTypeQualifier, exitTypeSpecifier, exitValuedCaseLabel, exitVariableDeclaration, exitVariableIdentifier, exitVersionStatement, exitVoidType, 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.LifecycleUser

    getJobParameters, getLexer, getParser, getRootNode, init, initOnce, resetState

    Methods inherited from interface org.antlr.v4.runtime.tree.ParseTreeListener

    enterEveryRule, exitEveryRule, visitErrorNode

    Methods inherited from interface io.github.douira.glsl_transformer.traversal.PartialParseTreeListener

    isDeepEnough, isFinished
  • Field Details

  • Constructor Details

    • SearchTerminalsImpl

      public SearchTerminalsImpl(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
    • SearchTerminalsImpl

      public SearchTerminalsImpl(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
    • SearchTerminalsImpl

      public SearchTerminalsImpl(int terminalTokenType)
      Creates a new target search phase with only the terminal token type given.
      Parameters:
      terminalTokenType - The type of the token to search in
    • SearchTerminalsImpl

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

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

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

    • getTargets

      public Collection<HandlerTarget<T>> getTargets()
      Description copied from class: SearchTerminals
      Returns the collection of targets to search for. This method should be efficient as it's called for every visited terminal node.
      Specified by:
      getTargets in class SearchTerminals<T extends JobParameters>
      Returns:
      The targets to search for
    • getTerminalTokenType

      protected int getTerminalTokenType()
      Description copied from class: SearchTerminals
      Returns the terminal token type to match the target's needles against. The available tokens are static int fields on GLSLLexer.
      Overrides:
      getTerminalTokenType in class SearchTerminals<T extends JobParameters>
      Returns:
      The terminal token type
    • setTerminalTokenType

      public void setTerminalTokenType(int terminalTokenType)
      Sets the terminal token type. Use SearchTerminals.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
    • 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 extends JobParameters> 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 extends JobParameters> 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 extends JobParameters> 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