12
Aug
09

a groovy debug trick



Have you ever encountered classes that were very badly documented? Did they also have a toString method that didn’t give you any information?

I’ve had my share of those kind of classes too. When you really need to use one of them, you start your IDE in debug mode and start inspecting the object, maybe you can find additional info. Before I do that, I tend to make use of the following function:


def consoleInspect(obj) {
    obj.metaClass.methods*.name.each { n ->
        try {
            println "result of $n is ${obj."$n"()}"
        } catch(e) {
            println "exception calling $n - probably because lack of parameters"
        }
    }
}

this will iterate over all of the object’s methods, and try to call them with no parameters. It will show the result of calling each method, along with the name of the method called.

It’s not the best thing since sliced bread, but sometimes it can help.

Advertisements

0 Responses to “a groovy debug trick”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Blog Stats

  • 221,338 hits

%d bloggers like this: