[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Filed set after constructor
|
Andre,
So what you are trying to do is add a field and initialize it based on an
argument passed on an existing constructor. This is a little unusual as you
would probably ITD a new constructor too however here is an example (using
the execution rather than call PCD):
public class Test {
public Test (String s) {
}
public static void main(String[] args) {
Test test = new Test("One");
System.out.println(test.getString());
}
}
aspect Aspect {
private String Test.string;
public String Test.getString () {
return string;
}
pointcut init (Test t, String s) :
this(t) && execution(Test.new(..)) && args(s,..);
before (Test t, String s) : init (t,s) {
t.string = s;
}
}
Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester, SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/
André Dantas Rocha <ad-rocha@xxxxxxxxxx>@eclipse.org on 12/01/2005 22:36:28
Please respond to aspectj-users@xxxxxxxxxxx
Sent by: aspectj-users-admin@xxxxxxxxxxx
To: <aspectj-users@xxxxxxxxxxx>
cc:
Subject: [aspectj-users] Filed set after constructor
Hi,
I'm introducing a new filed in a class and I want to set it after
construtor runs. Somethig like this:
// introduced field
String AClass.expressao;
// introduced method
public String AClass.getExpressao() {
return expressao;
}
pointcut pc() : call(AClass.new(..));
after() : pc() {
AClass ac = (AClass) thisJoinPoint.getTarget();
ac.expressao = thisJoinPoint.getArgs()[0];
}
But... thisJoinPoint.getTarget() returns null.
Is there a way to make it works?
Thanks,
Andre