use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationExtension in project webtools.sourceediting by eclipse.
the class JSPJavaValidator method adjustIndirectPosition.
/**
* Assumed the message offset is an indirect position. In other words, an
* error from an included file.
*
* @param m
* @param translation
*/
private void adjustIndirectPosition(IMessage m, IJSPTranslation translation) {
if (!(translation instanceof JSPTranslationExtension))
return;
IDocument jspDoc = ((JSPTranslationExtension) translation).getJspDocument();
if (!(jspDoc instanceof IStructuredDocument))
return;
IStructuredDocument sDoc = (IStructuredDocument) jspDoc;
IStructuredDocumentRegion[] regions = sDoc.getStructuredDocumentRegions(0, m.getOffset() + m.getLength());
// iterate backwards until you hit the include directive
for (int i = regions.length - 1; i >= 0; i--) {
IStructuredDocumentRegion region = regions[i];
if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) {
if (getDirectiveName(region).equals("include")) {
// $NON-NLS-1$
// $NON-NLS-1$
ITextRegion fileValueRegion = getAttributeValueRegion(region, "file");
if (fileValueRegion != null) {
m.setOffset(region.getStartOffset(fileValueRegion));
m.setLength(fileValueRegion.getTextLength());
} else {
m.setOffset(region.getStartOffset());
m.setLength(region.getTextLength());
}
/**
* Bug 219761 - Syntax error reported at wrong location
* (don't forget to adjust the line number, too)
*/
m.setLineNo(sDoc.getLineOfOffset(m.getOffset()) + 1);
break;
}
}
}
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationExtension 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();
}
}
}
Aggregations