Path: blob/master/src/java.compiler/share/classes/javax/tools/DocumentationTool.java
41152 views
/*1* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.tools;2627import java.io.Writer;28import java.nio.charset.Charset;29import java.util.Locale;30import java.util.concurrent.Callable;3132/**33* Interface to invoke Java programming language documentation tools from34* programs.35*36* @since 1.837*/38public interface DocumentationTool extends Tool, OptionChecker {39/**40* Creates a future for a documentation task with the given41* components and arguments. The task might not have42* completed as described in the DocumentationTask interface.43*44* <p>If a file manager is provided, it must be able to handle all45* locations defined in {@link DocumentationTool.Location},46* as well as47* {@link StandardLocation#SOURCE_PATH},48* {@link StandardLocation#CLASS_PATH}, and49* {@link StandardLocation#PLATFORM_CLASS_PATH}.50*51* @param out a Writer for additional output from the tool;52* use {@code System.err} if {@code null}53*54* @param fileManager a file manager; if {@code null} use the55* tool's standard file manager56*57* @param diagnosticListener a diagnostic listener; if {@code null}58* use the tool's default method for reporting diagnostics59*60* @param docletClass a class providing the necessary methods required61* of a doclet; a value of {@code null} means to use the standard doclet.62*63* @param options documentation tool options and doclet options,64* {@code null} means no options65*66* @param compilationUnits the compilation units to compile, {@code67* null} means no compilation units68*69* @return an object representing the compilation70*71* @throws RuntimeException if an unrecoverable error72* occurred in a user supplied component. The73* {@linkplain Throwable#getCause() cause} will be the error in74* user code.75*76* @throws IllegalArgumentException if any of the given77* compilation units are of other kind than78* {@linkplain JavaFileObject.Kind#SOURCE source}79*/80DocumentationTask getTask(Writer out,81JavaFileManager fileManager,82DiagnosticListener<? super JavaFileObject> diagnosticListener,83Class<?> docletClass,84Iterable<String> options,85Iterable<? extends JavaFileObject> compilationUnits);8687/**88* Returns a new instance of the standard file manager implementation89* for this tool. The file manager will use the given diagnostic90* listener for producing any non-fatal diagnostics. Fatal errors91* will be signaled with the appropriate exceptions.92*93* <p>The standard file manager will be automatically reopened if94* it is accessed after calls to {@code flush} or {@code close}.95* The standard file manager must be usable with other tools.96*97* @param diagnosticListener a diagnostic listener for non-fatal98* diagnostics; if {@code null} use the compiler's default method99* for reporting diagnostics100*101* @param locale the locale to apply when formatting diagnostics;102* {@code null} means the {@linkplain Locale#getDefault() default locale}.103*104* @param charset the character set used for decoding bytes; if105* {@code null} use the platform default106*107* @return the standard file manager108*/109StandardJavaFileManager getStandardFileManager(110DiagnosticListener<? super JavaFileObject> diagnosticListener,111Locale locale,112Charset charset);113114/**115* Interface representing a future for a documentation task. The116* task has not yet started. To start the task, call117* the {@linkplain #call call} method.118*119* <p>Before calling the {@code call} method, additional aspects of the120* task can be configured, for example, by calling the121* {@linkplain #setLocale setLocale} method.122*/123interface DocumentationTask extends Callable<Boolean> {124/**125* Adds root modules to be taken into account during module126* resolution.127* Invalid module names may cause either128* {@code IllegalArgumentException} to be thrown,129* or diagnostics to be reported when the task is started.130* @param moduleNames the names of the root modules131* @throws IllegalArgumentException may be thrown for some132* invalid module names133* @throws IllegalStateException if the task has started134* @since 9135*/136void addModules(Iterable<String> moduleNames);137138/**139* Sets the locale to be applied when formatting diagnostics and140* other localized data.141*142* @param locale the locale to apply; {@code null} means apply no143* locale144* @throws IllegalStateException if the task has started145*/146void setLocale(Locale locale);147148/**149* Performs this documentation task. The task may only150* be performed once. Subsequent calls to this method throw151* {@code IllegalStateException}.152*153* @return true if and only all the files were processed without errors;154* false otherwise155*156* @throws RuntimeException if an unrecoverable error occurred157* in a user-supplied component. The158* {@linkplain Throwable#getCause() cause} will be the error159* in user code.160*161* @throws IllegalStateException if called more than once162*/163@Override164Boolean call();165}166167/**168* Locations specific to {@link DocumentationTool}.169*170* @see StandardLocation171*/172enum Location implements JavaFileManager.Location {173/**174* Location of new documentation files.175*/176DOCUMENTATION_OUTPUT,177178/**179* Location to search for doclets.180*/181DOCLET_PATH,182183/**184* Location to search for taglets.185*/186TAGLET_PATH;187188public String getName() { return name(); }189190public boolean isOutputLocation() {191switch (this) {192case DOCUMENTATION_OUTPUT:193return true;194default:195return false;196}197}198}199200}201202203