int documentPosition = context.getInvocationOffset();
ContentAssistRequest contentAssistRequest = null;
String regionType = completionRegion.getType();
IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
// Handle the most common and best supported cases
if ((xmlnode.getNodeType() == Node.ELEMENT_NODE)
|| (xmlnode.getNodeType() == Node.DOCUMENT_NODE)) {
if (regionType == DOMRegionContext.XML_TAG_OPEN) {
contentAssistRequest = computeTagOpenProposals(matchString,
completionRegion, treeNode, xmlnode, context);
} else if (regionType == DOMRegionContext.XML_TAG_NAME) {
contentAssistRequest = computeTagNameProposals(matchString,
completionRegion, treeNode, xmlnode, context);
} else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
contentAssistRequest = computeAttributeProposals(matchString,
completionRegion, treeNode, xmlnode, context);
} else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
contentAssistRequest = computeEqualsProposals(matchString,
completionRegion, treeNode, xmlnode, context);
} else if ((regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)
&& (documentPosition == sdRegion.getTextEndOffset())
&& (sdRegion.getText(completionRegion).endsWith("\"") || sdRegion.getText(completionRegion).endsWith("\'"))) { //$NON-NLS-1$ //$NON-NLS-2$
// this is for when the cursor is at the end of the closing
// quote for an attribute..
IDOMNode actualNode = (IDOMNode) xmlnode.getModel()
.getIndexedRegion(
sdRegion.getStartOffset(completionRegion));
contentAssistRequest = new ContentAssistRequest(actualNode,
actualNode, sdRegion, completionRegion,
documentPosition, 0, matchString);
addTagCloseProposals(contentAssistRequest, context);
} else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
contentAssistRequest = computeAttributeValueProposals(
matchString, completionRegion, treeNode, xmlnode,
context);
} else if ((regionType == DOMRegionContext.XML_TAG_CLOSE)
|| (regionType == DOMRegionContext.XML_EMPTY_TAG_CLOSE)
|| (regionType
.equals(DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_CLOSE))) {
contentAssistRequest = computeTagCloseProposals(matchString,
completionRegion, treeNode, xmlnode, context);
} else if (regionType == DOMRegionContext.XML_END_TAG_OPEN) {
contentAssistRequest = computeEndTagOpenProposals(matchString,
completionRegion, treeNode, xmlnode, context);
} else if ((regionType == DOMRegionContext.XML_CONTENT)
|| (regionType == DOMRegionContext.XML_CHAR_REFERENCE)
|| (regionType == DOMRegionContext.XML_ENTITY_REFERENCE)
|| (regionType == DOMRegionContext.XML_PE_REFERENCE)) {
contentAssistRequest = computeContentProposals(matchString,
completionRegion, treeNode, xmlnode, context);
}
// These ITextRegion types begin DOM Elements as well and although
// internally harder to assist,
// text insertions directly before them can be made
else if ((documentPosition == sdRegion
.getStartOffset(completionRegion))
&& (regionType
.equals(DOMJSPRegionContextsPrivateCopy.JSP_COMMENT_OPEN)
|| regionType
.equals(DOMJSPRegionContextsPrivateCopy.JSP_DECLARATION_OPEN)
|| regionType
.equals(DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_OPEN)
|| regionType
.equals(DOMJSPRegionContextsPrivateCopy.JSP_EXPRESSION_OPEN)
|| regionType
.equals(DOMJSPRegionContextsPrivateCopy.JSP_SCRIPTLET_OPEN)
|| (regionType == DOMRegionContext.XML_DECLARATION_OPEN)
|| (regionType == DOMRegionContext.XML_PI_OPEN)
|| (regionType == DOMRegionContext.XML_COMMENT_OPEN) || (regionType == DOMRegionContext.XML_CDATA_OPEN))) {
contentAssistRequest = new ContentAssistRequest(treeNode,
xmlnode.getParentNode(), sdRegion, completionRegion,
documentPosition, 0, matchString);
addTagInsertionProposals(contentAssistRequest,
getElementPosition(treeNode), context);
addStartDocumentProposals(contentAssistRequest, context);
}
}
// Not a Document or Element? (odd cases go here for now)
else if (isCloseRegion(completionRegion)) {
contentAssistRequest = new ContentAssistRequest(treeNode,
xmlnode.getParentNode(), sdRegion, completionRegion,
sdRegion.getStartOffset(completionRegion)
+ completionRegion.getLength(), 0, matchString);
addStartDocumentProposals(contentAssistRequest, context);
if (documentPosition >= sdRegion.getTextEndOffset(completionRegion)) {
addTagInsertionProposals(contentAssistRequest,
getElementPosition(treeNode) + 1, context);
}
} else if ((documentPosition == sdRegion
.getStartOffset(completionRegion))
&& (regionType
.equals(DOMJSPRegionContextsPrivateCopy.JSP_COMMENT_OPEN)
|| regionType
.equals(DOMJSPRegionContextsPrivateCopy.JSP_DECLARATION_OPEN)