src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java

changeset 304
1d9e61e0a075
parent 288
d402db1005ad
child 326
90d40dd5cfc7
equal deleted inserted replaced
303:8ec37cf2b37e 304:1d9e61e0a075
66 final Types types; 66 final Types types;
67 final JCDiagnostic.Factory diags; 67 final JCDiagnostic.Factory diags;
68 final JavacMessages messages; 68 final JavacMessages messages;
69 69
70 /* name simplifier used by this formatter */ 70 /* name simplifier used by this formatter */
71 ClassNameSimplifier nameSimplifier; 71 protected ClassNameSimplifier nameSimplifier;
72
73 /* type/symbol printer used by this formatter */
74 private RichPrinter printer;
72 75
73 /* map for keeping track of a where clause associated to a given type */ 76 /* map for keeping track of a where clause associated to a given type */
74 Map<WhereClauseKind, Map<Type, JCDiagnostic>> whereClauses; 77 Map<WhereClauseKind, Map<Type, JCDiagnostic>> whereClauses;
75 78
76 /** Get the DiagnosticFormatter instance for this context. */ 79 /** Get the DiagnosticFormatter instance for this context. */
81 return instance; 84 return instance;
82 } 85 }
83 86
84 protected RichDiagnosticFormatter(Context context) { 87 protected RichDiagnosticFormatter(Context context) {
85 super((AbstractDiagnosticFormatter)Log.instance(context).getDiagnosticFormatter()); 88 super((AbstractDiagnosticFormatter)Log.instance(context).getDiagnosticFormatter());
86 this.formatter.setPrinter(printer); 89 setRichPrinter(new RichPrinter());
87 this.syms = Symtab.instance(context); 90 this.syms = Symtab.instance(context);
88 this.diags = JCDiagnostic.Factory.instance(context); 91 this.diags = JCDiagnostic.Factory.instance(context);
89 this.types = Types.instance(context); 92 this.types = Types.instance(context);
90 this.messages = JavacMessages.instance(context); 93 this.messages = JavacMessages.instance(context);
91 whereClauses = new LinkedHashMap<WhereClauseKind, Map<Type, JCDiagnostic>>(); 94 whereClauses = new LinkedHashMap<WhereClauseKind, Map<Type, JCDiagnostic>>();
115 } 118 }
116 return sb.toString(); 119 return sb.toString();
117 } 120 }
118 121
119 /** 122 /**
123 * Sets the type/symbol printer used by this formatter.
124 * @param printer the rich printer to be set
125 */
126 protected void setRichPrinter(RichPrinter printer) {
127 this.printer = printer;
128 formatter.setPrinter(printer);
129 }
130
131 /**
132 * Gets the type/symbol printer used by this formatter.
133 * @return type/symbol rich printer
134 */
135 protected RichPrinter getRichPrinter() {
136 return printer;
137 }
138
139 /**
120 * Preprocess a given diagnostic by looking both into its arguments and into 140 * Preprocess a given diagnostic by looking both into its arguments and into
121 * its subdiagnostics (if any). This preprocessing is responsible for 141 * its subdiagnostics (if any). This preprocessing is responsible for
122 * generating info corresponding to features like where clauses, name 142 * generating info corresponding to features like where clauses, name
123 * simplification, etc. 143 * simplification, etc.
124 * 144 *
215 * whether a class name can be compacted or not. Short names are not used 235 * whether a class name can be compacted or not. Short names are not used
216 * if a conflict is detected, e.g. when two classes with the same simple 236 * if a conflict is detected, e.g. when two classes with the same simple
217 * name belong to different packages - in this case the formatter reverts 237 * name belong to different packages - in this case the formatter reverts
218 * to fullnames as compact names might lead to a confusing diagnostic. 238 * to fullnames as compact names might lead to a confusing diagnostic.
219 */ 239 */
220 class ClassNameSimplifier { 240 protected class ClassNameSimplifier {
221 241
222 /* table for keeping track of all short name usages */ 242 /* table for keeping track of all short name usages */
223 Map<Name, List<Symbol>> nameClashes = new HashMap<Name, List<Symbol>>(); 243 Map<Name, List<Symbol>> nameClashes = new HashMap<Name, List<Symbol>>();
224 244
225 /** 245 /**
270 * Enhanced type/symbol printer that provides support for features like simple names 290 * Enhanced type/symbol printer that provides support for features like simple names
271 * and type variable disambiguation. This enriched printer exploits the info 291 * and type variable disambiguation. This enriched printer exploits the info
272 * discovered during type/symbol preprocessing. This printer is set on the delegate 292 * discovered during type/symbol preprocessing. This printer is set on the delegate
273 * formatter so that rich type/symbol info can be properly rendered. 293 * formatter so that rich type/symbol info can be properly rendered.
274 */ 294 */
275 protected Printer printer = new Printer() { 295 protected class RichPrinter extends Printer {
276 296
277 @Override 297 @Override
278 public String localize(Locale locale, String key, Object... args) { 298 public String localize(Locale locale, String key, Object... args) {
279 return formatter.localize(locale, key, args); 299 return formatter.localize(locale, key, args);
280 } 300 }

mercurial