Bug 418129 - Can't introduce annotation onto introduced method from trait-patterned aspect
Summary: Can't introduce annotation onto introduced method from trait-patterned aspect
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.7.3   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 1.7.4   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-26 14:31 EDT by Matthew Adams CLA
Modified: 2013-10-02 18:20 EDT (History)
1 user (show)

See Also:


Attachments
eclipse AspectJ testcase (9.10 KB, application/zip)
2013-09-26 14:31 EDT, Matthew Adams CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Adams CLA 2013-09-26 14:31:09 EDT
Created attachment 235865 [details]
eclipse AspectJ testcase

An aspect is introducing a field and a method.  Introducing an annotation onto the introduced field works fine; introducing an annotation onto the introduced **method** fails with the message "The method '...' does not exist" (where '...' is the method pattern).

Aspect follows trait pattern:

public interface Behavior { String hello(); }

=====

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Behaved {}

=====

public aspect Trait {

	public interface I extends Behavior {}
	
	declare parents: @Behaved * implements I;
	
	private String I.name = getClass().getName();
	
	public String I.hello() {
		return "hello" + name;
	}
}

=====

@Behaved
public class Target {
	public static aspect A {
		declare @field: * Target.name: @Tagged; // WORKY
		declare @method: * Target.hello(..): @Tagged; // NO WORKY
	}
}

=====

@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD,
		ElementType.CONSTRUCTOR })
@Retention(RetentionPolicy.RUNTIME)
public @interface Tagged {}

Test eclipse AspectJ project attached.
Comment 1 Andrew Clement CLA 2013-09-27 14:33:49 EDT
This comes down to a FIXME in the code (BcelClassWeaver):

weaveInAddedMethods(); // FIXME asc are these potentially affected by declare annotation?

The added methods are those like the one here, the method added to the top most implementor of an interface when the ITD method was on an interface.

The fix is not trivial. These added methods are not of the right type to pass to the matching code for the declare annotation patterns.
Comment 2 Matthew Adams CLA 2013-09-27 16:03:40 EDT
Andy, I'm not sure what your comment means.  Are you saying that it's not really fixable?
Comment 3 Andrew Clement CLA 2013-10-01 13:01:26 EDT
fixed. Not the cleanest impl but it works.
Comment 4 Matthew Adams CLA 2013-10-02 10:42:46 EDT
Andy, can you trigger a snapshot build?
http://repo.spring.io/snapshot/org/aspectj/aspectjrt/1.8.0.BUILD-SNAPSHOT/
looks out of date and I'm having trouble building locally.
Comment 5 Matthew Adams CLA 2013-10-02 18:20:02 EDT
Testing against 1.7.4.BUILD-SNAPSHOT worked jim-dandy.

AJDT 1.8.0(.latest) complains, and understandably, since it uses aspectj from the 1.8 branch, which didn't receive this fix, as it went into master, which is where 1.7.4 is coming from.