List of usage examples for org.eclipse.jdt.core.search SearchEngine createJavaSearchScope
public static IJavaSearchScope createJavaSearchScope(IJavaElement[] elements, int includeMask)
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 . co 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.SharedUDFClassTab.java
License:Apache License
/** * Set the main type & name attributes on the working copy based on the IJavaElement *///from w w w . j av a 2s.c o m protected void initializeMainTypeAndName(IJavaElement javaElement, ILaunchConfigurationWorkingCopy config) { String name = null; if (javaElement instanceof IMember) { IMember member = (IMember) javaElement; if (member.isBinary()) { javaElement = member.getClassFile(); } else { javaElement = member.getCompilationUnit(); } } if (javaElement instanceof ICompilationUnit || javaElement instanceof IClassFile) { try { IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaElement }, false); MainMethodSearchEngine engine = new MainMethodSearchEngine(); IType[] types = engine.searchMainMethods(getLaunchConfigurationDialog(), scope, false); if (types != null && (types.length > 0)) { // Simply grab the first main type found in the searched element name = types[0].getFullyQualifiedName(); } } catch (InterruptedException ie) { JDIDebugUIPlugin.log(ie); } catch (InvocationTargetException ite) { JDIDebugUIPlugin.log(ite); } } if (name == null) { name = EMPTY_STRING; } config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, name); if (name.length() > 0) { int index = name.lastIndexOf('.'); if (index > 0) { name = name.substring(index + 1); } name = getLaunchConfigurationDialog().generateName(name); config.rename(name); } }
From source file:com.aliyun.odps.eclipse.launch.configuration.udf.UDFClassTab.java
License:Apache License
/** * Show a dialog that lists all main types *//*from w ww. j ava2 s. c o m*/ 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 {/*w w w . j av a 2s.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 ww . j av a 2s .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 w w . j a va 2s. com*/ 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.editors.manifest.model.UiClassAttributeNode.java
License:Open Source License
private void handleBrowseClick() { Text text = getTextWidget();//ww w . j a v a 2s . c o m // we need to get the project of the manifest. IProject project = getProject(); if (project != null) { // Create a search scope including only the source folder of the current // project. IPackageFragmentRoot[] packageFragmentRoots = getPackageFragmentRoots(project, true /*include_containers*/); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(packageFragmentRoots, false); try { SelectionDialog dlg = JavaUI.createTypeDialog(text.getShell(), PlatformUI.getWorkbench().getProgressService(), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, // style false, // no multiple selection "**", //$NON-NLS-1$ //filter new HierarchyTypeSelection(project, mReferenceClass)); dlg.setMessage(String.format("Select class name for element %1$s:", getUiParent().getBreadcrumbTrailDescription(false /* include_root */))); if (dlg instanceof ITypeSelectionComponent) { ((ITypeSelectionComponent) dlg).triggerSearch(); } if (dlg.open() == Window.OK) { Object[] results = dlg.getResult(); if (results.length == 1) { handleNewType((IType) results[0]); } } } catch (JavaModelException e1) { AdtPlugin.log(e1, "UiClassAttributeNode HandleBrowser failed"); } } }
From source file:com.android.ide.eclipse.adt.internal.wizards.templates.NewTemplatePage.java
License:Open Source License
private String chooseActivity() { try {/* w w w .j a v a 2 s .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 ava2 s . 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 = 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 w w w. j a v a 2 s. 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.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; }