Top Description Constructors Methods
com.github.javaparser.utils

public final Class CodeGenerationUtils

extends Object
Class Inheritance
Imports
java.io.File, java.net.URISyntaxException, java.nio.file.Path, .Paths

Utilities that can be useful when generating code.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Path

Returns:

the root directory of the classloader for class c.
classLoaderRoot
(Class<?> c)

public static String
f(String format, Object... params)

A shortcut to String.format.

public static Path
fileInPackageAbsolutePath(String
the root directory in which the package resides
root
,
String
the package in which the file resides, like "com.laamella.parser"
pkg
,
String
the filename of the file in the package.
file
)

Calculates the path to a file in a package.

public static Path
public static Path
fileInPackageRelativePath(String pkg, String file)

Turns a package and a file into a relative path.

public static String
getterName(Class<?> type, String name)

public static String
public static Path
mavenModuleRoot(Class<?> c)

Useful for locating source code in your Maven project.

public static String
optionalOf(String text, boolean isOptional)

public static Path
packageAbsolutePath(String
the root directory in which the package resides
root
,
String
the package, like "com.laamella.parser"
pkg
)

Calculates the path of a package.

public static Path
public static String
packageToPath(String pkg)

Converts a package name like "com.laamella.parser" to a path like "com/laamella/parser"

public static String
setterName(String fieldName)

public static Path
subtractPaths(Path full, Path difference)

Shortens path "full" by cutting "difference" off the end of it.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

CodeGenerationUtilsback to summary
private CodeGenerationUtils()

Method Detail

classLoaderRootback to summary
public static Path classLoaderRoot(Class<?> c)
Returns:Path

the root directory of the classloader for class c.

fback to summary
public static String f(String format, Object... params)

A shortcut to String.format.

fileInPackageAbsolutePathback to summary
public static Path fileInPackageAbsolutePath(String root, String pkg, String file)

Calculates the path to a file in a package.

Parameters
root:String

the root directory in which the package resides

pkg:String

the package in which the file resides, like "com.laamella.parser"

file:String

the filename of the file in the package.

fileInPackageAbsolutePathback to summary
public static Path fileInPackageAbsolutePath(Path root, String pkg, String file)
fileInPackageRelativePathback to summary
public static Path fileInPackageRelativePath(String pkg, String file)

Turns a package and a file into a relative path. "com.laamella" and "Simple.java" will become "com/laamella/Simple.java"

getterNameback to summary
public static String getterName(Class<?> type, String name)
getterToPropertyNameback to summary
public static String getterToPropertyName(String getterName)
mavenModuleRootback to summary
public static Path mavenModuleRoot(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.

optionalOfback to summary
public static String optionalOf(String text, boolean isOptional)
packageAbsolutePathback to summary
public static Path packageAbsolutePath(String root, String pkg)

Calculates the path of a package.

Parameters
root:String

the root directory in which the package resides

pkg:String

the package, like "com.laamella.parser"

packageAbsolutePathback to summary
public static Path packageAbsolutePath(Path root, String pkg)
packageToPathback to summary
public static String packageToPath(String pkg)

Converts a package name like "com.laamella.parser" to a path like "com/laamella/parser"

setterNameback to summary
public static String setterName(String fieldName)
subtractPathsback to summary
public static Path subtractPaths(Path full, Path difference)

Shortens path "full" by cutting "difference" off the end of it.