Community
Participate
Working Groups
SearchEngine doesn't work all the times. For example the constructors, inner classes or packages are not found. //-- my code calling SearchEngine public static void findElementDecl(String fullQName, int kind, IJavaSearchScope scope) SearchEngine searchEngine = new SearchEngine(JavaUI.getSharedWorkingCopies()); searchEngine.search( ResourcesPlugin.getWorkspace() , createElemDeclPattern(fullQName, kind) , createWorkspaceSearchScope() , collector ); } private static ISearchPattern createElemDeclPattern(String name, int kind) { return SearchEngine.createSearchPattern(name, kind, IJavaSearchConstants.DECLARATIONS, IJavaSearchConstants.CASE_SENSITIVE); } public static IJavaSearchScope createWorkspaceSearchScope() { return SearchEngine.createWorkspaceScope(); } //-- code sample package p; public class C { public C() { super(); } public void method() { } class D { } } findElementDecl("p.C", TYPE, createWorkspaceSearchScope() ); OK findElementDecl("p.C", CLASS, createWorkspaceSearchScope() ); not found findElementDecl("p", PACKAGE, createWorkspaceSearchScope() ); not found findElementDecl("p.C.C()", CONSTRUCTOR, createWorkspaceSearchScope() ); not found findElementDecl("p.C.method()", METHOD, createWorkspaceSearchScope() ); OK findElementDecl("p.C.D", TYPE, createWorkspaceSearchScope() ); not found
Can you describe the workspace you're searching in? What's the project's classpath? Basically, I need steps to reconstruct this workspace. Also do you have any editor open? Does it fail if all editors are closed?
Created attachment 2597 [details] HI java project The workspace has only one java project (in attachment). SearchEngine has the same behavior if editors are opened or closed. Adriana
Except for findElementDecl("p.C", CLASS, createWorkspaceSearchScope() ); which is not supported (see bug 3336 and yourself to the CC list to stay informed of its progress), I get results for all cases. Note that I changed findElementDecl("p.C.C()", CONSTRUCTOR, createWorkspaceSearchScope() ); to findElementDecl("p.C()", CONSTRUCTOR, createWorkspaceSearchScope() ); to get the result.
For findElementDecl("p", PACKAGE, createWorkspaceSearchScope() ); findElementDecl("p.C.D", TYPE, createWorkspaceSearchScope() ); I still don't have any results. I will look may be it is something I do wrong ----------------------------------------------------------- There is another problem with the search engine. I have two projects first and second having both in the classpath the default JRE_LIB (..\eclipse\jre\lib\rt.jar). The projects are not dependent on each other. The first project is closed. When I search in the scope of the project "second" for the class "java.lang.Object" the search engine returns the java element contained in the archive of the project "first". Is this a normal behavior ? I expect the result to be the element contained in the archive of the project "second" (when I search in "second" project's scope) and both elements when I search in workspace scope. Regards Adriana
Please enter a separate bug for the second problem. For the original problem, to help you what's going one, you can run Eclipse with the -debug option and put a .options file in your Eclipse install directory with the following content: # Turn on debug tracing for org.eclipse.jdt.core plugin org.eclipse.jdt.core/debug=true # Reports java search activity org.eclipse.jdt.core/debug/search=true You should get a trace of the search engine activity.
As I supposed it was my fault (for the search of packages and inner classes). With the qualified name that you indicate for the constructors it works very well. Adriana
Closing