List of usage examples for org.eclipse.jdt.core.search SearchEngine createWorkspaceScope
public static IJavaSearchScope createWorkspaceScope()
From source file:org.eclipse.che.jdt.testplugin.JavaProjectHelper.java
License:Open Source License
public static void performDummySearch() throws JavaModelException { performDummySearch(SearchEngine.createWorkspaceScope(), PERFORM_DUMMY_SEARCH); }
From source file:org.eclipse.e4.tools.emf.editor3x.PDEClassContributionProvider.java
License:Open Source License
@SuppressWarnings("restriction") public void findContribution(final Filter filter, final ContributionResultHandler handler) { boolean followReferences = true; if (filter instanceof FilterEx) { FilterEx filterEx = (FilterEx) filter; if (filterEx.getSearchScope().contains(ResourceSearchScope.PROJECT) && !filterEx.getSearchScope().contains(ResourceSearchScope.REFERENCES)) { followReferences = false;//from w w w . ja v a 2 s . com } } IJavaSearchScope scope = null; if (followReferences == false) { IJavaProject javaProject = JavaCore.create(filter.project); IPackageFragmentRoot[] roots; try { roots = javaProject.getPackageFragmentRoots(); scope = SearchEngine.createJavaSearchScope(roots, false); } catch (JavaModelException e) { e.printStackTrace(); } } else { // filter.project may be null in the live editor scope = filter.project != null ? PDEJavaHelper.getSearchScope(filter.project) : SearchEngine.createWorkspaceScope(); } char[] packageName = null; char[] typeName = null; String currentContent = filter.namePattern; int index = currentContent.lastIndexOf('.'); if (index == -1) { // There is no package qualification // Perform the search only on the type name typeName = currentContent.toCharArray(); if (currentContent.startsWith("*")) { if (!currentContent.endsWith("*")) { currentContent += "*"; } typeName = currentContent.toCharArray(); packageName = "*".toCharArray(); } } else if ((index + 1) == currentContent.length()) { // There is a package qualification and the last character is a // dot // Perform the search for all types under the given package // Pattern for all types typeName = "".toCharArray(); //$NON-NLS-1$ // Package name without the trailing dot packageName = currentContent.substring(0, index).toCharArray(); } else { // There is a package qualification, followed by a dot, and // a type fragment // Type name without the package qualification typeName = currentContent.substring(index + 1).toCharArray(); // Package name without the trailing dot packageName = currentContent.substring(0, index).toCharArray(); } // char[] packageName = "at.bestsolution.e4.handlers".toCharArray(); // char[] typeName = "*".toCharArray(); TypeNameRequestor req = new TypeNameRequestor() { @Override public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { // Accept search results from the JDT SearchEngine String cName = new String(simpleTypeName); String pName = new String(packageName); // String label = cName + " - " + pName; //$NON-NLS-1$ String content = pName.length() == 0 ? cName : pName + "." + cName; //$NON-NLS-1$ // System.err.println("Found: " + label + " => " + pName + " => " + path); IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path); if (resource != null) { IProject project = resource.getProject(); IFile f = project.getFile("/META-INF/MANIFEST.MF"); if (f != null && f.exists()) { BufferedReader r = null; try { InputStream s = f.getContents(); r = new BufferedReader(new InputStreamReader(s)); String line; while ((line = r.readLine()) != null) { if (line.startsWith("Bundle-SymbolicName:")) { int start = line.indexOf(':'); int end = line.indexOf(';'); if (end == -1) { end = line.length(); } ContributionData data = new ContributionData( line.substring(start + 1, end).trim(), content, "Java", null); handler.result(data); break; } } } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (r != null) { try { r.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } } //Image image = (Flags.isInterface(modifiers)) ? PDEPluginImages.get(PDEPluginImages.OBJ_DESC_GENERATE_INTERFACE) : PDEPluginImages.get(PDEPluginImages.OBJ_DESC_GENERATE_CLASS); //addProposalToCollection(c, startOffset, length, label, content, image); } }; try { searchEngine.searchAllTypeNames(packageName, SearchPattern.R_PATTERN_MATCH, typeName, SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CAMELCASE_MATCH, IJavaSearchConstants.CLASS, scope, req, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.eclipse.e4.xwt.tools.ui.designer.dialogs.AccessorConfigurationDialog.java
License:Open Source License
protected void browseForAccessorClass(IPackageFragmentRoot root) { IProgressService service = PlatformUI.getWorkbench().getProgressService(); IJavaSearchScope scope = root != null ? SearchEngine.createJavaSearchScope(new IJavaElement[] { root }) : SearchEngine.createWorkspaceScope(); FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(getShell(), false, service, scope, IJavaSearchConstants.CLASS); dialog.setTitle("Choose a Type"); dialog.setInitialPattern("*Messages"); classFileNames = createFileListInput(".java", classFragment); if (dialog.open() == Window.OK) { IType selectedType = (IType) dialog.getFirstResult(); if (selectedType != null) { classNameText.setText(selectedType.getElementName()); }/*from w w w .j a v a2 s . co m*/ } }
From source file:org.eclipse.gemoc.execution.concurrent.ccsljavaxdsml.ui.builder.GemocLanguageDesignerBuilder.java
License:Open Source License
private static IType findAnyTypeInWorkspace(char[][] qualifications, char[][] typeNames) throws JavaModelException { class ResultException extends RuntimeException { private static final long serialVersionUID = 1L; private final IType fType; public ResultException(IType type) { fType = type;/*from w w w. j a v a2 s . c o m*/ } } TypeNameMatchRequestor requestor = new TypeNameMatchRequestor() { @Override public void acceptTypeNameMatch(TypeNameMatch match) { throw new ResultException(match.getType()); } }; try { new SearchEngine().searchAllTypeNames(qualifications, typeNames, SearchEngine.createWorkspaceScope(), requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); } catch (ResultException e) { return e.fType; } return null; }
From source file:org.eclipse.graphiti.tools.newprojectwizard.internal.SelectTypeOption.java
License:Open Source License
/** * Creates the string option control.//from w w w .j ava 2s . com * * @param parent * parent composite of the string option widget * @param span * the number of columns that the widget should span */ public void createControl(Composite parent, int span) { Composite composite = new Composite(groupOption.getGroup(), SWT.NONE); GridData gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = span; composite.setLayoutData(gd); composite.setLayout(new GridLayout(3, false)); labelControl = createLabel(composite, 1); labelControl.setEnabled(isEnabled()); text = new Text(composite, fStyle); if (getValue() != null) text.setText(getValue().toString()); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 1; text.setLayoutData(gd); text.setEnabled(isEnabled()); text.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (ignoreListener) return; SelectTypeOption.super.setValue(text.getText()); getSection().validateOptions(SelectTypeOption.this); } }); buttonControl = new Button(composite, SWT.PUSH); buttonControl.setText(Messages.SelectTypeOption_BrowseButton); buttonControl.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { Shell parent = Display.getCurrent().getActiveShell(); SelectionDialog dialog = null; try { dialog = JavaUI.createTypeDialog(parent, PlatformUI.getWorkbench().getProgressService(), SearchEngine.createWorkspaceScope(), IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES, false); } catch (JavaModelException jme) { MessageDialog.openError(parent, "Could not open type selection dialog", jme.getMessage()); //$NON-NLS-1$ return; } dialog.setTitle(Messages.SelectTypeOption_TitleSelectDomainObject); dialog.setMessage(Messages.SelectTypeOption_DescriptionSelectDomainObject); if (dialog.open() == Dialog.OK) { Object[] result = dialog.getResult(); if (result != null && result.length > 0 && result[0] instanceof IType) { IType type = (IType) result[0]; Bundle containingBundle = null; // Search for the first bundle that can resolve the // desired class Bundle[] bundles = Activator.getDefault().getBundle().getBundleContext().getBundles(); for (Bundle bundle : bundles) { try { Class<?> loadClass = bundle.loadClass(type.getFullyQualifiedName()); // Use the class loader of the class to identify // the containing bundle ClassLoader classLoader = loadClass.getClassLoader(); if (classLoader instanceof BundleReference) { containingBundle = ((BundleReference) classLoader).getBundle(); setBundleName(containingBundle.getSymbolicName()); text.setText(type.getFullyQualifiedName()); return; } } catch (ClassNotFoundException cnfe) { // Simply ignore } } // Search for a Java source file in the workspace ICompilationUnit compilationUnit = type.getCompilationUnit(); if (compilationUnit != null) { IResource resource = null; try { resource = compilationUnit.getCorrespondingResource(); } catch (JavaModelException e1) { // Simply ignore } if (resource != null && resource.exists()) { IProject project = resource.getProject(); if (project != null && project.exists()) { // Use project name as bundle name (should // fit in most cases setBundleName(project.getName()); text.setText(type.getFullyQualifiedName()); return; } } } text.setText(type.getFullyQualifiedName()); // Nothing found MessageDialog.openError(parent, "No Bundle found", //$NON-NLS-1$ "The class '" + type.getFullyQualifiedName() //$NON-NLS-1$ + "' could not be resolved within an installed plugin or as a Java source file in the workspace."); //$NON-NLS-1$ return; } } } public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } }); buttonControl.setEnabled(isEnabled()); }
From source file:org.eclipse.jpt.jpadiagrameditor.ui.internal.dialog.SelectTypeDialog.java
License:Open Source License
private void createBrowseBtn(Composite composite) { browseButton = new Button(composite, SWT.PUSH); browseButton.setText(JPAEditorMessages.SelectTypeDialog_browseBtnTxt); browseButton.setToolTipText(JPAEditorMessages.SelectTypeDialog_browseBtnDesc); browseButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); IProgressService service = PlatformUI.getWorkbench().getProgressService(); SelectionDialog d = null;// www. ja va 2 s . c om try { d = JavaUI.createTypeDialog(WorkbenchTools.getActiveShell(), service, scope, IJavaElementSearchConstants.CONSIDER_ALL_TYPES, false, text.getText().trim()); } catch (JavaModelException e1) { JPADiagramEditorPlugin.logError("Can't create type selaction dialog instance", e1); //$NON-NLS-1$ } d.open(); Object[] res = d.getResult(); if (res == null) return; Object[] obj = d.getResult(); if (obj == null) return; IType tp = (IType) obj[0]; text.setText(tp.getFullyQualifiedName()); text.setSelection(0, tp.getFullyQualifiedName().length()); } public void widgetDefaultSelected(SelectionEvent e) { } }); }
From source file:org.eclipse.jst.jsf.common.ui.internal.dialogfield.JavaUIHelper.java
License:Open Source License
/** * @param project// w w w .j a v a2s. c om * @param superType * @return the search scope */ static IJavaSearchScope findSearchScope(IProject project, String superType) { if (project != null) { if (superType == null || "".equals(superType)) { //$NON-NLS-1$ superType = "java.lang.Object";//$NON-NLS-1$ } return new JavaSearchScope(project, superType); } return SearchEngine.createWorkspaceScope(); }
From source file:org.eclipse.mat.jdt.OpenSourceFileJob.java
License:Open Source License
private void collectMatches(IProgressMonitor monitor) throws JavaModelException { matches = new ArrayList<IType>(); new SearchEngine().searchAllTypeNames(packageName != null ? packageName.toCharArray() : null, // SearchPattern.R_FULL_MATCH | SearchPattern.R_CASE_SENSITIVE, // typeName.toCharArray(), // SearchPattern.R_FULL_MATCH | SearchPattern.R_CASE_SENSITIVE, // IJavaSearchConstants.TYPE, // SearchEngine.createWorkspaceScope(), // new TypeNameMatchRequestor() { @Override/*from w ww.j a v a 2 s .c o m*/ public void acceptTypeNameMatch(TypeNameMatch match) { try { IType type = match.getType(); type = resolveInnerTypes(type); matches.add(type); } catch (JavaModelException e) { throw new RuntimeException(e); } } }, // IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, // monitor); }
From source file:org.eclipse.mylyn.internal.java.ui.AbstractJavaContextComputationStrategy.java
License:Open Source License
protected IType findTypeInWorkspace(String typeName) throws CoreException { int dot = typeName.lastIndexOf('.'); char[][] qualifications; String simpleName;/*from w w w. j a v a2 s . c o m*/ if (dot != -1) { qualifications = new char[][] { typeName.substring(0, dot).toCharArray() }; simpleName = typeName.substring(dot + 1); } else { qualifications = null; simpleName = typeName; } char[][] typeNames = new char[][] { simpleName.toCharArray() }; class ResultException extends RuntimeException { private static final long serialVersionUID = 1L; private final IType fType; public ResultException(IType type) { fType = type; } } TypeNameMatchRequestor requestor = new TypeNameMatchRequestor() { @Override public void acceptTypeNameMatch(TypeNameMatch match) { throw new ResultException(match.getType()); } }; try { new SearchEngine().searchAllTypeNames(qualifications, typeNames, SearchEngine.createWorkspaceScope(), requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); } catch (ResultException e) { return e.fType; } return null; }
From source file:org.eclipse.mylyn.internal.java.ui.search.AbstractJavaRelationProvider.java
License:Open Source License
private IJavaSearchScope createJavaSearchScope(IJavaElement element, int degreeOfSeparation) { Set<IInteractionElement> landmarks = ContextCore.getContextManager().getActiveLandmarks(); List<IInteractionElement> interestingElements = ContextCore.getContextManager().getActiveContext() .getInteresting();//from www . jav a 2 s . co m Set<IJavaElement> searchElements = new HashSet<IJavaElement>(); int includeMask = IJavaSearchScope.SOURCES; if (degreeOfSeparation == 1) { for (IInteractionElement landmark : landmarks) { AbstractContextStructureBridge bridge = ContextCore.getStructureBridge(landmark.getContentType()); if (includeNodeInScope(landmark, bridge)) { Object o = bridge.getObjectForHandle(landmark.getHandleIdentifier()); if (o instanceof IJavaElement) { IJavaElement landmarkElement = (IJavaElement) o; if (landmarkElement.exists()) { if (landmarkElement instanceof IMember && !landmark.getInterest().isPropagated()) { searchElements.add(((IMember) landmarkElement).getCompilationUnit()); } else if (landmarkElement instanceof ICompilationUnit) { searchElements.add(landmarkElement); } } } } } } else if (degreeOfSeparation == 2) { for (IInteractionElement interesting : interestingElements) { AbstractContextStructureBridge bridge = ContextCore .getStructureBridge(interesting.getContentType()); if (includeNodeInScope(interesting, bridge)) { Object object = bridge.getObjectForHandle(interesting.getHandleIdentifier()); if (object instanceof IJavaElement) { IJavaElement interestingElement = (IJavaElement) object; if (interestingElement.exists()) { if (interestingElement instanceof IMember && !interesting.getInterest().isPropagated()) { searchElements.add(((IMember) interestingElement).getCompilationUnit()); } else if (interestingElement instanceof ICompilationUnit) { searchElements.add(interestingElement); } } } } } } else if (degreeOfSeparation == 3 || degreeOfSeparation == 4) { for (IInteractionElement interesting : interestingElements) { AbstractContextStructureBridge bridge = ContextCore .getStructureBridge(interesting.getContentType()); if (includeNodeInScope(interesting, bridge)) { // TODO what to do when the element is not a java element, // how determine if a javaProject? IResource resource = ResourcesUiBridgePlugin.getDefault().getResourceForElement(interesting, true); if (resource != null) { IProject project = resource.getProject(); if (project != null && JavaProject.hasJavaNature(project) && project.exists()) { IJavaProject javaProject = JavaCore.create(project);// ((IJavaElement)o).getJavaProject(); if (javaProject != null && javaProject.exists()) { searchElements.add(javaProject); } } } } } if (degreeOfSeparation == 4) { includeMask = IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES; } } else if (degreeOfSeparation == 5) { return SearchEngine.createWorkspaceScope(); } if (searchElements.size() == 0) { return null; } else { IJavaElement[] elements = new IJavaElement[searchElements.size()]; int j = 0; for (IJavaElement searchElement : searchElements) { elements[j] = searchElement; j++; } return SearchEngine.createJavaSearchScope(elements, includeMask); } }