List of usage examples for org.eclipse.jdt.core.search SearchEngine createWorkspaceScope
public static IJavaSearchScope createWorkspaceScope()
From source file:edu.washington.cs.cupid.wizards.TypeUtil.java
License:Open Source License
/** * Search for <code>className</code> in the workspace. * @param className a simple or qualified class name * @return instances of the type/*from ww w .j a v a 2s . c o m*/ * @throws CoreException if an error occurred during the search */ public static List<IType> fetchTypes(String className) throws CoreException { if (className == null) { throw new NullPointerException("Class name to search for cannot be null"); } final List<IType> result = Lists.newArrayList(); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { if (match instanceof TypeDeclarationMatch) { if (match.getElement() instanceof IType) { result.add((IType) match.getElement()); } else { throw new RuntimeException("Unexpected match of type " + match.getElement().getClass()); } } } }; SearchEngine engine = new SearchEngine(); engine.search( SearchPattern.createPattern(className, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_FULL_MATCH), // pattern new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createWorkspaceScope(), //scope, requestor, // searchRequestor null // progress monitor ); return result; }
From source file:edu.washington.cs.cupid.wizards.TypeUtil.java
License:Open Source License
/** * Show a single-selection type search dialog. See {@link JavaUI#createTypeDialog}. * @param shell the parent shell of the dialog to be created * @return the selected type, or <code>null</code> if the dialog was cancelled. * @throws JavaModelException if the selection dialog could not be opened *//* ww w . j av a 2 s . c o m*/ public static IType showTypeDialog(Shell shell) throws JavaModelException { SelectionDialog dialog; dialog = JavaUI.createTypeDialog(shell, null, // IRunnableContext SearchEngine.createWorkspaceScope(), IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES, false // Multiple Selection ); dialog.open(); return dialog.getResult() == null ? null : (IType) dialog.getResult()[0]; }
From source file:fr.inria.diverse.trace.benchmark.EngineHelper.java
License:Open Source License
public void prepareEngine(URI model, IDebuggerHelper debugger, Language language) throws CoreException, EngineContextException { IRunConfiguration runConfiguration = new BenchmarkRunConfiguration(debugger, language, model); // We don't want to debug actually, ie we don't want the animator ExecutionMode executionMode = ExecutionMode.Run; // In this construction, the addons are created and loaded as well executionContext = new ModelExecutionContext(runConfiguration, executionMode); String className = executionContext.getRunConfiguration().getExecutionEntryPoint(); SearchPattern pattern = SearchPattern.createPattern(className, IJavaSearchConstants.CLASS, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); DefaultSearchRequestor requestor = new DefaultSearchRequestor(); SearchEngine engine = new SearchEngine(); engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null);/*ww w . ja v a2 s. c om*/ IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) requestor._binaryType.getPackageFragment() .getParent(); parameters = new ArrayList<>(); parameters.add(executionContext.getResourceModel().getContents().get(0)); String bundleName = null; bundleName = packageFragmentRoot.getPath().removeLastSegments(1).lastSegment().toString(); Class<?> c = null; Bundle bundle = Platform.getBundle(bundleName); // If not found, we try again with projects if (bundle == null) { String projectName = requestor._binaryType.getJavaProject().getElementName(); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); if (project != null && project.exists() && !project.getFullPath().equals(executionContext.getWorkspace().getProjectPath())) { Provisionner p = new Provisionner(); IStatus status = p.provisionFromProject(project, null); if (!status.isOK()) { throw new CoreException(new Status(1, "EngineHelper", "couldn't provision project :(")); } } bundleName = project.getName(); bundle = Platform.getBundle(bundleName); } try { c = bundle.loadClass(executionContext.getRunConfiguration().getExecutionEntryPoint()); } catch (ClassNotFoundException e) { e.printStackTrace(); throw new CoreException(new Status(1, "EngineHelper", "couldn't load Main class")); } method = null; try { method = c.getMethod("main", parameters.get(0).getClass().getInterfaces()[0]); } catch (Exception e) { e.printStackTrace(); throw new CoreException(new Status(1, "EngineHelper", "couldn't find main method")); } o = null; try { o = c.newInstance(); } catch (Exception e) { e.printStackTrace(); throw new CoreException(new Status(1, "EngineHelper", "couldn't create Main object")); } _executionEngine = new PlainK3ExecutionEngine(executionContext, o, method, parameters); debugger.setExecutionEngine(_executionEngine); }
From source file:mt.com.southedge.jclockwork.plugin.wizard.controls.CreateControlObject.java
License:Open Source License
/** * Handles and displays the selection dialog *//*ww w . j av a 2s .c om*/ protected void handleButtonInvocation() { try { SelectionDialog selDialog = JavaUI.createTypeDialog( PlatformUI.getWorkbench().getDisplay().getActiveShell(), PlatformUI.getWorkbench().getProgressService(), SearchEngine.createWorkspaceScope(), IJavaElementSearchConstants.CONSIDER_CLASSES, false); selDialog.setTitle(ClockWorkWizardMessages.ClockWorkWizard_Selection_Dialog_Title); if (selDialog.open() != IDialogConstants.CANCEL_ID) { processSelection(selDialog); } } catch (JavaModelException e1) { e1.printStackTrace(); } }
From source file:net.hillsdon.testlink.model.impl.Searcher.java
License:Open Source License
public Set<IResource> search(final String typeName) throws CoreException { SearchEngine searchEngine = new SearchEngine(); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); ResourceCollector results = new ResourceCollector(); SearchPattern pattern = SearchPattern.createPattern(typeName, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH); searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, results, new NullProgressMonitor()); return results.getCollectedPaths(); }
From source file:net.sourceforge.c4jplugin.internal.ui.contracthierarchy.actions.FocusOnTypeAction.java
License:Open Source License
public void run() { Shell parent = fViewPart.getSite().getShell(); TypeSelectionDialog2 dialog = new TypeSelectionDialog2(parent, false, PlatformUI.getWorkbench().getProgressService(), SearchEngine.createWorkspaceScope(), IJavaSearchConstants.TYPE);/*from ww w.j a v a 2 s. c o m*/ dialog.setTitle(ContractHierarchyMessages.FocusOnTypeAction_dialog_title); dialog.setMessage(ContractHierarchyMessages.FocusOnTypeAction_dialog_message); if (dialog.open() != IDialogConstants.OK_ID) { return; } Object[] types = dialog.getResult(); if (types != null && types.length > 0) { IType type = (IType) types[0]; fViewPart.setInputElement(type); } }
From source file:net.sourceforge.metrics.ui.dependencies.TangleAnalyzer.java
License:Open Source License
/** * @param packageNames//from w w w.java 2 s .c o m * @return */ private List<IJavaElement> getPackageFragments(List<String> packageNames) { monitor.subTask("Finding Packages in tangle"); SearchEngine searchEngine = new SearchEngine(); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); SearchPattern pattern = SearchPattern.createPattern("*", IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH); PackageCollector c = new PackageCollector(packageNames); try { searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, c, monitor); monitor.worked(100); return c.getResult(); } catch (CoreException e) { e.printStackTrace(); return new ArrayList<IJavaElement>(); } }
From source file:org.codehaus.groovy.eclipse.codebrowsing.tests.BrowsingTestCase.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 av a 2s. c o m*/ engine.searchAllTypeNames(null, SearchPattern.R_EXACT_MATCH, "!@$#!@".toCharArray(), SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE, IJavaSearchConstants.CLASS, scope, new TypeNameRequestor() { @Override 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.codehaus.groovy.eclipse.core.search.SyntheticAccessorSearchRequestor.java
License:Apache License
public void findSyntheticMatches(IJavaElement element, ISearchRequestor uiRequestor, IProgressMonitor monitor) throws CoreException { // findSyntheticMatches(element, IJavaSearchConstants.REFERENCES, new // SearchParticipant[] { new JavaSearchParticipant() }, // SearchEngine.createJavaSearchScope(new IJavaElement[] { element }), // uiRequestor, monitor); findSyntheticMatches(element, IJavaSearchConstants.REFERENCES, new SearchParticipant[] { new JavaSearchParticipant() }, SearchEngine.createWorkspaceScope(), uiRequestor, monitor);//from w ww.j av a 2s . co m }
From source file:org.cubictest.exporters.selenium.ui.SeleniumCustomStepSection.java
License:Open Source License
private void createBrowseClassButton(Composite composite) { browseClassButton = new Button(composite, SWT.PUSH); browseClassButton.setText("Browse..."); browseClassButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { }/*www. j av a 2s . com*/ public void widgetSelected(SelectionEvent e) { Shell shell = new Shell(); SelectionDialog dialog; try { dialog = JavaUI.createTypeDialog(shell, new ProgressMonitorDialog(shell), SearchEngine.createWorkspaceScope(), IJavaElementSearchConstants.CONSIDER_CLASSES, false); dialog.setTitle("Open ICustomTestStep implementation"); if (dialog.open() == SelectionDialog.OK) { IType result = (IType) dialog.getResult()[0]; ChangeCustomStepClassNameCommand command = new ChangeCustomStepClassNameCommand(); command.setCustomTestStepData(data); command.setPath(result.getPath().toPortableString()); command.setDisplayText(result.getFullyQualifiedName()); getCommandStack().execute(command); } } catch (JavaModelException ex) { ErrorHandler.logAndShowErrorDialog(ex); } } }); FormData layoutData = new FormData(); layoutData.left = new FormAttachment(classText, 5); browseClassButton.setLayoutData(layoutData); }