Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Re: Call pointcut semantics for toString

Thanks Wes,

I was just trying to understand the join point matching behavior according
to the following description in the "The AspectJ 5 Development Kit
Developer's Notebook":

A join point has potentially multiple signatures, but only one set of
modifiers. A kinded primitive pointcut matches a particular join point
if and only if:
  1. They are of the same kind
  2. The signature pattern (exactly) matches at least one signature
of the join point
  3. The modifiers pattern matches the modifiers of the subject of
the join point

I was having difficulty in understanding the signatures of a join point.
For example, for the following program, what are the signatures of the
call r.toString()?

class R{}
..
R r = new R();
r.toString();

According to the notebook, this call only has the signature
"String Object.toString()", hence, it is understandable that the pointcut
call(String R.toString()) won't match this call.

However, why the same pointcut will match the call in the following
program? (where I added a super class P for class R)

class P {
 public String toString() { return "";}
}
class R extends P{}
..
R r = new R();
r.toString();

This call has signatures String Object.toString(), and
String P.toString(), none of which can be matched
EXACTLY by the pointcut...

Also, the behavior of the following program is strange:
call(* R2.toString()) matches the call r2.toString();
while call(* R1.toString()) doesn't match the call r1.toString().
The only difference bewteen R1 and R2 is that R2 extends
Thread class.

	static class R1 {}
	static class R2 extends Thread {}
	static aspect Aspect {
		pointcut r1():call(* R1.toString()); before():r1(){}
		pointcut r2():call(* R2.toString()); before():r2(){}
	}
	public static void main(String[] args) {
		R1 r1 = new R1();
		r1.toString();

		R2 r2 = new R2();
		r2.toString();
	}

Thanks again!

On 12/31/06, Wes Isberg <wes@xxxxxxxxxxxxxx> wrote:
For the first code (call), see the warnings below from the
compiler.

For the execution case, a class also "has" the signatures
it inherits for the purpose of matching; i.e., T has R'
m(String s) because it extends S and m(String) is visible.
 To restrict matching to lexically-enclosing, use
within(..).

Wes

C:\home\wes\dev\tools\aspectj-1.5\bin\ToStringAndCallPointcut.java:15
[warning] does not match because declaring type is
java.lang.Object, if match desired use
target(ToStringAndCallPointcut$Foo)
[Xlint:unmatchedSuperTypeInCall]
pointcut tostringCall(): call(String Foo.toString());
                        ^^^^^^^^^^^
       [Xlint:unmatchedSuperTypeInCall]
       see also:
C:\home\wes\dev\tools\aspectj-1.5\bin\ToStringAndCallPointcut.java:27::0
C:\home\wes\dev\tools\aspectj-1.5\bin\ToStringAndCallPointcut.java:15
[warning] does not match because declaring type is
java.lang.Object, if match desired use
target(ToStringAndCallPointcut$Foo)
[Xlint:unmatchedSuperTypeInCall]
pointcut tostringCall(): call(String Foo.toString());
                        ^^^^^^^^^^^
       [Xlint:unmatchedSuperTypeInCall]
       see also:
C:\home\wes\dev\tools\aspectj-1.5\bin\ToStringAndCallPointcut.java:24::0
C:\home\wes\dev\tools\aspectj-1.5\bin\ToStringAndCallPointcut.java:16
[warning] does not match because declaring type is
java.lang.Object, if match desired use
target(ToStringAndCallPointcut$SubFoo)
[Xlint:unmatchedSuperTypeInCall]
pointcut tostringCall2():call(String SubFoo.toString());
                        ^^^^^^^^^^^^^^
       [Xlint:unmatchedSuperTypeInCall]
       see also:
C:\home\wes\dev\tools\aspectj-1.5\bin\ToStringAndCallPointcut.java:24::0
C:\home\wes\dev\tools\aspectj-1.5\bin\ToStringAndCallPointcut.java:16
[warning] does not match because declaring type is
java.lang.Object, if match desired use
target(ToStringAndCallPointcut$SubFoo)
[Xlint:unmatchedSuperTypeInCall]
pointcut tostringCall2():call(String SubFoo.toString());
                        ^^^^^^^^^^^^^^
       [Xlint:unmatchedSuperTypeInCall]
       see also:
C:\home\wes\dev\tools\aspectj-1.5\bin\ToStringAndCallPointcut.java:27::0



On Sat, 30 Dec 2006 22:45:41 -0800
 "Mr. Patient" <mr.patient@xxxxxxxxx> wrote:
> Hi again,
>
> This is a follow-up question about the semantics of
> execution, as well as
> the join point matching mechanism in AspectJ.
>
> According to the join point signature section of the
> developer's notebook:
>
http://www.eclipse.org/aspectj/doc/released/adk15notebook/join-point-signatures.html#method-execution-join-point-signatures,
> for the attached example, the signatures of the join
> point arising from the
> execution of the m method in class U would be:
>         R' U.m(String)
>         R' S.m(String)
>         R  P.m(String)
>         R  Q.m(String)
>
> Notice that there is no signature involving T, but why
> this join point
> is matched
> by pointcut: execution(* T.m(String))?  The signature
> pattern needs to exactly
> match at least one signature of the join point, right?
>
> Thanks again!
> David
> ======= the code ===================
>         interface Q {
>           R m(String s);
>         }
>
>         class P implements Q {
>           R m(String s) {...}
>         }
>
>         class S extends P {
>           R' m(String s) {...}
>         }
>
>         class T extends S { }
>
>         class U extends T {
>           R' m(String s) {...}
>         }
>
> On 12/30/06, Mr. Patient <mr.patient@xxxxxxxxx> wrote:
> > Hi All,
> >
> > Please see the following code: if the toString method
> is NOT declared in
> > SuperFoo class, both pointcut will match nothing -- I
> understand that is
> > because both toString calls (in the main method) have
> the signature
> > "String Object.toString()" only.
> >
> > However, when a toString method is declared in class
> SuperFoo, both
> > pointcuts will match some calls!  This seems
> contradictory to the previous
> > one, since in this case, both toString calls have
> signatures:
> > "String Object.toString()" and "String
> SuperFoo.toString()". -- Still,
> > none of them
> > could be matched by any of those two pointcuts.
> >
> > Is this a bug or there is something I misunderstood?
> >
> > I'm using AJDT 1.4.1.  Thanks a lot!
> >
> > Thanks,
> > David
> >
> > ===================================
> > public aspect ToStringAndCallPointcut {
> >        static class SuperFoo {
> > //              public String toString() {
> > //                      return "sub foo";
> > //              }
> >        }
> >
> >        static class Foo extends SuperFoo {
> >        }
> >
> >        static class SubFoo extends Foo {
> >        }
> >
> >        static aspect Aspect {
> >                pointcut tostringCall():
>        call(String Foo.toString());
> >                pointcut tostringCall2():call(String
> SubFoo.toString());
> >
> >                before():tostringCall(){}
> >                before():tostringCall2(){}
> >        }
> >
> >        public static void main(String[] args) {
> >                Foo foo = new SubFoo();
> >                System.out.println(foo.toString());
> >
> >                SubFoo sf = (SubFoo)foo;
> >                sf.toString();
> >        }
> > }
> >
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users

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



Back to the top