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

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

Introduction

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

Prototype

int REFERENCES

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

Click Source Link

Document

The search result is a reference.

Usage

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 .ja v a2s  . c  om
    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:com.codenvy.ide.ext.java.server.internal.core.search.matching.DeclarationOfAccessedFieldsPattern.java

License:Open Source License

public DeclarationOfAccessedFieldsPattern(IJavaElement enclosingElement) {
    super(null, null, null, null, null, IJavaSearchConstants.REFERENCES, R_PATTERN_MATCH);

    this.enclosingElement = enclosingElement;
    this.knownFields = new SimpleSet();
    this.mustResolve = true;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.DeclarationOfReferencedMethodsPattern.java

License:Open Source License

public DeclarationOfReferencedMethodsPattern(IJavaElement enclosingElement) {
    super(null, null, null, null, null, null, null, null, IJavaSearchConstants.REFERENCES, R_PATTERN_MATCH);

    this.enclosingElement = enclosingElement;
    this.knownMethods = new SimpleSet();
    this.mustResolve = true;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.VariablePattern.java

License:Open Source License

public VariablePattern(int patternKind, char[] name, int limitTo, int matchRule) {
    super(patternKind, matchRule);

    this.fineGrain = limitTo & FINE_GRAIN_MASK;
    if (this.fineGrain == 0) {
        switch (limitTo & 0xF) {
        case IJavaSearchConstants.DECLARATIONS:
            this.findDeclarations = true;
            break;
        case IJavaSearchConstants.REFERENCES:
            this.readAccess = true;
            this.writeAccess = true;
            break;
        case IJavaSearchConstants.READ_ACCESSES:
            this.readAccess = true;
            break;
        case IJavaSearchConstants.WRITE_ACCESSES:
            this.writeAccess = true;
            break;
        case IJavaSearchConstants.ALL_OCCURRENCES:
            this.findDeclarations = true;
            this.readAccess = true;
            this.writeAccess = true;
            break;
        }/*from  www. ja  v a2s  .co m*/
        this.findReferences = this.readAccess || this.writeAccess;
    }

    this.name = (this.isCaseSensitive || this.isCamelCase) ? name : CharOperation.toLowerCase(name);
}

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

License:Open Source License

public static Set<IIndexedJavaRef> findWorkspaceReferences(IJavaElement element, boolean resolveMatches) {
    JavaQueryParticipant searchEngine = new JavaQueryParticipant();
    ElementQuerySpecification query = new ElementQuerySpecification(element, IJavaSearchConstants.REFERENCES,
            WORKSPACE_SCOPE, "");

    return searchEngine.findMatches(query, resolveMatches);
}

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

License:Open Source License

public void search(ISearchRequestor requestor, QuerySpecification query, IProgressMonitor monitor)
        throws CoreException {
    try {/* w ww  . ja  v a 2s .co  m*/
        monitor.subTask("Locating GWT matches...");

        // Make sure we're searching for Java references
        switch (query.getLimitTo()) {
        case IJavaSearchConstants.REFERENCES:
        case IJavaSearchConstants.ALL_OCCURRENCES:
            // These we handle as expected
            break;
        case IJavaSearchConstants.READ_ACCESSES:
        case IJavaSearchConstants.WRITE_ACCESSES:
            // We don't actually check field references to see if they're read or
            // write accesses; we just treat this as a generic references search
            break;
        default:
            // Anything else (e.g., Declarations), we don't support
            return;
        }

        Set<IIndexedJavaRef> matchingJavaRefs = null;

        // Find all matching Java references in the index. The search algorithm
        // differs depending on whether we're doing an element query
        // (Ctrl-Shift-G) or a pattern query (Java Search dialog box)
        if (query instanceof ElementQuerySpecification) {
            ElementQuerySpecification elementQuery = (ElementQuerySpecification) query;
            matchingJavaRefs = findMatches(elementQuery, true);
        } else {
            assert (query instanceof PatternQuerySpecification);
            PatternQuerySpecification patternQuery = (PatternQuerySpecification) query;
            matchingJavaRefs = findMatches(patternQuery);
        }

        for (IIndexedJavaRef javaRef : matchingJavaRefs) {
            Match match = createMatch(javaRef, query);
            if (match != null) {
                // Report the match location to the Java Search engine
                requestor.reportMatch(match);
            }
        }
    } catch (Exception e) {
        // If we allow any exceptions to escape, the JDT will disable us
        GWTPluginLog.logError("Error finding Java Search matches", e);
    }
}

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

License:Open Source License

private static QuerySpecification createQuery(IJavaElement element) {
    return new ElementQuerySpecification(element, IJavaSearchConstants.REFERENCES, WORKSPACE_SCOPE, "");
}

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

License:Open Source License

private static QuerySpecification createQuery(String pattern, int searchFor) {
    return new PatternQuerySpecification(pattern, searchFor, false, IJavaSearchConstants.REFERENCES,
            WORKSPACE_SCOPE, "");
}

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

License:Open Source License

public void testLimitTo() throws CoreException {
    IJavaElement element = getTestType1().getField("keith");
    QuerySpecification query;//from   w  ww. j  ava 2s .c o  m

    // Limit to: references
    query = new ElementQuerySpecification(element, IJavaSearchConstants.REFERENCES, WORKSPACE_SCOPE, "");
    assertSearchMatch(createWindowsTestMatch(990, 5), query);

    // Limit to: all occurrences (declaration and all references, although in
    // this case we're only using our search engine so we'll only have refs)
    query = new ElementQuerySpecification(element, IJavaSearchConstants.ALL_OCCURRENCES, WORKSPACE_SCOPE, "");
    assertSearchMatch(createWindowsTestMatch(990, 5), query);

    // Limit to: read accesses (we don't differentiate between read/write
    // accesses, so this returns all references)
    query = new ElementQuerySpecification(element, IJavaSearchConstants.READ_ACCESSES, WORKSPACE_SCOPE, "");
    assertSearchMatch(createWindowsTestMatch(990, 5), query);

    // Limit to: write accesses (we don't differentiate between read/write
    // accesses, so this returns all references)
    query = new ElementQuerySpecification(element, IJavaSearchConstants.WRITE_ACCESSES, WORKSPACE_SCOPE, "");
    assertSearchMatch(createWindowsTestMatch(990, 5), query);

    // Limit to: declarations (unsupported)
    query = new ElementQuerySpecification(element, IJavaSearchConstants.DECLARATIONS, WORKSPACE_SCOPE, "");
    assertSearchMatches(NO_MATCHES, query);

    // Limit to: implementors (unsupported)
    query = new ElementQuerySpecification(element, IJavaSearchConstants.IMPLEMENTORS, WORKSPACE_SCOPE, "");
    assertSearchMatches(NO_MATCHES, query);
}

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

License:Open Source License

public void testPatternSearch() throws CoreException {
    Match[] expected;/*from w  w  w. ja  va 2 s .  c  o  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));
}