1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/javax/tools/DocumentationTool.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,183 @@ 1.4 +/* 1.5 + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 +package javax.tools; 1.29 + 1.30 +import java.io.Writer; 1.31 +import java.nio.charset.Charset; 1.32 +import java.util.Locale; 1.33 +import java.util.concurrent.Callable; 1.34 + 1.35 +/** 1.36 + * Interface to invoke Java™ programming language documentation tools from 1.37 + * programs. 1.38 + */ 1.39 +public interface DocumentationTool extends Tool, OptionChecker { 1.40 + /** 1.41 + * Creates a future for a documentation task with the given 1.42 + * components and arguments. The task might not have 1.43 + * completed as described in the DocumentationTask interface. 1.44 + * 1.45 + * <p>If a file manager is provided, it must be able to handle all 1.46 + * locations defined in {@link DocumentationTool.Location}, 1.47 + * as well as 1.48 + * {@link StandardLocation#SOURCE_PATH}, 1.49 + * {@link StandardLocation#CLASS_PATH}, and 1.50 + * {@link StandardLocation#PLATFORM_CLASS_PATH}. 1.51 + * 1.52 + * @param out a Writer for additional output from the tool; 1.53 + * use {@code System.err} if {@code null} 1.54 + * 1.55 + * @param fileManager a file manager; if {@code null} use the 1.56 + * tool's standard filemanager 1.57 + * 1.58 + * @param diagnosticListener a diagnostic listener; if {@code null} 1.59 + * use the tool's default method for reporting diagnostics 1.60 + * 1.61 + * @param docletClass a class providing the necessary methods required 1.62 + * of a doclet 1.63 + * 1.64 + * @param options documentation tool options and doclet options, 1.65 + * {@code null} means no options 1.66 + * 1.67 + * @param compilationUnits the compilation units to compile, {@code 1.68 + * null} means no compilation units 1.69 + * 1.70 + * @return an object representing the compilation 1.71 + * 1.72 + * @throws RuntimeException if an unrecoverable error 1.73 + * occurred in a user supplied component. The 1.74 + * {@linkplain Throwable#getCause() cause} will be the error in 1.75 + * user code. 1.76 + * 1.77 + * @throws IllegalArgumentException if any of the given 1.78 + * compilation units are of other kind than 1.79 + * {@linkplain JavaFileObject.Kind#SOURCE source} 1.80 + */ 1.81 + DocumentationTask getTask(Writer out, 1.82 + JavaFileManager fileManager, 1.83 + DiagnosticListener<? super JavaFileObject> diagnosticListener, 1.84 + Class<?> docletClass, 1.85 + Iterable<String> options, 1.86 + Iterable<? extends JavaFileObject> compilationUnits); 1.87 + 1.88 + /** 1.89 + * Gets a new instance of the standard file manager implementation 1.90 + * for this tool. The file manager will use the given diagnostic 1.91 + * listener for producing any non-fatal diagnostics. Fatal errors 1.92 + * will be signaled with the appropriate exceptions. 1.93 + * 1.94 + * <p>The standard file manager will be automatically reopened if 1.95 + * it is accessed after calls to {@code flush} or {@code close}. 1.96 + * The standard file manager must be usable with other tools. 1.97 + * 1.98 + * @param diagnosticListener a diagnostic listener for non-fatal 1.99 + * diagnostics; if {@code null} use the compiler's default method 1.100 + * for reporting diagnostics 1.101 + * 1.102 + * @param locale the locale to apply when formatting diagnostics; 1.103 + * {@code null} means the {@linkplain Locale#getDefault() default locale}. 1.104 + * 1.105 + * @param charset the character set used for decoding bytes; if 1.106 + * {@code null} use the platform default 1.107 + * 1.108 + * @return the standard file manager 1.109 + */ 1.110 + StandardJavaFileManager getStandardFileManager( 1.111 + DiagnosticListener<? super JavaFileObject> diagnosticListener, 1.112 + Locale locale, 1.113 + Charset charset); 1.114 + 1.115 + /** 1.116 + * Interface representing a future for a documentation task. The 1.117 + * task has not yet started. To start the task, call 1.118 + * the {@linkplain #call call} method. 1.119 + * 1.120 + * <p>Before calling the call method, additional aspects of the 1.121 + * task can be configured, for example, by calling the 1.122 + * {@linkplain #setLocale setLocale} method. 1.123 + */ 1.124 + interface DocumentationTask extends Callable<Boolean> { 1.125 + /** 1.126 + * Set the locale to be applied when formatting diagnostics and 1.127 + * other localized data. 1.128 + * 1.129 + * @param locale the locale to apply; {@code null} means apply no 1.130 + * locale 1.131 + * @throws IllegalStateException if the task has started 1.132 + */ 1.133 + void setLocale(Locale locale); 1.134 + 1.135 + /** 1.136 + * Performs this documentation task. The task may only 1.137 + * be performed once. Subsequent calls to this method throw 1.138 + * IllegalStateException. 1.139 + * 1.140 + * @return true if and only all the files were processed without errors; 1.141 + * false otherwise 1.142 + * 1.143 + * @throws RuntimeException if an unrecoverable error occurred 1.144 + * in a user-supplied component. The 1.145 + * {@linkplain Throwable#getCause() cause} will be the error 1.146 + * in user code. 1.147 + * 1.148 + * @throws IllegalStateException if called more than once 1.149 + */ 1.150 + Boolean call(); 1.151 + } 1.152 + 1.153 + /** 1.154 + * Locations specific to {@link DocumentationTool}. 1.155 + * 1.156 + * @see StandardLocation 1.157 + */ 1.158 + enum Location implements JavaFileManager.Location { 1.159 + /** 1.160 + * Location of new documentation files. 1.161 + */ 1.162 + DOCUMENTATION_OUTPUT, 1.163 + 1.164 + /** 1.165 + * Location to search for doclets. 1.166 + */ 1.167 + DOCLET_PATH, 1.168 + 1.169 + /** 1.170 + * Location to search for taglets. 1.171 + */ 1.172 + TAGLET_PATH; 1.173 + 1.174 + public String getName() { return name(); } 1.175 + 1.176 + public boolean isOutputLocation() { 1.177 + switch (this) { 1.178 + case DOCUMENTATION_OUTPUT: 1.179 + return true; 1.180 + default: 1.181 + return false; 1.182 + } 1.183 + } 1.184 + } 1.185 + 1.186 +}