Example usage for org.eclipse.jdt.core.search IJavaSearchConstants CLASS_AND_INTERFACE

List of usage examples for org.eclipse.jdt.core.search IJavaSearchConstants CLASS_AND_INTERFACE

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.search IJavaSearchConstants CLASS_AND_INTERFACE.

Prototype

int CLASS_AND_INTERFACE

To view the source code for org.eclipse.jdt.core.search IJavaSearchConstants CLASS_AND_INTERFACE.

Click Source Link

Document

The searched element is a class or interface type.

Usage

From source file:ar.com.fluxit.jqa.viewer.TypeCellEditor.java

License:Open Source License

@Override
protected Object openDialogBox(Control cellEditorWindow) {
    final FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(cellEditorWindow.getShell(),
            false, getContext(), new JavaWorkspaceScope(), IJavaSearchConstants.CLASS_AND_INTERFACE);
    dialog.setBlockOnOpen(true);/*from  w  ww.j av  a  2  s  . c o  m*/
    final int returnCode = dialog.open();
    if (returnCode == Window.OK) {
        // TODO improve
        final IJavaElement selectedType = (IJavaElement) dialog.getFirstResult();
        final IJavaElement selectedPackage = selectedType.getParent().getParent();
        return selectedPackage.getElementName() + "." + selectedType.getElementName();
    } else {
        return null;
    }
}

From source file:bndtools.editor.components.SvcInterfaceProposalProvider.java

License:Open Source License

@Override
protected List<IContentProposal> doGenerateProposals(String contents, int position) {
    final String prefix = contents.substring(0, position);
    final IJavaSearchScope scope = SearchEngine
            .createJavaSearchScope(new IJavaElement[] { searchContext.getJavaProject() });
    final ArrayList<IContentProposal> result = new ArrayList<IContentProposal>(100);
    final TypeNameRequestor typeNameRequestor = new TypeNameRequestor() {
        @Override//from   www .j a  v a 2s.c  o m
        public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName,
                char[][] enclosingTypeNames, String path) {
            boolean isInterface = Flags.isInterface(modifiers);
            result.add(
                    new JavaContentProposal(new String(packageName), new String(simpleTypeName), isInterface));
        }
    };
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                new SearchEngine().searchAllTypeNames(null, 0, prefix.toCharArray(),
                        SearchPattern.R_PREFIX_MATCH, IJavaSearchConstants.CLASS_AND_INTERFACE, scope,
                        typeNameRequestor, IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH, monitor);
            } catch (JavaModelException e) {
                throw new InvocationTargetException(e);
            }
        }
    };

    try {
        if (searchContext.getRunContext() == null) {
            runnable.run(new NullProgressMonitor());
        } else {
            searchContext.getRunContext().run(false, false, runnable);
        }
    } catch (InvocationTargetException e) {
        Plugin.log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error searching for Java types.",
                e.getTargetException()));
        return Collections.emptyList();
    } catch (InterruptedException e) {
        // Reset interrupted status and return empty
        Thread.currentThread().interrupt();
        return Collections.emptyList();
    }
    return result;
}

From source file:ca.ecliptical.pde.ds.search.DescriptorQueryParticipant.java

License:Open Source License

