Search in sources :

Example 6 with IJSPTranslation

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

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

Example 8 with IJSPTranslation

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

the class JSPTranslatorPersistenceTest method testCreateTranslationAdapter.

/**
 * <p>This test case follows the general pattern of how a translation is created, then can be
 * externalized when the workspace is closed, then reloaded when its opened again.</p>
 *
 * @throws Exception
 */
public void testCreateTranslationAdapter() throws Exception {
    String outFileName = "testCreateTranslationAdapter.obj";
    IStructuredModel structModel = null;
    try {
        structModel = getModelForRead("Test1.jsp");
        // verify there is not already an existing translation adapter
        IDOMDocument domDoc = ((IDOMModel) structModel).getDocument();
        INodeAdapter existingAdapter = domDoc.getAdapterFor(IJSPTranslation.class);
        assertNull("There should be no existing adapter for IJSPTranslation", existingAdapter);
        // create a translator and externalize it, then load the externalized translator
        JSPTranslator originalTranslator = writeTranslator(structModel, outFileName);
        JSPTranslator externalizedTranslator = (JSPTranslator) readObject(outFileName);
        // create an adaptr from the loaded externalized translator and add it to the doc
        JSPTranslationAdapter restoredAdapter = new JSPTranslationAdapter((IDOMModel) structModel, externalizedTranslator);
        domDoc.addAdapter(restoredAdapter);
        // verify we can retrieve the adapter we just set
        existingAdapter = domDoc.getAdapterFor(IJSPTranslation.class);
        assertNotNull("There should now be an existing adapter for IJSPTranslation", existingAdapter);
        assertTrue("Expected " + existingAdapter + " to be an instance of JSPTranslationAdapter", existingAdapter instanceof JSPTranslationAdapter);
        JSPTranslationAdapter retrievedAdapter = (JSPTranslationAdapter) existingAdapter;
        JSPTranslationExtension jspTranslationExtension = retrievedAdapter.getJSPTranslation();
        /* verify that the original translation is equal to that of the
			 * retrieved adapter created from the previously externalized translator
			 */
        assertEquals("The original translation should be the same as the restored externalized translation", originalTranslator.getTranslation().toString(), jspTranslationExtension.getJavaText());
    } finally {
        if (structModel != null) {
            structModel.releaseFromRead();
        }
    }
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) JSPTranslationExtension(org.eclipse.jst.jsp.core.internal.java.JSPTranslationExtension) 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) JSPTranslator(org.eclipse.jst.jsp.core.internal.java.JSPTranslator)

Aggregations

IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)8 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)6 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)6 IFile (org.eclipse.core.resources.IFile)5 IProject (org.eclipse.core.resources.IProject)4 CoreException (org.eclipse.core.runtime.CoreException)2 IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)2 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)2 List (java.util.List)1 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)1 IMarker (org.eclipse.core.resources.IMarker)1 IContentType (org.eclipse.core.runtime.content.IContentType)1 ILocalVariable (org.eclipse.jdt.core.ILocalVariable)1 IMethod (org.eclipse.jdt.core.IMethod)1 ISourceRange (org.eclipse.jdt.core.ISourceRange)1 ISourceReference (org.eclipse.jdt.core.ISourceReference)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 IProblem (org.eclipse.jdt.core.compiler.IProblem)1 IRegion (org.eclipse.jface.text.IRegion)1 Position (org.eclipse.jface.text.Position)1