Class JavaFileObjects
java.lang.Object
com.google.testing.compile.JavaFileObjects
A utility class for creating
JavaFileObject instances.- Author:
- Gregory Kick
-
Method Summary
Modifier and TypeMethodDescriptionstatic JavaFileObjectforResource(String resourceName) Returns aJavaFileObjectfor the class path resource with the givenresourceName.static JavaFileObjectforResource(URL resourceUrl) Returns aJavaFileObjectfor the resource at the givenURL.static JavaFileObjectforSourceLines(String fullyQualifiedName, Iterable<String> lines) An overload of#forSourceLinesthat takes anIterable<String>.static JavaFileObjectforSourceLines(String fullyQualifiedName, String... lines) Behaves exactly likeforSourceString(String, String), but joins lines so that multi-line source strings may omit the newline characters.static JavaFileObjectforSourceString(String fullyQualifiedName, String source) Creates aJavaFileObjectwith a path corresponding to thefullyQualifiedNamecontaining the givesource.
-
Method Details
-
forSourceString
Creates aJavaFileObjectwith a path corresponding to thefullyQualifiedNamecontaining the givesource. The returned object will always be read-only and have theJavaFileObject.Kind.SOURCEkind.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
Behaves exactly likeforSourceString(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
An overload of#forSourceLinesthat takes anIterable<String>. -
forResource
Returns aJavaFileObjectfor the resource at the givenURL. The returned object will always be read-only and the kind is inferred via theJavaFileObject.Kind.extension. -
forResource
Returns aJavaFileObjectfor the class path resource with the givenresourceName. This method is equivalent to invokingforResource(Resources.getResource(resourceName)).
-