Inter-type Implicit Variable or Inter-type Local Variable

inter-type 宣言の種類の一つとして、暗黙の(or 特殊な)変数を宣言できると便利かもしれない。たとえば、this とか super とか thisJoinPoint とかに相当する変数を新たに宣言できるようにしたい。


考えられるスコープとしては、クラス単位とメソッド単位があると思う。


public aspect MyAspect {

// クラス単位の場合
declare variable : String MyClass.str;


// メソッド単位の場合
declare variable : String MyClass.method().str;
}

クラス単位の場合、普通のフィールド inter-type 宣言とどう違うのか? 一つは、その変数に代入できるかどうかだと思う。declare variable された変数には、値を代入できない、と考えられる(と勝手に決める)。


メソッド単位の場合、メソッド単位で異なる型を持ってもいい、というのが重要になると思う。むしろ、これができることが、declare variable とかができたらいいのにな、という動機だったりする。


public aspect MyAspect {

declare variable : Integer MyClass.myMethod().var;
declare variable : Double MyClass.yourMethod().var;
}

みたいに。


使用例としては、this が使えるように、thisMethod とかが使えると便利に思う。


public aspect MyAspect {

declare variable : MyMethodMethod MyClass.myMethod(String).thisMethod;
declare variable : YourMethodMethod MyClass.yourMethod(int).thisMethod;
}


public class MyClass {
public void myMethod(String str) {
thisMethod.invoke(str + str);
}

public void yourMethod(int i) {
thisMethod.invoke(i + i);
}
}

書き方だけでいうと:


public aspect MyAspect {

declare variable MyClass {
void myMethod(String) : MyMethodMethod thisMethod;
void yourMethod(int) : YourMethodMethod thisMethod;
}
}

とかのほうが読みやすいかも。あるいは、一つのメソッドの複数の変数を宣言したいときもあるかもしれないので:

public aspect MyAspect {

declare variable MyClass {

void myMethod(String) {
MyMethodMethod thisMethod;
// その他
}

void yourMethod(int) {
YourMethodMethod thisMethod;
// その他
}
}
}

関連:

Michael Eichberg.
The Proxy Inter-Type Declaration.

DL:
http://www.st.informatik.tu-darmstadt.de/public/Publications.jsp

Macneil Shonle, Karl Lieberherr and Ankit Shah.
XAspects: An Extensible System for Domain Specific Aspect Languages.
OOPSLA '2003, Domain-Driven Development Track.

DL: http://www.ccs.neu.edu/research/demeter/biblio/XAspects.html
declare strategy とか declare traversal とか。