use of org.eclipse.jst.jsp.core.internal.java.JSPTranslation 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.JSPTranslation 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.JSPTranslation 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();
}
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslation in project webtools.sourceediting by eclipse.
the class JSPJavaCompletionProposalComputer method computeJavaCompletionProposals.
/**
* The same as the normal <code>computeCompeltaionProposals</code> except the calculated
* java position is offset by the given extra offset.
*
* @param viewer
* the viewer whose document is used to compute the proposals
* @param documentPosition
* an offset within the document for which completions should
* be computed
* @param javaPositionExtraOffset
* the extra offset for the java position
* @return an array of completion proposals or <code>null</code> if no
* proposals are possible
*/
protected List computeJavaCompletionProposals(ITextViewer viewer, int pos, int javaPositionExtraOffset) {
JSPProposalCollector collector = null;
IDOMModel xmlModel = null;
try {
xmlModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(viewer.getDocument());
IDOMDocument xmlDoc = xmlModel.getDocument();
if (fTranslationAdapter == null || xmlModel.getId() != fModelId) {
fTranslationAdapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
fModelId = xmlModel.getId();
}
if (fTranslationAdapter != null) {
JSPTranslation translation = fTranslationAdapter.getJSPTranslation();
int javaPosition = translation.getJavaOffset(pos) + javaPositionExtraOffset;
try {
ICompilationUnit cu = translation.getCompilationUnit();
// or without a valid position
if (cu == null || -1 == javaPosition)
return new ArrayList(0);
collector = getProposalCollector(cu, translation);
synchronized (cu) {
try {
cu.codeComplete(javaPosition, collector, null, fJavaTimeoutMonitor);
} catch (OperationCanceledException e) {
// $NON-NLS-1$
Logger.log(Logger.WARNING, "Computing Java proposals did not complete normally. The operation took too long to return.");
return new ArrayList(0);
}
}
} catch (CoreException coreEx) {
// a possible Java Model Exception due to not being a Web
// (Java) Project
coreEx.printStackTrace();
}
}
} catch (Exception exc) {
exc.printStackTrace();
// throw out exceptions on code assist.
} finally {
if (xmlModel != null) {
xmlModel.releaseFromRead();
}
}
ICompletionProposal[] results = new ICompletionProposal[0];
if (collector != null) {
results = collector.getJSPCompletionProposals();
if (results == null || results.length < 1)
this.setErrorMessage(JSPUIMessages.Java_Content_Assist_is_not_UI_);
}
return Arrays.asList(results);
}
Aggregations