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

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

Introduction

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

Prototype

int TYPE

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

Click Source Link

Document

The searched element is a type, which may include classes, interfaces, enums, and annotation types.

Usage

From source file:at.bestsolution.efxclipse.tooling.fxml.editors.FXMLCompletionProposalComputer.java

License:Open Source License

@Override
protected void addAttributeValueProposals(final ContentAssistRequest contentAssistRequest,
        final CompletionProposalInvocationContext context) {
    IDOMNode n = (IDOMNode) contentAssistRequest.getNode();

    if (Character.isUpperCase(n.getNodeName().charAt(0))) {
        NamedNodeMap m = n.getAttributes();
        IDOMNode attribute = null;//from   w w  w . j  av a2s  .  c om
        for (int i = 0; i < m.getLength(); i++) {
            IDOMNode a = (IDOMNode) m.item(i);
            if (a.contains(contentAssistRequest.getStartOffset())) {
                attribute = a;
            }
        }

        if (attribute != null) {
            if ("http://javafx.com/fxml".equals(attribute.getNamespaceURI())) {
                if ("constant".equals(attribute.getLocalName())) {
                    IType type = findType(n.getNodeName(), contentAssistRequest, context);
                    if (type != null) {
                        try {
                            List<IField> fields = new ArrayList<IField>();
                            collectStaticFields(fields, type);

                            for (IField f : fields) {
                                StyledString s = new StyledString(f.getElementName() + " : "
                                        + Signature.getSimpleName(Signature.toString(f.getTypeSignature())));
                                String owner = ((IType) f.getAncestor(IJavaElement.TYPE)).getElementName();
                                s.append(" - " + Signature.getSimpleName(owner), StyledString.QUALIFIER_STYLER);

                                FXMLCompletionProposal cp = createProposal(contentAssistRequest, context,
                                        "\"" + f.getElementName(), s, IconKeys.getIcon(IconKeys.CLASS_KEY),
                                        CLASS_ATTRIBUTE_MATCHER);

                                if (cp != null) {
                                    contentAssistRequest.addProposal(cp);
                                }
                            }

                        } catch (JavaModelException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                } else if ("controller".equals(attribute.getLocalName())) {
                    IJavaProject jproject = findProject(contentAssistRequest);

                    char[] typeName = null;
                    char[] packageName = null;
                    if (!contentAssistRequest.getMatchString().isEmpty()) {
                        if (contentAssistRequest.getMatchString().startsWith("\"")) {
                            typeName = contentAssistRequest.getMatchString().substring(1).toCharArray();
                        } else {
                            typeName = contentAssistRequest.getMatchString().toCharArray();
                        }
                    }

                    IJavaSearchScope searchScope = SearchEngine
                            .createJavaSearchScope(new IJavaElement[] { jproject });
                    SearchEngine searchEngine = new SearchEngine();
                    try {
                        searchEngine.searchAllTypeNames(packageName, SearchPattern.R_PATTERN_MATCH, typeName,
                                SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CAMELCASE_MATCH,
                                IJavaSearchConstants.TYPE, searchScope, new TypeNameRequestor() {
                                    public void acceptType(int modifiers, char[] packageName,
                                            char[] simpleTypeName, char[][] enclosingTypeNames, String path) {
                                        String sPackageName = new String(packageName);
                                        int priority = PRIORITY_LOWER_1;
                                        if (sPackageName.startsWith("com.sun")) {
                                            priority -= 10;
                                        }
                                        StyledString s = new StyledString(new String(simpleTypeName));
                                        s.append(" - " + sPackageName, StyledString.QUALIFIER_STYLER);

                                        FXMLCompletionProposal cp = createProposal(contentAssistRequest,
                                                context, "\"" + sPackageName + "." + new String(simpleTypeName),
                                                s, IconKeys.getIcon(IconKeys.CLASS_KEY),
                                                CLASS_ATTRIBUTE_MATCHER);

                                        if (cp != null) {
                                            contentAssistRequest.addProposal(cp);
                                        }
                                    }
                                }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor());
                    } catch (JavaModelException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                }
            } else if (attribute.getNodeName().contains(".")) {
                String[] parts = attribute.getNodeName().split("\\.");

                IType type = findType(parts[0], contentAssistRequest, context);
                if (type != null) {
                    IFXClass fxClass = FXPlugin.getClassmodel().findClass(type.getJavaProject(), type);
                    if (fxClass != null) {
                        IFXProperty p = fxClass.getStaticProperty(parts[1]);
                        if (p instanceof IFXPrimitiveProperty) {
                            createAttributeValuePrimitiveProposals(contentAssistRequest, context,
                                    (IFXPrimitiveProperty) p);
                        } else if (p instanceof IFXEnumProperty) {
                            createAttributeValueEnumProposals(contentAssistRequest, context,
                                    (IFXEnumProperty) p);
                        } else if (p instanceof IFXObjectProperty) {
                            createAttributeValueObjectProposals(contentAssistRequest, context,
                                    (IFXObjectProperty) p);
                        }
                    }
                }
            } else {
                IType type = findType(n.getNodeName(), contentAssistRequest, context);
                if (type != null) {
                    IFXClass fxClass = FXPlugin.getClassmodel().findClass(type.getJavaProject(), type);
                    if (fxClass != null) {
                        IFXProperty p = fxClass.getProperty(attribute.getNodeName());
                        if (p instanceof IFXPrimitiveProperty) {
                            createAttributeValuePrimitiveProposals(contentAssistRequest, context,
                                    (IFXPrimitiveProperty) p);
                        } else if (p instanceof IFXEnumProperty) {
                            createAttributeValueEnumProposals(contentAssistRequest, context,
                                    (IFXEnumProperty) p);
                        } else if (p instanceof IFXObjectProperty) {
                            createAttributeValueObjectProposals(contentAssistRequest, context,
                                    (IFXObjectProperty) p);
                        } else if (p instanceof IFXEventHandlerProperty) {
                            createAttributeValueEventHandlerProposals(contentAssistRequest, context,
                                    (IFXEventHandlerProperty) p);
                        }
                    }
                }
            }
        }
    }
}

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;/*ww w. j  a v  a 2s.  co  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;//  w w  w. 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.android.ide.eclipse.adt.internal.refactoring.core.AndroidPackageRenameParticipant.java

License:Open Source License

@Override
protected boolean initialize(final Object element) {
    mIsPackage = false;//from ww  w .ja  v  a 2s .  c  o m
    try {
        if (element instanceof IPackageFragment) {
            mPackageFragment = (IPackageFragment) element;
            if (!mPackageFragment.containsJavaResources())
                return false;
            IJavaProject javaProject = (IJavaProject) mPackageFragment.getAncestor(IJavaElement.JAVA_PROJECT);
            IProject project = javaProject.getProject();
            IResource manifestResource = project
                    .findMember(AdtConstants.WS_SEP + SdkConstants.FN_ANDROID_MANIFEST_XML);

            if (manifestResource == null || !manifestResource.exists()
                    || !(manifestResource instanceof IFile)) {
                RefactoringUtil.logInfo("Invalid or missing the " + SdkConstants.FN_ANDROID_MANIFEST_XML
                        + " in the " + project.getName() + " project.");
                return false;
            }
            mAndroidManifest = (IFile) manifestResource;
            String packageName = mPackageFragment.getElementName();
            ManifestData manifestData;
            manifestData = AndroidManifestHelper.parseForData(mAndroidManifest);
            if (manifestData == null) {
                return false;
            }
            mAppPackage = manifestData.getPackage();
            mOldName = packageName;
            mNewName = getArguments().getNewName();
            if (mOldName == null || mNewName == null) {
                return false;
            }

            if (RefactoringUtil.isRefactorAppPackage() && mAppPackage != null
                    && mAppPackage.equals(packageName)) {
                mIsPackage = true;
            }
            mAndroidElements = addAndroidElements();
            try {
                final IType type = javaProject.findType(SdkConstants.CLASS_VIEW);
                SearchPattern pattern = SearchPattern.createPattern("*", IJavaSearchConstants.TYPE,
                        IJavaSearchConstants.DECLARATIONS, SearchPattern.R_REGEXP_MATCH);
                IJavaSearchScope scope = SearchEngine
                        .createJavaSearchScope(new IJavaElement[] { mPackageFragment });
                final HashSet<IType> elements = new HashSet<IType>();
                SearchRequestor requestor = new SearchRequestor() {

                    @Override
                    public void acceptSearchMatch(SearchMatch match) throws CoreException {
                        Object elem = match.getElement();
                        if (elem instanceof IType) {
                            IType eType = (IType) elem;
                            IType[] superTypes = JavaModelUtil.getAllSuperTypes(eType,
                                    new NullProgressMonitor());
                            for (int i = 0; i < superTypes.length; i++) {
                                if (superTypes[i].equals(type)) {
                                    elements.add(eType);
                                    break;
                                }
                            }
                        }

                    }
                };
                SearchEngine searchEngine = new SearchEngine();
                searchEngine.search(pattern,
                        new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
                        requestor, null);
                List<String> views = new ArrayList<String>();
                for (IType elem : elements) {
                    views.add(elem.getFullyQualifiedName());
                }
                if (views.size() > 0) {
                    String[] classNames = views.toArray(new String[0]);
                    addLayoutChanges(project, classNames);
                }
            } catch (CoreException e) {
                RefactoringUtil.log(e);
            }

            return mIsPackage || mAndroidElements.size() > 0 || mFileChanges.size() > 0;
        }
    } catch (JavaModelException ignore) {
    }
    return false;
}

From source file:com.arcbees.gwtp.plugin.core.presenter.CreatePresenterPage.java

License:Apache License

private List<ResolvedSourceType> findClassName(String name) {
    int searchFor = IJavaSearchConstants.CLASS;
    int limitTo = IJavaSearchConstants.TYPE;
    int matchRule = SearchPattern.R_EXACT_MATCH;
    SearchPattern searchPattern = SearchPattern.createPattern(name, searchFor, limitTo, matchRule);

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

    final List<ResolvedSourceType> found = new ArrayList<ResolvedSourceType>();
    SearchRequestor requestor = new SearchRequestor() {
        @Override/*from  w ww.  j  ava 2s  .  com*/
        public void acceptSearchMatch(SearchMatch match) {
            // TODO
            System.out.println(match);
            Object element = match.getElement();
            found.add((ResolvedSourceType) element);
        }
    };

    SearchEngine searchEngine = new SearchEngine();
    SearchParticipant[] particpant = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
    try {
        searchEngine.search(searchPattern, particpant, scope, requestor, new NullProgressMonitor());
    } catch (CoreException e) {
        // TODO
        e.printStackTrace();
    }
    return found;
}

From source file:com.drgarbage.bytecodevisualizer.compare.OpenClassFileAction.java

License:Apache License

/**
 * Opens a dialog with a list of classes from the current workspace.
 * The selected class is returned as a java element.
 * @return the java element or <code>null</null>
 * @see IJavaElement/*from  w  ww.  j  a v a  2  s. co m*/
 */
private IJavaElement selectJavaElement() {

    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

    FilteredItemsSelectionDialog dialog = new OpenTypeSelectionDialog(shell, false,
            new ProgressMonitorDialog(shell), SearchEngine.createWorkspaceScope(), IJavaSearchConstants.TYPE);
    dialog.setTitle(ClassFileMergeViewer.CLASS_FILE_MERGEVIEWER_TITLE);
    dialog.setMessage(BytecodeVisualizerMessages.Message_file_to_compare);

    int resultCode = dialog.open();
    if (resultCode != IDialogConstants.OK_ID) {
        return null;
    }

    Object[] result = dialog.getResult();

    if (result != null) {
        if (result.length != 0) {
            IJavaElement je = (IJavaElement) result[0];
            return je;
        }
    }

    return null;
}

From source file:com.google.gwt.eclipse.core.search.JavaQueryParticipant.java

License:Open Source License

private static boolean isTypeSearch(QuerySpecification query) {
    if (query instanceof ElementQuerySpecification) {
        return (((ElementQuerySpecification) query).getElement().getElementType() == IJavaElement.TYPE);
    }/*from  www. jav a2s  .c  om*/

    return (((PatternQuerySpecification) query).getSearchFor() == IJavaSearchConstants.TYPE);
}

From source file:com.google.gwt.eclipse.core.search.JavaQueryParticipant.java

License:Open Source License

private Set<IIndexedJavaRef> findMatches(PatternQuerySpecification query) {
    // Translate the IJavaSearchConstant element type constants to IJavaElement
    // type constants.
    int elementType;
    switch (query.getSearchFor()) {
    case IJavaSearchConstants.TYPE:
        elementType = IJavaElement.TYPE;
        break;/*from  w w w  .j  av a2  s. co  m*/
    case IJavaSearchConstants.FIELD:
        elementType = IJavaElement.FIELD;
        break;
    case IJavaSearchConstants.METHOD:
    case IJavaSearchConstants.CONSTRUCTOR:
        // IJavaElement.METHOD represents both methods & ctors
        elementType = IJavaElement.METHOD;
        break;
    default:
        // We only support searching for types, fields, methods, and ctors
        return Collections.emptySet();
    }

    return JavaRefIndex.getInstance().findElementReferences(query.getPattern(), elementType,
            query.isCaseSensitive());
}

From source file:com.google.gwt.eclipse.core.search.JavaQueryParticipantTest.java

License:Open Source License

public void testParamTypeSearch() throws CoreException {
    // Search for JSNI reference param type
    Match[] expected = new Match[] { createWindowsTestMatch(789, 16), createWindowsTestMatch(897, 16) };
    assertSearchMatches(expected, createQuery("java.lang.String", IJavaSearchConstants.TYPE));
}

From source file:com.google.gwt.eclipse.core.search.JavaQueryParticipantTest.java

License:Open Source License

public void testPatternSearch() throws CoreException {
    Match[] expected;/* w  ww.ja  v  a2 s .co m*/

    // Search for type references by simple name
    expected = new Match[] { createWindowsTestMatch(840, 50), createWindowsTestMatch(1207, 50),
            createWindowsTestMatch(1419, 50) };
    assertSearchMatches(expected, createQuery("InnerSub", IJavaSearchConstants.TYPE));

    // Search for type with different casing
    expected = new Match[] { createWindowsTestMatch(840, 50), createWindowsTestMatch(1207, 50),
            createWindowsTestMatch(1419, 50) };
    assertSearchMatches(expected, createQuery("innersub", IJavaSearchConstants.TYPE));

    // Search for type with different casing with case-sensitive enabled
    QuerySpecification query = new PatternQuerySpecification("innersub", IJavaSearchConstants.TYPE, true,
            IJavaSearchConstants.REFERENCES, WORKSPACE_SCOPE, "");
    assertSearchMatches(NO_MATCHES, query);

    // Search for field references
    assertSearchMatch(createWindowsTestMatch(990, 5), createQuery("keith", IJavaSearchConstants.FIELD));

    // Search for method references using * wildcard
    expected = new Match[] { createWindowsTestMatch(1174, 5), createWindowsTestMatch(1259, 5),
            createWindowsTestMatch(1340, 8) };
    assertSearchMatches(expected, createQuery("sayH*", IJavaSearchConstants.METHOD));

    // Search for method references using ? wildcard
    expected = new Match[] { createWindowsTestMatch(1174, 5), createWindowsTestMatch(1259, 5) };
    assertSearchMatches(expected, createQuery("sayH?", IJavaSearchConstants.METHOD));

    // Search for constructor references with qualified type name and parameters
    assertSearchMatch(createWindowsTestMatch(892, 3),
            createQuery("com.hello.client.JavaQueryParticipantTest.InnerSub.InnerSub(String)",
                    IJavaSearchConstants.CONSTRUCTOR));
}