title: Eclipse JDT: Java Search Engine
body: <p>I need to find all the Java types (classe, interface, enum, annotation) in all projectes' source directories of workspace, given a name as String. For example, input "Test" would return all the Java types whose names start with "Test" defined in all the projects source directories. I tried to handle this with JDT's SearchEngine as follows</p>
  
  <pre><code>SearchPattern pattern = SearchPattern.createPattern("Test",
              IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS,
              SearchPattern.R_PREFIX_MATCH);
  IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
  SearchRequestor requestor = new SearchRequestor() {
          public void acceptSearchMatch(SearchMatch match) {
              System.out.println("Found: " + match.getElement());
          }
  };
  SearchEngine searchEngine = new SearchEngine();
  try {
          searchEngine.search(pattern, new SearchParticipant[] { SearchEngine
                          .getDefaultSearchParticipant() }, scope, requestor,
                          null);
  } catch (CoreException e) {
          e.printStackTrace();
  }
  </code></pre>
  
  <p>The code above returned some java types not in Eclipse workspace. For example:</p>
  
  <p>Found: TestSimple (not open) [in TestSimple.class [in &lt;default&gt; [in /home/me/test]]]</p>
  
  <p>TestSimple.java is a file created from command line in my home directory and it has nothing to do with Eclipse projects. (My Eclipse workspace is defined in /home/me/eclipse/workspace.) I am not sure why it is included in the search result? Is SearchEngine the best way to handle this scenario, given the fact that I just need the java type names, I don't need anything inside a class such as field, method or reference? Thanks</p>