use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter in project webtools.sourceediting by eclipse.
the class JSPTranslationTest method testUseBeanNoSpace.
/**
* Makes sure both beans are translated even though they are
* right next to each other with no space.
*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=103004
*/
public void testUseBeanNoSpace() {
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("INCLUDES_TESTS/useBean_tester.jsp"));
DOMModelForJSP sModel = (DOMModelForJSP) getStructuredModelForRead(f);
try {
setupAdapterFactory(sModel);
JSPTranslationAdapter adapter = (JSPTranslationAdapter) sModel.getDocument().getAdapterFor(IJSPTranslation.class);
JSPTranslation translation = adapter.getJSPTranslation();
String javaText = translation.getJavaText();
boolean bean1 = javaText.indexOf("javax.swing.JButton x = null;") != -1;
boolean bean2 = javaText.indexOf("javax.swing.JButton y = null;") != -1;
assertTrue(bean1);
assertTrue(bean2);
} finally {
if (sModel != null)
sModel.releaseFromRead();
}
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter in project webtools.sourceediting by eclipse.
the class JSPTranslationTest method testXMLJSPMapping.
public void testXMLJSPMapping() {
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("INCLUDES_TESTS/xml-jsp/most-tags-xml-jsp.jsp"));
DOMModelForJSP sModel = (DOMModelForJSP) getStructuredModelForRead(f);
try {
setupAdapterFactory(sModel);
JSPTranslationAdapter adapter = (JSPTranslationAdapter) sModel.getDocument().getAdapterFor(IJSPTranslation.class);
JSPTranslation translation = adapter.getJSPTranslation();
HashMap jsp2java = translation.getJsp2JavaMap();
Object[] jspRanges = jsp2java.keySet().toArray();
Position jspPos = null;
Position javaPos = null;
for (int i = 0; i < jspRanges.length; i++) {
jspPos = (Position) jspRanges[i];
javaPos = (Position) jsp2java.get(jspPos);
// System.out.println("jsp:" + printPos(jspPos) + " >> java:" + printPos(javaPos));
checkPosition(jspPos, javaPos);
}
} finally {
if (sModel != null)
sModel.releaseFromRead();
}
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter in project webtools.sourceediting by eclipse.
the class JSPTranslationTest method testXMLJSPCDATAText.
public void testXMLJSPCDATAText() {
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("INCLUDES_TESTS/cdata/cdata.jsp"));
DOMModelForJSP sModel = (DOMModelForJSP) getStructuredModelForRead(f);
try {
setupAdapterFactory(sModel);
JSPTranslationAdapter adapter = (JSPTranslationAdapter) sModel.getDocument().getAdapterFor(IJSPTranslation.class);
JSPTranslation translation = adapter.getJSPTranslation();
String transText = translation.getJavaText();
// named as .bin so no line conversion occurs (\n is in use)
InputStream in = getClass().getResourceAsStream("translated_xml_jsp_cdata.bin");
String knownText = loadChars(in);
assertEquals(knownText, transText);
} finally {
if (sModel != null)
sModel.releaseFromRead();
}
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter in project webtools.sourceediting by eclipse.
the class JSPTranslationTest method testJSPTranslationText.
public void testJSPTranslationText() {
IDOMModel model = getIncludeTestModelForRead();
ScannerUnitTests.verifyLengths(model, model.getStructuredDocument().get());
JSPTranslationAdapter adapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
JSPTranslation translation = adapter.getJSPTranslation();
// named as .bin so no line conversion occurs (\n is in use)
InputStream in = getClass().getResourceAsStream("translated_text.bin");
String knownTranslationText = loadChars(in);
try {
// improvements: may need finer tuned text compares later
// for different types of translations (includes, xml-jsp in script, attributes, etc...)
String text = translation.getJavaText();
assertNotNull("JSP translation text:", text);
assertEquals("JSP translation text does not match expected", knownTranslationText, text);
} finally {
if (model != null)
model.releaseFromRead();
}
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter in project webtools.sourceediting by eclipse.
the class JSPTranslationTest method testJSPTranslationAdapter.
public void testJSPTranslationAdapter() {
IDOMModel model = getIncludeTestModelForRead();
JSPTranslationAdapter adapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
JSPTranslation translation = adapter.getJSPTranslation();
try {
IJavaProject proj = adapter.getJavaProject();
assertNotNull("couldn't get java project:" + proj);
translation = adapter.getJSPTranslation();
assertNotNull("couldn't get translation:", translation);
} finally {
if (model != null)
model.releaseFromRead();
}
}
Aggregations