AbstractDiagnosticFormatter.java revision 414
/*
* Copyright 2008-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* This abstract class provides a basic implementation of the functionalities that should be provided
* by any formatter used by javac. Among the main features provided by AbstractDiagnosticFormatter are:
*
* <ul>
* <li> Provides a standard implementation of the visitor-like methods defined in the interface DiagnisticFormatter.
* Those implementations are specifically targeting JCDiagnostic objects.
* <li> Provides basic support for i18n and a method for executing all locale-dependent conversions
* <li> Provides the formatting logic for rendering the arguments of a JCDiagnostic object.
* <ul>
*
* <p><b>This is NOT part of any API supported by Sun Microsystems.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*/
/**
* JavacMessages object used by this formatter for i18n.
*/
protected JavacMessages messages;
/**
* Configuration object used by this formatter
*/
private SimpleConfiguration config;
/**
* Current depth level of the disgnostic being formatted
* (!= 0 for subdiagnostics)
*/
protected int depth = 0;
/**
* All captured types that have been encountered during diagnostic formatting.
* This info is used by the FormatterPrinter in order to print friendly unique
* ids for captured types
*/
/**
* Initialize an AbstractDiagnosticFormatter by setting its JavacMessages object.
* @param messages
*/
}
switch (d.getType()) {
case FRAGMENT: return "";
default:
}
}
return formatDiagnostic(d, locale);
}
}
//where
switch (pk) {
case START: return d.getIntStartPosition();
case END: return d.getIntEndPosition();
case LINE: return d.getLineNumber();
case COLUMN: return d.getColumnNumber();
case OFFSET: return d.getIntPosition();
default:
}
}
throw new IllegalArgumentException(); // d should have source set
if (fullname)
else if (fo instanceof BaseFileObject)
else
}
/**
* Format the arguments of a given diagnostic.
*
* @param d diagnostic whose arguments are to be formatted
* @param l locale object to be used for i18n
* @return a Collection whose elements are the formatted arguments of the diagnostic
*/
}
}
/**
* Format a single argument of a given diagnostic.
*
* @param d diagnostic whose argument is to be formatted
* @param arg argument to be formatted
* @param l locale object to be used for i18n
* @return string representation of the diagnostic argument
*/
if (arg instanceof JCDiagnostic) {
depth++;
try {
}
finally {
depth--;
}
return s;
}
}
}
}
else if (arg instanceof JavaFileObject) {
}
else if (arg instanceof Formattable) {
}
else {
}
}
/**
* Format an iterable argument of a given diagnostic.
*
* @param d diagnostic whose argument is to be formatted
* @param it iterable argument to be formatted
* @param l locale object to be used for i18n
* @return string representation of the diagnostic iterable argument
*/
sep = ",";
}
}
/**
* Format all the subdiagnostics attached to a given diagnostic.
*
* @param d diagnostic whose subdiagnostics are to be formatted
* @param l locale object to be used for i18n
* @return list of all string representations of the subdiagnostics
*/
depth++;
try {
int count = 0;
count++;
}
else
break;
}
}
finally {
depth--;
}
}
return subdiagnostics;
}
/**
* Format a subdiagnostics attached to a given diagnostic.
*
* @param parent multiline diagnostic whose subdiagnostics is to be formatted
* @param sub subdiagnostic to be formatted
* @param l locale object to be used for i18n
* @return string representation of the subdiagnostics
*/
return formatMessage(sub, l);
}
/** Format the faulty source code line and point to the error.
* @param d The diagnostic for which the error line should be printed
*/
int pos = d.getIntPosition();
throw new AssertionError();
return "";
if (config.isCaretEnabled()) {
}
}
}
/**
* Converts a String into a locale-dependent representation accordingly to a given locale.
*
* @param l locale object to be used for i18n
* @param key locale-independent key used for looking up in a resource file
* @param args localization arguments
* @return a locale-dependent string
*/
}
public boolean displaySource(JCDiagnostic d) {
}
public boolean isRaw() {
return false;
}
/**
* Creates a string with a given amount of empty spaces. Useful for
* indenting the text of a diagnostic message.
*
* @param nSpaces the amount of spaces to be added to the result string
* @return the indentation string
*/
else {
for (int i = 0 ; i < nSpaces ; i++)
}
}
/**
* Indent a string by prepending a given amount of empty spaces to each line
* of the string.
*
* @param s the string to be indented
* @param nSpaces the amount of spaces that should be prepended to each line
* of the string
* @return an indented string
*/
nl = "\n";
}
}
public SimpleConfiguration getConfiguration() {
return config;
}
static public class SimpleConfiguration implements Configuration {
protected boolean caretEnabled;
setCaretEnabled(true);
}
@SuppressWarnings("fallthrough")
this(parts);
}
}
}
try {
case 2: {
}
case 1: {
}
}
}
catch(NumberFormatException ex) {
}
}
}
setCaretEnabled(false);
else
setCaretEnabled(true);
}
}
}
}
}
if (enabled)
else
}
/**
* Shows a '^' sign under the source line displayed by the formatter
* (if applicable).
*
* @param caretEnabled if true enables caret
*/
public void setCaretEnabled(boolean caretEnabled) {
this.caretEnabled = caretEnabled;
}
/**
* Tells whether the caret display is active or not.
*
* @param caretEnabled if true the caret is enabled
*/
public boolean isCaretEnabled() {
return caretEnabled;
}
}
public Printer getPrinter() {
return printer;
}
}
/**
* AbstractDiagnosticFormatter. Provides alternate numbering of captured
* types (they are numbered starting from 1 on each new diagnostic, instead
* of relying on the underlying hashcode() method which generates unstable
* output). Also detects cycles in wildcard messages (e.g. if the wildcard
* type referred by a given captured type C contains C itself) which might
* lead to infinite loops.
*/
}
}
if (!allCaptured.contains(t)) {
}
return super.visitCapturedType(t, locale);
}
};
}