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