Skip to content

Instantly share code, notes, and snippets.

@oehme
Last active December 16, 2015 11:38
Show Gist options
  • Save oehme/5428626 to your computer and use it in GitHub Desktop.
Save oehme/5428626 to your computer and use it in GitHub Desktop.
class ExtractInterfaceProcessor extends AbstractClassProcessor {
override doRegisterGlobals(ClassDeclaration cls, RegisterGlobalsContext context) {
context.registerInterface(cls.qualifiedInterfaceName)
}
override doTransform(MutableClassDeclaration cls, extension TransformationContext context) {
findInterface(cls.qualifiedInterfaceName) => [ iface |
cls.declaredMethods.filter [
visibility == Visibility::PUBLIC
static == false
].forEach [ method |
iface.addMethod(method.simpleName) [ extracted |
extracted.visibility = method.visibility
extracted.returnType = method.returnType
method.parameters.forEach[extracted.addParameter(simpleName, type)]
extracted.docComment = method.docComment
extracted.exceptions = method.exceptions
]
]
iface.addAnnotation(typeof(ImplementedBy).findTypeGlobally) => [
set("value", cls.newTypeReference)
]
]
}
//def qualifiedInterfaceName() {} omitted
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment