Mon, 28 Jul 2008 10:22:10 +0100
6720185: DiagnosticFormatter refactoring
Summary: Brand new hierarchy of diagnostic formatters for achieving better reusability
Reviewed-by: jjg
mcimadamore@83 | 1 | /* |
mcimadamore@83 | 2 | * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. |
mcimadamore@83 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mcimadamore@83 | 4 | * |
mcimadamore@83 | 5 | * This code is free software; you can redistribute it and/or modify it |
mcimadamore@83 | 6 | * under the terms of the GNU General Public License version 2 only, as |
mcimadamore@83 | 7 | * published by the Free Software Foundation. Sun designates this |
mcimadamore@83 | 8 | * particular file as subject to the "Classpath" exception as provided |
mcimadamore@83 | 9 | * by Sun in the LICENSE file that accompanied this code. |
mcimadamore@83 | 10 | * |
mcimadamore@83 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mcimadamore@83 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mcimadamore@83 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mcimadamore@83 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
mcimadamore@83 | 15 | * accompanied this code). |
mcimadamore@83 | 16 | * |
mcimadamore@83 | 17 | * You should have received a copy of the GNU General Public License version |
mcimadamore@83 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
mcimadamore@83 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mcimadamore@83 | 20 | * |
mcimadamore@83 | 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
mcimadamore@83 | 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
mcimadamore@83 | 23 | * have any questions. |
mcimadamore@83 | 24 | */ |
mcimadamore@83 | 25 | package com.sun.tools.javac.api; |
mcimadamore@83 | 26 | |
mcimadamore@83 | 27 | import java.util.Locale; |
mcimadamore@83 | 28 | import javax.tools.Diagnostic; |
mcimadamore@83 | 29 | |
mcimadamore@83 | 30 | /** |
mcimadamore@83 | 31 | * Provides simple functionalities for javac diagnostic formatting |
mcimadamore@83 | 32 | * @param <D> type of diagnostic handled by this formatter |
mcimadamore@83 | 33 | */ |
mcimadamore@83 | 34 | public interface DiagnosticFormatter<D extends Diagnostic<?>> { |
mcimadamore@83 | 35 | |
mcimadamore@83 | 36 | /** |
mcimadamore@83 | 37 | * Whether the source code output for this diagnostic is to be displayed |
mcimadamore@83 | 38 | * |
mcimadamore@83 | 39 | * @param diag diagnostic to be formatted |
mcimadamore@83 | 40 | * @return true if the source line this diagnostic refers to is to be displayed |
mcimadamore@83 | 41 | */ |
mcimadamore@83 | 42 | boolean displaySource(D diag); |
mcimadamore@83 | 43 | |
mcimadamore@83 | 44 | /** |
mcimadamore@83 | 45 | * Format the contents of a diagnostics |
mcimadamore@83 | 46 | * |
mcimadamore@83 | 47 | * @param diag the diagnostic to be formatted |
mcimadamore@83 | 48 | * @param l locale object to be used for i18n |
mcimadamore@83 | 49 | * @return a string representing the diagnostic |
mcimadamore@83 | 50 | */ |
mcimadamore@83 | 51 | public String format(D diag, Locale l); |
mcimadamore@83 | 52 | |
mcimadamore@83 | 53 | /** |
mcimadamore@83 | 54 | * Controls the way in which a diagnostic message is displayed. |
mcimadamore@83 | 55 | * |
mcimadamore@83 | 56 | * @param diag diagnostic to be formatted |
mcimadamore@83 | 57 | * @param l locale object to be used for i18n |
mcimadamore@83 | 58 | * @return string representation of the diagnostic message |
mcimadamore@83 | 59 | */ |
mcimadamore@83 | 60 | public String formatMessage(D diag,Locale l); |
mcimadamore@83 | 61 | |
mcimadamore@83 | 62 | /** |
mcimadamore@83 | 63 | * Controls the way in which a diagnostic kind is displayed. |
mcimadamore@83 | 64 | * |
mcimadamore@83 | 65 | * @param diag diagnostic to be formatted |
mcimadamore@83 | 66 | * @param l locale object to be used for i18n |
mcimadamore@83 | 67 | * @return string representation of the diagnostic prefix |
mcimadamore@83 | 68 | */ |
mcimadamore@83 | 69 | public String formatKind(D diag, Locale l); |
mcimadamore@83 | 70 | |
mcimadamore@83 | 71 | /** |
mcimadamore@83 | 72 | * Controls the way in which a diagnostic source is displayed. |
mcimadamore@83 | 73 | * |
mcimadamore@83 | 74 | * @param diag diagnostic to be formatted |
mcimadamore@83 | 75 | * @param l locale object to be used for i18n |
mcimadamore@83 | 76 | * @return string representation of the diagnostic source |
mcimadamore@83 | 77 | */ |
mcimadamore@83 | 78 | public String formatSource(D diag, Locale l); |
mcimadamore@83 | 79 | |
mcimadamore@83 | 80 | /** |
mcimadamore@83 | 81 | * Controls the way in which a diagnostic position is displayed. |
mcimadamore@83 | 82 | * |
mcimadamore@83 | 83 | * @param diag diagnostic to be formatted |
mcimadamore@83 | 84 | * @param pk enum constant representing the position kind |
mcimadamore@83 | 85 | * @param l locale object to be used for i18n |
mcimadamore@83 | 86 | * @return string representation of the diagnostic position |
mcimadamore@83 | 87 | */ |
mcimadamore@83 | 88 | public String formatPosition(D diag, PositionKind pk, Locale l); |
mcimadamore@83 | 89 | //where |
mcimadamore@83 | 90 | /** |
mcimadamore@83 | 91 | * This enum defines a set of constants for all the kinds of position |
mcimadamore@83 | 92 | * that a diagnostic can be asked for. All positions are intended to be |
mcimadamore@83 | 93 | * relative to a given diagnostic source. |
mcimadamore@83 | 94 | */ |
mcimadamore@83 | 95 | public enum PositionKind { |
mcimadamore@83 | 96 | /** |
mcimadamore@83 | 97 | * Start position |
mcimadamore@83 | 98 | */ |
mcimadamore@83 | 99 | START, |
mcimadamore@83 | 100 | /** |
mcimadamore@83 | 101 | * End position |
mcimadamore@83 | 102 | */ |
mcimadamore@83 | 103 | END, |
mcimadamore@83 | 104 | /** |
mcimadamore@83 | 105 | * Line number |
mcimadamore@83 | 106 | */ |
mcimadamore@83 | 107 | LINE, |
mcimadamore@83 | 108 | /** |
mcimadamore@83 | 109 | * Column number |
mcimadamore@83 | 110 | */ |
mcimadamore@83 | 111 | COLUMN, |
mcimadamore@83 | 112 | /** |
mcimadamore@83 | 113 | * Offset position |
mcimadamore@83 | 114 | */ |
mcimadamore@83 | 115 | OFFSET |
mcimadamore@83 | 116 | } |
mcimadamore@83 | 117 | } |