Bug 198194 - within and pointcuts matching introduced method declarations on interfaces
Summary: within and pointcuts matching introduced method declarations on interfaces
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-28 20:35 EDT by Vincenz Braun CLA
Modified: 2009-02-25 01:40 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vincenz Braun CLA 2007-07-28 20:35:14 EDT
Take this little test case:

public interface Marker {

	String mark();
}

public class Foo {
	
	public static void main(String[] args) {
		System.err.println(new Foo().mark());
	}
}

public aspect MarkerAspect  {

	declare parents: Foo implements Marker;

	public String Marker.mark() {
			return "Foo";
	}
	
	pointcut mark(): execution(public String mark()) && within(Marker+);
	

	String around() : mark() {
		System.err.println(thisJoinPoint);
		return proceed();
	}
}

The around advice in the MarkerAdvice does not match the introduced method mark.
I think it should.
Comment 1 Eclipse Webmaster CLA 2007-07-29 09:23:32 EDT
Changing OS from Mac OS to Mac OS X as per bug 185991
Comment 2 Ron Bodkin CLA 2007-07-29 23:15:49 EDT
This behavior is correct as I understand it. Within deals with lexical structure, not typing. You can use this(Marker) to match methods defined on Marker. It is a little surprising that this is withincode(String Marker.mark()) but I think it's useful to have the current AspectJ semantics.

Per http://www.eclipse.org/aspectj/doc/released/progguide/semantics-pointcuts.html "The within pointcut picks out each join point where the code executing is defined in the declaration of one of the types in TypePattern." Clearly mark is defined lexically within MarkerAspect and NOT within a subtype of Marker.
Comment 3 Vincenz Braun CLA 2007-07-30 09:50:01 EDT
For the given test case I see no problem at all in using this(Marker).

But unfortunately the provided test case is too much condensed.
Actually we wanted to use the pertypewithin instantiation model
for an apsect. This aspect should then transparently be applied to 
Marker's regardless whether the interface and implementation of 
Marker were introduced or not.

In this scenario we now loose this transparency. Writing aspect
libraries we now have to consider the pertypewithin instantiation
model more carefully. In some cases this means we can not use
it at all and have to use our own per type management.

I considered within from the byte code perspective. And
I was surprised that although there is a mark() definition 
in Foo it is not matched.
Comment 4 Andrew Clement CLA 2007-10-26 08:18:40 EDT
clarify for 1.5.4
Comment 5 Andrew Clement CLA 2009-02-25 01:40:41 EST
within() is working as designed (lexical scoping)
pertypewithin() is based on that, so working as designed.

I basically understand Vincenz' point.  Whether the member is introduced via an ITD can make a difference as to whether a pertypewithin related aspect would catch the execution of a method.

I'm not sure how to proceed with the bug - it seems like there could be an enhancement in this area but I'd need multiple compelling use cases to justify any work done.