Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails[Groovy],How to get list of all methods a class has with out those inherited?

Tags:

grails

groovy

I am using this to collect all methods a class has:

grailsApplication.getMainContext().getBean("className").metaClass.methods*.name

But this returns all the methods including the inherited ones, how can I filter only the methods owned by the class?

like image 664
t31321 Avatar asked Mar 18 '23 19:03

t31321


1 Answers

This will give you the list of method names filtered to include only methods belonging to only the declaring class(SomeClass in this example):

SomeClass sc = new SomeClass()
List<String> declaringClassOnlyMethods = sc.metaClass.methods.findAll { MetaMethod method ->
    if(method.declaringClass.name == sc.class.name) {
        method.name
    }
}
like image 71
Durandal Avatar answered Apr 06 '23 22:04

Durandal