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

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

Introduction

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

Prototype

int DECLARATIONS

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

Click Source Link

Document

The search result is a declaration.

Usage

From source file:org.springframework.ide.eclipse.boot.properties.editor.metadata.JdtSearchingValueProvider.java

License:Open Source License

public static SearchPattern toPackagePattern(String wildCardedQuery) {
    int searchFor = IJavaSearchConstants.PACKAGE;
    int limitTo = IJavaSearchConstants.DECLARATIONS;
    int matchRule = SearchPattern.R_PATTERN_MATCH;
    return SearchPattern.createPattern(wildCardedQuery, searchFor, limitTo, matchRule);
}

From source file:org.springframework.ide.eclipse.boot.properties.editor.metadata.JdtSearchingValueProvider.java

License:Open Source License

public static SearchPattern toClassPattern(String wildCardedQuery) {
    int searchFor = IJavaSearchConstants.CLASS;
    int limitTo = IJavaSearchConstants.DECLARATIONS;
    int matchRule = SearchPattern.R_PATTERN_MATCH;
    return SearchPattern.createPattern(wildCardedQuery, searchFor, limitTo, matchRule);
}

From source file:org.springframework.ide.eclipse.boot.properties.editor.metadata.JdtSearchingValueProvider.java

License:Open Source License

public static SearchPattern toTypePattern(String wildCardedQuery) {
    int searchFor = IJavaSearchConstants.TYPE;
    int limitTo = IJavaSearchConstants.DECLARATIONS;
    int matchRule = SearchPattern.R_PATTERN_MATCH;
    return SearchPattern.createPattern(wildCardedQuery, searchFor, limitTo, matchRule);
}

From source file:org.talend.designer.runtime.visualization.internal.actions.OpenDeclarationAction.java

License:Open Source License

/**
 * Searches the source for the given class name.
 * //from   w  ww .  j a v a  2 s .  com
 * @param name The class name
 * @return The source
 * @throws CoreException
 */
IType doSearchSource(String name) throws CoreException {
    final List<IType> results = new ArrayList<IType>();

    // create requester
    SearchRequestor requestor = new SearchRequestor() {

        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            Object element = match.getElement();
            if (element instanceof IType) {
                results.add((IType) element);
            }
        }
    };

    String baseName = name.replace('$', '.');

    // create search engine and pattern
    SearchEngine engine = new SearchEngine();
    SearchPattern pattern = SearchPattern.createPattern(baseName, IJavaSearchConstants.TYPE,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);

    // search the source for the given name
    engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
            SearchEngine.createWorkspaceScope(), requestor, null);

    if (results.size() > 0) {
        // at most one source should be found
        return results.get(0);
    }

    return null;
}

From source file:org.teavm.eclipse.ui.AnyClassSelectionDialog.java

License:Apache License

@Override
protected SearchPattern createSearchPattern(String text) {
    return SearchPattern.createPattern("*" + text + "*", IJavaSearchConstants.CLASS,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH);
}

From source file:org.teavm.eclipse.ui.MainClassSelectionDialog.java

License:Apache License

@Override
protected SearchPattern createSearchPattern(String text) {
    return SearchPattern.createPattern("main(String[]) void", IJavaSearchConstants.METHOD,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
}

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.j  av a 2  s  .c  o  m
    }

    return element;
}

From source file:rs.snpe.android.refactoring.core.AndroidPackageRenameParticipant.java

License:Open Source License

@Override
protected boolean initialize(final Object element) {
    isPackage = false;//from w  w w . j  av a  2  s .  c  om
    try {
        if (element instanceof IPackageFragment) {
            packageFragment = (IPackageFragment) element;
            if (!packageFragment.containsJavaResources())
                return false;
            IJavaProject javaProject = (IJavaProject) packageFragment.getAncestor(IJavaElement.JAVA_PROJECT);
            IProject project = javaProject.getProject();
            IResource manifestResource = project
                    .findMember(AndroidConstants.WS_SEP + AndroidConstants.FN_ANDROID_MANIFEST);

            if (manifestResource == null || !manifestResource.exists()
                    || !(manifestResource instanceof IFile)) {
                Activator.logInfo("Invalid or missing the " + AndroidConstants.FN_ANDROID_MANIFEST + " in the "
                        + project.getName() + " project.");
                return false;
            }
            androidManifest = (IFile) manifestResource;
            String packageName = packageFragment.getElementName();
            AndroidManifestParser parser;
            try {
                parser = AndroidManifestParser.parseForData(androidManifest);
            } catch (CoreException e) {
                Activator.logInfo("Invalid or missing the " + AndroidConstants.FN_ANDROID_MANIFEST + " in the "
                        + project.getName() + " project.");
                return false;
            }
            javaPackage = parser.getPackage();
            oldName = packageName;
            newName = getArguments().getNewName();
            if (oldName == null || newName == null) {
                return false;
            }

            if (javaPackage != null && javaPackage.equals(packageName)) {
                isPackage = true;
            }
            androidElements = addAndroidElements();
            try {
                final IType type = javaProject.findType(AndroidConstants.CLASS_VIEW);
                SearchPattern pattern = SearchPattern.createPattern("*", IJavaSearchConstants.TYPE,
                        IJavaSearchConstants.DECLARATIONS, SearchPattern.R_REGEXP_MATCH);
                IJavaSearchScope scope = SearchEngine
                        .createJavaSearchScope(new IJavaElement[] { packageFragment });
                final HashSet<IType> elements = new HashSet<IType>();
                SearchRequestor requestor = new SearchRequestor() {
                    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) {
                Activator.log(e);
            }

            return isPackage || androidElements.size() > 0 || fileChanges.size() > 0;
        }
    } catch (JavaModelException ignore) {
    }
    return false;
}

From source file:tod.plugin.TODPluginUtils.java

License:Open Source License

/**
 * Searches for declarations of the given name and kind in the whole workspace. 
 *///from   w  ww  . j a  va2 s . com
public static List searchDeclarations(List<IJavaProject> aJavaProject, String aName, int aKind)
        throws CoreException {
    // Recursively add referenced projects (because Eclipse doesn't recursively include non-exported referenced projects) 
    Set<IJavaProject> theProjects = new HashSet<IJavaProject>();
    Stack<IJavaProject> theWorkingList = new ArrayStack<IJavaProject>();
    for (IJavaProject theProject : aJavaProject)
        theWorkingList.push(theProject);

    while (!theWorkingList.isEmpty()) {
        IJavaProject theProject = theWorkingList.pop();
        theProjects.add(theProject);

        IJavaModel theJavaModel = theProject.getJavaModel();
        IClasspathEntry[] theEntries = theProject.getResolvedClasspath(true);
        for (IClasspathEntry theEntry : theEntries)
            if (theEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                IJavaProject theReferencedProject = theJavaModel
                        .getJavaProject(theEntry.getPath().lastSegment());
                if (theReferencedProject.exists() && !theProjects.contains(theReferencedProject))
                    theWorkingList.push(theReferencedProject);
            }
    }

    SearchPattern thePattern = SearchPattern.createPattern(aName.replace('$', '.'), aKind,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);

    IJavaSearchScope theScope = SearchEngine
            .createJavaSearchScope(theProjects.toArray(new IJavaElement[theProjects.size()]), true);

    SearchEngine theSearchEngine = new SearchEngine();
    SimpleResultCollector theCollector = new SimpleResultCollector();

    theSearchEngine.search(thePattern, PARTICIPANTS, theScope, theCollector, null);

    return theCollector.getResults();
}