Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 318656 - [search] JSDT returns type from wrong project if in working copy
Summary: [search] JSDT returns type from wrong project if in working copy
Status: NEW
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: Future   Edit
Assignee: Project Inbox CLA
QA Contact: Chris Jaun CLA
URL:
Whiteboard: null shouldn't be in the array in cur...
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-01 19:55 EDT by Eugene Ostroukhov CLA
Modified: 2013-06-19 11:09 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 Eugene Ostroukhov CLA 2010-07-01 19:55:08 EDT
We have following simple code:
IJavaScriptProject jsProject = JavaScriptCore.create(project);
IType npopup = jsProject.findType("NotificationPopup");
IType uimanager = jsProject.findType("UIManager");
return npopup != null && uimanager != null;

Say we have projects "a" and "b". This method will work as expected if JS files that declare the types are closed. If files are open in the editor then the types from the editors will always be returned even if the jsProject doesn't contain them.
Comment 1 Eugene Ostroukhov CLA 2010-07-01 19:57:29 EDT
Just noticed that findTypes would return both the types from the editors and from the project.
Comment 2 Chris Jaun CLA 2010-07-02 10:03:29 EDT
Is there any reference between the two projects on the include path?
Comment 3 Eugene Ostroukhov CLA 2010-07-02 12:14:15 EDT
No. The projects do not reference each other.

Please note that behavior changing whether you have an open editor or not. I.e. if the editor is open - then getTypes method will return types both from the editor and the "jsProject" (if there is any). If the editor is closed then only the type from "jsProject" is returned.
Comment 4 Nitin Dahyabhai CLA 2010-07-02 13:57:04 EDT
Technically this is working as designed, it's just not a problem in JDT since type names are always qualified there.  IJavaScriptProject#findType(String) includes the contents of working copies from the default owner, which is where they are created as the compilation unit becomes a working copy, in the results.
Comment 5 Eugene Ostroukhov CLA 2010-07-02 14:08:08 EDT
JavaDoc for the method reads:
"Returns the first type found following this project's includepath with the given fully qualified name or null if none is found."

Current implementation will return type that is not on the include path if that type is opened in the editor. In our case it resulted in a bug that was tough to reproduce (as it is not intuitive that there's relation between opened editors and this method). I would expect that there are cases you would have working copy even without open editor. In such case plugin developers will not be able to understand where the type comes without spending several hours debugging.

Our current code is:
final IType[] types = project.findTypes(name);
if (types != null) {
  for (IType type : types) {
    if (type.getJavaScriptProject().equals(project)) {
      return true;
    }
  }
}

Please note pecularity of the findTypes method - it will return null if there are no types found. My personal expectation would be that it returns empty array. The JavaDoc for the method reads:

* @return the first type found following this project's includepath
* with the given fully qualified name or <code>null</code> if none is found

It looks like JavaDoc comes from the findType method.