public void search(ISearchRequestor requestor, QuerySpecification query, IProgressMonitor monitor)
        throws CoreException {
    if (debug.isDebugging())
        debug.trace(String.format("Query: %s", query)); //$NON-NLS-1$

    // we only look for straight references
    switch (query.getLimitTo()) {
    case IJavaSearchConstants.REFERENCES:
    case IJavaSearchConstants.ALL_OCCURRENCES:
        break;/*from  www . ja  v  a2  s . c o m*/
    default:
        return;
    }

    // we only look for types and methods
    if (query instanceof ElementQuerySpecification) {
        searchElement = ((ElementQuerySpecification) query).getElement();
        switch (searchElement.getElementType()) {
        case IJavaElement.TYPE:
        case IJavaElement.METHOD:
            break;
        default:
            return;
        }
    } else {
        String pattern = ((PatternQuerySpecification) query).getPattern();
        boolean ignoreMethodParams = false;
        searchFor = ((PatternQuerySpecification) query).getSearchFor();
        switch (searchFor) {
        case IJavaSearchConstants.UNKNOWN:
        case IJavaSearchConstants.METHOD:
            int leftParen = pattern.lastIndexOf('(');
            int rightParen = pattern.indexOf(')');
            ignoreMethodParams = leftParen == -1 || rightParen == -1 || leftParen >= rightParen;
            // no break
        case IJavaSearchConstants.TYPE:
        case IJavaSearchConstants.CLASS:
        case IJavaSearchConstants.CLASS_AND_INTERFACE:
        case IJavaSearchConstants.CLASS_AND_ENUM:
        case IJavaSearchConstants.INTERFACE:
        case IJavaSearchConstants.INTERFACE_AND_ANNOTATION:
            break;
        default:
            return;
        }

        // searchPattern = PatternConstructor.createPattern(pattern, ((PatternQuerySpecification) query).isCaseSensitive());
        int matchMode = getMatchMode(pattern) | SearchPattern.R_ERASURE_MATCH;
        if (((PatternQuerySpecification) query).isCaseSensitive())
            matchMode |= SearchPattern.R_CASE_SENSITIVE;

        searchPattern = new SearchPatternDescriptor(pattern, matchMode, ignoreMethodParams);
    }

    HashSet<IPath> scope = new HashSet<IPath>();
    for (IPath path : query.getScope().enclosingProjectsAndJars()) {
        scope.add(path);
    }

    if (scope.isEmpty())
        return;

    this.requestor = requestor;

    // look through all active bundles
    IPluginModelBase[] wsModels = PluginRegistry.getWorkspaceModels();
    IPluginModelBase[] exModels = PluginRegistry.getExternalModels();
    monitor.beginTask(Messages.DescriptorQueryParticipant_taskName, wsModels.length + exModels.length);
    try {
        // workspace models
        for (IPluginModelBase model : wsModels) {
            if (monitor.isCanceled())
                throw new OperationCanceledException();

            if (!model.isEnabled() || !(model instanceof IBundlePluginModelBase)) {
                monitor.worked(1);
                if (debug.isDebugging())
                    debug.trace(String.format("Non-bundle model: %s", model)); //$NON-NLS-1$

                continue;
            }

            IProject project = model.getUnderlyingResource().getProject();
            if (!scope.contains(project.getFullPath())) {
                monitor.worked(1);
                if (debug.isDebugging())
                    debug.trace(String.format("Project out of scope: %s", project.getName())); //$NON-NLS-1$

                continue;
            }

            // we can only search in Java bundle projects (for now)
            if (!project.hasNature(JavaCore.NATURE_ID)) {
                monitor.worked(1);
                if (debug.isDebugging())
                    debug.trace(String.format("Non-Java project: %s", project.getName())); //$NON-NLS-1$

                continue;
            }

            PDEModelUtility.modifyModel(new ModelModification(project) {
                @Override
                protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException {
                    if (model instanceof IBundlePluginModelBase)
                        searchBundle((IBundlePluginModelBase) model, monitor);
                }
            }, new SubProgressMonitor(monitor, 1));
        }

        // external models
        SearchablePluginsManager spm = PDECore.getDefault().getSearchablePluginsManager();
        IJavaProject javaProject = spm.getProxyProject();
        if (javaProject == null || !javaProject.exists() || !javaProject.isOpen()) {
            monitor.worked(exModels.length);
            if (debug.isDebugging())
                debug.trace("External Plug-in Search project inaccessible!"); //$NON-NLS-1$

            return;
        }

        for (IPluginModelBase model : exModels) {
            if (monitor.isCanceled())
                throw new OperationCanceledException();

            BundleDescription bd;
            if (!model.isEnabled() || (bd = model.getBundleDescription()) == null) {
                monitor.worked(1);
                if (debug.isDebugging())
                    debug.trace(String.format("Non-bundle model: %s", model)); //$NON-NLS-1$

                continue;
            }

            // check scope
            ArrayList<IClasspathEntry> cpEntries = new ArrayList<IClasspathEntry>();
            ClasspathUtilCore.addLibraries(model, cpEntries);
            ArrayList<IPath> cpEntryPaths = new ArrayList<IPath>(cpEntries.size());
            for (IClasspathEntry cpEntry : cpEntries) {
                cpEntryPaths.add(cpEntry.getPath());
            }

            cpEntryPaths.retainAll(scope);
            if (cpEntryPaths.isEmpty()) {
                monitor.worked(1);
                if (debug.isDebugging())
                    debug.trace(String.format("External bundle out of scope: %s", model.getInstallLocation())); //$NON-NLS-1$

                continue;
            }

            if (!spm.isInJavaSearch(bd.getSymbolicName())) {
                monitor.worked(1);
                if (debug.isDebugging())
                    debug.trace(String.format("Non-searchable external model: %s", bd.getSymbolicName())); //$NON-NLS-1$

                continue;
            }

            searchBundle(model, javaProject, new SubProgressMonitor(monitor, 1));
        }
    } finally {
        monitor.done();
    }
}

