Example usage for org.eclipse.jdt.core.search SearchPattern R_ERASURE_MATCH

List of usage examples for org.eclipse.jdt.core.search SearchPattern R_ERASURE_MATCH

Introduction

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

Prototype

int R_ERASURE_MATCH

To view the source code for org.eclipse.jdt.core.search SearchPattern R_ERASURE_MATCH.

Click Source Link

Document

Match rule: The search pattern matches search results as raw/parameterized types/methods with same erasure.

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  .j  a v  a  2  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:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchingNodeSet.java

License:Open Source License

public int addMatch(ASTNode node, int matchLevel) {
    int maskedLevel = matchLevel & PatternLocator.MATCH_LEVEL_MASK;
    switch (maskedLevel) {
    case PatternLocator.INACCURATE_MATCH:
        if (matchLevel != maskedLevel) {
            addTrustedMatch(node, new Integer(SearchMatch.A_INACCURATE + (matchLevel
                    & org.eclipse.jdt.internal.core.search.matching.PatternLocator.FLAVORS_MASK)));
        } else {/*www .j a  v a  2  s . c o m*/
            addTrustedMatch(node, POTENTIAL_MATCH);
        }
        break;
    case PatternLocator.POSSIBLE_MATCH:
        addPossibleMatch(node);
        break;
    case PatternLocator.ERASURE_MATCH:
        if (matchLevel != maskedLevel) {
            addTrustedMatch(node,
                    new Integer(SearchPattern.R_ERASURE_MATCH + (matchLevel & PatternLocator.FLAVORS_MASK)));
        } else {
            addTrustedMatch(node, ERASURE_MATCH);
        }
        break;
    case PatternLocator.ACCURATE_MATCH:
        if (matchLevel != maskedLevel) {
            addTrustedMatch(node,
                    new Integer(SearchMatch.A_ACCURATE + (matchLevel & PatternLocator.FLAVORS_MASK)));
        } else {
            addTrustedMatch(node, EXACT_MATCH);
        }
        break;
    }
    return matchLevel;
}

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

License:Open Source License

public String toString() {
    // TODO (jerome) should show both tables
    StringBuffer result = new StringBuffer();
    result.append("Exact matches:"); //$NON-NLS-1$
    Object[] keyTable = this.matchingNodes.keyTable;
    Object[] valueTable = this.matchingNodes.valueTable;
    for (int i = 0, l = keyTable.length; i < l; i++) {
        ASTNode node = (ASTNode) keyTable[i];
        if (node == null)
            continue;
        result.append("\n\t"); //$NON-NLS-1$
        switch (((Integer) valueTable[i]).intValue()) {
        case SearchMatch.A_ACCURATE:
            result.append("ACCURATE_MATCH: "); //$NON-NLS-1$
            break;
        case SearchMatch.A_INACCURATE:
            result.append("INACCURATE_MATCH: "); //$NON-NLS-1$
            break;
        case SearchPattern.R_ERASURE_MATCH:
            result.append("ERASURE_MATCH: "); //$NON-NLS-1$
            break;
        }//from  ww w.  j  av  a  2  s  . c  o  m
        node.print(0, result);
    }

    result.append("\nPossible matches:"); //$NON-NLS-1$
    Object[] nodes = this.possibleMatchingNodesSet.values;
    for (int i = 0, l = nodes.length; i < l; i++) {
        ASTNode node = (ASTNode) nodes[i];
        if (node == null)
            continue;
        result.append("\nPOSSIBLE_MATCH: "); //$NON-NLS-1$
        node.print(0, result);
    }
    return result.toString();
}

From source file:de.loskutov.dh.search.SearchHelper.java

License:Open Source License

/**
 * Blocks current thread until search is done
 *///w w w .  j ava2  s  .c o  m
public List<IJavaElement> getReferences(IProgressMonitor monitor) throws CoreException {

    pattern = SearchPattern.createPattern(searchRoot.getJavaElement(),
            IJavaSearchConstants.REFERENCES | ~IJavaSearchConstants.IMPORT_DECLARATION_TYPE_REFERENCE,
            // | IJavaSearchConstants.IGNORE_DECLARING_TYPE,
            SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE | SearchPattern.R_ERASURE_MATCH);

    if (pattern == null) {
        // this is packages???
        // System.out.println("Search patter is null for: " + elt.getElementName());
        return new ArrayList<IJavaElement>();
    }

    scope = conf.createScope(searchRoot.getJavaElement());
    JavaReferencesRequestor searchRequestor = new JavaReferencesRequestor();

    return search(searchRequestor, monitor);
}

