Class SearchTerminals<T extends JobParameters>
java.lang.Object
io.github.douira.glsl_transformer.transform.LifecycleUserImpl<T>
io.github.douira.glsl_transformer.transform.Transformation<T>
io.github.douira.glsl_transformer.core.ConfigurableTransformation<T>
io.github.douira.glsl_transformer.core.SearchTerminals<T>
- All Implemented Interfaces:
Activatable,ActivatableLifecycleUser<T>,LifecycleUser<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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe token type that matches any terminal token.static final intThe identifier token type.protected Collection<HandlerTarget<T>>The defalt collection of targets that is added onto when adding targets individually. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddReplacement(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.addReplacementExpression(String needle, String expressionContent) Adds a replacement target that replaces matching terminal nodes with new expression nodes parsed from the given string.addReplacementTerminal(String needle, String terminalContent) Adds a replacement target that replaces matching terminal nodes with new unparsed string nodes.addTarget(HandlerTarget<T> target) Adds a target for processing.protected booleanfindNeedle(String content, HandlerTarget<T> target) Checks if the given content contains a needle.protected booleanGets the value of a configuration property.protected Collection<HandlerTarget<T>>Gets the value of a configuration property.protected intGets the value of a configuration property.protected final booleanReturns the proper value of a configuration property.requireFullMatch(boolean requireFullMatch) Sets if the search should be done exactly or also larger strings that contain the needle are allowed.requireFullMatch(CachePolicy newPolicy) Changes the cache policy of a configuration property.requireFullMatch(Supplier<Boolean> requireFullMatch) Sets the supplier for a configuration property.singleTarget(HandlerTarget<T> target) Sets the single target to act on.protected final Collection<HandlerTarget<T>>targets()Returns the proper value of a configuration property.targets(CachePolicy newPolicy) Changes the cache policy of a configuration property.targets(Collection<HandlerTarget<T>> targets) Sets the collection of targets to act on.targets(Supplier<Collection<HandlerTarget<T>>> targets) Sets the supplier for a configuration property.protected final intReturns the proper value of a configuration property.terminalTokenType(int terminalTokenType) Sets the terminal token type to match the target's needles against.terminalTokenType(CachePolicy newPolicy) Changes the cache policy of a configuration property.terminalTokenType(Supplier<Integer> terminalTokenType) Sets the supplier for a configuration property.Methods inherited from class io.github.douira.glsl_transformer.core.ConfigurableTransformation
addSupplier, cachingSupplier, once, removeSupplier, swapPolicy, swapSupplier, swapSupplier, triggerJobInternal, valueMethods inherited from class io.github.douira.glsl_transformer.transform.Transformation
addDependency, addDependent, addEndDependent, addRootDependency, appendDependent, chainConcurrentDependency, chainConcurrentDependent, chainConcurrentSibling, chainDependency, chainDependent, prependDependency, repeat, repeatParallel, repeatSequential, setupGraphMethods inherited from class io.github.douira.glsl_transformer.transform.LifecycleUserImpl
activation, getPlanner, isActive, isInitialized, setInitialized, setPlannerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.github.douira.glsl_transformer.transform.LifecycleUser
getJobParameters, getLexer, getParser, getRootNode, init, initOnce, resetState
-
Field Details
-
IDENTIFIER
public static final int IDENTIFIERThe identifier token type.- See Also:
-
ANY_TYPE
public static final int ANY_TYPEThe token type that matches any terminal token.- See Also:
-
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
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 intarget- The target being searched for- Returns:
- If the target was found in the content
-
addTarget
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 nodeparseMethod- The parser method to create the new node with- Returns:
- This object
-
addReplacementExpression
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
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
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
Sets the terminal token type to match the target's needles against. The available tokens are staticintfields onGLSLLexer.- Parameters:
terminalTokenType- The terminal token type to match targets on- Returns:
- This object
-
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
Sets the collection of targets to act on.- Parameters:
targets- The targets to act on- Returns:
- This object
-
singleTarget
Sets the single target to act on. No other targets will be considered.- Parameters:
target- The target to act on- Returns:
- This object
-
terminalTokenType
Sets the supplier for a configuration property.- Parameters:
terminalTokenType- The value supplier- Returns:
- This object
-
requireFullMatch
Sets the supplier for a configuration property.- Parameters:
requireFullMatch- The value supplier- Returns:
- This object
-
targets
Sets the supplier for a configuration property.- Parameters:
targets- The value supplier- Returns:
- This object
-
terminalTokenType
Changes the cache policy of a configuration property.- Parameters:
newPolicy- The new cache policy- Returns:
- This object
-
requireFullMatch
Changes the cache policy of a configuration property.- Parameters:
newPolicy- The new cache policy- Returns:
- This object
-
targets
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
Returns the proper value of a configuration property.- Returns:
- The configuration property value
-