Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-dev] Q: Should this be an ajc error or warning?

Hi All,

Can someone tell to me should ajc compiler give an error or warning, enstead
of compiling normally?
Below is very small simple program, which is telling the problem.
First version is executing normally, as it should (the code is below, first
version). It is pringting the next:

A.doIt(...)
***********
Before advise: call(void B.doIt())
B target: B@173a10f
  class: B
  this: koe$CallPCDMatchingExample@530daa
  calls: 1
B.doIt(...)
-----------
***********

But if I changed pertarget() function to perthis() function, I'm got any
error or warning, when I'm not using corresponding this() within the same
source code, and it is executing wrong, without finding aspect code:
(unworking versions, see below)

A.doIt(...)
B.doIt(...)

Should perthis give an error or almost a warning, because this() method has
not been used anywhere, especially in a pointcut definition.
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) ; //

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



Back to the top