From source file:ca.ecliptical.pde.ds.search.DescriptorQueryParticipant.java

License:Open Source License

private void searchModel(DSModel dsModel, IJavaProject javaProject, Object matchElement,
        IProgressMonitor monitor) throws CoreException {
    IDSComponent component = dsModel.getDSComponent();
    if (component == null) {
        if (debug.isDebugging())
            debug.trace(String.format("No component definition found in file: %s", //$NON-NLS-1$
                    dsModel.getUnderlyingResource() == null ? dsModel.getInstallLocation()
                            : dsModel.getUnderlyingResource().getFullPath())); // TODO de-uglify!

        return;/*from   www.j a  v a 2  s  .c  o  m*/
    }

    IDSImplementation impl = component.getImplementation();
    if (impl == null) {
        if (debug.isDebugging())
            debug.trace(String.format("No component implementation found in file: %s", //$NON-NLS-1$
                    dsModel.getUnderlyingResource() == null ? dsModel.getInstallLocation()
                            : dsModel.getUnderlyingResource().getFullPath())); // TODO de-uglify!

        return;
    }

    IType implClassType = null;
    String implClassName = impl.getClassName();
    if (implClassName != null)
        implClassType = javaProject.findType(implClassName, monitor);

    if ((searchElement != null && searchElement.getElementType() == IJavaElement.TYPE)
            || searchFor == IJavaSearchConstants.TYPE || searchFor == IJavaSearchConstants.CLASS
            || searchFor == IJavaSearchConstants.CLASS_AND_INTERFACE
            || searchFor == IJavaSearchConstants.CLASS_AND_ENUM || searchFor == IJavaSearchConstants.UNKNOWN) {
        // match specific type references
        if (matches(searchElement, searchPattern, implClassType))
            reportMatch(requestor, impl.getDocumentAttribute(IDSConstants.ATTRIBUTE_IMPLEMENTATION_CLASS),
                    matchElement);
    }

    if ((searchElement != null && searchElement.getElementType() == IJavaElement.TYPE)
            || searchFor == IJavaSearchConstants.TYPE || searchFor == IJavaSearchConstants.CLASS
            || searchFor == IJavaSearchConstants.CLASS_AND_INTERFACE
            || searchFor == IJavaSearchConstants.CLASS_AND_ENUM || searchFor == IJavaSearchConstants.INTERFACE
            || searchFor == IJavaSearchConstants.INTERFACE_AND_ANNOTATION
            || searchFor == IJavaSearchConstants.UNKNOWN) {
        IDSService service = component.getService();
        if (service != null) {
            IDSProvide[] provides = service.getProvidedServices();
            if (provides != null) {
                for (IDSProvide provide : provides) {
                    String ifaceName = provide.getInterface();
                    IType ifaceType = javaProject.findType(ifaceName, monitor);
                    if (matches(searchElement, searchPattern, ifaceType))
                        reportMatch(requestor,
                                provide.getDocumentAttribute(IDSConstants.ATTRIBUTE_PROVIDE_INTERFACE),
                                matchElement);
                }
            }
        }

        IDSReference[] references = component.getReferences();
        if (references != null) {
            for (IDSReference reference : references) {
                String ifaceName = reference.getReferenceInterface();
                IType ifaceType = javaProject.findType(ifaceName, monitor);
                if (matches(searchElement, searchPattern, ifaceType))
                    reportMatch(requestor,
                            reference.getDocumentAttribute(IDSConstants.ATTRIBUTE_REFERENCE_INTERFACE),
                            matchElement);
            }
        }
    }

    if ((searchElement != null && searchElement.getElementType() == IJavaElement.METHOD)
            || searchFor == IJavaSearchConstants.METHOD || searchFor == IJavaSearchConstants.UNKNOWN) {
        // match specific method references
        String activate = component.getActivateMethod();
        if (activate == null)
            activate = "activate"; //$NON-NLS-1$

        IMethod activateMethod = findActivateMethod(implClassType, activate, monitor);
        if (matches(searchElement, searchPattern, activateMethod)) {
            if (component.getActivateMethod() == null)
                reportMatch(requestor, component, matchElement);
            else
                reportMatch(requestor,
                        component.getDocumentAttribute(IDSConstants.ATTRIBUTE_COMPONENT_ACTIVATE),
                        matchElement);
        }

        String modified = component.getModifiedMethod();
        if (modified != null) {
            IMethod modifiedMethod = findActivateMethod(implClassType, modified, monitor);
            if (matches(searchElement, searchPattern, modifiedMethod))
                reportMatch(requestor,
                        component.getDocumentAttribute(IDSConstants.ATTRIBUTE_COMPONENT_MODIFIED),
                        matchElement);
        }

        String deactivate = component.getDeactivateMethod();
        if (deactivate == null)
            deactivate = "deactivate"; //$NON-NLS-1$

        IMethod deactivateMethod = findDeactivateMethod(implClassType, deactivate, monitor);
        if (matches(searchElement, searchPattern, deactivateMethod)) {
            if (component.getDeactivateMethod() == null)
                reportMatch(requestor, component, matchElement);
            else
                reportMatch(requestor,
                        component.getDocumentAttribute(IDSConstants.ATTRIBUTE_COMPONENT_DEACTIVATE),
                        matchElement);
        }

        IDSReference[] references = component.getReferences();
        if (references != null) {
            for (IDSReference reference : references) {
                String refIface = reference.getReferenceInterface();
                if (refIface == null) {
                    if (debug.isDebugging())
                        debug.trace(String.format("No reference interface specified: %s", reference)); //$NON-NLS-1$

                    continue;
                }

                String bind = reference.getReferenceBind();
                if (bind != null) {
                    IMethod bindMethod = findBindMethod(implClassType, bind, refIface, monitor);
                    if (matches(searchElement, searchPattern, bindMethod))
                        reportMatch(requestor,
                                reference.getDocumentAttribute(IDSConstants.ATTRIBUTE_REFERENCE_BIND),
                                matchElement);
                }

                String unbind = reference.getReferenceUnbind();
                if (unbind != null) {
                    IMethod unbindMethod = findBindMethod(implClassType, unbind, refIface, monitor);
                    if (matches(searchElement, searchPattern, unbindMethod))
                        reportMatch(requestor,
                                reference.getDocumentAttribute(IDSConstants.ATTRIBUTE_REFERENCE_UNBIND),
                                matchElement);
                }

                String updated = reference.getXMLAttributeValue("updated"); //$NON-NLS-1$
                if (updated != null) {
                    IMethod updatedMethod = findUpdatedMethod(implClassType, updated, monitor);
                    if (matches(searchElement, searchPattern, updatedMethod))
                        reportMatch(requestor, reference.getDocumentAttribute("updated"), matchElement); //$NON-NLS-1$
                }
            }
        }
    }
}

