src/share/classes/com/sun/tools/javac/api/DiagnosticFormatter.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/api/DiagnosticFormatter.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,218 @@
     1.4 +/*
     1.5 + * Copyright (c) 2008, 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 com.sun.tools.javac.api;
    1.29 +
    1.30 +import java.util.Locale;
    1.31 +import java.util.Set;
    1.32 +import javax.tools.Diagnostic;
    1.33 +import com.sun.tools.javac.api.DiagnosticFormatter.*;
    1.34 +
    1.35 +/**
    1.36 + * Provides simple functionalities for javac diagnostic formatting.
    1.37 + * @param <D> type of diagnostic handled by this formatter
    1.38 + *
    1.39 + * <p><b>This is NOT part of any supported API.
    1.40 + * If you write code that depends on this, you do so at your own risk.
    1.41 + * This code and its internal interfaces are subject to change or
    1.42 + * deletion without notice.</b>
    1.43 + */
    1.44 +public interface DiagnosticFormatter<D extends Diagnostic<?>> {
    1.45 +
    1.46 +    /**
    1.47 +     * Whether the source code output for this diagnostic is to be displayed.
    1.48 +     *
    1.49 +     * @param diag diagnostic to be formatted
    1.50 +     * @return true if the source line this diagnostic refers to is to be displayed
    1.51 +     */
    1.52 +    boolean displaySource(D diag);
    1.53 +
    1.54 +    /**
    1.55 +     * Format the contents of a diagnostics.
    1.56 +     *
    1.57 +     * @param diag the diagnostic to be formatted
    1.58 +     * @param l locale object to be used for i18n
    1.59 +     * @return a string representing the diagnostic
    1.60 +     */
    1.61 +    public String format(D diag, Locale l);
    1.62 +
    1.63 +    /**
    1.64 +     * Controls the way in which a diagnostic message is displayed.
    1.65 +     *
    1.66 +     * @param diag diagnostic to be formatted
    1.67 +     * @param l locale object to be used for i18n
    1.68 +     * @return string representation of the diagnostic message
    1.69 +     */
    1.70 +    public String formatMessage(D diag,Locale l);
    1.71 +
    1.72 +    /**
    1.73 +     * Controls the way in which a diagnostic kind is displayed.
    1.74 +     *
    1.75 +     * @param diag diagnostic to be formatted
    1.76 +     * @param l locale object to be used for i18n
    1.77 +     * @return string representation of the diagnostic prefix
    1.78 +     */
    1.79 +    public String formatKind(D diag, Locale l);
    1.80 +
    1.81 +    /**
    1.82 +     * Controls the way in which a diagnostic source is displayed.
    1.83 +     *
    1.84 +     * @param diag diagnostic to be formatted
    1.85 +     * @param l locale object to be used for i18n
    1.86 +     * @param fullname whether the source fullname should be printed
    1.87 +     * @return string representation of the diagnostic source
    1.88 +     */
    1.89 +    public String formatSource(D diag, boolean fullname, Locale l);
    1.90 +
    1.91 +    /**
    1.92 +     * Controls the way in which a diagnostic position is displayed.
    1.93 +     *
    1.94 +     * @param diag diagnostic to be formatted
    1.95 +     * @param pk enum constant representing the position kind
    1.96 +     * @param l locale object to be used for i18n
    1.97 +     * @return string representation of the diagnostic position
    1.98 +     */
    1.99 +    public String formatPosition(D diag, PositionKind pk, Locale l);
   1.100 +    //where
   1.101 +    /**
   1.102 +     * This enum defines a set of constants for all the kinds of position
   1.103 +     * that a diagnostic can be asked for. All positions are intended to be
   1.104 +     * relative to a given diagnostic source.
   1.105 +     */
   1.106 +    public enum PositionKind {
   1.107 +        /**
   1.108 +         * Start position
   1.109 +         */
   1.110 +        START,
   1.111 +        /**
   1.112 +         * End position
   1.113 +         */
   1.114 +        END,
   1.115 +        /**
   1.116 +         * Line number
   1.117 +         */
   1.118 +        LINE,
   1.119 +        /**
   1.120 +         * Column number
   1.121 +         */
   1.122 +        COLUMN,
   1.123 +        /**
   1.124 +         * Offset position
   1.125 +         */
   1.126 +        OFFSET
   1.127 +    }
   1.128 +
   1.129 +    /**
   1.130 +     * Get a list of all the enabled verbosity options.
   1.131 +     * @return verbosity options
   1.132 +     */
   1.133 +    public Configuration getConfiguration();
   1.134 +    //where
   1.135 +
   1.136 +    /**
   1.137 +     * This interface provides functionalities for tuning the output of a
   1.138 +     * diagnostic formatter in multiple ways.
   1.139 +     */
   1.140 +    interface Configuration {
   1.141 +        /**
   1.142 +         * Configure the set of diagnostic parts that should be displayed
   1.143 +         * by the formatter.
   1.144 +         * @param visibleParts the parts to be set
   1.145 +         */
   1.146 +        public void setVisible(Set<DiagnosticPart> visibleParts);
   1.147 +
   1.148 +        /**
   1.149 +         * Retrieve the set of diagnostic parts that should be displayed
   1.150 +         * by the formatter.
   1.151 +         * @return verbosity options
   1.152 +         */
   1.153 +        public Set<DiagnosticPart> getVisible();
   1.154 +
   1.155 +        //where
   1.156 +        /**
   1.157 +         * A given diagnostic message can be divided into sub-parts each of which
   1.158 +         * might/might not be displayed by the formatter, according to the
   1.159 +         * current configuration settings.
   1.160 +         */
   1.161 +        public enum DiagnosticPart {
   1.162 +            /**
   1.163 +             * Short description of the diagnostic - usually one line long.
   1.164 +             */
   1.165 +            SUMMARY,
   1.166 +            /**
   1.167 +             * Longer description that provides additional details w.r.t. the ones
   1.168 +             * in the diagnostic's description.
   1.169 +             */
   1.170 +            DETAILS,
   1.171 +            /**
   1.172 +             * Source line the diagnostic refers to (if applicable).
   1.173 +             */
   1.174 +            SOURCE,
   1.175 +            /**
   1.176 +             * Subdiagnostics attached to a given multiline diagnostic.
   1.177 +             */
   1.178 +            SUBDIAGNOSTICS,
   1.179 +            /**
   1.180 +             * JLS paragraph this diagnostic might refer to (if applicable).
   1.181 +             */
   1.182 +            JLS;
   1.183 +        }
   1.184 +
   1.185 +        /**
   1.186 +         * Set a limit for multiline diagnostics.
   1.187 +         * Note: Setting a limit has no effect if multiline diagnostics are either
   1.188 +         * fully enabled or disabled.
   1.189 +         *
   1.190 +         * @param limit the kind of limit to be set
   1.191 +         * @param value the limit value
   1.192 +         */
   1.193 +        public void setMultilineLimit(MultilineLimit limit, int value);
   1.194 +
   1.195 +        /**
   1.196 +         * Get a multiline diagnostic limit.
   1.197 +         *
   1.198 +         * @param limit the kind of limit to be retrieved
   1.199 +         * @return limit value or -1 if no limit is set
   1.200 +         */
   1.201 +        public int getMultilineLimit(MultilineLimit limit);
   1.202 +        //where
   1.203 +        /**
   1.204 +         * A multiline limit control the verbosity of multiline diagnostics
   1.205 +         * either by setting a maximum depth of nested multidiagnostics,
   1.206 +         * or by limiting the amount of subdiagnostics attached to a given
   1.207 +         * diagnostic (or both).
   1.208 +         */
   1.209 +        public enum MultilineLimit {
   1.210 +            /**
   1.211 +             * Controls the maximum depth of nested multiline diagnostics.
   1.212 +             */
   1.213 +            DEPTH,
   1.214 +            /**
   1.215 +             * Controls the maximum amount of subdiagnostics that are part of a
   1.216 +             * given multiline diagnostic.
   1.217 +             */
   1.218 +            LENGTH;
   1.219 +        }
   1.220 +    }
   1.221 +}

mercurial