use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter 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();
}
}
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter in project webtools.sourceediting by eclipse.
the class TestModelIncludes method testTranslateMultiLineIncludedFileWithSpacesAndScriptletInInclude.
/**
* Verify included files are translated properly when they contain a
* multiple lines
*
* @throws Exception
*/
public void testTranslateMultiLineIncludedFileWithSpacesAndScriptletInInclude() throws Exception {
String projectName = "prj119576_c";
BundleResourceUtil.createSimpleProject(projectName, null, null);
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + projectName, "/" + projectName);
assertTrue("project could not be created", ResourcesPlugin.getWorkspace().getRoot().getProject(projectName).exists());
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/" + projectName + "/WebContent/body3.jsp"));
IDOMModel model = null;
try {
model = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(file);
assertTrue("model has no content", model.getStructuredDocument().getLength() > 0);
ModelHandlerForJSP.ensureTranslationAdapterFactory(model);
JSPTranslationAdapter adapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
String source = adapter.getJSPTranslation().getJavaText();
assertTrue("scriptlet with variable declaration not found\n" + source, source.indexOf("java.util.Date headerDate") > -1);
} finally {
if (model != null)
model.releaseFromRead();
}
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter in project webtools.sourceediting by eclipse.
the class JSPFindOccurrencesProcessor method getJavaElementsForCurrentSelection.
/**
* uses JSPTranslation to get currently selected Java elements.
*
* @return currently selected IJavaElements
*/
private IJavaElement[] getJavaElementsForCurrentSelection(IDocument document, ITextSelection selection) {
IJavaElement[] elements = new IJavaElement[0];
// get JSP translation object for this viewer's document
IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
try {
if (model != null && model instanceof IDOMModel) {
IDOMDocument xmlDoc = ((IDOMModel) model).getDocument();
JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
if (adapter != null) {
JSPTranslation translation = adapter.getJSPTranslation();
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102211
elements = translation.getElementsFromJspRange(selection.getOffset(), selection.getOffset() + selection.getLength());
}
}
} finally {
if (model != null)
model.releaseFromRead();
}
return elements;
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter in project webtools.sourceediting by eclipse.
the class JSPJavaJavadocHoverProcessor method getHoverInfo.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer,
* org.eclipse.jface.text.IRegion)
*/
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
// get JSP translation object for this viewer's document
IDOMModel xmlModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(textViewer.getDocument());
try {
if (xmlModel != null) {
IDOMDocument xmlDoc = xmlModel.getDocument();
JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
if (adapter != null) {
JSPTranslation translation = adapter.getJSPTranslation();
IJavaElement[] result = translation.getElementsFromJspRange(hoverRegion.getOffset(), hoverRegion.getOffset() + hoverRegion.getLength());
return translation.fixupMangledName(getHoverInfo(result));
}
}
} finally {
if (xmlModel != null)
xmlModel.releaseFromRead();
}
return null;
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter in project webtools.sourceediting by eclipse.
the class JSPSearchTests method testSearchLocalVariable.
public void testSearchLocalVariable() {
IDOMModel xmlModel = null;
try {
IPath jspTestFilePath = new Path("judo/SEARCH/searchTestJSP3.jsp");
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(jspTestFilePath);
xmlModel = (IDOMModel) getStructuredModelForRead(file);
ModelHandlerForJSP.ensureTranslationAdapterFactory(xmlModel);
IDOMDocument doc = xmlModel.getDocument();
JSPTranslationAdapter adapter = (JSPTranslationAdapter) doc.getAdapterFor(IJSPTranslation.class);
JSPTranslation translation = adapter.getJSPTranslation();
IJavaElement element = translation.getElementsFromJspRange(377, 384)[0];
TestJspSearchRequestor requestor = new TestJspSearchRequestor();
requestor.addCheckMatch("searchTestJSP3.jsp", 377, 384);
JSPSearchSupport.getInstance().search(element, new JSPSearchScope(), requestor, new NullProgressMonitor());
assertTrue("did not find all expected matches: search*", requestor.checkValid());
} finally {
if (xmlModel != null)
xmlModel.releaseFromRead();
}
}
Aggregations