Some code:
static def copyMethod(MutableClassDeclaration clazz, MethodDeclaration method) {
val methodDeclaration = clazz.addMethod(method.simpleName) [
it.abstract = method.abstract
it.docComment = method.docComment
it.visibility = method.visibility
it.synchronized = method.synchronized
it.deprecated = method.deprecated
it.static = method.static
it.exceptions = method.exceptions
it.varArgs = method.varArgs
it.strictFloatingPoint = method.strictFloatingPoint
]
for (t : method.typeParameters)
methodDeclaration.addTypeParameter(t.simpleName, t.upperBounds)
methodDeclaration.returnType = method.returnType
for (p : method.parameters) {
methodDeclaration.addParameter(p.simpleName, p.type)
}
return methodDeclaration
}
override doTransform(MutableClassDeclaration annotatedClass, extension TransformationContext context) {
for (m : annotatedClass.declaredMethods) {
val newMethod = annotatedClass.copyMethod(m)
newMethod.simpleName = newMethod.simpleName + "_copiedMethod"
newMethod.body = m.body
m.body = '''// new method'''
}
}
@SomeAnnotation
class SomeAnnotationTest {
def <T> void myMethod() {
var T myObj = null;
}
}
A probably related question ("how to copy type arguments") was already asked in https://groups.google.com/forum/#!msg/xtend-lang/X8uYmJOk4hA/lVXZjjjnrr0J.
--
You received this message because you are subscribed to the Google Groups "Xtend Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.