List of usage examples for org.eclipse.jdt.core.search IJavaSearchScope SOURCES
int SOURCES
To view the source code for org.eclipse.jdt.core.search IJavaSearchScope SOURCES.
Click Source Link
From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.editors.JFXBuildConfigurationEditor.java
License:Open Source License
private String handleRootclassSelection(Shell parent) { IFileEditorInput i = (IFileEditorInput) getEditorInput(); IJavaProject project = JavaCore.create(i.getFile().getProject()); if (project == null) { return null; }/*from ww w. java 2 s .c o m*/ IJavaElement[] elements = new IJavaElement[] { project }; int constraints = IJavaSearchScope.SOURCES; constraints |= IJavaSearchScope.APPLICATION_LIBRARIES; IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(elements, constraints); BusyIndicatorRunnableContext context = new BusyIndicatorRunnableContext(); MainTypeSelectionDialog dialog = new MainTypeSelectionDialog(parent, context, searchScope, 0); dialog.setTitle("Find class"); dialog.setMessage("Find the class used to launch the application"); if (dialog.open() == Window.CANCEL) { return null; } Object[] results = dialog.getResult(); IType type = (IType) results[0]; if (type != null) { return type.getFullyQualifiedName(); } return null; }
From source file:com.aliyun.odps.eclipse.launch.configuration.udf.UDFClassTab.java
License:Apache License
/** * Show a dialog that lists all main types *//* www. ja v a 2 s .c om*/ protected void handleSearchButtonSelected() { IJavaProject project = getJavaProject(); IJavaElement[] elements = null; if ((project == null) || !project.exists()) { IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); if (model != null) { try { elements = model.getJavaProjects(); } catch (JavaModelException e) { JDIDebugUIPlugin.log(e); } } } else { elements = new IJavaElement[] { project }; } if (elements == null) { elements = new IJavaElement[] {}; } int constraints = IJavaSearchScope.SOURCES; constraints |= IJavaSearchScope.APPLICATION_LIBRARIES; // constraints |= IJavaSearchScope.SYSTEM_LIBRARIES; IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(elements, constraints); UDFSearchEngine engine = new UDFSearchEngine(); IType[] types = null; try { types = engine.searchUDFClass(getLaunchConfigurationDialog(), searchScope, false); } catch (InvocationTargetException e) { setErrorMessage(e.getMessage()); return; } catch (InterruptedException e) { setErrorMessage(e.getMessage()); return; } DebugTypeSelectionDialog mmsd = new DebugTypeSelectionDialog(getShell(), types, LauncherMessages.JavaMainTab_Choose_Main_Type_11); if (mmsd.open() == Window.CANCEL) { return; } Object[] results = mmsd.getResult(); IType type = (IType) results[0]; if (type != null) { fMainText.setText(type.getFullyQualifiedName()); fProjText.setText(type.getJavaProject().getElementName()); } }
From source file:com.aliyun.odps.eclipse.launch.shortcut.udf.UDFLaunchShortcuts2.java
License:Apache License
protected IType[] findTypes(Object[] elements, IRunnableContext context) throws InterruptedException, CoreException { try {/*from w ww.j a v a2s .c o m*/ if (elements.length == 1) { IType type = isUDF(elements[0]); if (type != null) { return new IType[] { type }; } } IJavaElement[] javaElements = getJavaElements(elements); UDFSearchEngine engine = new UDFSearchEngine(); int constraints = IJavaSearchScope.SOURCES; constraints |= IJavaSearchScope.APPLICATION_LIBRARIES; IJavaSearchScope scope = SearchEngine.createJavaSearchScope(javaElements, constraints); return engine.searchUDFClass(context, scope, true); } catch (InvocationTargetException e) { throw (CoreException) e.getTargetException(); } }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gre.ClientRulesEngine.java
License:Open Source License
@Override public String displayFragmentSourceInput() { try {// w w w. j a 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 = AdtPlugin.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) { AdtPlugin.log(e, null); } catch (CoreException e) { AdtPlugin.log(e, null); } return null; }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gre.ClientRulesEngine.java
License:Open Source License
@Override public String displayCustomViewClassInput() { try {//w ww . j av a 2 s . c om 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 = AdtPlugin.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) { AdtPlugin.log(e, null); } catch (CoreException e) { AdtPlugin.log(e, null); } return null; }
From source file:com.android.ide.eclipse.adt.internal.wizards.templates.NewTemplatePage.java
License:Open Source License
private String chooseActivity() { try {// w ww .j ava 2s . com // 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 = AdtPlugin.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) { AdtPlugin.log(e, null); } catch (CoreException e) { AdtPlugin.log(e, null); } return null; }
From source file:com.android.ide.eclipse.auidt.internal.editors.layout.gre.ClientRulesEngine.java
License:Open Source License
@Override public String displayFragmentSourceInput() { try {/*from w w w. j a va2 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 = AdtPlugin.getDisplay().getActiveShell(); 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)) { 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) { AdtPlugin.log(e, null); } catch (CoreException e) { AdtPlugin.log(e, null); } return null; }
From source file:com.android.ide.eclipse.auidt.internal.wizards.templates.NewTemplatePage.java
License:Open Source License
private String chooseActivity() { try {//from ww w. j av 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 = AdtPlugin.getDisplay().getActiveShell(); 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) { AdtPlugin.log(e, null); } catch (CoreException e) { AdtPlugin.log(e, null); } return null; }
From source file:com.curlap.orb.plugin.common.JavaElementSearcher.java
License:Open Source License
protected IJavaSearchScope createScope(ICompilationUnit target) throws JavaModelException { IJavaElement[] elements = { target.getJavaProject() }; return SearchEngine.createJavaSearchScope(elements, IJavaSearchScope.SOURCES); }
From source file:com.ebmwebsourcing.petals.common.extensions.internal.wizards.JavaToWSDLWizardPage.java
License:Open Source License
/** * Open a dialog to select a class./*from w w w . jav a 2 s . c o m*/ */ private void openClassSelectionDialog() { if (this.javaProject == null) return; Shell shell = this.classText.getShell(); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { this.javaProject }, IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.REFERENCED_PROJECTS); String filter = this.classText.getText().trim(); filter = filter.length() == 0 ? "?" : filter; try { SelectionDialog dlg = JavaUI.createTypeDialog(shell, new ProgressMonitorDialog(shell), scope, IJavaElementSearchConstants.CONSIDER_INTERFACES, true, filter); if (dlg.open() == Window.OK) { IType type = (IType) dlg.getResult()[0]; String selection = type.getFullyQualifiedName(); this.classText.setText(selection); this.classText.setSelection(selection.length()); } } catch (JavaModelException e) { PetalsCommonWsdlExtPlugin.log(e, IStatus.ERROR); } }