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