CompletionProposalInvocationContext context,
IProgressMonitor monitor) {
List results = new ArrayList(0);
if(isValidContext(context)) {
ITextViewer viewer = context.getViewer();
int documentPosition = context.getInvocationOffset();
IndexedRegion treeNode = ContentAssistUtils.getNodeAt(viewer, documentPosition);
// get results from JSP completion processor
results = computeJavaCompletionProposals(viewer, documentPosition, 0);
IDOMNode xNode = null;
IStructuredDocumentRegion flat = null;
if (treeNode instanceof IDOMNode) {
xNode = (IDOMNode) treeNode;
flat = xNode.getFirstStructuredDocumentRegion();
if (flat != null && flat.getType() == DOMJSPRegionContexts.JSP_CONTENT) {
flat = flat.getPrevious();
}
}
// this is in case it's a <%@, it will be a region container...
ITextRegion openRegion = null;
if (flat != null && flat instanceof ITextRegionContainer) {
ITextRegionList v = ((ITextRegionContainer) flat).getRegions();
if (v.size() > 0)
openRegion = v.get(0);
}
// ADD CDATA PROPOSAL IF IT'S AN XML-JSP TAG
if (flat != null && flat.getType() != DOMJSPRegionContexts.JSP_SCRIPTLET_OPEN &&
flat.getType() != DOMJSPRegionContexts.JSP_DECLARATION_OPEN &&
flat.getType() != DOMJSPRegionContexts.JSP_EXPRESSION_OPEN &&
flat.getType() != DOMRegionContext.BLOCK_TEXT &&
(openRegion != null &&
openRegion.getType() != DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN) &&
!inAttributeRegion(flat, documentPosition)) {
// determine if cursor is before or after selected range
int adjustedDocPosition = documentPosition;
int realCaretPosition = viewer.getTextWidget().getCaretOffset();
int selectionLength = viewer.getSelectedRange().y;
if (documentPosition > realCaretPosition) {
adjustedDocPosition -= selectionLength;
}
CustomCompletionProposal cdataProposal = createCDATAProposal(adjustedDocPosition, selectionLength);