Search in sources :

Example 1 with SearchDocument

use of org.eclipse.jdt.core.search.SearchDocument in project che by eclipse.

the class IndexManager method addSource.

/**
     * Trigger addition of a resource to an index
     * Note: the actual operation is performed in background
     */
public void addSource(IFile resource, IPath containerPath, SourceElementParser parser) {
    //        if (JavaCore.getPlugin() == null) return;
    SearchParticipant participant = SearchEngine.getDefaultSearchParticipant();
    SearchDocument document = participant.getDocument(resource.getFullPath().toString());
    document.setParser(parser);
    IndexLocation indexLocation = computeIndexLocation(containerPath);
    scheduleDocumentIndexing(document, containerPath, indexLocation, participant);
}
Also used : FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) SearchParticipant(org.eclipse.jdt.core.search.SearchParticipant) SearchDocument(org.eclipse.jdt.core.search.SearchDocument)

Example 2 with SearchDocument

use of org.eclipse.jdt.core.search.SearchDocument in project webtools.sourceediting by eclipse.

the class JSPSearchParticipant method locateMatches.

public void locateMatches(SearchDocument[] indexMatches, SearchPattern pattern, IJavaSearchScope scope, SearchRequestor requestor, IProgressMonitor monitor) throws CoreException {
    if (monitor != null && monitor.isCanceled())
        return;
    // filter out null matches
    List filtered = new ArrayList();
    SearchDocument match = null;
    for (int i = 0; i < indexMatches.length; i++) {
        if (DEBUG)
            // $NON-NLS-1$
            System.out.println("found possible matching JavaSearchDocumentDelegate: " + indexMatches[i]);
        match = indexMatches[i];
        if (match != null) {
            // the file may not even exist
            if (match instanceof JavaSearchDocumentDelegate && ((JavaSearchDocumentDelegate) match).getFile().exists())
                filtered.add(match);
        }
    }
    indexMatches = (SearchDocument[]) filtered.toArray(new SearchDocument[filtered.size()]);
    SearchEngine.getDefaultSearchParticipant().locateMatches(indexMatches, pattern, scope, requestor, monitor);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SearchDocument(org.eclipse.jdt.core.search.SearchDocument)

Example 3 with SearchDocument

use of org.eclipse.jdt.core.search.SearchDocument in project webtools.sourceediting by eclipse.

the class JSPSearchQuery method doQuery.

protected IStatus doQuery(IProgressMonitor monitor) {
    IStatus status = Status.OK_STATUS;
    try {
        JSPSearchSupport support = JSPSearchSupport.getInstance();
        // index the file
        SearchDocument delegate = support.addJspFile(getFile());
        String scopePath = delegate.getPath();
        JSPSearchScope singleFileScope = new JSPSearchScope(new String[] { getFile().getFullPath().toString(), scopePath });
        // perform a searchs
        // by passing in this jsp search query, requstor can add matches
        support.searchRunnable(getJavaElement(), singleFileScope, new JSPSingleFileSearchRequestor(getInstance()), monitor);
    } catch (Exception e) {
        // $NON-NLS-1$	//$NON-NLS-2$
        status = new Status(IStatus.ERROR, "org.eclipse.wst.sse.ui", IStatus.OK, "", null);
    }
    return status;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) JSPSearchSupport(org.eclipse.jst.jsp.core.internal.java.search.JSPSearchSupport) JSPSearchScope(org.eclipse.jst.jsp.core.internal.java.search.JSPSearchScope) SearchDocument(org.eclipse.jdt.core.search.SearchDocument)

Example 4 with SearchDocument

use of org.eclipse.jdt.core.search.SearchDocument in project webtools.sourceediting by eclipse.

the class BasicRefactorSearchRequestor method getChanges.

/**
 * <p>This function is not safe because it does not check for existing {@link Change}s that
 * new {@link Change}s created by this method may conflict with.  These conflicts can
 * cause indeterminate results when applied to documents.  Long story short, don't
 * use this method any more.</p>
 *
 * @return all JSP changes for the search matches for the given Type, they may conflict
 * with already existing {@link Change}s
 *
 * @see #getChanges(RefactoringParticipant)
 *
 * @deprecated
 */
public Change[] getChanges() {
    JSPSearchSupport support = JSPSearchSupport.getInstance();
    List changes = new ArrayList();
    Iterator keys = fSearchDocPath2JavaEditMap.keySet().iterator();
    String searchDocPath = null;
    SearchDocument delegate = null;
    while (keys.hasNext()) {
        // create on the fly
        searchDocPath = (String) keys.next();
        MultiTextEdit javaEdit = (MultiTextEdit) fSearchDocPath2JavaEditMap.get(searchDocPath);
        delegate = support.getSearchDocument(searchDocPath);
        if (delegate != null && delegate instanceof JavaSearchDocumentDelegate) {
            JavaSearchDocumentDelegate javaDelegate = (JavaSearchDocumentDelegate) delegate;
            changes.add(createChange(javaDelegate, javaDelegate.getJspTranslation().getJspEdit(javaEdit)));
        }
    }
    return (Change[]) changes.toArray(new Change[changes.size()]);
}
Also used : JSPSearchSupport(org.eclipse.jst.jsp.core.internal.java.search.JSPSearchSupport) JavaSearchDocumentDelegate(org.eclipse.jst.jsp.core.internal.java.search.JavaSearchDocumentDelegate) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) TextChange(org.eclipse.ltk.core.refactoring.TextChange) Change(org.eclipse.ltk.core.refactoring.Change) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) SearchDocument(org.eclipse.jdt.core.search.SearchDocument)

