* compiler.getTask(null, fileManager, null, null, null, compilationUnits1).call();
*
* {@code Iterable<? extends JavaFileObject>} compilationUnits2 =
* fileManager.getJavaFileObjects(files2); // use alternative method
* // reuse the same file manager to allow caching of jar files
* compiler.getTask(null, fileManager, null, null, null, compilationUnits2).call();
*
* fileManager.close();</pre>
*
* </dd>
*
* <dt>{@link DiagnosticCollector}</dt>
* <dd>
* Used to collect diagnostics in a list, for example:
* <pre>
* {@code Iterable<? extends JavaFileObject>} compilationUnits = ...;
* JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
* {@code DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();}
* StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
* compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits).call();
*
* for (Diagnostic diagnostic : diagnostics.getDiagnostics())
* System.out.format("Error on line %d in %d%n",
* diagnostic.getLineNumber()
* diagnostic.getSource().toUri());
*
* fileManager.close();</pre>
* </dd>
*
* <dt>
* {@link ForwardingJavaFileManager}, {@link ForwardingFileObject}, and
* {@link ForwardingJavaFileObject}
* </dt>
* <dd>
*
* Subclassing is not available for overriding the behavior of a
* standard file manager as it is created by calling a method on a
* compiler, not by invoking a constructor. Instead forwarding
* (or delegation) should be used. These classes makes it easy to
* forward most calls to a given file manager or file object while
* allowing customizing behavior. For example, consider how to
* log all calls to {@linkplain JavaFileManager#flush}:
*
* <pre>
* final {@linkplain java.util.logging.Logger Logger} logger = ...;
* {@code Iterable<? extends JavaFileObject>} compilationUnits = ...;
* JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
* StandardJavaFileManager stdFileManager = compiler.getStandardFileManager(null, null, null);
* JavaFileManager fileManager = new ForwardingJavaFileManager(stdFileManager) {
* public void flush() {
* logger.entering(StandardJavaFileManager.class.getName(), "flush");
* super.flush();
* logger.exiting(StandardJavaFileManager.class.getName(), "flush");
* }
* };
* compiler.getTask(null, fileManager, null, null, null, compilationUnits).call();</pre>
* </dd>
*
* <dt>{@link SimpleJavaFileObject}</dt>
* <dd>
*
* This class provides a basic file object implementation which
* can be used as building block for creating file objects. For
* example, here is how to define a file object which represent
* source code stored in a string:
*
* <pre>
* /**
* * A file object used to represent source coming from a string.
* {@code *}/
* public class JavaSourceFromString extends SimpleJavaFileObject {
* /**
* * The source code of this "file".
* {@code *}/
* final String code;
*
* /**
* * Constructs a new JavaSourceFromString.
* * {@code @}param name the name of the compilation unit represented by this file object
* * {@code @}param code the source code for the compilation unit represented by this file object
* {@code *}/
* JavaSourceFromString(String name, String code) {
* super({@linkplain java.net.URI#create URI.create}("string:///" + name.replace('.','/') +
Kind.SOURCE.extension),
* Kind.SOURCE);
* this.code = code;
* }
*
* {@code @}Override
* public CharSequence getCharContent(boolean ignoreEncodingErrors) {
* return code;
* }
* }</pre>
* </dd>
* </dl>
*
* @author Peter von der Ahé
* @author Jonathan Gibbons
* @see DiagnosticListener
* @see Diagnostic
* @see JavaFileManager
=2= |