Hi Ramnivas -
You're right about the direct interpretation.
The workaround is to specify on the enclosing class in the
type pattern. The join points in the nested classes are
still "within" the outermost class. The problem with this
is that they are confusingly similar:
pertypewithin(lang15.*)
pertypewithin(lang15..*)
(See code below; it's great to have ajc working on this!)
Which raises a proposal of Jim's that I'd like to revive
for the AspectJ 5 release: virtual annotations that
developers "understand" about classes (but which aren't
attributes):
@Anonymous
@Nested
@Inner
@Interface
Then you could clearly say
pertypewithin(lang15..* && !@Nested && !@Interface)
Thanks -
Wes
-------------lang15/PerType.java
package lang15;
aspect PT pertypewithin(lang15.* && !PT) {
static int INDEX;
final int index = INDEX++;
public PT() {
System.out.println("creating " + toString());
}
before() : execution(* *(..)) {
System.out.println(index + ": " + thisJoinPointStaticPart);
}
public String toString() {
return "PT[" + index + "]";
}
}
public class PerType {
public static void main(String[] args) {
System.out.println("you got " + PT.aspectOf(PerType.class));
new PerType().new D().m();
new C().m();
}
static void print(String s) { System.out.println(s); }
void m() {print("PerType.m()"); }
static class C extends PerType {
void m() {print("C.m()"); }
}
class D extends PerType {
void m() {print("D.m()"); }
}
}
------------Original Message------------
From: Ramnivas Laddad <ramnivas@xxxxxxxxxxxxxxx>
To: aspectj-dev@xxxxxxxxxxx
Date: Tue, Jan-25-2005 2:20 PM
Subject: [aspectj-dev] Pertypewithin() and inner/nested type
How is pertypewithin() aspects state is associated with inner and
nested
types?
On most occasion (especially logging a la log4j), inner types (but not
necessarily nested types -- declared using static) need to share the
per-type state with the outermost type. However, a direct
interpretation
of pertypewithin() -- per type within (those matched by) the type
pattern -- will make one think that inner and nested state will have
*separate* state than the outer type.
This issue affects both pertype(Pointcut) or pertypewithin(TypePattern)
the same way (I think). Hence a separate email to avoid confusion.
-Ramnivas
_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-dev
_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-dev