Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to inspect objects while debugging groovy (eclipse plugin or other)

I have started to learn groovy by building a pet project. I fetch some html with XmlSlurper and parse it etc. I am using eclipse3.4 with groovy 1.6 plugin. I am having a very difficult time trying to iterate thorugh all the html elements etc. I expected to set some breakpoint, inspect the current variable where my contents are, see what it contains, what do I have to iterate over, evaluate some expressions etc etc.

But I almost cannot do anything like that: - some variables don't appear in the variables view (maybe its the ones not having a type?) - select any expression but you cannot evaluate - and worst of all (for me) is that any variable is shown with all its groovy stuff (metaclass, value...). The things that most of the time will interest the developer are buried inside the hierarchy and very difficult to find.

I had thougth that the ObjectExplorer mentioned in the doco would be able to help but I was unable to get it running with my script.

What do people use for this sort of thing while developing in groovy?

like image 768
Persimmonium Avatar asked May 17 '09 22:05

Persimmonium


People also ask

How do I inspect values in Eclipse?

Press Ctrl+Shift+d or Ctrl+Shift+i on a selected variable or expression to show its value. You can also add a permanent watch on an expression/variable that will then be shown in the Expressions view when debugging is on.

How do I debug a Groovy file?

Debug a Groovy applicationOpen your Groovy application in the editor. In the left gutter, set your breakpoints for the lines of code you want to debug. The debugger is aware of the Groovy syntax, and you can evaluate an expression on the breakpoint if you need.

What does [:] mean in Groovy?

[:] creates an empty Map. The colon is there to distinguish it from [] , which creates an empty List. This groovy code: def foo = [:]


1 Answers

Option 1:

Give following a try in your script

groovy.inspect.swingui.ObjectBrowser.inspect(object)

This gives all public fields, properties, methods, etc

Option 2:

You can also use obj.dump() and or object.inspect() method to see values of the object e.g. println obj.inspect() or assert obj.inspect() == "some values"

Other options:

  • Eclipse 3.4 debug perspective works pretty well. Even the one without type information show up. Can you give specific problem that you are facing with debugging in 3.4
  • println variables
  • Writing Unit test with asserts regarding expected output of the xml
like image 163
Kartik Shah Avatar answered Nov 16 '22 08:11

Kartik Shah