This module allows Aspect Oriented Programming in Pnuts using dynaop.
Specifies an Interceptor for Pointcuts represented by classPointcut and methodPointcut. When a method that matches the Pointcuts is called, enter() ( and also exit()) can be called at the beginning/end of the method respestively. When interceptor is specified, when a method that matches the Pointcuts is called, the method can be executed with the attached interceptor
classPointcut must be either Class, String, or dynaop.ClassPointcut.
methodPointcut must be either String, Method, or dynaop.MethodPointcut.
import java.util.*
interceptor(List, "add", function (this, args) println("adding ", args[0]))
x = extend(ArrayList)
x.add(1)
x.add(2)
Attaches mixinClass to classes represented by classPointcut.
In Java:
import dynaop.*;
public interface Mixin {
String getMessage();
}
public class MixinImpl implements Mixin, ProxyAware {
public String getMessage() {
return "Hello World";
}
public void setProxy(Proxy proxy) {
}
}
In Pnuts:
mixin(Date, MixinImpl) Date().getMessage()
Returns an interceptable object.
Returns an wrapper object that has interceptor's hook.
useAspects(true) changes the Configuration of the current context to org.pnuts.dynaop.AspectsConfiguration, so that interceptable instances can be created by a constructor, rather than calling extend() or wrap().
nodeAccess(false) resets the configuration possibly set by useAspects(true).
nodeAccess() with no parameter returns true if org.pnuts.dynaop.AspectsConfiguration is being used on the current context.
import java.util.*
interceptor(List, "add", function (this, args) println("adding ", args[0]))
useAspects(true)
x = ArrayList()
x.add(1)
x.add(2)
dynaop module includes an implementaion of Aspects which can be used instead of dynaop.bsh.BshAspects. When the following property is set, the program uses the Aspects that is configured by executing load("dynaop").
java -Ddynaop.aspects=org.pnuts.dynaop.PnutsAspects ...