Class ReplicateUtilities

java.lang.Object
com.illumon.compilertools.ReplicateUtilities

public class ReplicateUtilities extends Object
  • Constructor Details

    • ReplicateUtilities

      public ReplicateUtilities()
  • Method Details

    • locateBasePath

      public static Path locateBasePath()
    • applyFixup

      @NotNull public static @NotNull List<String> applyFixup(List<String> lines, String region, String searchPattern, Function<Matcher,List<String>> replacer)
      Take a list of lines; and apply a given fixup expressed as a code region, regular expression, then function from the matcher to the replacement line.
      Parameters:
      lines - the input lines
      region - the name of the region started by "// region <name>" and ended by "// endregion <name>"
      searchPattern - the pattern to search for
      replacer - a function from the search pattern's successful matcher to the new lines to apply as a List.
      Returns:
      a new list of lines with the fixup applied
    • simpleFixup

      @NotNull public static @NotNull List<String> simpleFixup(List<String> lines, String region, String... replacements)
      Take a list of lines; and apply a given fixup expressed as a code region and replacements
      Parameters:
      lines - the input lines
      region - the name of the region started by "// region <name>" and ended by "// endregion <name>"
      replacements - an array with an even number of elements, even elements are a thing to replace, the next element is the thing to replace it with
      Returns:
      a new list of lines with the fixup applied
    • standardCleanups

      public static List<String> standardCleanups(List<String> lines)
      Do whatever miscellaneous cleanups might be appropriate for all replicated classes. For now, this removes identical import lines.
    • insertRegion

      @NotNull public static @NotNull List<String> insertRegion(List<String> lines, String region, List<String> extraLines)
      Locates the region demarked by "// region <name>" and ended by "// endregion <name>" and adds extra lines at the top.
      Parameters:
      lines - the lines to process
      region - the name of the region
      extraLines - the lines to insert
      Returns:
      a new list of lines
    • removeRegion

      @NotNull public static @NotNull List<String> removeRegion(List<String> lines, String region)
      Locates the region demarked by "// region <name>" and ended by "// endregion <name>" and removes it.
      Parameters:
      lines - the lines to process
      region - the name of the region
      Returns:
      a new list of lines
    • replaceRegion

      @NotNull public static @NotNull List<String> replaceRegion(List<String> lines, String region, List<String> replacement)
      Locates the region demarked by "// region <name>" and ended by "// endregion <name>" and replaces the text with the contents of replacement.
      Parameters:
      lines - the lines to process
      region - the name of the region
      replacement - the lines to insert
      Returns:
      a new list of lines
    • replaceRegion

      @NotNull public static @NotNull List<String> replaceRegion(List<String> lines, String region, Function<List<String>,List<String>> replacement)
      Locates the region demarked by "// region <name>" and ended by "// endregion <name>" and replaces the text with the contents of replacement.
      Parameters:
      lines - the lines to process
      region - the name of the region
      replacement - the lines to insert
      Returns:
      a new list of lines
    • globalReplacements

      public static List<String> globalReplacements(int skip, List<String> lines, String... replacements)
    • globalReplacements

      public static List<String> globalReplacements(List<String> lines, String... replacements)
    • replaceInRegion

      public static List<String> replaceInRegion(String region, List<String> lines, String... replacements)
    • addImport

      public static List<String> addImport(List<String> lines, Class... importClasses)
    • removeImport

      public static List<String> removeImport(List<String> lines, Class... importClasses)
    • addImport

      public static List<String> addImport(List<String> lines, String... importString)
    • removeImport

      public static List<String> removeImport(List<String> lines, String... importRegex)
      Remove all of the specified imports -- Error if any are not found.
    • removeAnyImports

      public static List<String> removeAnyImports(List<String> lines, String... importRegex)
      Remove imports if they match any of the patterns.
    • fixupChunkAttributes

      @NotNull public static @NotNull List<String> fixupChunkAttributes(List<String> lines)
    • fixupChunkAttributes

      @NotNull public static @NotNull List<String> fixupChunkAttributes(List<String> lines, String genericType)
    • fixupChunkAttributes

      public static void fixupChunkAttributes(String objectPath) throws IOException
      Throws:
      IOException
    • indent

      public static List<String> indent(List<String> lines, int spaces)
    • findNoLocateRegions

      public static Map<String,List<String>> findNoLocateRegions(String replicateDest) throws IOException
      Throws:
      IOException