Class JavaFileObjects

java.lang.Object
io.micronaut.annotation.processing.test.JavaFileObjects

public final class JavaFileObjects extends Object
A utility class for creating JavaFileObject instances.
Author:
Gregory Kick
  • Method Details

    • forSourceString

      public static JavaFileObject forSourceString(String fullyQualifiedName, String source)
      Creates a JavaFileObject with a path corresponding to the fullyQualifiedName containing the give source. The returned object will always be read-only and have the JavaFileObject.Kind.SOURCE kind.

      Note that this method makes no attempt to verify that the name matches the contents of the source and compilation errors may result if they do not match.

      Parameters:
      fullyQualifiedName - the fully qualified name
      source - The source
      Returns:
      the java file object
    • forSourceLines

      public static JavaFileObject forSourceLines(String fullyQualifiedName, String... lines)
      Behaves exactly like forSourceString(String, String), but joins lines so that multi-line source strings may omit the newline characters. For example:
      
        JavaFileObjects.forSourceLines("example.HelloWorld",
            "package example;",
            "",
            "final class HelloWorld {",
            "  void sayHello() {",
            "    System.out.println(\"hello!\");",
            "  }",
            "}");
        
      Parameters:
      fullyQualifiedName - the fully qualified name
      lines - The source
      Returns:
      The java file object
    • forSourceLines

      public static JavaFileObject forSourceLines(String fullyQualifiedName, Iterable<String> lines)
      An overload of #forSourceLines that takes an Iterable<String>.
      Parameters:
      fullyQualifiedName - the fully qualified name
      lines - The source
      Returns:
      The java file object