From source file:com.curlap.orb.plugin.common.JavaElementSearcher.java

License:Open Source License

public List<TypeNameMatch> searchRawClassInfo(String className) throws JavaModelException {
    final List<TypeNameMatch> results = new ArrayList<TypeNameMatch>();
    TypeNameMatchRequestor requestor = new TypeNameMatchRequestor() {
        @Override//from   ww  w.  j av a2s  .  co m
        public void acceptTypeNameMatch(TypeNameMatch match) {
            results.add(match);
        }
    };
    new SearchEngine().searchAllTypeNames(null, SearchPattern.R_EXACT_MATCH, className.toCharArray(),
            SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.CLASS_AND_INTERFACE, scope, requestor,
            IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
    return results;
}

From source file:com.gwtplatform.plugin.controls.AddFieldDialog.java

License:Apache License

protected IType chooseType() {
    if (project == null) {
        return null;
    }/*from  w  w w.  j  a v  a2s .c  o  m*/

    IJavaElement[] elements = new IJavaElement[] { project };
    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements);

    FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(getShell(), false, null, scope,
            IJavaSearchConstants.CLASS_AND_INTERFACE);
    dialog.setTitle("Type Selection");
    dialog.setMessage("Select a type for the field");
    dialog.setInitialPattern("String");

    if (dialog.open() == Window.OK) {
        return (IType) dialog.getFirstResult();
    }
    return null;
}

