Community
Participate
Working Groups
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.
Just noticed that findTypes would return both the types from the editors and from the project.
Is there any reference between the two projects on the include path?
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.
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.
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.