Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Interface Constructors

Matthew Webster wrote:
If I use the pointcut:

      execution (*.new(..));

I will advise the execution of all constructors including interface types.
Can I exclude interface types without having to enumerate them? Using the

The only way I can think to do this in AspectJ-1.1 is ugly:

    execution(new(..)) &&
if(!thisJoinPointStaticPart.getSignature().getDeclaringType().isInterface())

You could imagine an AspectJ compiler completely optimizing this kind of test away; however, the current ajc-1.1.1 will require a couple of cheap methods calls here.

One outstanding language request is to add interface, aspect, and class to the type specifier language. This would let you write something like:
  execution( (!interface).new(..) )

You might want to bring this up when we begin the 1.2 language design discusions.

following scope (interface types do not descend from Object):

       within(java.lang.Object+)

does not work.

Whether or not interface types are a subtype of java.lang.Object is subject to some debate. For example, the following is legal code:

  Runnable r = ...;
  String s = r.toString();

This suggests that the Runnable interface is behaving in a fairly obvious way as if it is a subtype of Object. The unofficial Java Spec Report includes a detailed discussion of this issue at:
  http://www.ergnosis.com/java-spec-report/java-language/jls-9.2.html

AspectJ treats interfaces as subtypes of Object. Given the ability to add instance fields and concrete methods to interfaces through intertype declarations, interfaces in AspectJ behave even more like actual subtypes of Object than they do in pure Java.

-Jim




Back to the top