OpenJDK / lambda / collections / langtools
changeset 303:1d9e61e0a075
6852649: The Rich formatter printer should be an explicit class to facilitate overriding
Summary: Improve reusabiliy of the rich formatter by removing anonymous inner classes/changing visibility of fields
Reviewed-by: jjg
author | mcimadamore |
---|---|
date | Wed, 24 Jun 2009 10:51:13 +0100 |
parents | 8ec37cf2b37e |
children | 812d5486a023 |
files | src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java |
diffstat | 2 files changed, 25 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java Wed Jun 24 10:50:54 2009 +0100 +++ b/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java Wed Jun 24 10:51:13 2009 +0100 @@ -109,7 +109,7 @@ return formatDiagnostic(d, locale); } - abstract String formatDiagnostic(JCDiagnostic d, Locale locale); + protected abstract String formatDiagnostic(JCDiagnostic d, Locale locale); public String formatPosition(JCDiagnostic d, PositionKind pk,Locale l) { assert (d.getPosition() != Position.NOPOS);
--- a/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Wed Jun 24 10:50:54 2009 +0100 +++ b/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Wed Jun 24 10:51:13 2009 +0100 @@ -68,7 +68,10 @@ final JavacMessages messages; /* name simplifier used by this formatter */ - ClassNameSimplifier nameSimplifier; + protected ClassNameSimplifier nameSimplifier; + + /* type/symbol printer used by this formatter */ + private RichPrinter printer; /* map for keeping track of a where clause associated to a given type */ Map<WhereClauseKind, Map<Type, JCDiagnostic>> whereClauses; @@ -83,7 +86,7 @@ protected RichDiagnosticFormatter(Context context) { super((AbstractDiagnosticFormatter)Log.instance(context).getDiagnosticFormatter()); - this.formatter.setPrinter(printer); + setRichPrinter(new RichPrinter()); this.syms = Symtab.instance(context); this.diags = JCDiagnostic.Factory.instance(context); this.types = Types.instance(context); @@ -117,6 +120,23 @@ } /** + * Sets the type/symbol printer used by this formatter. + * @param printer the rich printer to be set + */ + protected void setRichPrinter(RichPrinter printer) { + this.printer = printer; + formatter.setPrinter(printer); + } + + /** + * Gets the type/symbol printer used by this formatter. + * @return type/symbol rich printer + */ + protected RichPrinter getRichPrinter() { + return printer; + } + + /** * Preprocess a given diagnostic by looking both into its arguments and into * its subdiagnostics (if any). This preprocessing is responsible for * generating info corresponding to features like where clauses, name @@ -217,7 +237,7 @@ * name belong to different packages - in this case the formatter reverts * to fullnames as compact names might lead to a confusing diagnostic. */ - class ClassNameSimplifier { + protected class ClassNameSimplifier { /* table for keeping track of all short name usages */ Map<Name, List<Symbol>> nameClashes = new HashMap<Name, List<Symbol>>(); @@ -272,7 +292,7 @@ * discovered during type/symbol preprocessing. This printer is set on the delegate * formatter so that rich type/symbol info can be properly rendered. */ - protected Printer printer = new Printer() { + protected class RichPrinter extends Printer { @Override public String localize(Locale locale, String key, Object... args) {