Interface FormatterStep

  • All Superinterfaces:
    Serializable
    All Known Implementing Classes:
    FormatterStep.Strict

    public interface FormatterStep
    extends Serializable
    An implementation of this class specifies a single step in a formatting process. The input is guaranteed to have unix-style newlines, and the output is required to not introduce any windows-style newlines as well.
    • Method Detail

      • getName

        String getName()
        The name of the step, for debugging purposes.
      • format

        @Nullable
        String format​(String rawUnix,
                      File file)
               throws Exception
        Returns a formatted version of the given content.
        Parameters:
        rawUnix - the content to format, guaranteed to have unix-style newlines ('\n'); never null
        file - the file which rawUnix was obtained from; never null. Pass an empty file using new File("") if and only if no file is actually associated with rawUnix
        Returns:
        the formatted content, guaranteed to only have unix-style newlines; may return null if the formatter step doesn't have any changes to make
        Throws:
        Exception - if the formatter step experiences a problem
      • filterByContentPattern

        default FormatterStep filterByContentPattern​(String contentPattern)
        Returns a new FormatterStep which will only apply its changes to files which pass the given filter.
        Parameters:
        contentPattern - java regular expression used to filter out files which content doesn't contain pattern
        Returns:
        FormatterStep
      • filterByFile

        default FormatterStep filterByFile​(SerializableFileFilter filter)
        Returns a new FormatterStep which will only apply its changes to files which pass the given filter. The provided filter must be serializable.
      • createLazy

        static <State extends SerializableFormatterStep createLazy​(String name,
                                                                     ThrowingEx.Supplier<State> stateSupplier,
                                                                     ThrowingEx.Function<State,​FormatterFunc> stateToFormatter)
        Parameters:
        name - The name of the formatter step
        stateSupplier - If the rule has any state, this supplier will calculate it lazily, and the result will be passed to stateToFormatter
        stateToFormatter - A pure function which generates a formatting function using only the state supplied by state and nowhere else.
        Returns:
        A FormatterStep
      • create

        static <State extends SerializableFormatterStep create​(String name,
                                                                 State state,
                                                                 ThrowingEx.Function<State,​FormatterFunc> stateToFormatter)
        Parameters:
        name - The name of the formatter step
        state - If the rule has any state, this state must contain all of it
        stateToFormatter - A pure function which generates a formatting function using only the state supplied by state and nowhere else.
        Returns:
        A FormatterStep
      • createNeverUpToDateLazy

        static FormatterStep createNeverUpToDateLazy​(String name,
                                                     ThrowingEx.Supplier<FormatterFunc> functionSupplier)
        Parameters:
        name - The name of the formatter step
        functionSupplier - A supplier which will lazily generate the function used by the formatter step
        Returns:
        A FormatterStep which will never report that it is up-to-date, because it is not equal to the serialized representation of itself.
      • createNeverUpToDate

        static FormatterStep createNeverUpToDate​(String name,
                                                 FormatterFunc function)
        Parameters:
        name - The name of the formatter step
        function - The function used by the formatter step
        Returns:
        A FormatterStep which will never report that it is up-to-date, because it is not equal to the serialized representation of itself.