dynaop module

This module allows Aspect Oriented Programming in Pnuts using dynaop.

Functions

interceptor( classPointcut , methodPointcut , enter ( this, args[] ) { , exit (this, args[] ) } ) or
( classPointcut , methodPointcut , dynaop.Interceptor interceptor )

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)
mixin( classPointcut {, interfaces } , mixinClass {, func(arg...) } )

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()
extend( Class class )

Returns an interceptable object.

wrap( Object object )

Returns an wrapper object that has interceptor's hook.

useAspects( { boolean b } )

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)

org.pnuts.dynaop.PnutsAspects

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 ...