#Plugback Active - Active Annotations for the Xtend Java language Plugback Active contains a set of active annotations useful for everyday work.
##What do you need To use Plugback Active you need:
- the latest version of Plugback Active, available on the maven repository. Check http://search.maven.org/#artifactdetails%7Ccom.plugback%7Cactive%7C1.0.3-BETA%7Cjar
- the Xtend library
##Available annotations
Using the Hook active annotation any method can be intercepted before or after it is executed.Place the @Hook(register=true)
annotation everywhere you want the method to be intercepted.
This will generate two event classes: BeforeClassNameMethodName
and AfterClassNameMethodName
.
These two classes contain the parameters of the original method that can be manipulated before and after the
methiod execution. The AfterClassNameMethodName
type contains the returned object too.
You can use these two classes in any other class to intercept that method call:
- create a method with just one argument of type
BeforeClassNameMethodName
orAfterClassNameMethodName
; - annotate the method using the
@Hook
annotation; - use the parameter of the method to manipulate the execution.
The following is an example taken from the unit test, where the methods into the Me class are intercepted into the You class:
package com.salvatoreromeo.x
import com.plugback.active.event.Hook
class Me{
@Hook(register = true)
def String myMethod(String ciao){
println("ok")
}
@Hook(register = true)
def void myMethod2(){
}
}
class You{
@Hook
def String yourMethod(BeforeMeMyMethod b){
println("ok")
}
@Hook
def String yourMethod2(AfterMeMyMethod2 a){
println("ok")
}
}