Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 354413 - Class reference searching not working. Complicates refactoring.
Summary: Class reference searching not working. Complicates refactoring.
Status: RESOLVED FIXED
Alias: None
Product: AJDT
Classification: Tools
Component: Core (show other bugs)
Version: 2.1.3   Edit
Hardware: PC Windows 7
: P3 critical (vote)
Target Milestone: 2.2.0   Edit
Assignee: AJDT-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-10 12:48 EDT by Stan Svec CLA
Modified: 2011-08-11 08:32 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stan Svec CLA 2011-08-10 12:48:50 EDT
For the purpose of replicating the bug from my current Eclipse, I downloaded new Eclipse IDE for Java EE Developers 64bit, Indigo version 3.7 and installed AJDT 2.1.3. Then I created a Java project P1 with one class C1. Next, I created a second Java project P2 and added project P1 into the classpath (Java Build Path - Projects). I finally created a class C2 in the project P2 with a reference to the class C1 from the project P1. 
 
Now if I refactor class C1, the changes will be propagated to the class C2. If I search for the references of the class C1 (Ctrl+Shift+G), then Eclipse finds references in the class C2. Everything works fine.
 
But when I convert the Java project P2 to an AspectJ project, everything mentioned above is only working until the first reference search or refactoring. Second and following attempts are not working. All refactoring changes in the class C1 are not propagated into the class C2. Reference search finds nothing. 
 
This issue complicates the development of one of my AspectJ libraries which I use in my many AspectJ projects.
 
I was able to replicate the same bug with AJDT 2.2.0dev and with Eclipse IDE for Java EE Developers 32bit + AJDT 2.3.1 on Windows Vista. 
 
Please, pardon my English and the report insufficiencies. I am not a native speaker and this is my first report.
Comment 1 Andrew Eisenberg CLA 2011-08-10 13:31:23 EDT
Thanks for the description.  I am able to reproduce this problem and I will have a deeper look over the next day or so.
Comment 2 Andrew Eisenberg CLA 2011-08-10 14:52:19 EDT
Interesting...if the file with references is a working copy (ie- it has unsaved changes), then the search results are correct, but if the file has no unsaved changes, then search does not work.
Comment 3 Stan Svec CLA 2011-08-10 17:06:44 EDT
I didn't notice before. Thank you for taking a look on it.
Comment 4 Andrew Eisenberg CLA 2011-08-10 17:52:37 EDT
I had orignally thought this problem was Very Bad.  But, it is not.  Here is what is happening:

First, some background: There is something called a state file that is generated by JDT for each project after each build.  It keeps track of references between compilation units and is generally used to help with incremental compilation.  AspectJ does not create a state file (it keeps state in memory), but even if it did create a state file, it would not be compatible with JDT's.

After a build, a state object is generated.  It is occasionally written to disk, but not always.  It is also cached in memory.  On proper shutdown, it is always written to disk.

The problem happens when a project was once a Java project and then it is converted to an AJ project.  The state object remains cached in memory, and the one stored on disk is not deleted.  And over time, this state object becomes outdated as the project changes.

The Java search engine is being "smart" in that it wants to do a deep search on only the smallest amount of classes for references.  So, if a state object exists for a project, the search engine looks at the state object to see the smallest amount of files that it *really* needs to search.

The problem is that for AJ projects that have stale states around, this information will be incorrect and it will miss references inside of AJ projects.  If, however, as is usually the case, the state object does not exist for the AJ project, then searching will occur (but it will be slightly less efficient than if there were a correct state file).

Workaround:
1. Shut down eclipse
2. Open directory workspace/.metadata/.plugins/org.eclipse.core.resources/<AJ_Project_Name>/org.eclipse.jdt.core/
3. delete state.dat
4. restart eclipse
This should ensure that the state file and state object no longer exists for that project and searching will work correctly.

Fix:
AJDT needs to remove the cached state object and delete the state file when a project becomes and AJ project.

Please let me know if this workaround does the trick for you.
Comment 5 Andrew Eisenberg CLA 2011-08-10 18:08:51 EDT
Fix is committed and will be available on the 3.7 branch in a few hours.
Comment 6 Stan Svec CLA 2011-08-11 08:32:08 EDT
Perfect. Workaround does the trick for me. Thank you for explanation and very fast reaction.