Package com.vaadin.copilot
Class Util
java.lang.Object
com.vaadin.copilot.Util
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringdecideEntityPackage(JavaSourcePathDetector.ModuleInfo moduleInfo, Path referenceFile, String mainPackage) static StringdecideRepositoryPackage(JavaSourcePathDetector.ModuleInfo moduleInfo, Path referenceFile, String mainPackage) static StringdecideServicePackage(JavaSourcePathDetector.ModuleInfo moduleInfo, Path referenceFile, String mainPackage) static StringescapeSingleQuote(String value) findCommonAncestor(List<Path> paths) Finds the common ancestor path for the given paths.findCurrentModule(com.vaadin.flow.server.VaadinSession session, com.fasterxml.jackson.databind.JsonNode currentView) Finds the module where the (first of) currently open view(s) is defined.findCurrentViewFile(com.vaadin.flow.server.VaadinSession session, com.fasterxml.jackson.databind.JsonNode currentView) Finds a file related to the current view, to be able to determine which folder / project module to create new files in.static StringfindFeaturePackage(String viewPackage, String mainPackage) static StringgetClassNameFromFilename(Path filename, Path sourceFolder) static StringgetFilenameFromClassName(String className) Converts a fully qualified class name to a filename.static StringgetGetterName(String propertyName, String javaType) Generates the getter method name for a given property.getJavaPackages(Path sourceFolder) static StringgetPackageName(String className) Extracts the package name from a fully qualified class name.getParameterTypes(Method method) Gets the parameter types of a method.static StringgetRelativeName(File projectFile, File folder) Returns the name of the file, relative to the given folder.static StringgetSetterName(String propertyName) Generates the setter method name for a given property.static StringgetSimpleName(String className) Extracts the simple class name from a fully qualified class name.static FilegetSinglePackage(File javaSourceFolder) Finds the first folder inside the given folder that contains more than one sub-folder.static StringincreaseTrailingNumber(String filename) Takes a filename and increases a trailing number on the name (excluding the extension).static StringinsertLines(String text, List<Integer> lineNumbers, String toInsert) Inserts the given string on the given line numbers in the given textstatic booleanisFileInside(File toCheck, File container) Checks if a file is inside a container folder.listAllFolders(Path startPath) static PathreplaceFolderInPath(Path path, String oldFolderName, String newFolderName, String parentFolder) Replaces any folder with the given name in the path with a new folder name.static StringConverts a string to title case.static String
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
increaseTrailingNumber
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
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
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 modifyoldFolderName- the name of the folder to replacenewFolderName- the name of the folder to replace withparentFolder- the name of the folder containing the folder to replace- Returns:
- the modified path
-
findCommonAncestor
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(com.vaadin.flow.server.VaadinSession session, com.fasterxml.jackson.databind.JsonNode currentView) Finds a file related to the current view, to be able to determine which folder / project module to create new files in.- Parameters:
session- the vaadin session to usecurrentView- 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(com.vaadin.flow.server.VaadinSession session, com.fasterxml.jackson.databind.JsonNode currentView) Finds the module where the (first of) currently open view(s) is defined.- Parameters:
session- the vaadin session to usecurrentView- 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
-
getGetterName
Generates the getter method name for a given property.- Parameters:
propertyName- the name of the propertyjavaType- the Java type of the property- Returns:
- the getter method name
-
getSetterName
Generates the setter method name for a given property.- Parameters:
propertyName- the name of the property- Returns:
- the setter method name
-
getFilenameFromClassName
Converts a fully qualified class name to a filename.- Parameters:
className- the fully qualified class name- Returns:
- the filename corresponding to the class name
-
getClassNameFromFilename
-
getPackageName
Extracts the package name from a fully qualified class name.- Parameters:
className- the fully qualified class name- Returns:
- the package name
-
getSimpleName
Extracts the simple class name from a fully qualified class name.- Parameters:
className- the fully qualified class name- Returns:
- the simple class name
-
findFeaturePackage
-
getJavaPackages
-
listAllFolders
-
decideEntityPackage
public static String decideEntityPackage(JavaSourcePathDetector.ModuleInfo moduleInfo, Path referenceFile, String mainPackage) -
decideRepositoryPackage
public static String decideRepositoryPackage(JavaSourcePathDetector.ModuleInfo moduleInfo, Path referenceFile, String mainPackage) -
decideServicePackage
public static String decideServicePackage(JavaSourcePathDetector.ModuleInfo moduleInfo, Path referenceFile, String mainPackage) -
getParameterTypes
Gets the parameter types of a method.- Parameters:
method- the method to get parameter types for- Returns:
- a list of parameter types
-
getRelativeName
Returns the name of the file, relative to the given folder.- Parameters:
projectFile- the filefolder- the folder to make relative to- Returns:
- the relative name of the file
-
isFileInside
Checks if a file is inside a container folder.- Parameters:
toCheck- the file to checkcontainer- the container folder- Returns:
- true if the file is inside the container folder
-
insertLines
Inserts the given string on the given line numbers in the given text -
truncate
-
escapeSingleQuote
-