Bug 298683 - Spurious error in editor using generics
Summary: Spurious error in editor using generics
Status: RESOLVED FIXED
Alias: None
Product: AJDT
Classification: Tools
Component: Core (show other bugs)
Version: 2.0.1   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 2.1.1   Edit
Assignee: AJDT-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 298692
  Show dependency tree
 
Reported: 2009-12-31 12:01 EST by Andrew Eisenberg CLA
Modified: 2010-09-01 17:37 EDT (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 Andrew Eisenberg CLA 2009-12-31 12:01:53 EST
From the mailing list:

==============
Essentially I tried creating an Eclipse AspectJ project with just one MyAspect.aj file (in the default namespace) with the following contents (toy example):

public aspect MyAspect
{
    public interface MyInterface
    {
    }

    declare parents: MyObject implements MyInterface;

    public boolean MyInterface.instanceOf(Class<? extends Object> c)
    {
        return c.isInstance(this);
    }
}

class MyObject
{
}

class Main
{
    public static void main(String[] args)
    {
        new MyObject().instanceOf(MyObject.class);
    }
}

I get, over "instanceOf" in the main method, the following error: "The method instanceOf(Class<Object>) from the type MyObject refers to the missing type Object". Notice that it is declared as Class<? extends Object> but during weaving becomes Class<Object>.

Here is my setup:

* Mac OS X 10.4 Tiger
* Eclipse Galileo
* Mac OS X JavaVM 1.5.0 (J2SE-1.5)
* AspectJ 1.6.6
* AJDT 2.0.1

I downloaded the standalone aspectj-1.6.6.jar at http://www.eclipse.org/aspectj/, installed it correctly, and ran the command "ajc -1.5 MyAspect.aj -showWeaveInfo" and it didn't give me that error (or any other error). What it did give me was the following:

Type 'MyAspect$MyInterface' (MyAspect.aj) has intertyped method from 'MyAspect' (MyAspect.aj:'boolean MyAspect$MyInterface.instanceOf(java.lang.Class<? extends java.lang.Object>)')

Extending interface set for type 'MyObject' (MyAspect.aj) to include 'MyAspect$MyInterface' (MyAspect.aj)

Type 'MyObject' (MyAspect.aj) has intertyped method from 'MyAspect' (MyAspect.aj:'boolean MyAspect$MyInterface.instanceOf(java.lang.Class<? extends java.lang.Object>)')

So I think there is a disconnect between how ajc behaves on the command line and how ajdt behaves in Eclipse. I'd be particularly curious to know if there are any setups possible that would get Eclipse to weave this properly. Right now I am removing a ton of generics from my project, but you can obviously understand that I would prefer to keep them around if at all possible. :)
========================

The problem is that AJDT does not use ajc to analyze the code when within the AJ Editor.  There is probably some problem with the type augmentation when generics are being used in this situation.  I will have a look at this.
Comment 1 Andrew Eisenberg CLA 2009-12-31 12:03:32 EST
Please note that your code is compiling and will rub correctly, what you are seeing is an error in the editor.
Comment 2 Andrew Eisenberg CLA 2009-12-31 13:29:06 EST
There are two issues here.

The first one happens when the  Main class is in the same file.  Here, it seems like AJDT is not properly erasing the type signatures for parameters with an explicit upper bounds (eg- 'extends Object).

The second problem happens when the Main class is in a different file.  Here, there is a handle identifier problem.  Again, the problem is with type parameters with explicit upper bounds.  The type signatures for these kinds of types look something like this: "QClass\<+QObject;>;" (this translates to Class<? extends Object>).

The problem is that '+' is internally interpreted by AJDT to mean a pointcut, but it also is used by JDT to represent an explicit upper bound to a type parameter.  What this means is that explicit upper bounds are not tested by AJDT.

The correct solution, I believe is to stop using '+' to represent pointcuts in handle identifiers in IJavaElements.  This will require a similar change to AspectJ for use in IProgramElements.
Comment 3 Andrew Eisenberg CLA 2010-01-02 01:09:52 EST
Committed a fix for the first issue.

When the ITD with a type parameter with an upper bound is only referenced within the same file, you should not see any more spurious editor errors.  Since the full fix also requires a change to the AspectJ compiler, that will have to wait until after the 2.0.2 release.
Comment 4 Andrew Eisenberg CLA 2010-09-01 17:37:09 EDT
Fixed now.