Summary: | [search] SearchEngine not returning correct result | ||||||
---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Máirtín <sshshtgttsbiow> | ||||
Component: | Core | Assignee: | Frederic Fusier <frederic_fusier> | ||||
Status: | VERIFIED FIXED | QA Contact: | |||||
Severity: | normal | ||||||
Priority: | P3 | ||||||
Version: | 3.3 | ||||||
Target Milestone: | 3.4 M1 | ||||||
Hardware: | PC | ||||||
OS: | Windows XP | ||||||
Whiteboard: | |||||||
Attachments: |
|
Description
Máirtín
2007-07-12 12:08:13 EDT
The version of Eclipse that I am using is Version: 3.3.0, Build id: I20070503-1400. Here's your code snippet with a search requestor which may workaround your problem waiting for a build with the fix of this problem: final Set<SearchMatch> classesThatExtendFoo= new HashSet<SearchMatch>(); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); SearchPattern pattern = SearchPattern.createPattern("Foo", IJavaSearchConstants.TYPE, IJavaSearchConstants.IMPLEMENTORS, SearchPattern.R_EXACT_MATCH); final String qualifiedType = "a.b.c.Foo"; SearchRequestor requestor = new SearchRequestor() { public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException { Object element = searchMatch.getElement(); if (element instanceof IType) { IType type = (IType) element; // Look if super interface names matches the qualified type String[] superInterfaces = type.getSuperInterfaceNames(); int length = superInterfaces == null ? 0 : superInterfaces.length; for (int i=0; i<length; i++) { if (superInterfaces[i].equals(qualifiedType)) { System.out.println(searchMatch); classesThatExtendFoo.add(searchMatch); return; } } // Look if an import declaration matches the qualified type IImportDeclaration[] imports = ((ICompilationUnit) type.getAncestor(IJavaElement.COMPILATION_UNIT)).getImports(); length = imports == null ? 0 : imports.length; for (int i=0; i<length; i++) { String importName = imports[i].getElementName(); if (importName.equals(qualifiedType)) { System.out.println(searchMatch); classesThatExtendFoo.add(searchMatch); return; } if (imports[i].isOnDemand()) { int idx = importName.lastIndexOf('.'); if (idx > 0 && importName.substring(0, idx).equals(qualifiedType.substring(0, idx))) { System.out.println(searchMatch); classesThatExtendFoo.add(searchMatch); return; } } } } } } new SearchEngine().search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant()}, scope, requestor, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); You will then be able to find following classes even if Foo is not implemented yet: Bar1.java package x.y.z; import a.b.c.Foo; public class Bar1 implements Foo {} Bar2.java package x.y.z; import a.b.c.*; public class Bar2 implements Foo {} Bar3.java package x.y.z; public class Bar3 implements a.b.c.Foo {} Created attachment 73680 [details]
Proposed patch
Released for 3.4M1 in HEAD stream. Verified for 3.4M1 using build I20070802-0800. |