Class CompilerTools

java.lang.Object
com.illumon.compilertools.CompilerTools

public class CompilerTools extends Object
  • Field Details

  • Constructor Details

    • CompilerTools

      public CompilerTools()
  • Method Details

    • setLogEnabled

      public static boolean setLogEnabled(boolean logEnabled)
      Enables or disables compilation logging.
      Parameters:
      logEnabled - Whether or not logging should be enabled
      Returns:
      The value of logEnabled before calling this method.
    • writeClass

      public static void writeClass(File destinationDirectory, String className, byte[] data) throws IOException
      Throws:
      IOException
    • writeClass

      public static void writeClass(File destinationDirectory, String className, byte[] data, String message) throws IOException
      Throws:
      IOException
    • resetContext

      public static void resetContext()
    • setContext

      public static void setContext(@Nullable @Nullable CompilerTools.Context context)
    • getContext

      public static CompilerTools.Context getContext()
    • doWithContext

      public static <RETURN_TYPE> RETURN_TYPE doWithContext(@NotNull @NotNull CompilerTools.Context context, @NotNull @NotNull Supplier<RETURN_TYPE> action)
    • compile

      public static Class<?> compile(String className, String classBody, String packageNameRoot)
    • compile

      public static Class<?> compile(String className, String classBody, String packageNameRoot, Map<String,Class<?>> parameterClasses)
    • compile

      public static Class<?> compile(String className, String classBody, String packageNameRoot, StringBuilder codeLog)
    • compile

      public static Class<?> compile(@NotNull @NotNull String className, @NotNull @NotNull String classBody, @NotNull @NotNull String packageNameRoot, @Nullable @Nullable StringBuilder codeLog, @NotNull @NotNull Map<String,Class<?>> parameterClasses)
      Compile a class.
      Parameters:
      className - Class name
      classBody - Class body, before update with "$CLASS_NAME$" replacement and package name prefixing
      packageNameRoot - Package name prefix
      codeLog - Optional "log" for final class code
      parameterClasses - Generic parameters, empty if none required
      Returns:
      The compiled class
    • createEscapedJoinedString

      public static String createEscapedJoinedString(String originalString)
      Transform a string into the corresponding Java source code that compiles into that string. This involves escaping special characters, surrounding it with quotes, and (if the string is larger than the max string length for Java literals), splitting it into substrings and constructing a call to String.join() that combines those substrings.
    • createEscapedJoinedString

      public static String createEscapedJoinedString(String originalString, int maxStringLength)
    • tryCompile

      public static com.fishlib.base.Pair<Boolean,String> tryCompile(File basePath, Collection<File> javaFiles) throws IOException
      Try to compile the set of files, returning a pair of success and compiler output.
      Parameters:
      basePath - the base path for the java classes
      javaFiles - the java source files
      Returns:
      a Pair of success, and the compiler output
      Throws:
      IOException
    • getJavaClassPath

      public static String getJavaClassPath()
      Retrieve the java class path from our existing Java class path, and IntelliJ/TeamCity environment variables.
      Returns:
    • main

      public static void main(String[] args)