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;
}
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;
}
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();
}
}
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);
}
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());
}
Aggregations