List of usage examples for org.eclipse.jdt.core.search SearchEngine search
public void search(IWorkspace workspace, ISearchPattern searchPattern, IJavaSearchScope scope, IJavaSearchResultCollector resultCollector) throws JavaModelException
From source file:com.iw.plugins.spindle.ui.widgets.TypeChooserWidget.java
License:Mozilla Public License
public void configure(final IJavaProject project, final IRunnableContext context) { try {/*from w w w .j av a2 s . com*/ final boolean baseIsInterface = fHierarchyRoot.isInterface(); fSearchResults = new ArrayList(); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { IJavaSearchScope scope = null; try { // we want to rip out the JRE entry as there's no chance of finding a tapestry class there. ArrayList roots = new ArrayList(); IClasspathEntry[] classpath = project.getRawClasspath(); for (int i = 0; i < classpath.length; i++) { if (classpath[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath cpPath = classpath[i].getPath(); if (JavaRuntime.JRE_CONTAINER.equals(cpPath.segment(0))) continue; } roots.add(project.findPackageFragmentRoots(classpath[i])); } scope = SearchEngine.createJavaSearchScope( (IJavaElement[]) roots.toArray(new IJavaElement[roots.size()]), true); } catch (JavaModelException e1) { scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, true); } ISearchPattern pattern = SearchEngine.createSearchPattern("*", IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, true); SearchEngine engine = new SearchEngine(); IJavaSearchResultCollector collector = new IJavaSearchResultCollector() { public void aboutToStart() { } public void accept(IResource resource, int start, int end, IJavaElement enclosingElement, int accuracy) throws CoreException { if (accuracy != EXACT_MATCH) return; if (enclosingElement.getElementType() != IJavaElement.TYPE) return; IType type = (IType) enclosingElement; System.out.println(type.getFullyQualifiedName()); if (baseIsInterface) { if (!CoreUtils.implementsInterface(type, fHierarchyRoot.getElementName())) return; } else { if (!CoreUtils.extendsType(type, fHierarchyRoot)) return; } System.out.println(type.getFullyQualifiedName()); fSearchResults.add(type); } public void done() { } public IProgressMonitor getProgressMonitor() { return monitor; } }; try { engine.search(ResourcesPlugin.getWorkspace(), pattern, scope, collector); } catch (JavaModelException e) { UIPlugin.log(e); } } }; context.run(false, true, runnable); } catch (InvocationTargetException e) { UIPlugin.log(e); } catch (InterruptedException e) { //do nothing; } catch (JavaModelException e) { UIPlugin.log(e); } }