Search in sources :

Example 1 with JavaSearchDocumentDelegate

use of org.eclipse.jst.jsp.core.internal.java.search.JavaSearchDocumentDelegate 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 2 with JavaSearchDocumentDelegate

use of org.eclipse.jst.jsp.core.internal.java.search.JavaSearchDocumentDelegate 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)

Example 3 with JavaSearchDocumentDelegate

use of org.eclipse.jst.jsp.core.internal.java.search.JavaSearchDocumentDelegate in project webtools.sourceediting by eclipse.

the class BasicJSPSearchRequestor method acceptSearchMatch.

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

Example 4 with JavaSearchDocumentDelegate

use of org.eclipse.jst.jsp.core.internal.java.search.JavaSearchDocumentDelegate in project webtools.sourceediting by eclipse.

the class BasicRefactorSearchRequestor method acceptSearchMatch.

/**
 * @see org.eclipse.jdt.core.search.SearchRequestor#acceptSearchMatch(org.eclipse.jdt.core.search.SearchMatch)
 */
public void acceptSearchMatch(SearchMatch javaMatch) throws CoreException {
    String matchDocumentPath = javaMatch.getResource().getFullPath().toString();
    SearchDocument searchDoc = JSPSearchSupport.getInstance().getSearchDocument(matchDocumentPath);
    if (searchDoc != null && searchDoc instanceof JavaSearchDocumentDelegate) {
        String renameText = getRenameText((JavaSearchDocumentDelegate) searchDoc, javaMatch);
        // if rename text is null then don't create an edit for it
        if (renameText != null) {
            // add it for the correct document
            addJavaEdit(searchDoc.getPath(), new ReplaceEdit(javaMatch.getOffset(), javaMatch.getLength(), renameText));
        }
    }
}
Also used : JavaSearchDocumentDelegate(org.eclipse.jst.jsp.core.internal.java.search.JavaSearchDocumentDelegate) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) SearchDocument(org.eclipse.jdt.core.search.SearchDocument)

Aggregations

SearchDocument (org.eclipse.jdt.core.search.SearchDocument)4 JavaSearchDocumentDelegate (org.eclipse.jst.jsp.core.internal.java.search.JavaSearchDocumentDelegate)4 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 JSPSearchSupport (org.eclipse.jst.jsp.core.internal.java.search.JSPSearchSupport)2 Change (org.eclipse.ltk.core.refactoring.Change)2 TextChange (org.eclipse.ltk.core.refactoring.TextChange)2 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)2 Document (org.eclipse.jface.text.Document)1 IDocument (org.eclipse.jface.text.IDocument)1 JSPTranslation (org.eclipse.jst.jsp.core.internal.java.JSPTranslation)1 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)1