Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] Pertypewithin() and inner/nested type

Hi Wes,

The virtual annotation idea is a useful one. It does make me a little nervous due to potential for confusion with other annotation syntax. But I can't quite think of an alternative (short of withininner(), withinanonymous()...).

The virtual annotation syntax can also address the package-level vs. type-level annotation issue raised in Eric Bodden's recent email. For example, one can restrict @BusinessDomain to only types (and not subpackages) by using the following declare annotations syntax:
declare annotation : !@Package org.xyz.model..* : @BusinessDomain ;

Of course, Proposal in Wes' email (declare @field etc.) can also address the excluding package:
	declare @class : org.xyz.model..* : @BusinessDomain ;

(I am assuming @class stands for types -- classes and interfaces).

-Ramnivas

Wes Isberg wrote:
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

  

Back to the top