Package com.github.javaparser.utils
Class CodeGenerationUtils
- java.lang.Object
-
- com.github.javaparser.utils.CodeGenerationUtils
-
public final class CodeGenerationUtils extends java.lang.Object
Utilities that can be useful when generating code.
-
-
Constructor Summary
Constructors Modifier Constructor Description private
CodeGenerationUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.nio.file.Path
classLoaderRoot(java.lang.Class<?> c)
static java.lang.String
f(java.lang.String format, java.lang.Object... params)
A shortcut to String.format.static java.nio.file.Path
fileInPackageAbsolutePath(java.lang.String root, java.lang.String pkg, java.lang.String file)
Calculates the path to a file in a package.static java.nio.file.Path
fileInPackageAbsolutePath(java.nio.file.Path root, java.lang.String pkg, java.lang.String file)
static java.nio.file.Path
fileInPackageRelativePath(java.lang.String pkg, java.lang.String file)
Turns a package and a file into a relative path.static java.lang.String
getterName(java.lang.Class<?> type, java.lang.String name)
static java.lang.String
getterToPropertyName(java.lang.String getterName)
static java.nio.file.Path
mavenModuleRoot(java.lang.Class<?> c)
Useful for locating source code in your Maven project.static java.lang.String
optionalOf(java.lang.String text, boolean isOptional)
static java.nio.file.Path
packageAbsolutePath(java.lang.String root, java.lang.String pkg)
Calculates the path of a package.static java.nio.file.Path
packageAbsolutePath(java.nio.file.Path root, java.lang.String pkg)
static java.lang.String
packageToPath(java.lang.String pkg)
Converts a package name like "com.laamella.parser" to a path like "com/laamella/parser"static java.lang.String
setterName(java.lang.String fieldName)
static java.nio.file.Path
subtractPaths(java.nio.file.Path full, java.nio.file.Path difference)
Shortens path "full" by cutting "difference" off the end of it.
-
-
-
Method Detail
-
getterName
public static java.lang.String getterName(java.lang.Class<?> type, java.lang.String name)
-
getterToPropertyName
public static java.lang.String getterToPropertyName(java.lang.String getterName)
-
setterName
public static java.lang.String setterName(java.lang.String fieldName)
-
optionalOf
public static java.lang.String optionalOf(java.lang.String text, boolean isOptional)
-
f
public static java.lang.String f(java.lang.String format, java.lang.Object... params)
A shortcut to String.format.
-
fileInPackageAbsolutePath
public static java.nio.file.Path fileInPackageAbsolutePath(java.lang.String root, java.lang.String pkg, java.lang.String file)
Calculates the path to a file in a package.- Parameters:
root
- the root directory in which the package residespkg
- the package in which the file resides, like "com.laamella.parser"file
- the filename of the file in the package.
-
fileInPackageAbsolutePath
public static java.nio.file.Path fileInPackageAbsolutePath(java.nio.file.Path root, java.lang.String pkg, java.lang.String file)
-
fileInPackageRelativePath
public static java.nio.file.Path fileInPackageRelativePath(java.lang.String pkg, java.lang.String file)
Turns a package and a file into a relative path. "com.laamella" and "Simple.java" will become "com/laamella/Simple.java"
-
packageToPath
public static java.lang.String packageToPath(java.lang.String pkg)
Converts a package name like "com.laamella.parser" to a path like "com/laamella/parser"
-
packageAbsolutePath
public static java.nio.file.Path packageAbsolutePath(java.lang.String root, java.lang.String pkg)
Calculates the path of a package.- Parameters:
root
- the root directory in which the package residespkg
- the package, like "com.laamella.parser"
-
packageAbsolutePath
public static java.nio.file.Path packageAbsolutePath(java.nio.file.Path root, java.lang.String pkg)
-
classLoaderRoot
public static java.nio.file.Path classLoaderRoot(java.lang.Class<?> c)
- Returns:
- the root directory of the classloader for class c.
-
mavenModuleRoot
public static java.nio.file.Path mavenModuleRoot(java.lang.Class<?> c)
Useful for locating source code in your Maven project. Finds the classpath for class c, then backs up out of "target/(test-)classes", giving the directory containing the pom.xml.
-
subtractPaths
public static java.nio.file.Path subtractPaths(java.nio.file.Path full, java.nio.file.Path difference)
Shortens path "full" by cutting "difference" off the end of it.
-
-