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?
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.
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.
[:] creates an empty Map. The colon is there to distinguish it from [] , which creates an empty List. This groovy code: def foo = [:]
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With