Bug 99228 - [generics][itds] ITD of a field into a generic class
Summary: [generics][itds] ITD of a field into a generic class
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 1.5.0 M3   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-09 14:30 EDT by Samuel Gélineau CLA
Modified: 2005-06-14 12:04 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 Samuel Gélineau CLA 2005-06-09 14:30:06 EDT
using an intertype declaration to add a field to a generic class compiles, but
the field is not added:

class Normal {}
class Generic<T> {}

aspect Injector {
  void Normal.method() {}
  void Generic.method() {}
  int Normal.field;
  int Generic.field;

  void test() {
    new Normal().method(); // works
    new Generic<Integer>().method(); // works
    int normal = new Normal().field; // works
    int generic = new Generic<Integer>().field; // unresolved field
  }
}
Comment 1 Andrew Clement CLA 2005-06-10 06:40:42 EDT
Ok, this fails because of how the compiler represents Parameterized Types.

Generic types (Generic<T>) are represented by SourceTypeBindings that are a
subclass of ReferenceBinding.  Within SourceTypeBinding we have added AspectJ
extensions to resolve inter-type declarations.  This is the 'memberFinder' that
exists in our variant of SourceTypeBinding.  A specific parameterized instance
of the generic type (Generic<Integer>) is represented by a
ParameterizedTypeBinding - this is also a subtype of ReferenceBinding (it is
*not* a subtype of SourceTypeBinding).  ParameterizedTypeBinding stores a
reference to its generic type (SourceTypeBinding) in its 'type' field.  Now,
ParameterizedTypeBinding knows nothing about intertype field declarations and so
when asked for 'field' below it cannot be found.

A potential fix is to override getField() in ParameterizedTypeBinding - have it
look locally first - if it is not found then delegate to its generic type to
find the field (which will result in it finding the ITD'd field - you can't ITD
on parameterized types so it doesn't make sense to duplicate the lookup code in
ParameterizedTypeBinding).  This fix *works* - I just need to think it through a
little more and make sure its right.  I'm also interested as to why 'new
Generic<Integer>().method()' resolves OK - as there is no specialized processing
in ParameterizedTypeBinding for it (I dont think)?
Comment 2 Andrew Clement CLA 2005-06-14 10:52:06 EDT
Fix checked in as written up - testcases too. waiting on build before closing.
Comment 3 Andrew Clement CLA 2005-06-14 12:04:27 EDT
Fix available, see aspectj download page: aspectj-DEVELOPMENT-20050614164300.jar