Search in sources :

Example 16 with IJsTranslation

use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.

the class JSDTHtmlCompletionProcessor method getEndScriptProposal.

public ICompletionProposal getEndScriptProposal(ITextViewer viewer, int offset) {
    /* add </script if necisary */
    IJsTranslation tran = getJSPTranslation(viewer);
    if (tran == null)
        return null;
    int missingAtOffset = tran.getMissingTagStart();
    if (offset >= missingAtOffset && missingAtOffset > -1) {
        String allText = viewer.getDocument().get();
        // $NON-NLS-1$
        String text = "</script>";
        int startInTag = -1;
        for (int i = 0; i < text.length() && allText.length() > offset - 1; i++) {
            if (allText.charAt(offset - 1) == text.charAt(i)) {
                startInTag = i;
                break;
            }
        }
        if (startInTag == -1) {
            // $NON-NLS-1$
            String displayText = Messages.getString("JSDTHtmlCompletionProcessor.1");
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            return new CustomCompletionProposal("\n" + text + "\n", offset, 0, offset, null, displayText, null, Messages.getString("JSDTHtmlCompletionProcessor.4"), 100);
        }
        String text1 = allText.substring(offset - startInTag - 1, offset).toLowerCase();
        String text2 = text.substring(0, startInTag + 1).toLowerCase();
        if (startInTag > -1 && text2.compareTo(text1) == 0) {
            // $NON-NLS-1$
            String displayText = Messages.getString("JSDTHtmlCompletionProcessor.5");
            // $NON-NLS-1$
            return new CustomCompletionProposal(text, offset - startInTag - 1, 0, text.length(), null, displayText, null, Messages.getString("JSDTHtmlCompletionProcessor.6"), 100);
        }
    }
    return null;
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)

Example 17 with IJsTranslation

use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation 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 18 with IJsTranslation

use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.

the class JsFindOccurrencesProcessor method getJavaElementsForCurrentSelection.

/**
 * uses JSPTranslation to get currently selected Java elements.
 *
 * @return currently selected IJavaElements
 */
private IJavaScriptElement[] getJavaElementsForCurrentSelection(IDocument document, ITextSelection selection) {
    IJavaScriptElement[] elements = new IJavaScriptElement[0];
    // get JSP translation object for this viewer's document
    IStructuredModel model = null;
    try {
        model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
        if (model != null && model instanceof IDOMModel) {
            IDOMDocument xmlDoc = ((IDOMModel) model).getDocument();
            JsTranslationAdapter adapter = (JsTranslationAdapter) xmlDoc.getAdapterFor(IJsTranslation.class);
            if (adapter != null) {
                IJsTranslation translation = adapter.getJsTranslation(false);
                // https://bugs.eclipse.org/bugs/show_bug.cgi?id=102211
                elements = translation.getElementsFromJsRange(translation.getJavaScriptOffset(selection.getOffset()), translation.getJavaScriptOffset(selection.getOffset() + selection.getLength()));
            }
        }
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
    return elements;
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IJavaScriptElement(org.eclipse.wst.jsdt.core.IJavaScriptElement) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) JsTranslationAdapter(org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)

Example 19 with IJsTranslation

use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.

the class JsSearchDocument method getPath.

/**
 * the path to the Java compilation unit
 *
 * @see org.eclipse.jdt.core.search.SearchDocument#getPath()
 */
public String getPath() {
    // important that isDirty() check is second to cache modification stamp
    if ((this.fCUPath == null) || isDirty() || (this.fCUPath == UNKNOWN_PATH)) {
        IJsTranslation trans = getJSTranslation();
        if (trans != null) {
            this.fCUPath = trans.getJavaPath();
            // save since it's expensive to calculate again later
            fCachedCharContents = trans.getJsText().toCharArray();
        }
    }
    return fCUPath != null ? fCUPath : UNKNOWN_PATH;
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)

Example 20 with IJsTranslation

use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.

the class JsSearchDocument method getJSTranslation.

/**
 * It's not recommended for clients to hold on to this JSPTranslation
 * since it's kind of large. If possible, hold on to the
 * JSPSearchDocument, which is more of a lightweight proxy.
 *
 * @return the JSPTranslation for the jsp file, or null if it's an
 *         unsupported file.
 */
public final IJsTranslation getJSTranslation() {
    IJsTranslation translation = null;
    IFile jspFile = getFile();
    if (!JsSearchSupport.isJsp(jspFile)) {
        return translation;
    }
    IStructuredModel model = null;
    try {
        // get existing model for read, then get document from it
        IModelManager modelManager = getModelManager();
        if (modelManager != null) {
            model = modelManager.getModelForRead(jspFile);
        }
        // handle unsupported
        if (model instanceof IDOMModel) {
            IDOMModel xmlModel = (IDOMModel) model;
            JsTranslationAdapterFactory.setupAdapterFactory(xmlModel);
            IDOMDocument doc = xmlModel.getDocument();
            JsTranslationAdapter adapter = (JsTranslationAdapter) doc.getAdapterFor(IJsTranslation.class);
            translation = adapter.getJsTranslation(false);
        }
    } catch (IOException e) {
        Logger.logException(e);
    } catch (CoreException e) {
        Logger.logException(e);
    } catch (UnsupportedCharsetExceptionWithDetail e) {
    // no need to log this. Just consider it an invalid file for our
    // purposes.
    // Logger.logException(e);
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
    return translation;
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) UnsupportedCharsetExceptionWithDetail(org.eclipse.wst.sse.core.internal.exceptions.UnsupportedCharsetExceptionWithDetail) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) JsTranslationAdapter(org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter) IOException(java.io.IOException)

Aggregations

IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)51 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)41 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)41 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)32 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)15 List (java.util.List)6 IJavaScriptElement (org.eclipse.wst.jsdt.core.IJavaScriptElement)6 IDocument (org.eclipse.jface.text.IDocument)5 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)5 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)4 CoreException (org.eclipse.core.runtime.CoreException)3 BadLocationException (org.eclipse.jface.text.BadLocationException)3 Document (org.eclipse.jface.text.Document)3 JavaScriptModelException (org.eclipse.wst.jsdt.core.JavaScriptModelException)3 ArrayList (java.util.ArrayList)2 IRegion (org.eclipse.jface.text.IRegion)2 ITypedRegion (org.eclipse.jface.text.ITypedRegion)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IProblem (org.eclipse.wst.jsdt.core.compiler.IProblem)2 NodeImpl (org.eclipse.wst.xml.core.internal.document.NodeImpl)2