REPL code review -- TypePrinter

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Sep 21 00:06:30 UTC 2015



On 19/09/15 20:29, Robert Field wrote:
>
> On 09/11/15 08:25, Maurizio Cimadamore wrote:
>> * TypePrinter - so, this is needed when you need to print the type of 
>> some expression; it seems the exact copy of the printer used by the 
>> RichDiagnosticFormatter, except for the fact that you want to omit 
>> the captured type-variable details. So, maybe you could split this 
>> process in two: first you map the original type onto a type where all 
>> captured variables have been replaced by their bounds (i.e from 
>> List<#CAP1> to List<Object>) - then you call the 
>> RichDiagnosticFormatter printer onto it (the best way to do that 
>> would probably be to create a fake diagnostic with a type as its 
>> argument, and then feed that to the diagnostic formatter - that 
>> should give you back a string). The RichDiagnosticFormatter, by 
>> default will also generate stuff that you probably don't want, such 
>> as 'where' clauses to disambiguate type-variable names with the same 
>> names but different owners - but such features can be selectively 
>> disabled (via javac command line options).
>
> By "the printer used by the RichDiagnosticFormatter" do you mean 
> RichDiagnosticFormatter.RichPrinter?  They are both subclasses of 
> Printer and share similar structures.
>
> That approach seems convoluted and fragile.  Am I missing something?
I'm just saying that there's a very sophisticated and configurable 
type/symbol printer (RichDiagnosticFormatter.RichPrinter) - so it seems 
a bit odd to see some of the same goodies available in that printer 
being almost exactly replicated there. If there was a way to reuse the 
rich printer code in some way, I would say that should lead to more 
maintainable code in the long run.

Maurizio
>
> -Robert
>



More information about the kulla-dev mailing list