src/share/classes/javax/tools/Diagnostic.java

changeset 1
9a66ca7c79fa
child 554
9d9f26857129
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/javax/tools/Diagnostic.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,170 @@
     1.4 +/*
     1.5 + * Copyright 2005-2006 Sun Microsystems, Inc.  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.  Sun designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.26 + * have any questions.
    1.27 + */
    1.28 +
    1.29 +package javax.tools;
    1.30 +
    1.31 +import java.util.Locale;
    1.32 +
    1.33 +/**
    1.34 + * Interface for diagnostics from tools.  A diagnostic usually reports
    1.35 + * a problem at a specific position in a source file.  However, not
    1.36 + * all diagnostics are associated with a position or a file.
    1.37 + *
    1.38 + * <p>A position is a zero-based character offset from the beginning of
    1.39 + * a file.  Negative values (except {@link #NOPOS}) are not valid
    1.40 + * positions.
    1.41 + *
    1.42 + * <p>Line and column numbers begin at 1.  Negative values (except
    1.43 + * {@link #NOPOS}) and 0 are not valid line or column numbers.
    1.44 + *
    1.45 + * @param <S> the type of source object used by this diagnostic
    1.46 + *
    1.47 + * @author Peter von der Ah&eacute;
    1.48 + * @author Jonathan Gibbons
    1.49 + * @since 1.6
    1.50 + */
    1.51 +public interface Diagnostic<S> {
    1.52 +
    1.53 +    /**
    1.54 +     * Kinds of diagnostics, for example, error or warning.
    1.55 +     */
    1.56 +    enum Kind {
    1.57 +        /**
    1.58 +         * Problem which prevents the tool's normal completion.
    1.59 +         */
    1.60 +        ERROR,
    1.61 +        /**
    1.62 +         * Problem which does not usually prevent the tool from
    1.63 +         * completing normally.
    1.64 +         */
    1.65 +        WARNING,
    1.66 +        /**
    1.67 +         * Problem similar to a warning, but is mandated by the tool's
    1.68 +         * specification.  For example, the Java&trade; Language
    1.69 +         * Specification, 3rd Ed. mandates warnings on certain
    1.70 +         * unchecked operations and the use of deprecated methods.
    1.71 +         */
    1.72 +        MANDATORY_WARNING,
    1.73 +        /**
    1.74 +         * Informative message from the tool.
    1.75 +         */
    1.76 +        NOTE,
    1.77 +        /**
    1.78 +         * Diagnostic which does not fit within the other kinds.
    1.79 +         */
    1.80 +        OTHER,
    1.81 +    }
    1.82 +
    1.83 +    /**
    1.84 +     * Used to signal that no position is available.
    1.85 +     */
    1.86 +    public final static long NOPOS = -1;
    1.87 +
    1.88 +    /**
    1.89 +     * Gets the kind of this diagnostic, for example, error or
    1.90 +     * warning.
    1.91 +     * @return the kind of this diagnostic
    1.92 +     */
    1.93 +    Kind getKind();
    1.94 +
    1.95 +    /**
    1.96 +     * Gets the source object associated with this diagnostic.
    1.97 +     *
    1.98 +     * @return the source object associated with this diagnostic.
    1.99 +     * {@code null} if no source object is associated with the
   1.100 +     * diagnostic.
   1.101 +     */
   1.102 +    S getSource();
   1.103 +
   1.104 +    /**
   1.105 +     * Gets a character offset from the beginning of the source object
   1.106 +     * associated with this diagnostic that indicates the location of
   1.107 +     * the problem.  In addition, the following must be true:
   1.108 +     *
   1.109 +     * <p>{@code getStartPostion() <= getPosition()}
   1.110 +     * <p>{@code getPosition() <= getEndPosition()}
   1.111 +     *
   1.112 +     * @return character offset from beginning of source; {@link
   1.113 +     * #NOPOS} if {@link #getSource()} would return {@code null} or if
   1.114 +     * no location is suitable
   1.115 +     */
   1.116 +    long getPosition();
   1.117 +
   1.118 +    /**
   1.119 +     * Gets the character offset from the beginning of the file
   1.120 +     * associated with this diagnostic that indicates the start of the
   1.121 +     * problem.
   1.122 +     *
   1.123 +     * @return offset from beginning of file; {@link #NOPOS} if and
   1.124 +     * only if {@link #getPosition()} returns {@link #NOPOS}
   1.125 +     */
   1.126 +    long getStartPosition();
   1.127 +
   1.128 +    /**
   1.129 +     * Gets the character offset from the beginning of the file
   1.130 +     * associated with this diagnostic that indicates the end of the
   1.131 +     * problem.
   1.132 +     *
   1.133 +     * @return offset from beginning of file; {@link #NOPOS} if and
   1.134 +     * only if {@link #getPosition()} returns {@link #NOPOS}
   1.135 +     */
   1.136 +    long getEndPosition();
   1.137 +
   1.138 +    /**
   1.139 +     * Gets the line number of the character offset returned by
   1.140 +     * {@linkplain #getPosition()}.
   1.141 +     *
   1.142 +     * @return a line number or {@link #NOPOS} if and only if {@link
   1.143 +     * #getPosition()} returns {@link #NOPOS}
   1.144 +     */
   1.145 +    long getLineNumber();
   1.146 +
   1.147 +    /**
   1.148 +     * Gets the column number of the character offset returned by
   1.149 +     * {@linkplain #getPosition()}.
   1.150 +     *
   1.151 +     * @return a column number or {@link #NOPOS} if and only if {@link
   1.152 +     * #getPosition()} returns {@link #NOPOS}
   1.153 +     */
   1.154 +    long getColumnNumber();
   1.155 +
   1.156 +    /**
   1.157 +     * Gets a diagnostic code indicating the type of diagnostic.  The
   1.158 +     * code is implementation-dependent and might be {@code null}.
   1.159 +     *
   1.160 +     * @return a diagnostic code
   1.161 +     */
   1.162 +    String getCode();
   1.163 +
   1.164 +    /**
   1.165 +     * Gets a localized message for the given locale.  The actual
   1.166 +     * message is implementation-dependent.  If the locale is {@code
   1.167 +     * null} use the default locale.
   1.168 +     *
   1.169 +     * @param locale a locale; might be {@code null}
   1.170 +     * @return a localized message
   1.171 +     */
   1.172 +    String getMessage(Locale locale);
   1.173 +}

mercurial