Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Should it be an error: compiling perthis without errors, when rigth was pertarget!

Hi,

Can someone tell to me why these my code modifications are giving any errors
or even warnings at all?

I can compile with any errors with the same source code, only
pertarget(pointcut) has been changed to ** perthis(pointcut)  ** !
Should perthis give an error or almost a warning, because this() method has
not been used anywhere, especially in a pointcut definition.
Now it is generating unworking byte code, if you will change pertarget to
perthis (as I have done in code block B) (the code is below).

Also another modifications can be dangerous, if you are mixing aspect words
and their rigth usage, as I did,
resulting code can work or not! More on below after the first code sample
(changes C, E, F).

1. Can some give short explanation for this (see code changes: C - F)?
2. Should we use only call(), pertarget() and target() or execution(),
perthis() and this() together?

thanks in advance,

Tuomas

A base code, working code:
*********************

 public class koe {

  public static void main(String[] args) {
    A a = new A();
    B b = new B();
    A bInDisguise = new B();
    D d = new D();

    a.doIt();
    b.doIt();               // AspectJ 1.2 matches here
    b.doIt();               // AspectJ 1.2 matches here

    bInDisguise.doIt();     // this is matched also with sdk 1.5.0-beta-b32c
    // and ajc 1.1.1 when commands were: ajc -source 1.4 *.java and
    // java -version:1.4 -cp .;%classpath% koe
    d.doIt();
  }

static aspect CallPCDMatchingExample pertarget(methodcall(B)) {

    private int cntCalls = 0;
    pointcut methodcall(B target) :
       call( * *.doIt(..)) && target(target) ; //

    before(B target): methodcall(target) { //
 System.out.println("***********");
 cntCalls++;
 System.out.println("Before advise: " + thisJoinPoint);
 System.out.println("B target: " + target);
 System.out.println("  class: " + target.getClass().getName());
 System.out.println("  this: " + this);
 System.out.println("  calls: " + cntCalls);
    }

   after(B target): methodcall(target) { //
       System.out.println("-----------");
   }
 }
 }

class A {
   public void doIt() { System.out.println("A.doIt(...)"); };
 }

 public class B extends A {
   public void doIt() {
       System.out.println("B.doIt(...)");
   };
 }

 class D extends B {
   public void doIt() {
       System.out.println("D.doIt(...)");
   };
 }

B. unworking code:
**************'

static aspect CallPCDMatchingExample perthis(methodcall(B)) {

    ...
    pointcut methodcall(B target) :
 call( * *.doIt(..)) && this(target) ; //
...

C. working code:
**************'

static aspect CallPCDMatchingExample perthis(methodcall(B)) {

  ...
   pointcut methodcall(B target) :
 execution( * *.doIt(..)) && this(target) ; //

E working code !!??:
**************'

static aspect CallPCDMatchingExample pertarget(methodcall(B)) {

   ...
    pointcut methodcall(B target) :
       execution( * *.doIt(..)) && target(target) ; //

F: working code !! ??:
**************'

static aspect CallPCDMatchingExample pertarget(methodcall(B)) {

    ...
    pointcut methodcall(B target) :
       execution( * *.doIt(..)) && this(target) ; //



Back to the top