private boolean isComment(IDOMNode node) { boolean result = false; if (node != null) { result = node.getNodeType() == Node.COMMENT_NODE; } return result; }
private boolean isDocumentNode(IDOMNode node) { return ((node != null) && (node.getNodeType() == Node.DOCUMENT_NODE)); }
protected INodeAdapter createAdapter(INodeNotifier target) { PageDirectiveAdapter result = null; if (target instanceof IDOMNode) { IDOMNode node = (IDOMNode) target; if (node.getNodeType() == Node.DOCUMENT_NODE) { result = getAdapterInstance(target); } } return result; }
public boolean isBodyContainer(IDOMNode node) { switch (node.getNodeType()) { case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_NODE: return true; case Node.ELEMENT_NODE: return isBodyContainerElement((Element) node); default: return false; } }
protected IDOMNode getDeepestChildNode(IDOMNode node) { IDOMNode result = null; IDOMNode lastChild = (IDOMNode) node.getLastChild(); if (lastChild == null) result = node; else { result = getDeepestChildNode(lastChild); if ((result.getNodeType() == Node.TEXT_NODE || result.getNodeType() == Node.COMMENT_NODE) && !isEndTagMissing(node)) result = node; } return result; }
/** * This method will find the indentation for this node. It will search * backwards starting from the beginning of the node until a character * other than a space or a tab is found. If this node is null or it's a * document node or it's a first level node (node's parent is a document * node) the default empty string will be returned as the indentation. */ protected String getNodeIndent(Node node) { String result = EMPTY_STRING; if ((node != null) && (node.getNodeType() != Node.DOCUMENT_NODE) && (node.getParentNode() != null) && (node.getParentNode().getNodeType() != Node.DOCUMENT_NODE)) { IDOMNode siblingTextNode = (IDOMNode) node.getPreviousSibling(); if ((siblingTextNode != null) && (siblingTextNode.getNodeType() == Node.TEXT_NODE)) { // find the indentation String siblingText = siblingTextNode.getNodeValue(); int siblingTextLength = siblingText.length(); if ((siblingText != null) && (siblingTextLength > 0) && ((siblingText.charAt(siblingTextLength - 1) == SPACE_CHAR) || (siblingText.charAt(siblingTextLength - 1) == TAB_CHAR))) { int searchIndex = siblingTextLength - 1; while ((searchIndex >= 0) && ((siblingText.charAt(searchIndex) == SPACE_CHAR) || (siblingText.charAt(searchIndex) == TAB_CHAR))) searchIndex--; if (searchIndex < siblingTextLength) result = siblingText.substring(searchIndex + 1, siblingTextLength); } } } return result; }
public boolean isBodyHeader(IDOMNode node, String uri, String localname) { switch (node.getNodeType()) { case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_NODE: return isDocumentHeader(uri, localname); case Node.ELEMENT_NODE: return isElementHeader((Element) node, uri, localname); default: return false; } }
private Span getDataSpan(IDOMNode node) { switch (node.getNodeType()) { case Node.ELEMENT_NODE : return getDataSpanForElement((IDOMElement) node); case Node.TEXT_NODE : return getDataSpanForText((IDOMText) node); default : return new Span(0, -1); } }
public int getLength() { if (this.node.getNodeType() == Node.ELEMENT_NODE) { return ((IDOMElement) this.node).getStartEndOffset() - this.node.getStartOffset(); } return this.node.getLength(); }
/** * Determines whether a node is "linkable" that is, the component it refers to * can be the target of a "go to definition" navigation. * * @param node the node to test, must not be null; * @return true if the node is linkable, false otherwise. */ private boolean isLinkable(IDOMNode node) { if (node == null) { return false; } short nodeType = node.getNodeType(); boolean isLinkable = false; if (nodeType == Node.ATTRIBUTE_NODE) { IDOMAttr attr = (IDOMAttr) node; String name = attr.getName(); // isLinkableAttribute is a template method. Derived classes should // override. isLinkable = isLinkableAttribute(name); } return isLinkable; }
/** */ protected void cleanupCSSAttrValue(IDOMNode node) { if (node == null || node.getNodeType() != Node.ELEMENT_NODE) return; IDOMElement element = (IDOMElement) node; if (!element.isGlobalTag()) return; Attr attr = element.getAttributeNode("style"); //$NON-NLS-1$ if (attr == null) return; String value = getCSSValue(attr); if (value == null) return; String oldValue = ((IDOMNode) attr).getValueSource(); if (oldValue != null && value.equals(oldValue)) return; attr.setValue(value); }
protected ContentAssistRequest computeContentProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { ContentAssistRequest contentAssistRequest = null; // setup to add children at the content node's position contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, getStructuredDocumentRegion(documentPosition), completionRegion, documentPosition, 0, matchString); if ((node != null) && (node.getNodeType() == Node.DOCUMENT_NODE) && (((Document) node).getDoctype() == null)) { addStartDocumentProposals(contentAssistRequest); } addTagInsertionProposals(contentAssistRequest, getElementPositionForModelQuery(nodeAtOffset)); if (node.getNodeType() != Node.DOCUMENT_NODE) { addEndTagProposals(contentAssistRequest); } // entities? addEntityProposals(contentAssistRequest, documentPosition, completionRegion, node); // addEntityProposals(contentAssistRequest); return contentAssistRequest; }
private Object[] getStartEndFixInfo(IDOMNode xmlNode, String tagName, ITextRegion r) { // quick fix info String tagClose = "/>"; //$NON-NLS-1$ int tagCloseOffset = xmlNode.getFirstStructuredDocumentRegion().getEndOffset(); if ((r != null) && (r.getType() == DOMRegionContext.XML_TAG_CLOSE)) { tagClose = "/"; //$NON-NLS-1$ tagCloseOffset--; } IDOMNode firstChild = (IDOMNode) xmlNode.getFirstChild(); while ((firstChild != null) && (firstChild.getNodeType() == Node.TEXT_NODE)) { firstChild = (IDOMNode) firstChild.getNextSibling(); } int endOffset = xmlNode.getEndOffset(); int firstChildStartOffset = firstChild == null ? endOffset : firstChild.getStartOffset(); Object[] additionalFixInfo = {tagName, tagClose, new Integer(tagCloseOffset), new Integer(xmlNode.getFirstStructuredDocumentRegion().getEndOffset()), // startTagEndOffset new Integer(firstChildStartOffset), // firstChildStartOffset new Integer(endOffset)}; // endOffset return additionalFixInfo; }
protected IDOMNode getParentIndentNode(IDOMNode node) { IDOMNode result = null; IDOMNode parentNode = (IDOMNode) node.getParentNode(); if (parentNode.getNodeType() == Node.DOCUMENT_NODE) result = parentNode; else { ITextRegion region = parentNode.getLastStructuredDocumentRegion().getFirstRegion(); if (region.getType() == DOMRegionContext.XML_END_TAG_OPEN) result = parentNode; else result = getParentIndentNode(parentNode); } return result; }
public IContextInformation[] getAttributeInformation(int offset) { /* * need to take care of special cases w/ ambiguous regions <tag>| * </tag> also end tags.. */ IContextInformation[] results = EMPTY_CONTEXT_INFO; IStructuredDocumentRegion sdRegion = fModelUtil.getDocument().getRegionAtCharacterOffset(offset); if (!canProposeInfo(sdRegion)) { return EMPTY_CONTEXT_INFO; } IDOMNode node = fModelUtil.getXMLNode(offset); if (node != null) { switch (node.getNodeType()) { case Node.ELEMENT_NODE : results = getInfoForElement(node); break; // future... // case Node.TEXT_NODE : // results = getInfoForText(node); // break; } } return results; }
/** * This method is used from parent's setChildEditable() * * case 1:<parent><node attr="value"/> <node2></parent> * x####################x case 2:<parent><node attr="value"> <child> * </child> </node> </parent> x###################? ?#######x (? : * editable if node.isEditable() == true) */ void lockBoth(IDOMNode node) { if (node == null) { return; } IStructuredDocumentRegion flatNode; boolean canInsert = false; // end node (element) if (node.getNodeType() == Node.ELEMENT_NODE) { flatNode = node.getEndStructuredDocumentRegion(); if (flatNode != null) { canInsert = node.isChildEditable(); lock(flatNode, canInsert, false); } } // start node flatNode = node.getStartStructuredDocumentRegion(); if (flatNode != null) { lock(flatNode, false, canInsert); } }
public static ITextSelection convertFromDesignSelectionToTextSelection( ISelection selection) { if (selection instanceof IStructuredSelection) { IStructuredSelection nodes = convertFromDesignSelection((IStructuredSelection) selection); IDOMNode node = (IDOMNode) nodes.getFirstElement(); if (node != null && node.getNodeType() != Node.DOCUMENT_NODE) { return new TextSelection(node.getStartOffset(), node .getEndOffset() - node.getStartOffset()); } } else if (selection instanceof DesignRange) { return convertFromDesignSelection((DesignRange) selection); } return new TextSelection(0, 0); } }
IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); if ((node.getNodeType() == Node.DOCUMENT_NODE) || (documentPosition >= sdRegion.getEndOffset())) { if ((node.getNodeType() != Node.DOCUMENT_NODE) && (node.getEndStructuredDocumentRegion() == null)) { addEndTagProposals(contentAssistRequest); if ((node.getNodeType() != Node.DOCUMENT_NODE) && (node.getEndStructuredDocumentRegion() != null)) { addTagCloseProposals(contentAssistRequest);
if (node == null) return; if (node.getNodeType() == Node.TEXT_NODE) return; Node parent = node.getParentNode();
protected boolean isEndTagMissing(IDOMNode node) { boolean result = false; if ((node != null) && (node.getNodeType() != Node.DOCUMENT_NODE) && !isJSPTag(node)) { IStructuredDocumentRegion startTagStructuredDocumentRegion = node.getFirstStructuredDocumentRegion(); IStructuredDocumentRegion endTagStructuredDocumentRegion = node.getLastStructuredDocumentRegion(); ITextRegion startTagNameRegion = null; if (startTagStructuredDocumentRegion.getRegions().size() > 1) startTagNameRegion = startTagStructuredDocumentRegion.getRegions().get(1); ITextRegion endTagNameRegion = null; if (endTagStructuredDocumentRegion.getRegions().size() > 1) endTagNameRegion = endTagStructuredDocumentRegion.getRegions().get(1); ITextRegionList startTagRegions = startTagStructuredDocumentRegion.getRegions(); if (startTagNameRegion == endTagNameRegion && startTagNameRegion != null && (startTagRegions.get(0)).getType() != DOMRegionContext.XML_END_TAG_OPEN && (startTagRegions.get(startTagRegions.size() - 1).getType()) != DOMRegionContext.XML_EMPTY_TAG_CLOSE) // end tag missing result = true; } return result; }