Example 5 with SearchDocument

use of org.eclipse.jdt.core.search.SearchDocument in project webtools.sourceediting by eclipse.

the class BasicRefactorSearchRequestor method getChanges.

/**
 * Gets new {@link Change}s created as a result of this {@link SearchRequestor}.
 * Any existing {@link TextChange}s that had new edits added to them will not be
 * returned.
 *
 * @param participant {@link RefactoringParticipant} to determine if there are already existing
 * {@link TextChange}s for the documents that this {@link SearchRequestor} found.
 * If existing
 * {@link TextChange}s are found then they will be used for any new edits, else new {@link TextChange}s
 * will be created.
 *
 * @return Any new {@link TextChange}s created by this {@link SearchRequestor}.  If edits were
 * added to existing {@link TextChange}s then those existing {@link TextChange}s will not be
 * returned in this array.
 */
public Change[] getChanges(RefactoringParticipant participant) {
    JSPSearchSupport support = JSPSearchSupport.getInstance();
    List changes = new ArrayList();
    Iterator keys = fSearchDocPath2JavaEditMap.keySet().iterator();
    String searchDocPath = null;
    SearchDocument delegate = null;
    while (keys.hasNext()) {
        // create on the fly
        searchDocPath = (String) keys.next();
        MultiTextEdit javaEdit = (MultiTextEdit) fSearchDocPath2JavaEditMap.get(searchDocPath);
        delegate = support.getSearchDocument(searchDocPath);
        if (delegate != null && delegate instanceof JavaSearchDocumentDelegate) {
            JavaSearchDocumentDelegate javaDelegate = (JavaSearchDocumentDelegate) delegate;
            Change change = createChange(javaDelegate, javaDelegate.getJspTranslation().getJspEdit(javaEdit), participant);
            changes.add(change);
        }
    }
    return (Change[]) changes.toArray(new Change[changes.size()]);
}
Also used : JSPSearchSupport(org.eclipse.jst.jsp.core.internal.java.search.JSPSearchSupport) JavaSearchDocumentDelegate(org.eclipse.jst.jsp.core.internal.java.search.JavaSearchDocumentDelegate) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) TextChange(org.eclipse.ltk.core.refactoring.TextChange) Change(org.eclipse.ltk.core.refactoring.Change) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) SearchDocument(org.eclipse.jdt.core.search.SearchDocument)

Aggregations

SearchDocument (org.eclipse.jdt.core.search.SearchDocument)10 JSPSearchSupport (org.eclipse.jst.jsp.core.internal.java.search.JSPSearchSupport)4 JavaSearchDocumentDelegate (org.eclipse.jst.jsp.core.internal.java.search.JavaSearchDocumentDelegate)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Iterator (java.util.Iterator)2 SearchParticipant (org.eclipse.jdt.core.search.SearchParticipant)2 FileIndexLocation (org.eclipse.jdt.internal.core.index.FileIndexLocation)2 IndexLocation (org.eclipse.jdt.internal.core.index.IndexLocation)2 Change (org.eclipse.ltk.core.refactoring.Change)2 TextChange (org.eclipse.ltk.core.refactoring.TextChange)2 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)2 IFile (org.eclipse.core.resources.IFile)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Document (org.eclipse.jface.text.Document)1 IDocument (org.eclipse.jface.text.IDocument)1 JSPTranslation (org.eclipse.jst.jsp.core.internal.java.JSPTranslation)1 JSPSearchScope (org.eclipse.jst.jsp.core.internal.java.search.JSPSearchScope)1 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)1