Search in sources :

Example 16 with JSPTranslationAdapter

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

the class JSPJavaTranslatorCoreTest method test_codas.

public void test_codas() throws Exception {
    String testName = "testPreludeAndCodas";
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName);
    synchronized (creationLock) {
        if (!project.isAccessible()) {
            // Create new project
            project = BundleResourceUtil.createSimpleProject(testName, null, null);
            assertTrue(project.exists());
            BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName);
        }
    }
    IFile main = project.getFile("/web stuff/coda-user/test.jsp");
    assertTrue("sample test file not accessible", main.isAccessible());
    IDOMModel model = null;
    try {
        model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(main);
        ModelHandlerForJSP.ensureTranslationAdapterFactory(model);
        JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
        IJSPTranslation translation = translationAdapter.getJSPTranslation();
        assertNotNull("no Java translation found", translation);
        assertTrue("coda0 contents not included", translation.getJavaText().indexOf("int coda0") > 0);
        assertTrue("coda1 contents not included", translation.getJavaText().indexOf("int coda1") > 0);
        assertTrue("import statement not found", translation.getJavaText().indexOf("import java.lang.ref.Reference") > 0);
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) 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) IProject(org.eclipse.core.resources.IProject)

Example 17 with JSPTranslationAdapter

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

the class JSPJavaTranslatorCoreTest method test_prelude_and_coda.

public void test_prelude_and_coda() throws Exception {
    String testName = "testPreludeAndCodas";
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName);
    synchronized (creationLock) {
        if (!project.isAccessible()) {
            // Create new project
            project = BundleResourceUtil.createSimpleProject(testName, null, null);
            assertTrue(project.exists());
            BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName);
        }
    }
    IFile main = project.getFile("/web stuff/both/test.jsp");
    assertTrue("sample test file not accessible", main.isAccessible());
    IDOMModel model = null;
    try {
        model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(main);
        ModelHandlerForJSP.ensureTranslationAdapterFactory(model);
        JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
        IJSPTranslation translation = translationAdapter.getJSPTranslation();
        assertNotNull("no Java translation found", translation);
        assertTrue("prelude0 contents not included", translation.getJavaText().indexOf("int prelude0") > 0);
        assertTrue("prelude1 contents included", translation.getJavaText().indexOf("int prelude1") < 0);
        assertTrue("coda0 contents not included", translation.getJavaText().indexOf("int coda0") > 0);
        assertTrue("coda1 contents included", translation.getJavaText().indexOf("int coda1") < 0);
        assertTrue("import statement not found", translation.getJavaText().indexOf("import java.lang.ref.Reference") > 0);
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) 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) IProject(org.eclipse.core.resources.IProject)

Example 18 with JSPTranslationAdapter

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

the class JSPJavaTranslatorCoreTest method testVariablesFromIncludedFragments.

public void testVariablesFromIncludedFragments() throws Exception {
    String testName = "testVariablesFromIncludedFragments";
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName);
    synchronized (creationLock) {
        if (!project.isAccessible()) {
            // Create new project
            project = BundleResourceUtil.createSimpleProject(testName, null, null);
            assertTrue(project.exists());
            BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName);
        }
    }
    IFile main = project.getFile("/WebContent/main.jsp");
    assertTrue("sample test file not accessible", main.isAccessible());
    IDOMModel model = null;
    try {
        model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(main);
        ModelHandlerForJSP.ensureTranslationAdapterFactory(model);
        JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
        IJSPTranslation translation = translationAdapter.getJSPTranslation();
        assertNotNull("no Java translation found", translation);
        assertTrue("String variableFromHeader1 not found", translation.getJavaText().indexOf("String variableFromHeader1") > 0);
        assertTrue("header1 contents not included", translation.getJavaText().indexOf("String variableFromHeader1 = \"initialized in header 1\";") > 0);
        assertTrue("header2 contents not included", translation.getJavaText().indexOf("variableFromHeader1 = \"reassigned in header 2\";") > 0);
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) 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) IProject(org.eclipse.core.resources.IProject)

Example 19 with JSPTranslationAdapter

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

the class JSPJavaTranslatorCoreTest method test_107338.

public void test_107338() throws Exception {
    String projectName = "bug_107338";
    // Create new project
    IProject project = BundleResourceUtil.createSimpleProject(projectName, null, null);
    assertTrue(project.exists());
    BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + projectName, "/" + projectName);
    project.open(new NullProgressMonitor());
    IFile file = project.getFile("WebContent/test107338.jsp");
    assertTrue(file.exists());
    IStructuredModel model = StructuredModelManager.getModelManager().getModelForRead(file);
    IDOMModel jspModel = (IDOMModel) model;
    String jspSource = model.getStructuredDocument().get();
    assertTrue("line delimiters have been converted to Windows [CRLF]", jspSource.indexOf("\r\n") < 0);
    assertTrue("line delimiters have been converted to Mac [CR]", jspSource.indexOf("\r") < 0);
    ModelHandlerForJSP.ensureTranslationAdapterFactory(model);
    IDOMDocument xmlDoc = jspModel.getDocument();
    JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
    JSPTranslation translation = translationAdapter.getJSPTranslation();
    // System.err.print(translation.getJavaText());
    assertTrue("new-line beginning scriptlet missing from translation", translation.getJavaText().indexOf("int i = 0;") >= 0);
    model.releaseFromRead();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) 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) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter) IProject(org.eclipse.core.resources.IProject)

Example 20 with JSPTranslationAdapter

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

the class JSPJavaTranslatorCoreTest method test_preludes.

public void test_preludes() throws Exception {
    String testName = "testPreludeAndCodas";
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName);
    synchronized (creationLock) {
        if (!project.isAccessible()) {
            // Create new project
            project = BundleResourceUtil.createSimpleProject(testName, null, null);
            assertTrue(project.exists());
            BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName);
        }
    }
    IFile main = project.getFile("/web stuff/prelude-user/test.jsp");
    assertTrue("sample test file not accessible", main.isAccessible());
    IDOMModel model = null;
    try {
        model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(main);
        ModelHandlerForJSP.ensureTranslationAdapterFactory(model);
        JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
        IJSPTranslation translation = translationAdapter.getJSPTranslation();
        assertNotNull("no Java translation found", translation);
        assertTrue("prelude0 contents not included", translation.getJavaText().indexOf("int prelude0") > 0);
        assertTrue("prelude1 contents not included", translation.getJavaText().indexOf("int prelude1") > 0);
        assertTrue("import statement not found", translation.getJavaText().indexOf("import java.lang.ref.Reference") > 0);
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) 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) IProject(org.eclipse.core.resources.IProject)

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