Class Util

java.lang.Object
com.vaadin.copilot.Util

public class Util extends Object
  • Constructor Details

    • Util

      public Util()
  • Method Details

    • increaseTrailingNumber

      public static String increaseTrailingNumber(String filename)
      Takes a filename and increases a trailing number on the name (excluding the extension).

      For example, "file1.txt" would return "file2.txt", "file.txt" would return "file1.txt" and "file123.txt" would return "file124.txt". If the filename doesn't end with a number, a 1 is added at the end.

      Parameters:
      filename - the string to increase
      Returns:
      the input string with the trailing number increased by one, or with a 1 added at the end if it didn't end with a number
    • getSinglePackage

      public static File getSinglePackage(File javaSourceFolder)
      Finds the first folder inside the given folder that contains more than one sub-folder.

      Parameters:
      javaSourceFolder - the root java source folder
      Returns:
      the first folder that contains more than one sub-folder
    • titleCase

      public static String titleCase(String input)
      Converts a string to title case.

      For example, "hello world" becomes "Hello World".

      Parameters:
      input - the input string
      Returns:
      the input string converted to title case
    • replaceFolderInPath

      public static Path replaceFolderInPath(Path path, String oldFolderName, String newFolderName, String parentFolder)
      Replaces any folder with the given name in the path with a new folder name.
      Parameters:
      path - the path to modify
      oldFolderName - the name of the folder to replace
      newFolderName - the name of the folder to replace with
      parentFolder - the name of the folder containing the folder to replace
      Returns:
      the modified path
    • findCommonAncestor

      public static Optional<Path> findCommonAncestor(List<Path> paths)
      Finds the common ancestor path for the given paths.

      For instance if you pass in /foo/bar/baz and /foo/bar, this returns /foo/bar

      Parameters:
      paths - the paths to process
      Returns:
      the common ancestor path
    • findCurrentViewFile

      public static Optional<File> findCurrentViewFile(ProjectManager projectManager, elemental.json.JsonObject currentView)
      Finds a file related to the current view, to be able to determine which folder / project module to create new files in.
      Parameters:
      projectManager - the project manager
      currentView - JSON data for the current view, with either "viewFile" pointing to a Hilla view file or "uiId" refering to an open Flow UI
      Returns:
      a file (Java or TSX) used for the current view
    • findCurrentModule

      public static Optional<JavaSourcePathDetector.ModuleInfo> findCurrentModule(ProjectManager projectManager, elemental.json.JsonObject currentView)
      Finds the module where the (first of) currently open view(s) is defined.
      Parameters:
      projectManager - the project manager
      currentView - JSON data for the current view, with either "viewFile" pointing to a Hilla view file or "uiId" referring to an open Flow UI
      Returns:
      the module where the current view is defined