Search in sources :

Example 21 with JSPTranslation

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

the class JSPTranslationTest method testXMLJSPCDATAText.

public void testXMLJSPCDATAText() {
    IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("INCLUDES_TESTS/cdata/cdata.jsp"));
    DOMModelForJSP sModel = (DOMModelForJSP) getStructuredModelForRead(f);
    try {
        setupAdapterFactory(sModel);
        JSPTranslationAdapter adapter = (JSPTranslationAdapter) sModel.getDocument().getAdapterFor(IJSPTranslation.class);
        JSPTranslation translation = adapter.getJSPTranslation();
        String transText = translation.getJavaText();
        // named as .bin so no line conversion occurs (\n is in use)
        InputStream in = getClass().getResourceAsStream("translated_xml_jsp_cdata.bin");
        String knownText = loadChars(in);
        assertEquals(knownText, transText);
    } finally {
        if (sModel != null)
            sModel.releaseFromRead();
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslation(org.eclipse.jst.jsp.core.internal.java.JSPTranslation) DOMModelForJSP(org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP) InputStream(java.io.InputStream) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)

Example 22 with JSPTranslation

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

the class JSPTranslationTest method testJSPTranslationText.

public void testJSPTranslationText() {
    IDOMModel model = getIncludeTestModelForRead();
    ScannerUnitTests.verifyLengths(model, model.getStructuredDocument().get());
    JSPTranslationAdapter adapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
    JSPTranslation translation = adapter.getJSPTranslation();
    // named as .bin so no line conversion occurs (\n is in use)
    InputStream in = getClass().getResourceAsStream("translated_text.bin");
    String knownTranslationText = loadChars(in);
    try {
        // improvements: may need finer tuned text compares later
        // for different types of translations (includes, xml-jsp in script, attributes, etc...)
        String text = translation.getJavaText();
        assertNotNull("JSP translation text:", text);
        assertEquals("JSP translation text does not match expected", knownTranslationText, text);
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
Also used : IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslation(org.eclipse.jst.jsp.core.internal.java.JSPTranslation) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) InputStream(java.io.InputStream) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)

Example 23 with JSPTranslation

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

the class JSPTranslationTest method testJSPTranslationAdapter.

public void testJSPTranslationAdapter() {
    IDOMModel model = getIncludeTestModelForRead();
    JSPTranslationAdapter adapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
    JSPTranslation translation = adapter.getJSPTranslation();
    try {
        IJavaProject proj = adapter.getJavaProject();
        assertNotNull("couldn't get java project:" + proj);
        translation = adapter.getJSPTranslation();
        assertNotNull("couldn't get translation:", translation);
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslation(org.eclipse.jst.jsp.core.internal.java.JSPTranslation) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)

Example 24 with JSPTranslation

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

the class JSPJavaCompletionProposalComputer method computeJavaCompletionProposals.

/**
 * The same as the normal <code>computeCompeltaionProposals</code> except the calculated
 * java position is offset by the given extra offset.
 *
 * @param viewer
 *            the viewer whose document is used to compute the proposals
 * @param documentPosition
 *            an offset within the document for which completions should
 *            be computed
 * @param javaPositionExtraOffset
 * 				the extra offset for the java position
 * @return an array of completion proposals or <code>null</code> if no
 *         proposals are possible
 */
protected List computeJavaCompletionProposals(ITextViewer viewer, int pos, int javaPositionExtraOffset) {
    JSPProposalCollector collector = null;
    IDOMModel xmlModel = null;
    try {
        xmlModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(viewer.getDocument());
        IDOMDocument xmlDoc = xmlModel.getDocument();
        if (fTranslationAdapter == null || xmlModel.getId() != fModelId) {
            fTranslationAdapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
            fModelId = xmlModel.getId();
        }
        if (fTranslationAdapter != null) {
            JSPTranslation translation = fTranslationAdapter.getJSPTranslation();
            int javaPosition = translation.getJavaOffset(pos) + javaPositionExtraOffset;
            try {
                ICompilationUnit cu = translation.getCompilationUnit();
                // or without a valid position
                if (cu == null || -1 == javaPosition)
                    return new ArrayList(0);
                collector = getProposalCollector(cu, translation);
                synchronized (cu) {
                    try {
                        cu.codeComplete(javaPosition, collector, null, fJavaTimeoutMonitor);
                    } catch (OperationCanceledException e) {
                        // $NON-NLS-1$
                        Logger.log(Logger.WARNING, "Computing Java proposals did not complete normally. The operation took too long to return.");
                        return new ArrayList(0);
                    }
                }
            } catch (CoreException coreEx) {
                // a possible Java Model Exception due to not being a Web
                // (Java) Project
                coreEx.printStackTrace();
            }
        }
    } catch (Exception exc) {
        exc.printStackTrace();
    // throw out exceptions on code assist.
    } finally {
        if (xmlModel != null) {
            xmlModel.releaseFromRead();
        }
    }
    ICompletionProposal[] results = new ICompletionProposal[0];
    if (collector != null) {
        results = collector.getJSPCompletionProposals();
        if (results == null || results.length < 1)
            this.setErrorMessage(JSPUIMessages.Java_Content_Assist_is_not_UI_);
    }
    return Arrays.asList(results);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslation(org.eclipse.jst.jsp.core.internal.java.JSPTranslation) CoreException(org.eclipse.core.runtime.CoreException) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

JSPTranslation (org.eclipse.jst.jsp.core.internal.java.JSPTranslation)24 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)21 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)14 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)12 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)9 IFile (org.eclipse.core.resources.IFile)6 IJavaElement (org.eclipse.jdt.core.IJavaElement)6 IPath (org.eclipse.core.runtime.IPath)5 Path (org.eclipse.core.runtime.Path)5 DOMModelForJSP (org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP)4 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)4 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 CoreException (org.eclipse.core.runtime.CoreException)3 IDocument (org.eclipse.jface.text.IDocument)3 Position (org.eclipse.jface.text.Position)3 ArrayList (java.util.ArrayList)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2