Class CodeGenerationUtils

java.lang.Object
com.github.javaparser.utils.CodeGenerationUtils

public final class CodeGenerationUtils extends Object
Utilities that can be useful when generating code.
  • Method Details

    • getterName

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

      public static String getterToPropertyName(String getterName)
    • setterName

      public static String setterName(String fieldName)
    • optionalOf

      public static String optionalOf(String text, boolean isOptional)
    • f

      public static String f(String format, Object... params)
      A shortcut to String.format.
    • fileInPackageAbsolutePath

      public static Path fileInPackageAbsolutePath(String root, String pkg, String file)
      Calculates the path to a file in a package.
      Parameters:
      root - the root directory in which the package resides
      pkg - the package in which the file resides, like "com.laamella.parser"
      file - the filename of the file in the package.
    • fileInPackageAbsolutePath

      public static Path fileInPackageAbsolutePath(Path root, String pkg, String file)
    • fileInPackageRelativePath

      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"
    • packageToPath

      public static String packageToPath(String pkg)
      Converts a package name like "com.laamella.parser" to a path like "com/laamella/parser"
    • packageAbsolutePath

      public static Path packageAbsolutePath(String root, String pkg)
      Calculates the path of a package.
      Parameters:
      root - the root directory in which the package resides
      pkg - the package, like "com.laamella.parser"
    • packageAbsolutePath

      public static Path packageAbsolutePath(Path root, String pkg)
    • classLoaderRoot

      public static Path classLoaderRoot(Class<?> c)
      Returns:
      the root directory of the classloader for class c.
    • mavenModuleRoot

      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.
    • subtractPaths

      public static Path subtractPaths(Path full, Path difference)
      Shortens path "full" by cutting "difference" off the end of it.