From source file:com.liferay.ide.ui.snippets.wizard.AbstractModelWizardPage.java

License:Open Source License

protected IType chooseClass() {
    IJavaProject project = getJavaProject();
    if (project == null) {
        return null;
    }/*from w w  w . j a va2 s .  co  m*/

    IJavaElement[] elements = new IJavaElement[] { project };
    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements);

    FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(getShell(), false,
            getWizard().getContainer(), scope, IJavaSearchConstants.CLASS_AND_INTERFACE);
    dialog.setTitle(Msgs.modelClassSelection);
    dialog.setMessage(Msgs.newTypeWizardPage_SuperClassDialog_message);
    dialog.setInitialPattern(getSuperClass());

    if (dialog.open() == Window.OK) {
        return (IType) dialog.getFirstResult();
    }
    return null;
}

From source file:com.siteview.mde.internal.ui.editor.contentassist.XMLContentAssistProcessor.java

License:Open Source License

private ICompletionProposal[] computeCompletionProposal(IDocumentAttributeNode attr, int offset,
        IDocument doc) {/*from  www.j  a v a  2  s.c o m*/
    if (offset < attr.getValueOffset())
        return null;
    int[] offests = new int[] { offset, offset, offset };
    String[] guess = guessContentRequest(offests, doc, false);
    if (guess == null)
        return null;
    //      String element = guess[0];
    //      String attribute = guess[1];
    String attrValue = guess[2];

    IMonitorObject obj = XMLUtil.getTopLevelParent(attr);
    if (obj instanceof IMonitorExtension) {
        if (attr.getAttributeName().equals(IMonitorExtension.P_POINT) && offset >= attr.getValueOffset()) {
            return computeExtPointAttrProposals(attr, offset, attrValue);
        }
        ISchemaAttribute sAttr = XMLUtil.getSchemaAttribute(attr, ((IMonitorExtension) obj).getPoint());
        if (sAttr == null)
            return null;

        if (sAttr.getKind() == IMetaAttribute.JAVA) {
            IResource resource = obj.getModel().getUnderlyingResource();
            if (resource == null)
                return null;
            // Revisit: NEW CODE HERE
            ArrayList list = new ArrayList();
            ICompletionProposal[] proposals = null;

            generateTypePackageProposals(attrValue, resource.getProject(), list, offset - attrValue.length(),
                    IJavaSearchConstants.CLASS_AND_INTERFACE);

            if ((list != null) && (list.size() != 0)) {
                // Convert the results array list into an array of completion
                // proposals
                proposals = (ICompletionProposal[]) list.toArray(new ICompletionProposal[list.size()]);
                sortCompletions(proposals);
                return proposals;
            }
            return null;
        } else if (sAttr.getKind() == IMetaAttribute.RESOURCE) {
            // provide proposals with all resources in current plugin?

        } else if (sAttr.getKind() == IMetaAttribute.IDENTIFIER) {
            String[] validAttributes = (String[]) PDESchemaHelper.getValidAttributes(sAttr).keySet()
                    .toArray(new String[0]);
            Arrays.sort(validAttributes);
            ArrayList objs = new ArrayList(validAttributes.length);
            for (int i = 0; i < validAttributes.length; i++)
                objs.add(new VirtualSchemaObject(validAttributes[i], null, F_ATTRIBUTE_ID_VALUE));
            return computeAttributeProposal(attr, offset, attrValue, objs);
        } else { // we have an IMetaAttribute.STRING kind
            if (sAttr.getType() == null)
                return null;
            ISchemaRestriction sRestr = (sAttr.getType()).getRestriction();
            ArrayList objs = new ArrayList();
            if (sRestr == null) {
                ISchemaSimpleType type = sAttr.getType();
                if (type != null && type.getName().equals("boolean")) //$NON-NLS-1$
                    objs = F_V_BOOLS;
            } else {
                Object[] restrictions = sRestr.getChildren();
                for (int i = 0; i < restrictions.length; i++)
                    if (restrictions[i] instanceof ISchemaObject)
                        objs.add(new VirtualSchemaObject(((ISchemaObject) restrictions[i]).getName(), null,
                                F_ATTRIBUTE_VALUE));
            }
            return computeAttributeProposal(attr, offset, attrValue, objs);
        }
    } else if (obj instanceof IMonitorExtensionPoint) {
        if (attr.getAttributeValue().equals(IMonitorExtensionPoint.P_SCHEMA)) {
            // provide proposals with all schema files in current plugin?

        }
    }
    return null;
}

