# Class JavaFileObjects

java.lang.Object
com.google.testing.compile.JavaFileObjects

public final class JavaFileObjects extends Object
A utility class for creating `JavaFileObject` instances.

Author:
  Gregory Kick

## Method Summary

Modifier and Type
Method
Description
`static JavaFileObject`
`forResource(String resourceName)`
Returns a `JavaFileObject` for the class path resource with the given `resourceName`.
`static JavaFileObject`
`forResource(URL resourceUrl)`
Returns a `JavaFileObject` for the resource at the given `URL`.
`static JavaFileObject`
`forSourceLines(String fullyQualifiedName, Iterable<String> lines)`
An overload of `#forSourceLines` that takes an `Iterable<String>`.
`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.
`static JavaFileObject`
`forSourceString(String fullyQualifiedName, String source)`
Creates a `JavaFileObject` with a path corresponding to the `fullyQualifiedName` containing the give `source`.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## 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.

### 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!\");",
          "  }",
          "}");

### forSourceLines

public static JavaFileObject forSourceLines(String fullyQualifiedName, Iterable<String> lines)
An overload of `#forSourceLines` that takes an `Iterable<String>`.

### forResource

public static JavaFileObject forResource(URL resourceUrl)
Returns a `JavaFileObject` for the resource at the given `URL`. The returned object will always be read-only and the kind is inferred via the `JavaFileObject.Kind.extension`.

### forResource

public static JavaFileObject forResource(String resourceName)
Returns a `JavaFileObject` for the class path resource with the given `resourceName`. This method is equivalent to invoking `forResource(Resources.getResource(resourceName))`.