List of usage examples for org.eclipse.jdt.core.search SearchEngine createWorkspaceScope
public static IJavaSearchScope createWorkspaceScope()
From source file:org.eclim.plugin.jdt.command.search.SearchCommand.java
License:Open Source License
/** * Gets the search scope to use.// w w w.j ava2 s .c o m * * @param scope The string name of the scope. * @param project The current project. * * @return The IJavaSearchScope equivalent. */ protected IJavaSearchScope getScope(String scope, IJavaProject project) throws Exception { if (project == null) { return SearchEngine.createWorkspaceScope(); } else if (SCOPE_PROJECT.equals(scope)) { return SearchEngine.createJavaSearchScope(new IJavaElement[] { project }); } return SearchEngine.createWorkspaceScope(); }
From source file:org.eclipse.ajdt.internal.ui.dialogs.TypeSelectionComponent.java
License:Open Source License
private void fillViewMenu(IMenuManager viewMenu) { if (!fMultipleSelection) { ToggleStatusLineAction showStatusLineAction = new ToggleStatusLineAction(); showStatusLineAction.setChecked(fSettings.getBoolean(SHOW_STATUS_LINE)); viewMenu.add(showStatusLineAction); }/*from ww w. j a v a2 s. c o m*/ FullyQualifyDuplicatesAction fullyQualifyDuplicatesAction = new FullyQualifyDuplicatesAction(); fullyQualifyDuplicatesAction.setChecked(fSettings.getBoolean(FULLY_QUALIFY_DUPLICATES)); viewMenu.add(fullyQualifyDuplicatesAction); if (fScope == null) { fFilterActionGroup = new WorkingSetFilterActionGroup(getShell(), JavaPlugin.getActivePage(), new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { IWorkingSet ws = (IWorkingSet) event.getNewValue(); if (ws == null || (ws.isAggregateWorkingSet() && ws.isEmpty())) { fScope = SearchEngine.createWorkspaceScope(); fTitleLabel.setText(null); } else { fScope = JavaSearchScopeFactory.getInstance().createJavaSearchScope(ws, true); fTitleLabel.setText(ws.getLabel()); } fViewer.setSearchScope(fScope, true); } }); String setting = fSettings.get(WORKINGS_SET_SETTINGS); if (setting != null) { try { IMemento memento = XMLMemento.createReadRoot(new StringReader(setting)); fFilterActionGroup.restoreState(memento); } catch (WorkbenchException e) { } } IWorkingSet ws = fFilterActionGroup.getWorkingSet(); if (ws == null || (ws.isAggregateWorkingSet() && ws.isEmpty())) { fScope = SearchEngine.createWorkspaceScope(); fTitleLabel.setText(null); } else { fScope = JavaSearchScopeFactory.getInstance().createJavaSearchScope(ws, true); fTitleLabel.setText(ws.getLabel()); } fFilterActionGroup.fillViewMenu(viewMenu); } }
From source file:org.eclipse.ajdt.internal.ui.dialogs.TypeSelectionDialog2.java
License:Open Source License
private void ensureConsistency() throws InvocationTargetException, InterruptedException { // we only have to ensure history consistency here since the search engine // takes care of working copies. class ConsistencyRunnable implements IRunnableWithProgress { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (fgFirstTime) { // Join the initialize after load job. IJobManager manager = Platform.getJobManager(); manager.join(JavaUI.ID_PLUGIN, monitor); }/*from ww w . ja v a 2 s . co m*/ OpenTypeHistory history = OpenTypeHistory.getInstance(); if (fgFirstTime || history.isEmpty()) { monitor.beginTask(JavaUIMessages.TypeSelectionDialog_progress_consistency, 100); if (history.needConsistencyCheck()) { refreshSearchIndices(new SubProgressMonitor(monitor, 90)); history.checkConsistency(new SubProgressMonitor(monitor, 10)); } else { refreshSearchIndices(monitor); } monitor.done(); fgFirstTime = false; } else { history.checkConsistency(monitor); } } public boolean needsExecution() { OpenTypeHistory history = OpenTypeHistory.getInstance(); return fgFirstTime || history.isEmpty() || history.needConsistencyCheck(); } private void refreshSearchIndices(IProgressMonitor monitor) throws InvocationTargetException { try { new SearchEngine().searchAllTypeNames(null, 0, // make sure we search a concrete name. This is faster according to Kent "_______________".toCharArray(), //$NON-NLS-1$ SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, IJavaSearchConstants.ENUM, SearchEngine.createWorkspaceScope(), new TypeNameRequestor() { }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor); } catch (JavaModelException e) { throw new InvocationTargetException(e); } } } ConsistencyRunnable runnable = new ConsistencyRunnable(); if (!runnable.needsExecution()) return; IRunnableContext context = fRunnableContext != null ? fRunnableContext : PlatformUI.getWorkbench().getProgressService(); context.run(true, true, runnable); }
From source file:org.eclipse.andmore.internal.editors.Hyperlinks.java
License:Open Source License
/** * Opens a Java method referenced by the given on click attribute method name * * @param project the project containing the click handler * @param method the method name of the on click handler * @return true if the method was opened, false otherwise *///ww w .jav a 2s . com public static boolean openOnClickMethod(IProject project, String method) { // Search for the method in the Java index, filtering by the required click handler // method signature (public and has a single View parameter), and narrowing the scope // first to Activity classes, then to the whole workspace. final AtomicBoolean success = new AtomicBoolean(false); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { Object element = match.getElement(); if (element instanceof IMethod) { IMethod methodElement = (IMethod) element; String[] parameterTypes = methodElement.getParameterTypes(); if (parameterTypes != null && parameterTypes.length == 1 && ("Qandroid.view.View;".equals(parameterTypes[0]) //$NON-NLS-1$ || "QView;".equals(parameterTypes[0]))) { //$NON-NLS-1$ // Check that it's public if (Flags.isPublic(methodElement.getFlags())) { JavaUI.openInEditor(methodElement); success.getAndSet(true); } } } } }; try { IJavaSearchScope scope = null; IType activityType = null; IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); if (javaProject != null) { activityType = javaProject.findType(CLASS_ACTIVITY); if (activityType != null) { scope = SearchEngine.createHierarchyScope(activityType); } } if (scope == null) { scope = SearchEngine.createWorkspaceScope(); } SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; int matchRule = SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE; SearchPattern pattern = SearchPattern.createPattern("*." + method, IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, matchRule); SearchEngine engine = new SearchEngine(); engine.search(pattern, participants, scope, requestor, new NullProgressMonitor()); boolean ok = success.get(); if (!ok && activityType != null) { // TODO: Create a project+dependencies scope and search only that scope // Try searching again with a complete workspace scope this time scope = SearchEngine.createWorkspaceScope(); engine.search(pattern, participants, scope, requestor, new NullProgressMonitor()); // TODO: There could be more than one match; add code to consider them all // and pick the most likely candidate and open only that one. ok = success.get(); } return ok; } catch (CoreException e) { AndmoreAndroidPlugin.log(e, null); } return false; }
From source file:org.eclipse.andmore.internal.editors.layout.gre.ClientRulesEngine.java
License:Open Source License
@Override public String displayFragmentSourceInput() { try {//from w w w . ja v a 2 s. c o m // Compute a search scope: We need to merge all the subclasses // android.app.Fragment and android.support.v4.app.Fragment IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); IProject project = mRulesEngine.getProject(); final IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); if (javaProject != null) { IType oldFragmentType = javaProject.findType(CLASS_V4_FRAGMENT); // First check to make sure fragments are available, and if not, // warn the user. IAndroidTarget target = Sdk.getCurrent().getTarget(project); // No, this should be using the min SDK instead! if (target.getVersion().getApiLevel() < 11 && oldFragmentType == null) { // Compatibility library must be present MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Fragment Warning", null, "Fragments require API level 11 or higher, or a compatibility " + "library for older versions.\n\n" + " Do you want to install the compatibility library?", MessageDialog.QUESTION, new String[] { "Install", "Cancel" }, 1 /* default button: Cancel */); int answer = dialog.open(); if (answer == 0) { if (!AddSupportJarAction.install(project)) { return null; } } else { return null; } } // Look up sub-types of each (new fragment class and compatibility fragment // class, if any) and merge the two arrays - then create a scope from these // elements. IType[] fragmentTypes = new IType[0]; IType[] oldFragmentTypes = new IType[0]; if (oldFragmentType != null) { ITypeHierarchy hierarchy = oldFragmentType.newTypeHierarchy(new NullProgressMonitor()); oldFragmentTypes = hierarchy.getAllSubtypes(oldFragmentType); } IType fragmentType = javaProject.findType(CLASS_FRAGMENT); if (fragmentType != null) { ITypeHierarchy hierarchy = fragmentType.newTypeHierarchy(new NullProgressMonitor()); fragmentTypes = hierarchy.getAllSubtypes(fragmentType); } IType[] subTypes = new IType[fragmentTypes.length + oldFragmentTypes.length]; System.arraycopy(fragmentTypes, 0, subTypes, 0, fragmentTypes.length); System.arraycopy(oldFragmentTypes, 0, subTypes, fragmentTypes.length, oldFragmentTypes.length); scope = SearchEngine.createJavaSearchScope(subTypes, IJavaSearchScope.SOURCES); } Shell parent = AndmoreAndroidPlugin.getShell(); final AtomicReference<String> returnValue = new AtomicReference<String>(); final AtomicReference<SelectionDialog> dialogHolder = new AtomicReference<SelectionDialog>(); final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, // Use ? as a default filter to fill dialog with matches "?", //$NON-NLS-1$ new TypeSelectionExtension() { @Override public Control createContentArea(Composite parentComposite) { Composite composite = new Composite(parentComposite, SWT.NONE); composite.setLayout(new GridLayout(1, false)); Button button = new Button(composite, SWT.PUSH); button.setText("Create New..."); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String fqcn = createNewFragmentClass(javaProject); if (fqcn != null) { returnValue.set(fqcn); dialogHolder.get().close(); } } }); return composite; } @Override public ITypeInfoFilterExtension getFilterExtension() { return new ITypeInfoFilterExtension() { @Override public boolean select(ITypeInfoRequestor typeInfoRequestor) { int modifiers = typeInfoRequestor.getModifiers(); if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers) || Flags.isEnum(modifiers) || Flags.isAbstract(modifiers)) { return false; } return true; } }; } }); dialogHolder.set(dialog); dialog.setTitle("Choose Fragment Class"); dialog.setMessage("Select a Fragment class (? = any character, * = any string):"); if (dialog.open() == IDialogConstants.CANCEL_ID) { return null; } if (returnValue.get() != null) { return returnValue.get(); } Object[] types = dialog.getResult(); if (types != null && types.length > 0) { return ((IType) types[0]).getFullyQualifiedName(); } } catch (JavaModelException e) { AndmoreAndroidPlugin.log(e, null); } catch (CoreException e) { AndmoreAndroidPlugin.log(e, null); } return null; }
From source file:org.eclipse.andmore.internal.editors.layout.gre.ClientRulesEngine.java
License:Open Source License
@Override public String displayCustomViewClassInput() { try {/* ww w .j a v a2 s . c o m*/ IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); IProject project = mRulesEngine.getProject(); final IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); if (javaProject != null) { // Look up sub-types of each (new fragment class and compatibility fragment // class, if any) and merge the two arrays - then create a scope from these // elements. IType[] viewTypes = new IType[0]; IType fragmentType = javaProject.findType(CLASS_VIEW); if (fragmentType != null) { ITypeHierarchy hierarchy = fragmentType.newTypeHierarchy(new NullProgressMonitor()); viewTypes = hierarchy.getAllSubtypes(fragmentType); } scope = SearchEngine.createJavaSearchScope(viewTypes, IJavaSearchScope.SOURCES); } Shell parent = AndmoreAndroidPlugin.getShell(); final AtomicReference<String> returnValue = new AtomicReference<String>(); final AtomicReference<SelectionDialog> dialogHolder = new AtomicReference<SelectionDialog>(); final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, // Use ? as a default filter to fill dialog with matches "?", //$NON-NLS-1$ new TypeSelectionExtension() { @Override public Control createContentArea(Composite parentComposite) { Composite composite = new Composite(parentComposite, SWT.NONE); composite.setLayout(new GridLayout(1, false)); Button button = new Button(composite, SWT.PUSH); button.setText("Create New..."); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String fqcn = createNewCustomViewClass(javaProject); if (fqcn != null) { returnValue.set(fqcn); dialogHolder.get().close(); } } }); return composite; } @Override public ITypeInfoFilterExtension getFilterExtension() { return new ITypeInfoFilterExtension() { @Override public boolean select(ITypeInfoRequestor typeInfoRequestor) { int modifiers = typeInfoRequestor.getModifiers(); if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers) || Flags.isEnum(modifiers) || Flags.isAbstract(modifiers)) { return false; } return true; } }; } }); dialogHolder.set(dialog); dialog.setTitle("Choose Custom View Class"); dialog.setMessage("Select a Custom View class (? = any character, * = any string):"); if (dialog.open() == IDialogConstants.CANCEL_ID) { return null; } if (returnValue.get() != null) { return returnValue.get(); } Object[] types = dialog.getResult(); if (types != null && types.length > 0) { return ((IType) types[0]).getFullyQualifiedName(); } } catch (JavaModelException e) { AndmoreAndroidPlugin.log(e, null); } catch (CoreException e) { AndmoreAndroidPlugin.log(e, null); } return null; }
From source file:org.eclipse.andmore.internal.wizards.templates.NewTemplatePage.java
License:Open Source License
private String chooseActivity() { try {//from www . j a v a2 s .c o m // Compute a search scope: We need to merge all the subclasses // android.app.Fragment and android.support.v4.app.Fragment IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); IProject project = mValues.project; IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); IType activityType = null; if (javaProject != null) { activityType = javaProject.findType(CLASS_ACTIVITY); } if (activityType == null) { IJavaProject[] projects = BaseProjectHelper.getAndroidProjects(null); for (IJavaProject p : projects) { activityType = p.findType(CLASS_ACTIVITY); if (activityType != null) { break; } } } if (activityType != null) { NullProgressMonitor monitor = new NullProgressMonitor(); ITypeHierarchy hierarchy = activityType.newTypeHierarchy(monitor); IType[] classes = hierarchy.getAllSubtypes(activityType); scope = SearchEngine.createJavaSearchScope(classes, IJavaSearchScope.SOURCES); } Shell parent = AndmoreAndroidPlugin.getShell(); final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, // Use ? as a default filter to fill dialog with matches "?", //$NON-NLS-1$ new TypeSelectionExtension() { @Override public ITypeInfoFilterExtension getFilterExtension() { return new ITypeInfoFilterExtension() { @Override public boolean select(ITypeInfoRequestor typeInfoRequestor) { int modifiers = typeInfoRequestor.getModifiers(); if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers) || Flags.isEnum(modifiers)) { return false; } return true; } }; } }); dialog.setTitle("Choose Activity Class"); dialog.setMessage("Select an Activity class (? = any character, * = any string):"); if (dialog.open() == IDialogConstants.CANCEL_ID) { return null; } Object[] types = dialog.getResult(); if (types != null && types.length > 0) { return ((IType) types[0]).getFullyQualifiedName(); } } catch (JavaModelException e) { AndmoreAndroidPlugin.log(e, null); } catch (CoreException e) { AndmoreAndroidPlugin.log(e, null); } return null; }
From source file:org.eclipse.andmore.SourceRevealer.java
License:Open Source License
private List<SearchMatch> searchForPattern(String pattern, int searchFor, Predicate<SearchMatch> filterPredicate) { SearchEngine se = new SearchEngine(); SearchPattern searchPattern = SearchPattern.createPattern(pattern, searchFor, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); SearchResultAccumulator requestor = new SearchResultAccumulator(filterPredicate); try {/*from w ww . j a v a 2 s .c om*/ se.search(searchPattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createWorkspaceScope(), requestor, new NullProgressMonitor()); } catch (CoreException e) { AndmoreAndroidPlugin.printErrorToConsole(e.getMessage()); return Collections.emptyList(); } return requestor.getMatches(); }
From source file:org.eclipse.buildship.ui.view.execution.OpenTestSourceFileJob.java
License:Open Source License
private void searchForTestSource(String className, String methodName, IProgressMonitor monitor) { monitor.setTaskName(String.format("Open test source file for class %s.", className)); try {//from w w w. j a va2 s .c o m // search for Java file SearchEngine searchEngine = new SearchEngine(); SearchPattern pattern = SearchPattern.createPattern(className, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); ShowTestSourceFileSearchRequester requester = new ShowTestSourceFileSearchRequester(methodName); searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createWorkspaceScope(), requester, monitor); // if no Java file has been found, search for Groovy file if (!requester.isFoundJavaTestSourceFile()) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); workspaceRoot.accept( new ShowTestSourceFileResourceVisitor(methodName, className, ImmutableList.of("groovy"))); //$NON-NLS-1$ } } catch (CoreException e) { UiPlugin.logger().error(e.getMessage(), e); } finally { monitor.done(); } }
From source file:org.eclipse.che.jdt.testplugin.JavaProjectHelper.java
License:Open Source License
public static void mustPerformDummySearch() throws JavaModelException { performDummySearch(SearchEngine.createWorkspaceScope(), true); }