Bug 295477 - Adding an import removes other import statements
Summary: Adding an import removes other import statements
Status: NEW
Alias: None
Product: AJDT
Classification: Tools
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: AJDT-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-18 10:37 EST by Simone Gianni CLA
Modified: 2010-12-07 14:34 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 Simone Gianni CLA 2009-11-18 10:37:23 EST
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.5) Gecko/2009010218 Gentoo Firefox/3.0.5
Build Identifier: 20090619-0625 AspectJ 1.6.6

I cannot yet fully reproduce this issue, but it happens quite often. I'll try to investigate it better and produce a test case if I manage to, but it will not be easy.

While writing an aspect in the AJ editor, I frequently use the CTRL+SPACE to have Eclipse resolve a class name and add the import clause.

Sometimes, it adds the new import, but removes all the other imports that were there.

Hitting CTRL-Z reverts the removed imports, but trying it again removes them again, so I usually end up inserting the import manually.

If i insert the import manually and use CTRL+SPACE on the "import" line (and not in code) the problem does not appear.

Closing and reopening eclipse removes the error, and this make it hard to reproduce, cause it does not always happen on the same aspects. Sometimes you are editing an aspect for hours without this problem, then it happens, then you close eclipse and go back working on it another day and it works properly.



Reproducible: Sometimes
Comment 1 Andrew Eisenberg CLA 2009-11-18 11:54:11 EST
Hmmm...I think I know what is happening here.

The class ImportRewrite (in JDT not AJDT) is in control of adding and removing imports from a compilation unit.  When adding imports from a content assist proposal, all imports are analyzed and if an import can't be matched, then it is removed.  

AJDT generally does a pretty good job of making sure that all import references are found, but sometimes they are missed.  Without checking directly, this may have something to do with pointcuts not being properly parsed.

Question: are the missing imports coming from references in pointcuts?  My guess is yes.

I'll see if there's something I can do here.  But, if you can find a failing test case for me, that would be very helpful.
Comment 2 Simone Gianni CLA 2009-11-19 06:33:35 EST
Hi Andrew,
thanks for answering.

Imports for pointcuts are sometimes removed if using CTRL+O (Organize imports), but the bug we are facing is a complete removal of all imports except the one that is currently being added.

Since it is "state related" (it does not happen always), could it be that JDT is using some "compilation unit state" that somehow gets corrupted?

For example, if AspectJ build fails somewhere, could it be that the compilation unit "metadata" used by JDT to find imports is partial or corrupted, resulting in JDT removing all imports? 

Sorry if I'm using vague terminology, but I'm not a JDT expert and I don't have time right now to correctly investigate this bug deeper ... so I'm just guessing.

I hope I'll have time to investigate this further during this weekend.
Comment 3 Andrew Eisenberg CLA 2010-04-28 19:25:22 EDT
Try to solve for 2.1.0.
Comment 4 Andrew Eisenberg CLA 2010-06-16 18:11:57 EDT
Determining what will be tackled for 2.1.1 release.
Comment 5 Jon Steinich CLA 2010-12-07 14:34:48 EST
I've had this happen a few times, but haven't found a reproducible scenario yet.

It feels like having errors in the aspect file makes it more likely to happen, but I don't have definitive proof.