net.hillsdon.testlink.model.impl.Searcher.java Source code

Java tutorial

Introduction

Here is the source code for net.hillsdon.testlink.model.impl.Searcher.java

Source

/*******************************************************************************
 * Copyright (c) 2008 Matthew Hillsdon.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Matthew Hillsdon <matt@hillsdon.net>
 *******************************************************************************/
package net.hillsdon.testlink.model.impl;

import java.util.Set;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.core.search.SearchParticipant;
import org.eclipse.jdt.core.search.SearchPattern;

public class Searcher implements ISearcher {

    public Set<IResource> search(final String typeName) throws CoreException {
        SearchEngine searchEngine = new SearchEngine();
        IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
        ResourceCollector results = new ResourceCollector();
        SearchPattern pattern = SearchPattern.createPattern(typeName, IJavaSearchConstants.TYPE,
                IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH);
        searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
                results, new NullProgressMonitor());
        return results.getCollectedPaths();
    }

}