001 /*
002 * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025 package com.sun.tools.javac.api;
026
027 import java.util.Locale;
028 import javax.tools.Diagnostic;
029
030 /**
031 * Provides simple functionalities for javac diagnostic formatting
032 * @param <D> type of diagnostic handled by this formatter
033 */
034 public interface DiagnosticFormatter<D extends Diagnostic<?>> {
035
036 /**
037 * Whether the source code output for this diagnostic is to be displayed
038 *
039 * @param diag diagnostic to be formatted
040 * @return true if the source line this diagnostic refers to is to be displayed
041 */
042 boolean displaySource(D diag);
043
044 /**
045 * Format the contents of a diagnostics
046 *
047 * @param diag the diagnostic to be formatted
048 * @param l locale object to be used for i18n
049 * @return a string representing the diagnostic
050 */
051 public String format(D diag, Locale l);
052
053 /**
054 * Controls the way in which a diagnostic message is displayed.
055 *
056 * @param diag diagnostic to be formatted
057 * @param l locale object to be used for i18n
058 * @return string representation of the diagnostic message
059 */
060 public String formatMessage(D diag,Locale l);
061
062 /**
063 * Controls the way in which a diagnostic kind is displayed.
064 *
065 * @param diag diagnostic to be formatted
066 * @param l locale object to be used for i18n
067 * @return string representation of the diagnostic prefix
068 */
069 public String formatKind(D diag, Locale l);
070
071 /**
072 * Controls the way in which a diagnostic source is displayed.
073 *
074 * @param diag diagnostic to be formatted
075 * @param l locale object to be used for i18n
076 * @param fullname whether the source fullname should be printed
077 * @return string representation of the diagnostic source
078 */
079 public String formatSource(D diag, boolean fullname, Locale l);
080
081 /**
082 * Controls the way in which a diagnostic position is displayed.
083 *
084 * @param diag diagnostic to be formatted
085 * @param pk enum constant representing the position kind
086 * @param l locale object to be used for i18n
087 * @return string representation of the diagnostic position
088 */
089 public String formatPosition(D diag, PositionKind pk, Locale l);
090 //where
091 /**
092 * This enum defines a set of constants for all the kinds of position
093 * that a diagnostic can be asked for. All positions are intended to be
094 * relative to a given diagnostic source.
095 */
096 public enum PositionKind {
097 /**
098 * Start position
099 */
100 START,
101 /**
102 * End position
103 */
104 END,
105 /**
106 * Line number
107 */
108 LINE,
109 /**
110 * Column number
111 */
112 COLUMN,
113 /**
114 * Offset position
115 */
116 OFFSET
117 }
118 }