3

I would like to see the contents of a certain Enumeration<T> instance. In the absence of a List/Array like type accepting it in its constructor another viable option would be a Debugger Visualizer, something that exists in VS.

How can I do it in IntelliJ?

mark
  • 59,016
  • 79
  • 296
  • 580

1 Answers1

3

IntelliJ IDEA has Data Type Renderers for the debugger:

IntelliJ IDEA allows you to specify how different objects are displayed in the debugger on a class-by-class basis. You can assign expressions to display rather than rely on the object's String representation.

For example, if an object represents a user, you may want to see users represented by their login name; or, for a cache entry object, its age and contents may be appropriate. IntelliJ IDEA refers to these as type renderers.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • 1
    Although, I do not see an option to load a third party jar implementing a complex renderer. – mark Sep 18 '12 at 15:41
  • It should be in a project classpath. – CrazyCoder Sep 18 '12 at 16:05
  • But where do I mention the renderers type? The documentation does not mention that a custom renderer is even supported. – mark Sep 18 '12 at 16:12
  • You can google several examples, like this one: http://blogs.jetbrains.com/idea/2008/04/type-renderers/ – CrazyCoder Sep 18 '12 at 16:18
  • 1
    You misunderstand me. Your example shows how to render a custom type using the default facilities provided by IntelliJ. I am talking about how to render a customer type using a **custom renderer**! In VS you can return a proxy object instead of the original one, which would be displayed in the debugger. For instance, if I wanted to display a binary tree as a flat list - I can do so. Expanding a tree object in the watch window will show the respective flat list. Can I do this in IntelliJ? – mark Sep 18 '12 at 16:23
  • In the **Expression** field you can use your own classes, something like `new foo.MyProxy(this)` will work if `MyProxy` accepts the type of the object you want to render and defines custom `toString()`. It's also possible to use static methods provided by your project classes: `foo.MyRenderer.render(this)`. – CrazyCoder Sep 18 '12 at 16:34
  • 1
    Unlike VS Studio, it can't support image and visualisations not based on texts – tribbloid Jul 19 '20 at 19:04
  • Note: IntelliJ can show `BufferedImage` (cf. https://stackoverflow.com/questions/32712312/is-it-possible-to-watch-bufferedimage-objects-while-debugging-in-intellij), therefore you might be able to render some debugging images in your program with some effort (I am afraid you will not be able to provide this debugger-side unfortunately) – Suma Jan 22 '21 at 12:19