Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] An intertype declaration question

If the aspect is concrete, you can use AspectName.aspectOf().instanceVar 

If it is not, then you might be able to use a static member variable (e.g., AspectName.instanceVar) instead (though for an abstract aspect, this is always different than a member variable).

A last thing you could do (that should always work) is to write advice on the ITD method that accesses the instanceVar. In an extreme case, you could pass capture ALL the context of the ITD and write around advice that doesn't proceed...

Ron Bodkin
Chief Technology Officer
New Aspects of Software
m: (415) 509-2895

> ------------Original Message------------
> From: Charles Zhang <czhang@xxxxxxxxxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Fri, Jan-30-2004 8:05 AM
> Subject: Re: [aspectj-users] An intertype declaration question
> 
> Thanks for the answer. How do I access the aspect instance variable "mem"
> from the declared constructor in this case?
> 
> Charles
> 
> On Fri, 30 Jan 2004, Nicholas Lesiecki wrote:
> 
> > I believe a careful review of the programming guide will answer this
> > question. But the short answer is mem at line 5 refers to Test's mem, not
> > Atest's mem.
> >
> > Cheers,
> > nick
> >
> > On 1/29/04 3:16 PM, "Charles Zhang" <czhang@xxxxxxxxxxxxxxxx> wrote:
> >
> > > Hi, I have the following class:
> > > class Test
> > > {
> > > ... main(String []) {
> > >  Test t = new Test(1); // a constructor defined in aspect
> > >  System.out.println(t.mem); // a public member declared in aspect
> > > }
> > > and the following aspect
> > > 1 aspect ATest{
> > > 2   private int mem = 0;
> > > 3   public int Test.mem = 0;
> > > 4   public Test.new(int nop) {
> > > 5    mem = 8;
> > > 6 }
> > >
> > > The value of mem is 8, although "mem" at line 6 should refer to the aspect
> > > instance but not the class instance, which should not influence the
> > > output. Have I made a mistake here or  misunderstood the semantics? How do
> > > I access aspect instance variable in this case?
> > >
> > > Thanks.
> > >
> > > Charles
> > >
> > > _______________________________________________
> > > aspectj-users mailing list
> > > aspectj-users@xxxxxxxxxxx
> > > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> > --
> > Nicholas Lesiecki
> > Software Craftsman, specializing in J2EE,
> > Agile Methods, and aspect-oriented programming
> >
> > Check out my books:
> > * Mastering AspectJ: http://tinyurl.com/66vf
> > * Java Tools for Extreme Programming: http://tinyurl.com/66vt
> >
> > Check out my articles on AspectJ:
> > * http://tinyurl.com/66vu and http://tinyurl.com/66vv
> >
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 
> 


Back to the top