Path: blob/master/src/jdk.javadoc/share/classes/jdk/javadoc/doclet/Reporter.java
66649 views
/*1* Copyright (c) 1998, 2021, 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 jdk.javadoc.doclet;2627import java.io.PrintWriter;28import java.util.Locale;29import javax.lang.model.element.Element;30import javax.tools.Diagnostic;31import javax.tools.FileObject;3233import com.sun.source.util.DocTreePath;3435/**36* Interface for reporting diagnostics and other messages.37*38* <p>Diagnostics consist of a {@link Diagnostic.Kind diagnostic kind} and a message,39* and may additionally be associated with an {@link Element element},40* a {@link DocTreePath tree node} in a documentation comment,41* or an arbitrary position in a given {@link FileObject file}.42* Other messages may be written directly to one of two streams that are informally43* for use by "standard output" and "diagnostic output", where "standard output"44* means the output that is the expected result of executing some operation,45* such as the command-line help that is generated when using a {@code --help} option,46* and "diagnostic output" refers to any errors, warnings and other output that is47* a side-effect of executing the operation.48*49* <p>The exact manner in which diagnostics are output is unspecified and depends50* on the enclosing context. For example:51* <ul>52* <li>The {@link javax.tools.DocumentationTool} API allows a client to specify a53* {@link javax.tools.DiagnosticListener} to which diagnostics will be54* {@link javax.tools.DiagnosticListener#report reported}. If no listener is specified,55* diagnostics will be written to a given stream, or to {@code System.err} if no such56* stream is provided.57* <li>The {@link java.util.spi.ToolProvider} API allows a client to specify58* the streams to be used for reporting standard and diagnostic output.59* </ul>60*61* @since 962*/63public interface Reporter {6465/**66* Prints a diagnostic message.67*68* @param kind the kind of diagnostic69* @param message the message to be printed70*/71void print(Diagnostic.Kind kind, String message);7273/**74* Prints a diagnostic message related to a tree node in a documentation comment.75*76* @param kind the kind of diagnostic77* @param path the path for the tree node78* @param message the message to be printed79*/80void print(Diagnostic.Kind kind, DocTreePath path, String message);8182/**83* Prints a diagnostic message related to an element.84*85* @param kind the kind of diagnostic86* @param element the element87* @param message the message to be printed88*/89void print(Diagnostic.Kind kind, Element element, String message);9091/**92* Prints a diagnostic message related to a position within a range of characters in a file.93* The positions are all 0-based character offsets from the beginning of content of the file.94* The positions should satisfy the relation {@code start <= pos <= end}.95*96* @implSpec97* This implementation always throws {@code UnsupportedOperationException}.98* The implementation provided by the {@code javadoc} tool to99* {@link Doclet#init(Locale, Reporter) initialize} a doclet100* overrides this implementation.101*102* @param kind the kind of diagnostic103* @param file the file104* @param start the beginning of the enclosing range105* @param pos the position106* @param end the end of the enclosing range107* @param message the message to be printed108*109* @since 17110*/111default void print(Diagnostic.Kind kind, FileObject file, int start, int pos, int end, String message) {112throw new UnsupportedOperationException();113}114115/**116* Returns a writer that can be used to write non-diagnostic output,117* or {@code null} if no such writer is available.118*119* @apiNote120* The value may or may not be the same as that returned by {@link #getDiagnosticWriter()}.121*122* @implSpec123* This implementation returns {@code null}.124* The implementation provided by the {@code javadoc} tool to125* {@link Doclet#init(Locale, Reporter) initialize} a doclet126* always returns a non-{@code null} value.127*128* @return the writer129* @since 17130*/131default PrintWriter getStandardWriter() {132return null;133}134135/**136* Returns a writer that can be used to write diagnostic output,137* or {@code null} if no such writer is available.138*139* @apiNote140* The value may or may not be the same as that returned by {@link #getStandardWriter()}.141*142* @implSpec143* This implementation returns {@code null}.144* The implementation provided by the {@code javadoc} tool to145* {@link Doclet#init(Locale, Reporter) initialize} a doclet146* always returns a non-{@code null} value.147*148* @return the writer149* @since 17150*/151default PrintWriter getDiagnosticWriter() {152return null;153}154155}156157158