List of usage examples for org.eclipse.jdt.core.search SearchEngine createSearchPattern
public static ISearchPattern createSearchPattern(String stringPattern, int searchFor, int limitTo, boolean isCaseSensitive)
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. ja v a 2 s . c o m 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); } }
From source file:com.iw.plugins.spindle.util.FieldBindingsPreferencePage.java
License:Mozilla Public License
public static IJavaElement[] unfold(String folded) { if (folded != null && !"".equals(folded.trim())) { ISearchPattern searchPattern = null; StringTokenizer tok = new StringTokenizer(folded, ","); while (tok.hasMoreTokens()) { String fragment = tok.nextToken(); if (searchPattern == null) { searchPattern = SearchEngine.createSearchPattern(fragment, IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, false); } else { searchPattern = SearchEngine.createOrSearchPattern(searchPattern, SearchEngine.createSearchPattern(fragment, IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, false)); }/*from w w w . j ava 2s. c o m*/ } try { UnfoldSearchCollector collector = new UnfoldSearchCollector(); long start = new Date().getTime(); new SearchEngine().search(TapestryPlugin.getDefault().getWorkspace(), searchPattern, SearchEngine.createWorkspaceScope(), collector); return collector.getFoundElements(); } catch (JavaModelException jmex) { jmex.printStackTrace(); } } return new IJavaElement[0]; }