protected ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int pos, int javaPositionExtraOffset) {
initialize(pos);
JSPProposalCollector collector = null;
IDOMModel xmlModel = null;
try {
if (viewer instanceof StructuredTextViewer)
fViewer = (StructuredTextViewer) viewer;
xmlModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(fViewer.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();
fJavaPosition = translation.getJavaOffset(getDocumentPosition())+javaPositionExtraOffset;
if (DEBUG)
System.out.println(debug(translation));
try {
ICompilationUnit cu = translation.getCompilationUnit();
// can't get java proposals w/out a compilation unit
// or without a valid position
if (cu == null || -1 == fJavaPosition)
return new ICompletionProposal[0];
collector = getProposalCollector(cu, translation);
synchronized (cu) {
cu.codeComplete(fJavaPosition, collector, (WorkingCopyOwner) null);
}
}
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();