Class WrapIdentifier<T extends JobParameters>

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

public class WrapIdentifier<T extends JobParameters> extends ConfigurableTransformation<T>
The wrap identifier transformation wraps the usage of a certain identifier with new code by replacing its usage with a new expression and inserting code that takes care of handling the conversion from the new to the old value. It also checks that the wrapped value isn't already present in the code. This class uses a chaining configuration pattern. The class is constructed with an empty constructor and then configured by calling some configuration methods. Additionally, configuration values can be generated dynamically by overriding the getter methods.
  • Field Details

    • detectionResultsDirect

      protected Collection<String> detectionResultsDirect
      The current list of detection results to use if the getter method for the detection result configuration property is not set differently. Items are added to this list with the addDetectionResult(String) method.
    • externalDeclarationsDirect

      protected Collection<String> externalDeclarationsDirect
      The current list of injection external declarations to use if the getter method for the external declarations configuration property is not set differently. Items are added to this list with the addExternalDeclaration(String)
  • Constructor Details

    • WrapIdentifier

      public WrapIdentifier()
  • Method Details

    • setupGraph

      protected void setupGraph()
      Setup is done here so that it can be overridden in subclasses.
      Overrides:
      setupGraph in class Transformation<T extends JobParameters>
    • activation

      public WrapIdentifier<T> activation(Supplier<Boolean> activation)
      Overwrite to make type more specific
      Specified by:
      activation in interface Activatable
      Specified by:
      activation in interface ActivatableLifecycleUser<T extends JobParameters>
      Overrides:
      activation in class LifecycleUserImpl<T extends JobParameters>
      Parameters:
      activation - The activation supplier
      Returns:
      This object
    • addDetectionResult

      public void addDetectionResult(String detectionResult)
      Adds a detection result to the list of static detection result to use. This constitutes the default behavior of getDetectionResults().
      Parameters:
      detectionResult - The detection result to add
    • addExternalDeclaration

      public void addExternalDeclaration(String externalDeclaration)
      Adds an external declaration to the list of external declarations to use. This constitutes the default behavior of getInjectionExternalDeclarations().
      Parameters:
      externalDeclaration - The external declaration to add
    • getWrapResultDetector

      protected ActivatableLifecycleUser<T> getWrapResultDetector()
      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. This method can deal with a list of detection results that is longer than one item. It can even handle this list's contents or identity changing, but it doesn't handle the list getting longer and added items will be ignored. If the list gets shorter, the generated wrap throw targets will become no-ops but still exist.
      Returns:
      The configuration property value
    • getDetectionResults

      protected Collection<String> getDetectionResults()
      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
    • getParsedReplacement

      protected String getParsedReplacement()
      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
    • getParseMethod

      protected Function<io.github.douira.glsl_transformer.GLSLParser,​ExtendedContext> getParseMethod()
      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
    • getWrappingReplacer

      protected ActivatableLifecycleUser<T> getWrappingReplacer()
      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
    • getWrapHandlerTargets

      protected Collection<HandlerTarget<T>> getWrapHandlerTargets()
      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
    • getWrapTarget

      protected String getWrapTarget()
      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
    • getInjector

      protected ActivatableLifecycleUser<T> getInjector()
      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
    • getInjectionLocation

      protected InjectionPoint getInjectionLocation()
      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
    • getInjectionExternalDeclarations

      protected Collection<String> getInjectionExternalDeclarations()
      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
    • wrapResultDetector

      public WrapIdentifier<T> wrapResultDetector(ActivatableLifecycleUser<T> wrapResultDetector)
      Sets the detector that will be used to check if the detection result exists already. Generated from the detection result by default.
      Parameters:
      wrapResultDetector - The result detector
      Returns:
      This object
    • detectionResults

      public WrapIdentifier<T> detectionResults(Collection<String> detectionResults)
      Sets the result that will be present in the code after the wrapping. Generated from the parsed replacement by default. However, if a parsed replacement is used, the detection result should usually be set manually if the replacement isn't just a single identifier. If used without an explicit expression to insert, this must be an identifier since it's not parsed.
      Parameters:
      detectionResults - The detection results
      Returns:
      This object
    • detectionResult

      public WrapIdentifier<T> detectionResult(String detectionResult)
      Sets a single detection result. Other detection results will be ignored.
      Parameters:
      detectionResult - The detection result
      Returns:
      This object
      See Also:
      detectionResults(Collection)
    • parsedReplacement

      public WrapIdentifier<T> parsedReplacement(String parsedReplacement)
      Sets the parsed replacement that replaces the target. Has no default but is only used if a parser method is set.
      Parameters:
      parsedReplacement - The parsed replacement
      Returns:
      This object
    • parseMethod

      public WrapIdentifier<T> parseMethod(Function<io.github.douira.glsl_transformer.GLSLParser,​ExtendedContext> parseMethod)
      Sets the parser method that will be used to parse the wrap expression. Is the default expression parsing method by default.
      Parameters:
      parseMethod - The replacement parsing method
      Returns:
      This object
    • wrappingReplacer

      public WrapIdentifier<T> wrappingReplacer(ActivatableLifecycleUser<T> wrappingReplacer)
      Sets the replacer that will be used to replace the target with the wrap expression.
      Parameters:
      wrappingReplacer - The replacer
      Returns:
      This object
    • wrapHandlerTargets

      public WrapIdentifier<T> wrapHandlerTargets(Collection<HandlerTarget<T>> wrapHandlerTargets)
      Sets the handler target that does the replacement of the target. Generated from the wrap target by default.
      Parameters:
      wrapHandlerTargets - The replacement target handler
      Returns:
      This object
    • wrapTarget

      public WrapIdentifier<T> wrapTarget(String wrapTarget)
      Sets the target that will be replaced.
      Parameters:
      wrapTarget - The replacement target identifier
      Returns:
      This object
    • injector

      public WrapIdentifier<T> injector(ActivatableLifecycleUser<T> injector)
      Sets the injector that will be used to inject additional code after replacement is done. Generated from the injection location and the injection external declaration by default.
      Parameters:
      injector - The injector
      Returns:
      This object
    • injectionLocation

      public WrapIdentifier<T> injectionLocation(InjectionPoint injectionLocation)
      Sets the injection location for the generated injector.
      Parameters:
      injectionLocation - The injection location
      Returns:
      This object
    • injectionExternalDeclarations

      public WrapIdentifier<T> injectionExternalDeclarations(Collection<String> injectionExternalDeclarations)
      Sets the external declarations for the generated injector.
      Parameters:
      injectionExternalDeclarations - The external declarations
      Returns:
      This object
    • injectionExternalDeclaration

      public WrapIdentifier<T> injectionExternalDeclaration(String injectionExternalDeclaration)
      Sets a single external declaration for the generated injector. No other external declarations will be considered.
      Parameters:
      injectionExternalDeclaration - The external declaration
      Returns:
      This object
    • wrapResultDetector

      public WrapIdentifier<T> wrapResultDetector(Supplier<ActivatableLifecycleUser<T>> wrapResultDetector)
      Sets the supplier for a configuration property.
      Parameters:
      wrapResultDetector - The value supplier
      Returns:
      This object
    • detectionResults

      public WrapIdentifier<T> detectionResults(Supplier<Collection<String>> detectionResults)
      Sets the supplier for a configuration property.
      Parameters:
      detectionResults - The value supplier
      Returns:
      This object
    • parsedReplacement

      public WrapIdentifier<T> parsedReplacement(Supplier<String> parsedReplacement)
      Sets the supplier for a configuration property.
      Parameters:
      parsedReplacement - The value supplier
      Returns:
      This object
    • parseMethod

      public WrapIdentifier<T> parseMethod(Supplier<Function<io.github.douira.glsl_transformer.GLSLParser,​ExtendedContext>> parseMethod)
      Sets the supplier for a configuration property.
      Parameters:
      parseMethod - The value supplier
      Returns:
      This object
    • wrappingReplacer

      public WrapIdentifier<T> wrappingReplacer(Supplier<ActivatableLifecycleUser<T>> wrappingReplacer)
      Sets the supplier for a configuration property.
      Parameters:
      wrappingReplacer - The value supplier
      Returns:
      This object
    • wrapHandlerTargets

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

      public WrapIdentifier<T> wrapTarget(Supplier<String> wrapTarget)
      Sets the supplier for a configuration property.
      Parameters:
      wrapTarget - The value supplier
      Returns:
      This object
    • injector

      public WrapIdentifier<T> injector(Supplier<ActivatableLifecycleUser<T>> injector)
      Sets the supplier for a configuration property.
      Parameters:
      injector - The value supplier
      Returns:
      This object
    • injectionLocation

      public WrapIdentifier<T> injectionLocation(Supplier<InjectionPoint> injectionLocation)
      Sets the supplier for a configuration property.
      Parameters:
      injectionLocation - The value supplier
      Returns:
      This object
    • injectionExternalDeclarations

      public WrapIdentifier<T> injectionExternalDeclarations(Supplier<Collection<String>> injectionExternalDeclarations)
      Sets the supplier for a configuration property.
      Parameters:
      injectionExternalDeclarations - The value supplier
      Returns:
      This object
    • wrapResultDetector

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

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

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

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

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

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

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

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

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

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

      protected final ActivatableLifecycleUser<T> wrapResultDetector()
      Returns the proper value of a configuration property.
      Returns:
      The configuration property value
    • detectionResults

      protected final Collection<String> detectionResults()
      Returns the proper value of a configuration property.
      Returns:
      The configuration property value
    • detectionResult

      protected final String detectionResult()
      Returns the proper value of a configuration property.
      Returns:
      The configuration property value
    • parsedReplacement

      protected final String parsedReplacement()
      Returns the proper value of a configuration property.
      Returns:
      The configuration property value
    • parseMethod

      protected final Function<io.github.douira.glsl_transformer.GLSLParser,​ExtendedContext> parseMethod()
      Returns the proper value of a configuration property.
      Returns:
      The configuration property value
    • wrappingReplacer

      protected final ActivatableLifecycleUser<T> wrappingReplacer()
      Returns the proper value of a configuration property.
      Returns:
      The configuration property value
    • wrapHandlerTargets

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

      protected final String wrapTarget()
      Returns the proper value of a configuration property.
      Returns:
      The configuration property value
    • injector

      protected final ActivatableLifecycleUser<T> injector()
      Returns the proper value of a configuration property.
      Returns:
      The configuration property value
    • injectionLocation

      protected final InjectionPoint injectionLocation()
      Returns the proper value of a configuration property.
      Returns:
      The configuration property value
    • injectionExternalDeclarations

      protected final Collection<String> injectionExternalDeclarations()
      Returns the proper value of a configuration property.
      Returns:
      The configuration property value