Reuse of Java Data Type Renderer expressions
I'm working on writing data type renderers for Java in IntelliJ 2016.2 and ran into some annoyances when trying to refer to data type renderers from within other
renderers (in order to reuse renderer work I had already done). Two examples (I attached my sample code and screenshots of Variables window in a debugging session)
Example #1. I'm writing a renderer for a wrapper class. This class (MyFruitWrapper) contains a reference to another object (MyFruit). I already have a renderer written for the MyFruit class and I'd like to have MyFruitWrapper reuse that renderer.
I tried writing expressions for "MyFruitWrapper" such as:
((MyFruit)this.fruit)
...to try to get it to use the MyFruit renderer. No luck.
So, I could obviously expand a MyFruitWrapper object in the "Variables" pane when debugging and see the "fruit" data member with its MyFruit renderer. But, that requires an extra click. And, when I have a List of MyFruitWrapper objects (see "wrappers" List in screenshot), I want to see the MyFruit renderer applied for each item in the list without expanding each item. And, yes, I could write an expression for MyFruitWrapper that would use the data members/methods of "fruit" to build up an expression for MyFruitWrapper. But, this is duplicate effort as I already have a renderer defined for MyFruit.
Example #2. When authoring a data type expression for a class (MySubFruit) that derives from another class (MyFruit) I would like to use the renderer for the parent class when defining the child class expression. I tried things like this...
((MyFruit)this) + " size: " + this.size
...to try and use the base MyFruit renderer and decorate its results with the extra MySubFruit.size member. But, no luck.
Is there any way to reuse existing data type renderer expressions? Yes, I could manually create renderer expressions in MySubFruit that use parent class members. And, I could also manually create expressions in MyFruitWrapper that use the "this.fruit" method to get access to the wrapped object's members/methods. But, this is somewhat annoying because I already have renderers defined for MyFruit and want to refer to that expression in other renderers as a form of "code reuse". Yes, I also could create a bunch of toDebug() methods in my Java classes that do whatever I want and write renderer expressions that call "this.toDebug()". But, this feels annoying because I can't refer to other expressions when writing an expression. I was able to get this kind of reuse when creating custom visualizer expressions in VisualStudio for C++ code by hacking around with the autoexp.dat config file.
Thanks for any tips...
Sample code:

What I am currently seeing with my renderers (notice how the "sub" member is only showing the "MySubFruit" expression where I would also like it to show the "MyFruit" expression as well. And, the List of MyFruitWrapper's doesn't have renderers working.

By hand-crafting duplicate expressions, I was able to create the visualizations below, which shows what I'd like to see, but requires more duplicate expressions than I'd like...

Please sign in to leave a comment.
This is not possible right now, renderer expression is evaluated as is.
I do not have good ideas about how to specify this on a user level. Please file a feature request if you have.
https://youtrack.jetbrains.com/issue/IDEA-170893