Grails [Groovy] How to get a list of all methods that a class has with inherited ones?

I use this to collect all the methods that a class has:

grailsApplication.getMainContext (). GetBean ("class name"). MetaClass.methods * .name

But this returns all methods including inherited ones, how can I filter only methods that belong to a class ?

+3


source to share


1 answer


This will give you a list of method names, filtered to include only methods belonging only to the declaration 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
    }
}

      

+5


source







All Articles