Search in sources :

Example 1 with SearchDocument

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

the class JsSearchQuery method doQuery.

protected IStatus doQuery() {
    IStatus status = Status.OK_STATUS;
    try {
        JsSearchSupport support = JsSearchSupport.getInstance();
        // index the file
        SearchDocument delegate = support.addJspFile(getFile());
        String scopePath = delegate.getPath();
        JsSearchScope singleFileScope = new JsSearchScope(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()));
        support.searchRunnable(getJavaElement(), singleFileScope, new JsSingleFileSearchRequestor(getInstance()));
    } 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) JsSearchScope(org.eclipse.wst.jsdt.web.core.javascript.search.JsSearchScope) IStatus(org.eclipse.core.runtime.IStatus) JsSearchSupport(org.eclipse.wst.jsdt.web.core.javascript.search.JsSearchSupport) SearchDocument(org.eclipse.wst.jsdt.core.search.SearchDocument)

Example 2 with SearchDocument

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

the class JsSearchSupport method getSearchDocument.

/**
 * Centralized place to access JSPSearchDocuments (used by
 * JSPSearchParticipant and JSPSearchRequestor)
 *
 * @param searchDocPath
 * @param doc
 * @return the JSPSearchDocument or null if one is not found
 */
public SearchDocument getSearchDocument(String searchDocPath) {
    SearchDocument delegate = null;
    IFile f = fileForCUPath(searchDocPath);
    if (f != null) {
        delegate = createSearchDocument(f);
    } else {
    // handle failure case... (file deleted maybe?)
    }
    return delegate;
}
Also used : IFile(org.eclipse.core.resources.IFile) SearchDocument(org.eclipse.wst.jsdt.core.search.SearchDocument)

Example 3 with SearchDocument

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

the class BasicRefactorSearchRequestor method acceptSearchMatch.

/**
 * @see org.eclipse.wst.jsdt.core.search.SearchRequestor#acceptSearchMatch(org.eclipse.wst.jsdt.core.search.SearchMatch)
 */
public void acceptSearchMatch(SearchMatch javaMatch) throws CoreException {
    String matchDocumentPath = javaMatch.getResource().getFullPath().toString();
    SearchDocument searchDoc = JsSearchSupport.getInstance().getSearchDocument(matchDocumentPath);
    if (searchDoc != null && searchDoc instanceof JSDTSearchDocumentDelegate) {
        String renameText = getRenameText((JSDTSearchDocumentDelegate) searchDoc, javaMatch);
        // add it for the correct document
        addJavaEdit(searchDoc.getPath(), new ReplaceEdit(javaMatch.getOffset(), javaMatch.getLength(), renameText));
    }
}
Also used : JSDTSearchDocumentDelegate(org.eclipse.wst.jsdt.web.core.javascript.search.JSDTSearchDocumentDelegate) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) SearchDocument(org.eclipse.wst.jsdt.core.search.SearchDocument)

Example 4 with SearchDocument

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

the class BasicJsSearchRequestor method acceptSearchMatch.

/**
 * Maps java search coordinates to corresponding JSP coordinates. Adds the
 * matches to the Search Results view.
 *
 * @see org.eclipse.wst.jsdt.core.search.SearchRequestor#acceptSearchMatch(org.eclipse.wst.jsdt.core.search.SearchMatch)
 */
public void acceptSearchMatch(SearchMatch match) throws CoreException {
    if (JsSearchSupport.getInstance().isCanceled()) {
        return;
    }
    String matchDocumentPath = match.getResource().getFullPath().toString();
    SearchDocument searchDoc = JsSearchSupport.getInstance().getSearchDocument(matchDocumentPath);
    if (searchDoc != null && searchDoc instanceof JSDTSearchDocumentDelegate) {
        JSDTSearchDocumentDelegate javaSearchDoc = (JSDTSearchDocumentDelegate) searchDoc;
        int jspStart = match.getOffset();
        int jspEnd = match.getOffset() + match.getLength();
        IJsTranslation trans = javaSearchDoc.getJspTranslation();
        String jspText = trans.getHtmlText();
        String javaText = javaSearchDoc.getJavaText();
        if (BasicJsSearchRequestor.DEBUG) {
            displayDebugInfo(match, jspStart, jspEnd, jspText, javaText);
        }
        if (jspStart > -1 && jspEnd > -1) {
            addSearchMatch(new Document(trans.getHtmlText()), javaSearchDoc.getFile(), jspStart, jspEnd, jspText);
        }
    }
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation) JSDTSearchDocumentDelegate(org.eclipse.wst.jsdt.web.core.javascript.search.JSDTSearchDocumentDelegate) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) SearchDocument(org.eclipse.wst.jsdt.core.search.SearchDocument) SearchDocument(org.eclipse.wst.jsdt.core.search.SearchDocument)

Example 5 with SearchDocument

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

the class JsSearchParticipant method locateMatches.

public void locateMatches(SearchDocument[] indexMatches, SearchPattern pattern, IJavaScriptSearchScope 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 JSDTSearchDocumentDelegate) && ((JSDTSearchDocumentDelegate) 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.wst.jsdt.core.search.SearchDocument)

Aggregations

SearchDocument (org.eclipse.wst.jsdt.core.search.SearchDocument)6 JSDTSearchDocumentDelegate (org.eclipse.wst.jsdt.web.core.javascript.search.JSDTSearchDocumentDelegate)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 JsSearchSupport (org.eclipse.wst.jsdt.web.core.javascript.search.JsSearchSupport)2 Iterator (java.util.Iterator)1 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 Change (org.eclipse.ltk.core.refactoring.Change)1 DocumentChange (org.eclipse.ltk.core.refactoring.DocumentChange)1 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)1 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)1 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)1 JsSearchScope (org.eclipse.wst.jsdt.web.core.javascript.search.JsSearchScope)1