Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] AspectJ precedence

I would rather see the aspect source than the generated code...  you shouldn't infer how to code the aspects from the generated code.

If I have this:

public class C {
  public void m1() {}
  public void m2() {}
}
aspect Trace {
  before: execution(* m*(..)) {}
}

then both will be advised.  If I refactor m2 into an aspect:

public class C {
  public void m1() {}
}

aspect A {
  public void C.m2() {}
}

My aspect will still work just fine, and both m1 and m2 will still be advised.

I'm assuming what you have done is that you have a within() component to your tracing aspect and your problem is that you have failed to include the aspect in the within() clause.

If I change my advice to:

aspect Trace {
  before: execution(* m*(..)) && within(C) {}
}

I will only advise m1() because m2() is lexically part of the aspect, *not* part of the target type.  If I want to advise both places I would use

aspect Trace {
  before(): execution(* m*(..)) && within(C || A) {}
}

So, C and A were in the same package I would say within(somepackage..*) and it will advise both places.

You would not use precedence in this situation, it doesn't affect whether ITDs happen before advice.  ITDs always happen first and advice always happens second.  Precedence is for choosing the order in which advice runs when multiple pieces apply at the same join point.

Andy.


On 26 Feb 2008 01:13:56 -0000, vinodh subbiah <vinodhts@xxxxxxxxxxxxxx> wrote:

Hi All,
  Im having 2 aspects and I want to set a precedence between them

I have a java class Foo
I have a aspect    FooAspect ( have method m1() declared on class Foo
I have a logger aspect LogAspect

Now if i try setting the precedence Im not able to see any logging on method m1 when it is called.

Is there any way i can set this ..

Thanks
Vinodh

Below is some of the code i got from .class file generated.

Here showConditons which declared on Class has the tracing ,but I
addingObject(..) methods which are added using the Aspect into the class are not surronded with the Trace .
So Im not able to see the trace if any.
Any help appreaciated.

Thanks again :)

I set the precedence in another aspect like
declare precedence : CEAspect,TraceAspect ;
So i first add the methods to the Class FOO and then surrond it with trace.


Showing the crosscuting with TraceAspect
public void showConditions()
{
              TraceAspect.aspectOf().ajc$before$com.xuaspect_TraceAspect$1$b314f86e(ajc$tjp_1);
              printConditions();
                TraceAspect.aspectOf().ajc$afterReturning$com.xuaspect_TraceAspect$2$b314f86e(ajc$tjp_1);
}

Only method injected no trace aspect added

    public void addingObject(IlrAlphaMem ilralphamem, Object obj)
    {
        CEAspect.ajc$interMethod$com.xuaspect_CEAspect$com.xuaspect_CEvents$addingObject(this, ilralphamem, obj);
    }

    public void addingObject(IlrDefaultDiscMem ilrdefaultdiscmem, Object obj)
    {
        CEAspect.ajc$interMethod$com.xuaspect_CEAspect$com.xuaspect_CEvents$addingObject(this, ilrdefaultdiscmem, obj);
    }

    public void addingObject(IlrDefaultJoinMem ilrdefaultjoinmem, Object obj)
    {
        CEAspect.ajc$interMethod$com.xuaspect_CEAspect$com.xuaspect_CEvents$addingObject(this, ilrdefaultjoinmem, obj);
    }

Vinodh Subbiah,
580 Laforet Street,Apt 14
Windsor N9C3G8
Canada
Ph 519-971-7847

Times Job change

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top