From source file:com.siteview.mde.internal.ui.editor.monitor.rows.ClassAttributeRow.java

License:Open Source License

public void createContents(Composite parent, FormToolkit toolkit, int span) {
    super.createContents(parent, toolkit, span);

    if (part.isEditable()) {
        fTypeFieldAssistDisposer = PDEJavaHelperUI.addTypeFieldAssistToText(text, getProject(),
                IJavaSearchConstants.CLASS_AND_INTERFACE);
    }/*from   ww w . j  a  v  a2s  .  c  o  m*/
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockJava.java

License:Open Source License

/********************************************************************************/

void handleJavaSearch(String proj, String bid, String patstr, String foritems, boolean defs, boolean refs,
        boolean impls, boolean equiv, boolean exact, boolean system, IvyXmlWriter xw) throws BedrockException {
    IJavaProject ijp = getJavaProject(proj);

    our_plugin.waitForEdits();//from   w  w w .  ja v  a  2 s . c  om

    int forflags = 0;
    if (foritems == null)
        forflags = IJavaSearchConstants.TYPE;
    else if (foritems.equalsIgnoreCase("CLASS"))
        forflags = IJavaSearchConstants.CLASS;
    else if (foritems.equalsIgnoreCase("INTERFACE"))
        forflags = IJavaSearchConstants.INTERFACE;
    else if (foritems.equalsIgnoreCase("ENUM"))
        forflags = IJavaSearchConstants.ENUM;
    else if (foritems.equalsIgnoreCase("ANNOTATION"))
        forflags = IJavaSearchConstants.ANNOTATION_TYPE;
    else if (foritems.equalsIgnoreCase("CLASS&ENUM"))
        forflags = IJavaSearchConstants.CLASS_AND_ENUM;
    else if (foritems.equalsIgnoreCase("CLASS&INTERFACE"))
        forflags = IJavaSearchConstants.CLASS_AND_INTERFACE;
    else if (foritems.equalsIgnoreCase("TYPE"))
        forflags = IJavaSearchConstants.TYPE;
    else if (foritems.equalsIgnoreCase("FIELD"))
        forflags = IJavaSearchConstants.FIELD;
    else if (foritems.equalsIgnoreCase("METHOD"))
        forflags = IJavaSearchConstants.METHOD;
    else if (foritems.equalsIgnoreCase("CONSTRUCTOR"))
        forflags = IJavaSearchConstants.CONSTRUCTOR;
    else if (foritems.equalsIgnoreCase("PACKAGE"))
        forflags = IJavaSearchConstants.PACKAGE;
    else if (foritems.equalsIgnoreCase("FIELDWRITE"))
        forflags = IJavaSearchConstants.FIELD | IJavaSearchConstants.WRITE_ACCESSES;
    else if (foritems.equalsIgnoreCase("FIELDREAD"))
        forflags = IJavaSearchConstants.FIELD | IJavaSearchConstants.READ_ACCESSES;
    else
        forflags = IJavaSearchConstants.TYPE;

    int limit = 0;
    if (defs && refs)
        limit = IJavaSearchConstants.ALL_OCCURRENCES;
    else if (defs)
        limit = IJavaSearchConstants.DECLARATIONS;
    else if (refs)
        limit = IJavaSearchConstants.REFERENCES;
    else if (impls)
        limit = IJavaSearchConstants.IMPLEMENTORS;

    int mrule = SearchPattern.R_PATTERN_MATCH;
    if (equiv)
        mrule = SearchPattern.R_EQUIVALENT_MATCH;
    else if (exact)
        mrule = SearchPattern.R_EXACT_MATCH;

    SearchPattern pat = SearchPattern.createPattern(patstr, forflags, limit, mrule);
    if (pat == null) {
        throw new BedrockException(
                "Invalid java search pattern `" + patstr + "' " + forflags + " " + limit + " " + mrule);
    }

    FindFilter filter = null;
    if (forflags == IJavaSearchConstants.METHOD) {
        String p = patstr;
        int idx = p.indexOf("(");
        if (idx > 0)
            p = p.substring(0, idx);
        idx = p.lastIndexOf(".");
        if (idx > 0) {
            if (defs)
                filter = new ClassFilter(p.substring(0, idx));
        }
    }

    // TODO: create scope for only user's items
    IJavaElement[] pelt;
    if (ijp != null)
        pelt = new IJavaElement[] { ijp };
    else
        pelt = getAllProjects();

    ICompilationUnit[] working = getWorkingElements(pelt);
    for (ICompilationUnit xcu : working) {
        try {
            BedrockPlugin.logD("WORK WITH " + xcu.isWorkingCopy() + " " + xcu.getPath() + xcu.getSourceRange());
        } catch (JavaModelException e) {
            BedrockPlugin.logD("WORK WITH ERROR: " + e);
        }
    }

    IJavaSearchScope scp = null;
    int fg = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS;
    if (system) {
        fg |= IJavaSearchScope.SYSTEM_LIBRARIES | IJavaSearchScope.APPLICATION_LIBRARIES;
        scp = SearchEngine.createWorkspaceScope();
    } else {
        scp = SearchEngine.createJavaSearchScope(pelt, fg);
    }

    SearchEngine se = new SearchEngine(working);
    SearchParticipant[] parts = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
    FindHandler fh = new FindHandler(xw, filter, system);

    BedrockPlugin.logD("BEGIN SEARCH " + pat);
    BedrockPlugin.logD("SEARCH SCOPE " + system + " " + fg + " " + scp);

    try {
        se.search(pat, parts, scp, fh, null);
    } catch (Throwable e) {
        throw new BedrockException("Problem doing Java search: " + e, e);
    }
}