# HG changeset patch # User mcimadamore # Date 1217236930 -3600 # Node ID 98e1d4f8aacdb31a201700423bcd31889e469e3b # Parent 2589047a9c5de21334ea715413beda9f8753674f 6720185: DiagnosticFormatter refactoring Summary: Brand new hierarchy of diagnostic formatters for achieving better reusability Reviewed-by: jjg diff -r 2589047a9c5d -r 98e1d4f8aacd langtools/src/share/classes/com/sun/tools/javac/api/DiagnosticFormatter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/src/share/classes/com/sun/tools/javac/api/DiagnosticFormatter.java Mon Jul 28 10:22:10 2008 +0100 @@ -0,0 +1,117 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * 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. + */ +package com.sun.tools.javac.api; + +import java.util.Locale; +import javax.tools.Diagnostic; + +/** + * Provides simple functionalities for javac diagnostic formatting + * @param type of diagnostic handled by this formatter + */ +public interface DiagnosticFormatter> { + + /** + * Whether the source code output for this diagnostic is to be displayed + * + * @param diag diagnostic to be formatted + * @return true if the source line this diagnostic refers to is to be displayed + */ + boolean displaySource(D diag); + + /** + * Format the contents of a diagnostics + * + * @param diag the diagnostic to be formatted + * @param l locale object to be used for i18n + * @return a string representing the diagnostic + */ + public String format(D diag, Locale l); + + /** + * Controls the way in which a diagnostic message is displayed. + * + * @param diag diagnostic to be formatted + * @param l locale object to be used for i18n + * @return string representation of the diagnostic message + */ + public String formatMessage(D diag,Locale l); + + /** + * Controls the way in which a diagnostic kind is displayed. + * + * @param diag diagnostic to be formatted + * @param l locale object to be used for i18n + * @return string representation of the diagnostic prefix + */ + public String formatKind(D diag, Locale l); + + /** + * Controls the way in which a diagnostic source is displayed. + * + * @param diag diagnostic to be formatted + * @param l locale object to be used for i18n + * @return string representation of the diagnostic source + */ + public String formatSource(D diag, Locale l); + + /** + * Controls the way in which a diagnostic position is displayed. + * + * @param diag diagnostic to be formatted + * @param pk enum constant representing the position kind + * @param l locale object to be used for i18n + * @return string representation of the diagnostic position + */ + public String formatPosition(D diag, PositionKind pk, Locale l); + //where + /** + * This enum defines a set of constants for all the kinds of position + * that a diagnostic can be asked for. All positions are intended to be + * relative to a given diagnostic source. + */ + public enum PositionKind { + /** + * Start position + */ + START, + /** + * End position + */ + END, + /** + * Line number + */ + LINE, + /** + * Column number + */ + COLUMN, + /** + * Offset position + */ + OFFSET + } +} diff -r 2589047a9c5d -r 98e1d4f8aacd langtools/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java Mon Jul 28 10:22:10 2008 +0100 @@ -0,0 +1,169 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * 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. + */ +package com.sun.tools.javac.util; + +import java.util.Collection; +import java.util.Locale; +import javax.tools.JavaFileObject; + +import com.sun.tools.javac.api.DiagnosticFormatter; +import com.sun.tools.javac.api.Formattable; +import com.sun.tools.javac.api.DiagnosticFormatter.PositionKind; +import com.sun.tools.javac.file.JavacFileManager; + +/** + * 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: + * + *