mardi 20 janvier 2015

method call interception in scala

Hi I was wondering if there is a way to reflectively (or otherwise) intercept all method calls send to a class. I know that unknown methods can be intercepted using Dynamic, but how about methods already defined in the class?


I would like to find a way to do it without having to modify the syntax of methods (as it is done to intercept methods in the aspects framework).


As an example of what I would like to do imagine this:



class A extends AProxy {
def foo =
println("do something")
}

class AProxy extends Dynamic {
def captureKnownMethods = {
//Capture all methods defined in A
}

def applyDynamic(args) = {
//Capture unknown methods
}


}



A myclass = new A
myclass.foo //method call captured by captureKnownMethods
myclass.bar //method call captured by applyDynamic





Aucun commentaire:

Enregistrer un commentaire