Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groovy: how to get properties declared in base class

In the following code, I need all the properties available in Child class (i.e. foo, bar). I am not interested in all other properties added by groovy.

class Parent {def foo}
class Child extends Parent {def bar}

So far none of these gets the result:

println Child.fields
println Child.properties.each{k,v->println "$k -> $v"}
println Child.declaredFields.findAll { !it.synthetic }.collect {it.name}
println Child.methods.findAll {it.name.startsWith("get")}.collect {it.name}

I am trying to find out some direct method which would give me this.

like image 807
kdabir Avatar asked Apr 20 '13 09:04

kdabir


1 Answers

This will give you what you need:

assert ['foo', 'class', 'bar'] == B.metaClass.properties*.name
like image 185
Erik Pragt Avatar answered Oct 31 '22 20:10

Erik Pragt