Path: blob/master/src/jdk.javadoc/share/classes/jdk/javadoc/doclet/Reporter.java
41159 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* @param kind the kind of diagnostic97* @param file the file98* @param start the beginning of the enclosing range99* @param pos the position100* @param end the end of the enclosing range101* @param message the message to be printed102*103* @since 17104*/105void print(Diagnostic.Kind kind, FileObject file, int start, int pos, int end, String message);106107/**108* Returns a writer that can be used to write non-diagnostic output,109* or {@code null} if no such writer is available.110*111* @apiNote112* The value may or may not be the same as that returned by {@link #getDiagnosticWriter()}.113*114* @implSpec115* This implementation returns {@code null}.116* The implementation provided by the {@code javadoc} tool to117* {@link Doclet#init(Locale, Reporter) initialize} a doclet118* always returns a non-{@code null} value.119*120* @return the writer121* @since 17122*/123default PrintWriter getStandardWriter() {124return null;125}126127/**128* Returns a writer that can be used to write diagnostic output,129* or {@code null} if no such writer is available.130*131* @apiNote132* The value may or may not be the same as that returned by {@link #getStandardWriter()}.133*134* @implSpec135* This implementation returns {@code null}.136* The implementation provided by the {@code javadoc} tool to137* {@link Doclet#init(Locale, Reporter) initialize} a doclet138* always returns a non-{@code null} value.139*140* @return the writer141* @since 17142*/143default PrintWriter getDiagnosticWriter() {144return null;145}146147}148149150