Bug 64585 - Stale ITD example code in Programming Guide
Summary: Stale ITD example code in Programming Guide
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Docs (show other bugs)
Version: 1.2   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 1.2.1   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-28 12:54 EDT by George Harley CLA
Modified: 2004-10-21 04:31 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description George Harley CLA 2004-05-28 12:54:27 EDT
In the section Appendix B -> Static crosscutting -> Conflicts of the Programming
Guide there is some sample code given on use of ITDs to add a field and method
to every type in a named Java package ...

<snip>
  aspect A {
      private Registry otherPackage.*.r;
      public void otherPackage.*.register(Registry r) {
	  r.register(this);
	  this.r = r;
      }
  }
</snip>

This code is no longer valid as use of wildcarding in ITD definitions was
obsoleted in the 1.1 release.

Suggest it be replaced with a code fragment that introduces the field and 
method on an interface that every type in the named package implements.
Comment 1 Adrian Colyer CLA 2004-07-28 12:03:39 EDT
The new text...

Inter-type declarations raise the possibility of conflicts among locally 
declared members and inter-type members. For example, assuming otherPackage is 
not the package containing the aspect A, the code 

  aspect A {
      private Registry otherPackage.onType.r;
      public void otherPackage.onType.register(Registry r) {
    r.register(this);
    this.r = r;
      }
  }

declares that onType in otherPackage has a field r. This field, however, is only 
accessible from the code inside of aspect A. The aspect also declares that 
onType has a method "register", but makes this method accessible from 
everywhere. 

If onType already defines a private or package-protected field "r", there is no 
conflict: The aspect cannot see such a field, and no code in otherPackage can 
see the inter-type "r". 

If onType defines a public field "r", there is a conflict: The expression 

  this.r = r

is an error, since it is ambiguous whether the private inter-type "r" or the 
public locally-defined "r" should be used. 

If onType defines a method "register(Registry)" there is a conflict, since it 
would be ambiguous to any code that could see such a defined method which 
"register(Registry)" method was applicable. 

Conflicts are resolved as much as possible as per Java's conflict resolution 
rules: 
A subclass can inherit multiple fields from its superclasses, all with the same 
name and type. However, it is an error to have an ambiguous reference to a 
field.
A subclass can only inherit multiple methods with the same name and argument 
types from its superclasses if only zero or one of them is concrete (i.e., all 
but one is abstract, or all are abstract).
Comment 2 Adrian Colyer CLA 2004-07-28 12:06:25 EDT
Now updated in CVS tree and on AspectJ website.
Comment 3 Adrian Colyer CLA 2004-10-21 04:31:26 EDT
Fix released as part of AspectJ 1.2.1