Generation of Groovy source from parent Java class
You can use Groovy to generate the Groovy source code.

The source code generator

Here's an example source code generator.

import groovy.text.SimpleTemplateEngine

def generate(Class klass, String packageName, String name, String template) {
    def engine = new SimpleTemplateEngine()
    def binding = [
        packageName: packageName,
        name: name,
        superClass: klass.name,
        methods: klass.metaClass.methods
            .findAll { !(it.toString().contains(' final ')) }
            .collect {    
                def args = []        
                def m = it.toString() =~ /(.*) (.*\.)(.*)(\((.*)\).*)/

                m.matches()                
                if(m.group(5).size() &gt; 0) {
                    m.group(5).split(',').eachWithIndex {arg, index -&gt;
                        args &lt;&lt; "$arg p$index"
                    }
                }

                return "${m.group(1).replace('native', '')} ${m.group(3)}(${args.join(', ')})"
            }
    ]

    engine.createTemplate(template).make(binding).toString()
}


How it works

It's actually quite simple. The method signatures are gathered from the class's MetaClass. Then some hefty formatting is applied to write the method signatures correctly. Also, final methods are excluded.

Example

def template = '''
package $packageName

/* Code auto generated
 * do edit what You want 
 */

class $name extends $superClass {
&lt;% 
methods.each {
    println ''
    println "\t$it {"
    println ''
    println "\t}"
} %&gt;
}
'''

generate(Object, 'my.script', 'SelfGenerator', template)


Generated source code

package my.script

/* Code auto generated
 * do edit what You want 
 */

class SelfGenerator extends java.lang.Object {

    public boolean equals(java.lang.Object p0) {

    }

    public  int hashCode() {

    }

    public java.lang.String toString() {

    }

}


Templates

Ideally, you'd have two templates: one for the class and one for the methods. That would avoid the clunky JSP-style programming. You can read more about Groovy's template engines here.