use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class AbstractContentAssistProcessor method isCursorAfterXMLPI.
/**
* This method can check if the cursor is after the XMLPI
*
* @param car
*/
protected boolean isCursorAfterXMLPI(ContentAssistRequest car) {
Node aNode = car.getNode();
boolean xmlpiFound = false;
Document parent = aNode.getOwnerDocument();
int xmlpiNodePosition = -1;
boolean isAfterXMLPI = false;
if (parent == null) {
// blank document case
return true;
}
for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
// $NON-NLS-1$
boolean xmlpi = ((child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) && child.getNodeName().equals("xml"));
xmlpiFound = xmlpiFound || xmlpi;
if (xmlpiFound) {
if (child instanceof IDOMNode) {
xmlpiNodePosition = ((IDOMNode) child).getEndOffset();
isAfterXMLPI = (car.getReplacementBeginPosition() >= xmlpiNodePosition);
}
break;
}
}
return isAfterXMLPI;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class AbstractContentAssistProcessor method addStartDocumentProposals.
protected void addStartDocumentProposals(ContentAssistRequest contentAssistRequest) {
Node aNode = contentAssistRequest.getNode();
boolean xmlpiFound = false;
Document owningDocument = aNode.getOwnerDocument();
// ==> // int xmlpiNodePosition = -1;
// make sure xmlpi is root element
// don't want doctype proposal if XMLPI isn't first element...
Node first = owningDocument.getFirstChild();
boolean xmlpiIsFirstElement = ((first != null) && (first.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE));
boolean insertDoctype = xmlpiIsFirstElement;
for (Node child = owningDocument.getFirstChild(); child != null; child = child.getNextSibling()) {
// $NON-NLS-1$
boolean xmlpi = ((child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) && child.getNodeName().equals("xml"));
xmlpiFound = xmlpiFound || xmlpi;
if (xmlpiFound) {
if (child instanceof IDOMNode) {
// ==> // int xmlpiNodePosition =
// ((XMLNode)child).getEndOffset();
}
// skip white space and text
while (((child = child.getNextSibling()) != null) && (child.getNodeType() == Node.TEXT_NODE)) {
// just skipping
}
// check if theres a node inbetween XMLPI and cursor position
if ((child != null) && (child instanceof IDOMNode)) {
if ((contentAssistRequest.getReplacementBeginPosition() >= ((IDOMNode) child).getEndOffset()) || !xmlpiIsFirstElement) {
insertDoctype = false;
}
}
break;
}
}
if (xmlpiFound && (owningDocument.getDoctype() == null) && isCursorAfterXMLPI(contentAssistRequest) && insertDoctype) {
addDocTypeProposal(contentAssistRequest);
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class AbstractContentAssistProcessor method computeCompletionProposals.
protected ContentAssistRequest computeCompletionProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode treeNode, IDOMNode xmlnode) {
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(documentPosition, matchString, completionRegion, treeNode, xmlnode);
} else if (regionType == DOMRegionContext.XML_TAG_NAME) {
contentAssistRequest = computeTagNameProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
} else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
contentAssistRequest = computeAttributeProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
} else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
contentAssistRequest = computeEqualsProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
} else if (// $NON-NLS-1$ //$NON-NLS-2$
(regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) && (documentPosition == sdRegion.getTextEndOffset()) && (sdRegion.getText(completionRegion).endsWith("\"") || sdRegion.getText(completionRegion).endsWith("\'"))) {
// 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 = newContentAssistRequest(actualNode, actualNode, sdRegion, completionRegion, documentPosition, 0, matchString);
addTagCloseProposals(contentAssistRequest);
} else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
contentAssistRequest = computeAttributeValueProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
} else if ((regionType == DOMRegionContext.XML_TAG_CLOSE) || (regionType == DOMRegionContext.XML_EMPTY_TAG_CLOSE) || (regionType.equals(DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_CLOSE))) {
contentAssistRequest = computeTagCloseProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
} else if (regionType == DOMRegionContext.XML_END_TAG_OPEN) {
contentAssistRequest = computeEndTagOpenProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
} else if ((regionType == DOMRegionContext.XML_CONTENT) || (regionType == DOMRegionContext.XML_CHAR_REFERENCE) || (regionType == DOMRegionContext.XML_ENTITY_REFERENCE) || (regionType == DOMRegionContext.XML_PE_REFERENCE)) {
contentAssistRequest = computeContentProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
} else // text insertions directly before them can be made
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 = newContentAssistRequest(treeNode, xmlnode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString);
addTagInsertionProposals(contentAssistRequest, getElementPositionForModelQuery(treeNode));
addStartDocumentProposals(contentAssistRequest);
}
} else // Not a Document or Element? (odd cases go here for now)
if (isCloseRegion(completionRegion)) {
contentAssistRequest = newContentAssistRequest(treeNode, xmlnode.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion) + completionRegion.getLength(), 0, matchString);
addStartDocumentProposals(contentAssistRequest);
if (documentPosition >= sdRegion.getTextEndOffset(completionRegion)) {
addTagInsertionProposals(contentAssistRequest, getElementPositionForModelQuery(treeNode) + 1);
}
} 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 = newContentAssistRequest(treeNode, xmlnode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString);
addTagInsertionProposals(contentAssistRequest, getElementPositionForModelQuery(treeNode));
addStartDocumentProposals(contentAssistRequest);
}
return contentAssistRequest;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class AbstractContentAssistProcessor method computeTagNameProposals.
protected ContentAssistRequest computeTagNameProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) {
ContentAssistRequest contentAssistRequest = null;
IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
if (sdRegion != nodeAtOffset.getFirstStructuredDocumentRegion()) {
// completing the *first* tag in "<tagname1 |<tagname2"
IDOMNode actualNode = (IDOMNode) node.getModel().getIndexedRegion(sdRegion.getStartOffset(completionRegion));
if (actualNode != null) {
if (actualNode.getFirstStructuredDocumentRegion() == sdRegion) {
// start tag
if (documentPosition > sdRegion.getStartOffset(completionRegion) + completionRegion.getLength()) {
// it's attributes
contentAssistRequest = newContentAssistRequest(actualNode, actualNode, sdRegion, completionRegion, documentPosition - matchString.length(), matchString.length(), matchString);
if (node.getStructuredDocument().getRegionAtCharacterOffset(sdRegion.getStartOffset(completionRegion) - 1).getRegionAtCharacterOffset(sdRegion.getStartOffset(completionRegion) - 1).getType() == DOMRegionContext.XML_TAG_OPEN) {
addAttributeNameProposals(contentAssistRequest);
}
addTagCloseProposals(contentAssistRequest);
} else {
// it's name
contentAssistRequest = newContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, documentPosition - matchString.length(), matchString.length(), matchString);
addTagNameProposals(contentAssistRequest, getElementPositionForModelQuery(actualNode));
}
} else {
if (documentPosition >= sdRegion.getStartOffset(completionRegion) + completionRegion.getLength()) {
// insert name
contentAssistRequest = newContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString);
} else {
// replace name
contentAssistRequest = newContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString);
}
addEndTagNameProposals(contentAssistRequest);
}
}
} else {
if (documentPosition > sdRegion.getStartOffset(completionRegion) + completionRegion.getTextLength()) {
// unclosed tag with only a name; should prompt for attributes
// and a close instead
contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition - matchString.length(), matchString.length(), matchString);
addAttributeNameProposals(contentAssistRequest);
addTagCloseProposals(contentAssistRequest);
} else {
if (sdRegion.getRegions().get(0).getType() != DOMRegionContext.XML_END_TAG_OPEN) {
int replaceLength = documentPosition - sdRegion.getStartOffset(completionRegion);
contentAssistRequest = newContentAssistRequest(node, node.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), replaceLength, matchString);
addTagNameProposals(contentAssistRequest, getElementPositionForModelQuery(nodeAtOffset));
} else {
IDOMNode actualNode = (IDOMNode) node.getModel().getIndexedRegion(documentPosition);
if (actualNode != null) {
if (documentPosition >= sdRegion.getStartOffset(completionRegion) + completionRegion.getTextLength()) {
contentAssistRequest = newContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString);
} else {
contentAssistRequest = newContentAssistRequest(actualNode, actualNode.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString);
}
addEndTagNameProposals(contentAssistRequest);
}
}
}
}
return contentAssistRequest;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class AbstractContentAssistProcessor method isCursorAfterDoctype.
/**
* Checks if cursor position is after doctype tag...
*
* @param car
*/
protected boolean isCursorAfterDoctype(ContentAssistRequest car) {
Node aNode = car.getNode();
Document parent = aNode.getOwnerDocument();
int xmldoctypeNodePosition = -1;
boolean isAfterDoctype = true;
if (parent == null) {
// blank document case
return true;
}
for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child instanceof IDOMNode) {
if (child.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
xmldoctypeNodePosition = ((IDOMNode) child).getEndOffset();
isAfterDoctype = (car.getReplacementBeginPosition() >= xmldoctypeNodePosition);
break;
}
}
}
return isAfterDoctype;
}
Aggregations