List of usage examples for org.eclipse.jdt.core.search SearchEngine createWorkspaceScope
public static IJavaSearchScope createWorkspaceScope()
From source file:org.eclipse.mylyn.internal.sandbox.ui.hyperlinks.JavaResourceHyperlink.java
License:Open Source License
/** * Starts a search for the type with the given name. Reports back to 'searchCompleted(...)'. * //w w w.j a v a2 s . c om * @param typeName * the type to search for */ protected void startSourceSearch(final String typeName) { Job search = new Job("Searching...") { @Override protected IStatus run(IProgressMonitor monitor) { try { // search for the type in the workspace final List<IType> results = new ArrayList<IType>(); SearchRequestor collector = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { Object element = match.getElement(); if (element instanceof IType) { results.add((IType) element); } } }; // do a case-sensitive search for the class name see bug 244352 SearchEngine engine = new SearchEngine(); SearchPattern pattern = SearchPattern.createPattern(typeName, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createWorkspaceScope(), collector, monitor); searchCompleted(results, typeName, null); } catch (CoreException e) { searchCompleted(null, typeName, e.getStatus()); } return Status.OK_STATUS; } }; search.schedule(); }
From source file:org.eclipse.objectteams.otdt.internal.core.ext.AbstractMarkable.java
License:Open Source License
/** * Get all direct and indirect subtypes of all types in 'types'. * @param types//from ww w.ja v a2 s.c o m * @param monitor * @return * @throws JavaModelException */ Set<IType> getSubTypes(Set<IType> types, IProgressMonitor monitor) throws JavaModelException { monitor.beginTask(OTCoreExtMessages.AbstractMarkable_baseClassHierarchy_progress, types.size()); IJavaSearchScope workspaceScope = SearchEngine.createWorkspaceScope(); Set<IType> subTypes = new HashSet<IType>(13); for (IType type : types) { TypeHierarchy hier = new TypeHierarchy(type, null, workspaceScope, true); hier.refresh(monitor); for (IType subType : hier.getAllSubtypes(type)) subTypes.add(subType); monitor.worked(1); } monitor.done(); return subTypes; }
From source file:org.eclipse.objectteams.otdt.internal.refactoring.util.RefactoringUtil.java
License:Open Source License
public static ArrayList<IRoleType> getAllRolesForBase(IType baseType) throws CoreException { OTSearchEngine engine = new OTSearchEngine(); IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope(); SearchPattern pattern = SearchPattern.createPattern(baseType, IJavaSearchConstants.PLAYEDBY_REFERENCES); final ArrayList<IRoleType> roles = new ArrayList<IRoleType>(); if (pattern == null) OTRefactoringPlugin.getInstance().getLog() .log(new Status(Status.ERROR, OTRefactoringPlugin.PLUGIN_ID, "Error creating pattern")); //$NON-NLS-1$ else/*from www . j a v a2 s . c o m*/ engine.search(pattern, searchScope, new SearchRequestor() { public void acceptSearchMatch(SearchMatch match) throws CoreException { Object element = match.getElement(); if (element instanceof IType) roles.add((IRoleType) OTModelManager.getOTElement((IType) element)); } }, null); return roles; }
From source file:org.eclipse.objectteams.otdt.internal.ui.callinmarkers.CallinMarkerCreator2.java
License:Open Source License
/** chained scheduling:<ul> * <li> first wait until the indexes are ready (only on first invocation), * <li> only then schedule our job. *///from w w w.j a v a 2 s .c o m protected synchronized void schedule(final CallinMarkerJob job, final IStatusLineManager statusLine) { if (this.isInitialized) { doSchedule(job, statusLine); return; } else { this.isInitialized = true; Job waitForIndex = new Job( OTDTUIPlugin.getResourceString("CallinMarkerCreator2.wait_for_index_message")) { //$NON-NLS-1$ @Override protected IStatus run(IProgressMonitor monitor) { try { // dummy query for waiting until the indexes are ready (see AbstractJavaModelTest) new SearchEngine().searchAllTypeNames(null, SearchPattern.R_EXACT_MATCH, "!@$#!@".toCharArray(), //$NON-NLS-1$ SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE, IJavaSearchConstants.CLASS, SearchEngine.createWorkspaceScope(), new TypeNameRequestor() { public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { } }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); } catch (CoreException e) { } finally { // chaining: doSchedule(job, statusLine); } return Status.OK_STATUS; } }; waitForIndex.setPriority(Job.DECORATE); waitForIndex.schedule(100); } }
From source file:org.eclipse.objectteams.otdt.tests.AbstractJavaModelTests.java
License:Open Source License
public static void waitUntilIndexesReady() { // dummy query for waiting until the indexes are ready SearchEngine engine = new SearchEngine(); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); try {//from w w w. j a va 2 s. c om engine.searchAllTypeNames(null, SearchPattern.R_EXACT_MATCH, "!@$#!@".toCharArray(), SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE, IJavaSearchConstants.CLASS, scope, new TypeNameRequestor() { public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { } }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); } catch (CoreException e) { } }
From source file:org.eclipse.osee.framework.ui.skynet.FindInWorkspaceOperation.java
License:Open Source License
@Override protected void doWork(final IProgressMonitor monitor) throws Exception { final Map<String, Artifact> guids = getGuidMap(); monitor.beginTask("Searching Java Files", guids.size()); findByName(guids, monitor);/*from ww w. j a va 2s. c o m*/ if (guids.isEmpty()) { return; } final NullProgressMonitor subMonitor = new NullProgressMonitor(); SearchPattern searchPattern = SearchPattern.createPattern("ObjectId", IJavaSearchConstants.ANNOTATION_TYPE, IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, SearchPattern.R_PATTERN_MATCH); IJavaSearchScope workspaceScope = SearchEngine.createWorkspaceScope(); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { ICompilationUnit unit = null; IJavaElement jElement = JavaCore.create(match.getResource()); if (jElement != null && jElement.exists() && jElement.getElementType() == IJavaElement.COMPILATION_UNIT) { unit = (ICompilationUnit) jElement; } String uuid = getGuid(unit.getSource()); if (guids.containsKey(uuid)) { monitor.worked(1); collector.onResource(unit.getResource()); guids.remove(uuid); if (guids.isEmpty()) { subMonitor.setCanceled(true); } } } }; SearchEngine engine = new SearchEngine(); try { engine.search(searchPattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, workspaceScope, requestor, subMonitor); } catch (OperationCanceledException ex) { //do nothings } for (Artifact artifact : guids.values()) { collector.onNotFound(artifact); } }
From source file:org.eclipse.pde.internal.ds.ui.editor.dialogs.DSEditProvideDialog.java
License:Open Source License
private void doOpenSelectionDialog(int scopeType, FormEntry entry) { try {// w w w.java 2 s . co m String filter = entry.getValue(); filter = filter.substring(filter.lastIndexOf(".") + 1); //$NON-NLS-1$ SelectionDialog dialog = JavaUI.createTypeDialog(Activator.getActiveWorkbenchShell(), PlatformUI.getWorkbench().getProgressService(), SearchEngine.createWorkspaceScope(), scopeType, false, filter); dialog.setTitle(Messages.DSProvideDetails_selectType); if (dialog.open() == Window.OK) { IType type = (IType) dialog.getResult()[0]; entry.setValue(type.getFullyQualifiedName('$')); entry.commit(); } } catch (CoreException e) { } }
From source file:org.eclipse.pde.internal.ds.ui.editor.dialogs.DSEditReferenceDialog.java
License:Open Source License
private void doOpenSelectionDialog(int scopeType, FormEntry entry) { try {// w w w . jav a 2s . c o m String filter = entry.getValue(); filter = filter.substring(filter.lastIndexOf(".") + 1); //$NON-NLS-1$ SelectionDialog dialog = JavaUI.createTypeDialog(Activator.getActiveWorkbenchShell(), PlatformUI.getWorkbench().getProgressService(), SearchEngine.createWorkspaceScope(), scopeType, false, filter); dialog.setTitle(Messages.DSReferenceDetails_selectType); if (dialog.open() == Window.OK) { IType type = (IType) dialog.getResult()[0]; entry.setValue(type.getFullyQualifiedName('$')); entry.commit(); } } catch (CoreException e) { } }
From source file:org.eclipse.pde.internal.ds.ui.editor.sections.DSProvideSection.java
License:Open Source License
private void doOpenSelectionDialog(int scopeType) { try {/*from w w w. ja v a 2s.c o m*/ String filter = ""; //$NON-NLS-1$ filter = filter.substring(filter.lastIndexOf(".") + 1); //$NON-NLS-1$ SelectionDialog dialog = JavaUI.createTypeDialog(Activator.getActiveWorkbenchShell(), PlatformUI.getWorkbench().getProgressService(), SearchEngine.createWorkspaceScope(), scopeType, true, filter, new DSTypeSelectionExtension(getDSModel())); dialog.setTitle(Messages.DSProvideDetails_selectType); if (dialog.open() == Window.OK) { Object[] result = dialog.getResult(); for (int i = 0; i < result.length; i++) { IType type = (IType) result[i]; String fullyQualifiedName = type.getFullyQualifiedName('$'); addProvide(fullyQualifiedName); } } } catch (CoreException e) { } }
From source file:org.eclipse.pde.internal.ds.ui.editor.sections.DSReferenceSection.java
License:Open Source License
private void doOpenSelectionDialog(int scopeType) { try {//from ww w . ja va 2 s . com String filter = ""; //$NON-NLS-1$ filter = filter.substring(filter.lastIndexOf(".") + 1); //$NON-NLS-1$ SelectionDialog dialog = JavaUI.createTypeDialog(Activator.getActiveWorkbenchShell(), PlatformUI.getWorkbench().getProgressService(), SearchEngine.createWorkspaceScope(), scopeType, true, filter); dialog.setTitle(Messages.DSReferenceDetails_selectType); if (dialog.open() == Window.OK) { Object[] result = dialog.getResult(); for (int i = 0; i < result.length; i++) { IType type = (IType) result[i]; String fullyQualifiedName = type.getFullyQualifiedName('$'); addReference(fullyQualifiedName); } } } catch (CoreException e) { } }