From source file:org.eclipse.ajdt.internal.ui.refactoring.RippleMethodFinder2.java

License:Open Source License

private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException {
    fDeclarations = new ArrayList();

    class MethodRequestor extends SearchRequestor {
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            IMethod method = (IMethod) match.getElement();
            boolean isBinary = method.isBinary();
            if (fBinaryRefs != null || !(fExcludeBinaries && isBinary)) {
                fDeclarations.add(method);
            }// ww w  .  j  av  a 2 s . c  o m
            if (isBinary && fBinaryRefs != null) {
                fDeclarationToMatch.put(method, match);
            }
        }
    }

    int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE
            | IJavaSearchConstants.IGNORE_RETURN_TYPE;
    int matchRule = SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE;
    SearchPattern pattern = SearchPattern.createPattern(fMethod, limitTo, matchRule);
    SearchParticipant[] participants = SearchUtils.getDefaultSearchParticipants();
    IJavaSearchScope scope = RefactoringScopeFactory.createRelatedProjectsScope(fMethod.getJavaProject(),
            IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES
                    | IJavaSearchScope.SYSTEM_LIBRARIES);
    MethodRequestor requestor = new MethodRequestor();
    SearchEngine searchEngine = owner != null ? new SearchEngine(owner) : new SearchEngine();

    searchEngine.search(pattern, participants, scope, requestor, monitor);
}

From source file:org.eclipse.che.jdt.internal.core.search.matching.MatchingNodeSet.java

License:Open Source License

public int addMatch(ASTNode node, int matchLevel) {
    int maskedLevel = matchLevel
            & org.eclipse.jdt.internal.core.search.matching.PatternLocator.MATCH_LEVEL_MASK;
    switch (maskedLevel) {
    case org.eclipse.jdt.internal.core.search.matching.PatternLocator.INACCURATE_MATCH:
        if (matchLevel != maskedLevel) {
            addTrustedMatch(node, new Integer(SearchMatch.A_INACCURATE + (matchLevel
                    & org.eclipse.jdt.internal.core.search.matching.PatternLocator.FLAVORS_MASK)));
        } else {/*from w  w w  . j av a  2 s .c  o  m*/
            addTrustedMatch(node, POTENTIAL_MATCH);
        }
        break;
    case org.eclipse.jdt.internal.core.search.matching.PatternLocator.POSSIBLE_MATCH:
        addPossibleMatch(node);
        break;
    case org.eclipse.jdt.internal.core.search.matching.PatternLocator.ERASURE_MATCH:
        if (matchLevel != maskedLevel) {
            addTrustedMatch(node, new Integer(SearchPattern.R_ERASURE_MATCH + (matchLevel
                    & org.eclipse.jdt.internal.core.search.matching.PatternLocator.FLAVORS_MASK)));
        } else {
            addTrustedMatch(node, ERASURE_MATCH);
        }
        break;
    case org.eclipse.jdt.internal.core.search.matching.PatternLocator.ACCURATE_MATCH:
        if (matchLevel != maskedLevel) {
            addTrustedMatch(node,
                    new Integer(SearchMatch.A_ACCURATE + (matchLevel & PatternLocator.FLAVORS_MASK)));
        } else {
            addTrustedMatch(node, EXACT_MATCH);
        }
        break;
    }
    return matchLevel;
}

From source file:org.testng.eclipse.ui.OpenEditorAtLineAction.java

License:Open Source License

protected IJavaElement findElement(IJavaProject project, String className) throws CoreException {
    IJavaElement element = project.findType(className);

    //fix for bug 37333
    if (element == null) {
        SearchPattern pattern = SearchPattern.createPattern(className, IJavaSearchConstants.TYPE,
                IJavaSearchConstants.DECLARATIONS,
                SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE | SearchPattern.R_ERASURE_MATCH);
        IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, false);
        NonPublicClassInCUCollector requestor = new NonPublicClassInCUCollector();

        SearchEngine searchEngine = new SearchEngine();
        searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
                scope, requestor, new NullProgressMonitor());

        element = requestor.fFound;/*ww w.  ja  v a2s  .c  o m*/
    }

    return element;
}