Search in sources :

Example 1 with JSPTranslator

use of org.eclipse.jst.jsp.core.internal.java.JSPTranslator in project liferay-ide by liferay.

the class CUCacheWTP method _createJSPTranslation.

private JSPTranslationPrime _createJSPTranslation(File file) {
    IDOMModel jspModel = null;
    try {
        // try to find the file in the current workspace, if it can't find
        // it then fall back to copy
        IFile jspFile = getIFile(file);
        jspModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(jspFile);
        IDOMDocument domDocument = jspModel.getDocument();
        IDOMNode domNode = (IDOMNode) domDocument.getDocumentElement();
        IProgressMonitor npm = new NullProgressMonitor();
        JSPTranslator translator = new JSPTranslatorPrime();
        if (domNode != null) {
            translator.reset((IDOMNode) domDocument.getDocumentElement(), npm);
        } else {
            translator.reset((IDOMNode) domDocument.getFirstChild(), npm);
        }
        translator.translate();
        IJavaProject javaProject = JavaCore.create(jspFile.getProject());
        return new JSPTranslationPrime(javaProject, translator, jspFile);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (jspModel != null) {
            jspModel.releaseFromRead();
        }
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) IJavaProject(org.eclipse.jdt.core.IJavaProject) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) JSPTranslator(org.eclipse.jst.jsp.core.internal.java.JSPTranslator)

Example 2 with JSPTranslator

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

the class JSPTranslatorPersistenceTest method writeTranslator.

private static JSPTranslator writeTranslator(String jspFileName, String externalizedFileName) throws IOException, CoreException {
    JSPTranslator translator = new JSPTranslator();
    IStructuredModel model = null;
    try {
        model = getModelForRead(jspFileName);
        translator = writeTranslator(model, externalizedFileName);
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
    return translator;
}
Also used : IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) JSPTranslator(org.eclipse.jst.jsp.core.internal.java.JSPTranslator)

Example 3 with JSPTranslator

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

the class JSPJavaTranslatorCoreTest method test_389174.

public void test_389174() throws CoreException, IOException {
    IProject j = BundleResourceUtil.createJavaWebProject(getName());
    assertTrue(j.exists());
    String typeName = "List<List<Boolean>>";
    InputStream source = new ByteArrayInputStream(("<jsp:useBean id=\"x\" type=\"" + typeName + "\" />").getBytes());
    IFile file = j.getFile(getName() + "_test.jsp");
    file.create(source, IResource.FORCE, null);
    JSPTranslator translator = new JSPTranslator();
    IDOMModel structuredModel = null;
    try {
        structuredModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(file);
        translator.reset(structuredModel.getDocument(), new NullProgressMonitor());
        translator.translate();
        assertTrue("specified type did not survive translation", translator.getTranslation().indexOf(typeName) >= 0);
        IJSPProblem[] translationProblems = (IJSPProblem[]) translator.getTranslationProblems().toArray(new IJSPProblem[0]);
        for (int i = 0; i < translationProblems.length; i++) {
            assertEquals("expected IJSPProblem type: " + translationProblems[i].getMessage(), Integer.toHexString(IProblem.UndefinedType), Integer.toHexString(translationProblems[i].getID()));
        }
    } finally {
        if (structuredModel != null)
            structuredModel.releaseFromRead();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IJSPProblem(org.eclipse.jst.jsp.core.internal.java.IJSPProblem) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IProject(org.eclipse.core.resources.IProject) JSPTranslator(org.eclipse.jst.jsp.core.internal.java.JSPTranslator)

Example 4 with JSPTranslator

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

the class JSPTranslatorPersistenceTest method testTranslationsDeepEqual.

public void testTranslationsDeepEqual() throws Exception {
    String outFileName = "testTranslationTextComparison.obj";
    JSPTranslator originalTranslator = writeTranslator("Test1.jsp", outFileName);
    JSPTranslator externalizedTranslator = (JSPTranslator) readObject(outFileName);
    assertEquals("The original translation should be deeply equal to the restored externalized translation", originalTranslator, externalizedTranslator);
}
Also used : JSPTranslator(org.eclipse.jst.jsp.core.internal.java.JSPTranslator)

Example 5 with JSPTranslator

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

the class JSPTranslatorPersistenceTest method testTranslationTextComparison.

public void testTranslationTextComparison() throws Exception {
    String outFileName = "testTranslationTextComparison.obj";
    JSPTranslator originalTranslator = writeTranslator("Test1.jsp", outFileName);
    StringBuffer originalTranslation = originalTranslator.getTranslation();
    JSPTranslator externalizedTranslator = (JSPTranslator) readObject(outFileName);
    StringBuffer externalizedTranslation = externalizedTranslator.getTranslation();
    assertEquals("The original translation should be the same as the restored externalized translation", originalTranslation.toString(), externalizedTranslation.toString());
}
Also used : JSPTranslator(org.eclipse.jst.jsp.core.internal.java.JSPTranslator)

Aggregations

JSPTranslator (org.eclipse.jst.jsp.core.internal.java.JSPTranslator)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)3 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)3 IFile (org.eclipse.core.resources.IFile)2 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)2 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 IProject (org.eclipse.core.resources.IProject)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IJSPProblem (org.eclipse.jst.jsp.core.internal.java.IJSPProblem)1 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)1 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)1 JSPTranslationExtension (org.eclipse.jst.jsp.core.internal.java.JSPTranslationExtension)1 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)1