Search in sources :

Example 26 with JSPTranslationAdapter

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

the class JSPTranslationTest method testUseBeanNoSpace.

/**
 * Makes sure both beans are translated even though they are
 * right next to each other with no space.
 *
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=103004
 */
public void testUseBeanNoSpace() {
    IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("INCLUDES_TESTS/useBean_tester.jsp"));
    DOMModelForJSP sModel = (DOMModelForJSP) getStructuredModelForRead(f);
    try {
        setupAdapterFactory(sModel);
        JSPTranslationAdapter adapter = (JSPTranslationAdapter) sModel.getDocument().getAdapterFor(IJSPTranslation.class);
        JSPTranslation translation = adapter.getJSPTranslation();
        String javaText = translation.getJavaText();
        boolean bean1 = javaText.indexOf("javax.swing.JButton x = null;") != -1;
        boolean bean2 = javaText.indexOf("javax.swing.JButton y = null;") != -1;
        assertTrue(bean1);
        assertTrue(bean2);
    } 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) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)

Example 27 with JSPTranslationAdapter

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

the class JSPTranslationTest method testXMLJSPMapping.

public void testXMLJSPMapping() {
    IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("INCLUDES_TESTS/xml-jsp/most-tags-xml-jsp.jsp"));
    DOMModelForJSP sModel = (DOMModelForJSP) getStructuredModelForRead(f);
    try {
        setupAdapterFactory(sModel);
        JSPTranslationAdapter adapter = (JSPTranslationAdapter) sModel.getDocument().getAdapterFor(IJSPTranslation.class);
        JSPTranslation translation = adapter.getJSPTranslation();
        HashMap jsp2java = translation.getJsp2JavaMap();
        Object[] jspRanges = jsp2java.keySet().toArray();
        Position jspPos = null;
        Position javaPos = null;
        for (int i = 0; i < jspRanges.length; i++) {
            jspPos = (Position) jspRanges[i];
            javaPos = (Position) jsp2java.get(jspPos);
            // System.out.println("jsp:" + printPos(jspPos) + " >> java:" + printPos(javaPos));
            checkPosition(jspPos, javaPos);
        }
    } 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) HashMap(java.util.HashMap) Position(org.eclipse.jface.text.Position) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)

Example 28 with JSPTranslationAdapter

use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter 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 29 with JSPTranslationAdapter

use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter 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 30 with JSPTranslationAdapter

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

Aggregations

IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)30 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)30 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)26 IFile (org.eclipse.core.resources.IFile)17 JSPTranslation (org.eclipse.jst.jsp.core.internal.java.JSPTranslation)14 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)10 IProject (org.eclipse.core.resources.IProject)9 Path (org.eclipse.core.runtime.Path)7 JSPTranslationExtension (org.eclipse.jst.jsp.core.internal.java.JSPTranslationExtension)6 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)6 IPath (org.eclipse.core.runtime.IPath)5 IJavaElement (org.eclipse.jdt.core.IJavaElement)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 InputStream (java.io.InputStream)3 List (java.util.List)3 IProblem (org.eclipse.jdt.core.compiler.IProblem)3 ISelection (org.eclipse.jface.viewers.ISelection)3 DOMModelForJSP (org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP)3 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)3 HashMap (java.util.HashMap)2