List of usage examples for org.eclipse.jdt.core.search SearchEngine createWorkspaceScope
public static IJavaSearchScope createWorkspaceScope()
From source file:org.hibernate.eclipse.console.utils.DialogSelectionHelper.java
License:Open Source License
static public String chooseImplementation(String supertype, String initialSelection, String title, Shell shell) {/*from www. j a va2 s . com*/ SelectionDialog dialog = null; try { final IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); // TODO: limit to a certain implementor dialog = JavaUI.createTypeDialog(shell, PlatformUI.getWorkbench().getProgressService(), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, supertype); } catch (JavaModelException jme) { return null; } dialog.setTitle(title); dialog.setMessage(title); if (dialog.open() == IDialogConstants.CANCEL_ID) return null; Object[] types = dialog.getResult(); if (types != null && types.length > 0) { IType type = (IType) types[0]; return type.getFullyQualifiedName('.'); } return null; }
From source file:org.jboss.byteman.eclipse.validation.BytemanJavaValidator.java
License:Open Source License
/** * quick check which ensures that the target class or interface is known in the workspace * @param eventClass//from ww w. j a v a2 s . co m * * TODO -- decide whether we need to make this check NORMAL rather than FAST * TODO -- n.b. that will also require making other dependent type checks NORMAL */ @Check(CheckType.FAST) public void checkClassClause(EventClass eventClass) { boolean isInterface = eventClass.getKeyword().equalsIgnoreCase("INTERFACE"); String fullName = eventClass.getName(); String cachedResultKey = (isInterface ? "interface " : "class ") + fullName; List<TypeSearchResult> cachedResults = (List<TypeSearchResult>) getContext().get(cachedResultKey); if (cachedResults == null) { String typeName = fullName; String packageName = null; // n.b. unlike Java Byteman uses $ to separate embedded subclasses int dollarIndex = typeName.lastIndexOf('$'); int dotIndex = typeName.lastIndexOf('.'); if (dollarIndex > 0 && dollarIndex < dotIndex) { // hmm foo.bar$baz.mumble is not allowed // must be foo.bar.baz$mumble if (isInterface) { error("invalid trigger interface " + fullName, BytemanPackage.eINSTANCE.getEventClass_Name()); } else { error("invalid trigger class " + fullName, BytemanPackage.eINSTANCE.getEventClass_Name()); } return; } if (dollarIndex > 0) { // ok, we should be able to search for foo.bar.baz$mumble by passing // foo.bar as the package name and baz.mumble as the type name // but eclipse is not playing ball. So, we have to pass it foo.bar.baz as the package name and // mumble as the type name. typeName = typeName.replace('$', '.'); dotIndex = dollarIndex; } int len = typeName.length(); if (dotIndex > 0 && dotIndex < len - 1) { packageName = typeName.substring(0, dotIndex); typeName = typeName.substring(dotIndex + 1); } SearchEngine searchEngine = new SearchEngine(); final List<TypeSearchResult> results = new ArrayList<TypeSearchResult>(); // if a match contains embedded types and the original used a dot as separator then // we have to reject the match since Byteman requires use of $ to identify the embedding final boolean acceptEmbeddedTypes = (dollarIndex > 0 || dotIndex < 0); TypeNameRequestor requestor = new TypeNameRequestor() { public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { if (acceptEmbeddedTypes || enclosingTypeNames.length == 0) { results.add(new TypeSearchResult(modifiers, packageName, simpleTypeName, enclosingTypeNames, path)); } } }; char[] packageNameChars = (packageName == null ? null : packageName.toCharArray()); char[] typeNameChars = typeName.toCharArray(); IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope(); try { searchEngine.searchAllTypeNames(packageNameChars, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, typeNameChars, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, (isInterface ? IJavaSearchConstants.INTERFACE : IJavaSearchConstants.CLASS), searchScope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); } catch (JavaModelException e) { // TODO : ho hum probably should not happen but just ignore for now } // if we have any matches then we are ok otherwise we flag the classname // as invalid if (results.isEmpty()) { if (isInterface) { error("unknown trigger interface " + fullName, BytemanPackage.eINSTANCE.getEventClass_Name()); } else { error("unknown trigger class " + fullName, BytemanPackage.eINSTANCE.getEventClass_Name()); } // erase any current rule class getContext().remove(RULE_CLASS_KEY); } else { // save this result as the current rule class and cache it // so we don't have to repeat the lookup getContext().put(RULE_CLASS_KEY, results); getContext().put(cachedResultKey, results); } } else { // install this result as the current rule class getContext().put(RULE_CLASS_KEY, cachedResults); } }
From source file:org.jboss.byteman.eclipse.validation.BytemanJavaValidator.java
License:Open Source License
@Check(CheckType.FAST) public void checkMethodClause(EventMethod eventMethod) { // delete any previous cache of possible trigger methods getContext().remove(RULE_METHOD_KEY); String methodName = eventMethod.getName(); // we can only check the method if we already know the possible classes List<TypeSearchResult> types = (List<TypeSearchResult>) getContext().get(RULE_CLASS_KEY); if (types == null) { error("unknown trigger method " + methodName, BytemanPackage.eINSTANCE.getEventMethod_Name()); } else if (methodName.equals("<clinit>")) { // cannot verify presence of <clinit> via search // just check it has no arguments ParameterTypes parameterTypes = eventMethod.getParameterTypes(); if (parameterTypes != null) { EList<String> paramTypeNames = parameterTypes.getParamTypeNames(); int paramTypeCount = paramTypeNames.size(); if (paramTypeCount != 0) { error("invalid parameter types for class initializer" + methodName, BytemanPackage.eINSTANCE.getEventMethod_ParameterTypes()); }//ww w .jav a 2s. c om } } else { boolean isConstructor = methodName.equals("<init>"); // look for methods on each of the possible types ParameterTypes parameterTypes = eventMethod.getParameterTypes(); EList<String> paramTypeNames; int paramTypeCount; if (parameterTypes != null) { paramTypeNames = parameterTypes.getParamTypeNames(); paramTypeCount = paramTypeNames.size(); } else { paramTypeNames = null; // -1 indicates any method with the relevant signature will do // whereas 0 indicates an empty parameter list () paramTypeCount = -1; } final List<MethodSearchResult> methods = new ArrayList<MethodSearchResult>(); // accumulate matching methods SearchEngine searchEngine = new SearchEngine(); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; for (TypeSearchResult result : types) { String typeName = result.name.replace('$', '.'); // now build type qualified method name StringBuilder builder = new StringBuilder(); builder.append(typeName); // append method name to type name except when it is a constructor or class initializer if (!isConstructor) { builder.append('.'); builder.append(methodName); } if (paramTypeCount >= 0) { String separator = ""; builder.append("("); for (int i = 0; i < paramTypeCount; i++) { builder.append(separator); String paramTypeName = paramTypeNames.get(i); // ho hum eclipse doesn't like $ to separate embedded types if (paramTypeName.indexOf('$') > 0) { paramTypeName = paramTypeName.replace('$', '.'); } builder.append(paramTypeName); separator = ","; } builder.append(")"); } final String stringPattern = builder.toString(); int searchFor = (isConstructor ? IJavaSearchConstants.CONSTRUCTOR : IJavaSearchConstants.METHOD); int limitTo = IJavaSearchConstants.DECLARATIONS; int matchType = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; SearchPattern pattern = SearchPattern.createPattern(stringPattern, searchFor, limitTo, matchType); final TypeSearchResult typeResult = result; SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { // only accept if we have an accurate match if (match.getAccuracy() == SearchMatch.A_ACCURATE) { MethodSearchResult methodResult = new MethodSearchResult(stringPattern, typeResult, match); methods.add(methodResult); } } }; try { searchEngine.search(pattern, participants, scope, requestor, null); } catch (CoreException e) { // TODO : ho hum not sure if this will happen when we have // no such method or because something is wrong with paths etc // but just ignore for now } } // if we have no matches then plant an error if (methods.isEmpty()) { error("unknown trigger method " + methodName, BytemanPackage.eINSTANCE.getEventMethod_Name()); } else { // cache details of potential trigger methods for current rule getContext().put(RULE_METHOD_KEY, methods); } } }
From source file:org.jboss.ide.eclipse.as.ui.util.PackageTypeSearcher.java
License:Open Source License
public ArrayList getPackageProposals() { IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); SearchPattern packagePattern = SearchPattern.createPattern(fullString, IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PREFIX_MATCH); if (packagePattern == null) return new ArrayList(); SearchEngine searchEngine = new SearchEngine(); LocalTextfieldSearchRequestor requestor = new LocalTextfieldSearchRequestor(); try {/* w ww. j a va2s . c om*/ searchEngine.search(packagePattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, new NullProgressMonitor()); ArrayList results = requestor.getResults(); Collections.sort(results, new Comparator() { public int compare(Object o1, Object o2) { if (!(o1 instanceof IPackageFragment)) return 0; if (!(o2 instanceof IPackageFragment)) return 0; IPackageFragment o1a = (IPackageFragment) o1; IPackageFragment o2a = (IPackageFragment) o2; return o1a.getElementName().compareTo(o2a.getElementName()); } }); return results; } catch (CoreException ce) { } return new ArrayList(); }
From source file:org.jboss.ide.eclipse.as.ui.util.PackageTypeSearcher.java
License:Open Source License
public IPackageFragment getPackage() { IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); SearchPattern packagePattern = SearchPattern.createPattern(packageName, IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); if (packagePattern == null) return null; SearchEngine searchEngine = new SearchEngine(); LocalTextfieldSearchRequestor requestor = new LocalTextfieldSearchRequestor(); try {//ww w .jav a 2 s . c o m searchEngine.search(packagePattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, new NullProgressMonitor()); ArrayList results = requestor.getResults(); if (results.size() != 1) // TODO: there can be multiple packagefragments for the same name in a workspace return null; return (IPackageFragment) results.get(0); } catch (CoreException ce) { } return null; }
From source file:org.jboss.tools.common.model.ui.attribute.editor.JavaEclipseChoicerEditor.java
License:Open Source License
public Object callExternal(Shell shell) { IJavaProject jp = null;/* w w w . j ava 2 s . c o m*/ DefaultValueAdapter adapter = (DefaultValueAdapter) getInput(); XModelObject o = adapter.getModelObject(); if (o != null) { IProject p = EclipseResourceUtil.getProject(o); if (p != null) { jp = EclipseResourceUtil.getJavaProject(p); } } String title = MessageFormat.format("Select {0}", getAttributeName()); if (adapter != null && adapter.getAttribute() != null) { String key = "" + adapter.getAttribute().getModelEntity().getName() + "." //$NON-NLS-1$//$NON-NLS-2$ + adapter.getAttribute().getName().replace(' ', '_') + ".edit"; //$NON-NLS-1$ String t = WizardKeys.getLabelText(key); if (t != null) { title = t; } else { title = MessageFormat.format("Select {0}", WizardKeys.getAttributeDisplayName(adapter.getAttribute(), true)); } } FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(shell, false, ModelUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(), jp == null ? SearchEngine.createWorkspaceScope() : SearchEngine.createJavaSearchScope(new IJavaElement[] { jp }), IJavaSearchConstants.TYPE, createTypeSelectionExtension()); dialog.setTitle(title); IValueProvider valueProvider = (IValueProvider) adapter.getAdapter(IValueProvider.class); String v = valueProvider.getStringValue(true); dialog.setInitialPattern(v); int status = dialog.open(); if (status == FilteredItemsSelectionDialog.OK) { Object result = dialog.getFirstResult(); if (result instanceof IType) { return ((IType) result).getFullyQualifiedName('.'); } } return null; }
From source file:org.jboss.tools.forge.ui.ext.control.JavaClassChooserControlBuilder.java
License:Open Source License
@Override protected void browseButtonPressed(ForgeWizardPage page, InputComponent<?, Object> input, Text containerText) { IRunnableContext context = new BusyIndicatorRunnableContext(); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); int style = IJavaElementSearchConstants.CONSIDER_ALL_TYPES; try {/*from ww w. ja v a 2s . co m*/ SelectionDialog dialog = JavaUI.createTypeDialog(page.getShell(), context, scope, style, false, containerText.getText()); dialog.setTitle("Type Selection"); dialog.setMessage("Choose type name:"); if (dialog.open() == Window.OK) { IType res = (IType) dialog.getResult()[0]; containerText.setText(res.getFullyQualifiedName('.')); } } catch (JavaModelException ex) { ForgeUIPlugin.log(ex); } }
From source file:org.jboss.tools.forge.ui.internal.ext.control.JavaClassChooserControlBuilder.java
License:Open Source License
@Override protected void browseButtonPressed(ForgeWizardPage page, InputComponent<?, ?> input, Text containerText) { IRunnableContext context = new BusyIndicatorRunnableContext(); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); int style = IJavaElementSearchConstants.CONSIDER_ALL_TYPES; try {//from w w w . j av a2 s . com SelectionDialog dialog = JavaUI.createTypeDialog(page.getShell(), context, scope, style, false, containerText.getText()); dialog.setTitle("Type Selection"); dialog.setMessage("Choose type name:"); if (dialog.open() == Window.OK) { IType res = (IType) dialog.getResult()[0]; containerText.setText(res.getFullyQualifiedName('.')); } } catch (JavaModelException ex) { ForgeUIPlugin.log(ex); } }
From source file:org.jboss.tools.forge.ui.internal.ext.control.many.JavaClassChooserMultipleControlBuilder.java
License:Open Source License
@Override protected void addButtonPressed(ForgeWizardPage page, InputComponent<?, ?> input, List containerList) { IRunnableContext context = new BusyIndicatorRunnableContext(); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); int style = IJavaElementSearchConstants.CONSIDER_ALL_TYPES; try {/*from w w w . j ava 2 s . c o m*/ SelectionDialog dialog = JavaUI.createTypeDialog(page.getShell(), context, scope, style, true); dialog.setTitle("Type Selection"); dialog.setMessage("Choose type name:"); if (dialog.open() == Window.OK) { for (Object item : dialog.getResult()) { IType res = (IType) item; containerList.add(res.getFullyQualifiedName('.')); } updateItems(input, containerList); } } catch (JavaModelException ex) { ForgeUIPlugin.log(ex); } }
From source file:org.jboss.tools.fuse.transformation.editor.internal.wizards.JavaPage.java
License:Open Source License
/** * @param project//from w w w . j a v a 2s . co m * @return the scope of resources to be searched */ private IJavaSearchScope computeSearchScope(IProject project) { IJavaSearchScope searchScope; if (project == null) { ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService() .getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection selectionToPass = (IStructuredSelection) selection; if (selectionToPass.getFirstElement() instanceof IFile) { project = ((IFile) selectionToPass.getFirstElement()).getProject(); } } } if (CamelUtils.project() != null) { if (project == null) { project = CamelUtils.project(); } IJavaProject javaProject = JavaCore.create(project); searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject }); } else { searchScope = SearchEngine.createWorkspaceScope(); } return searchScope; }