protected boolean nodeHasSiblings(IDOMNode node) { return (node.getPreviousSibling() != null) || (node.getNextSibling() != null); }
/** */ private boolean canRemoveTailingSpaces(IDOMNode node) { if (node == null) return false; if (node.getNextSibling() != null) return false; Node parent = node.getParentNode(); if (parent == null || parent.getNodeType() != Node.ELEMENT_NODE) return false; CMElementDeclaration decl = getElementDeclaration((Element) parent); if (decl == null || (!decl.supports(HTMLCMProperties.LINE_BREAK_HINT))) return false; String hint = (String) decl.getProperty(HTMLCMProperties.LINE_BREAK_HINT); return hint.equals(HTMLCMProperties.Values.BREAK_BEFORE_START_AND_AFTER_END); }
public void setEditable(boolean editable, boolean deep) { if (deep) { IDOMNode node = (IDOMNode) getFirstChild(); while (node != null) { node.setEditable(editable, deep); node = (IDOMNode) node.getNextSibling(); } } setChildEditable(editable); setDataEditable(editable); }
private boolean noSiblingsAndNoFollowingComment(IDOMNode node) { IDOMNode nextSibling = (IDOMNode) node.getNextSibling(); return !nodeHasSiblings(node) || (noLineDelimiter(node) && isComment(nextSibling) && noLineDelimiter(nextSibling)); }
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; }
private void findCSS(List cssNodes, IDOMNode node) { ICSSModelAdapter adapter; adapter = (ICSSModelAdapter) node.getAdapterFor(IStyleSheetAdapter.class); if (adapter != null) { ICSSModel model = adapter.getModel(); if (model != null && model.getStyleSheetType() == ICSSModel.EMBEDDED) { cssNodes.add(model.getDocument()); } } else { adapter = (ICSSModelAdapter) node.getAdapterFor(IStyleDeclarationAdapter.class); if (adapter != null) { ICSSModel model = adapter.getModel(); if (model != null && model.getStyleSheetType() == ICSSModel.INLINE) { cssNodes.add(model.getDocument()); } } } for (IDOMNode child = (IDOMNode) node.getFirstChild(); child != null; child = (IDOMNode) child.getNextSibling()) { findCSS(cssNodes, child); } }
protected void formatChildren(IDOMNode node, IStructuredFormatContraints formatContraints) { String singleIndent = getFormatPreferences().getIndent(); String lineIndent = formatContraints.getCurrentIndent(); if (node != null && (fProgressMonitor == null || !fProgressMonitor.isCanceled())) { // normalize node first to combine adjacent text nodes node.normalize(); IDOMNode nextChild = (IDOMNode) node.getFirstChild(); while (nextChild != null) { IDOMNode eachChildNode = nextChild; nextChild = (IDOMNode) eachChildNode.getNextSibling(); IStructuredFormatter formatter = getFormatter(eachChildNode); IStructuredFormatContraints childFormatContraints = formatter.getFormatContraints(); String childIndent = lineIndent + singleIndent; childFormatContraints.setCurrentIndent(childIndent); childFormatContraints.setClearAllBlankLines(formatContraints.getClearAllBlankLines()); childFormatContraints.setInPreserveSpaceElement(formatContraints.getInPreserveSpaceElement()); // format each child formatter.format(eachChildNode, childFormatContraints); if (nextChild != null && nextChild.getParentNode() == null) // nextNode is deleted during format nextChild = (IDOMNode) eachChildNode.getNextSibling(); } } }
/** * Keeps text inline with its parent (no reflow necessary) * * @param node * @param doc * @param compressedText * @param parentNode */ private void handleNoReflow(IDOMNode node, IStructuredDocument doc, String compressedText, IDOMNode parentNode) { String nodeIndentation; // enough space and text has no line delimiters and (node has no // siblings or followed by inline comment) and // parentFirstStructuredDocumentRegionContainsLineDelimiters if (isEndTagMissing(parentNode)) { parentNode = (IDOMNode) parentNode.getParentNode(); while (isEndTagMissing(parentNode)) parentNode = (IDOMNode) parentNode.getParentNode(); // add parent's indentation to end nodeIndentation = getNodeIndent(parentNode); String lineDelimiter = getLineDelimiter(doc, node.getStartOffset()); if (!compressedText.endsWith(lineDelimiter + nodeIndentation)) { compressedText = StringUtils.appendIfNotEndWith(compressedText, lineDelimiter); compressedText = StringUtils.appendIfNotEndWith(compressedText, nodeIndentation); } } if ((parentNode != null) && (parentNode.getNodeType() == Node.DOCUMENT_NODE) && (node.getNodeValue().length() > 0) && (node.getNodeValue().trim().length() == 0) && ((node.getPreviousSibling() == null) || (node.getNextSibling() == null))) // delete spaces at the beginning or end of the document compressedText = EMPTY_STRING; replaceNodeValue(node, compressedText); }
/** * getNodeAt method * * @return org.w3c.dom.Node * @param offset * int */ Node getNodeAt(int offset) { IDOMNode parent = this; IDOMNode child = (IDOMNode) getFirstChild(); while (child != null) { if (child.getEndOffset() <= offset) { child = (IDOMNode) child.getNextSibling(); continue; } if (child.getStartOffset() > offset) { break; } IStructuredDocumentRegion startStructuredDocumentRegion = child.getStartStructuredDocumentRegion(); if (startStructuredDocumentRegion != null) { if (startStructuredDocumentRegion.getEnd() > offset) return child; } // dig more parent = child; child = (IDOMNode) parent.getFirstChild(); } return parent; }
if (parent == null) return; Node next = node.getNextSibling();
protected void formatNode(IDOMNode node, IStructuredFormatContraints formatContraints) { if (node != null) { // lineDelimiterFound means multi line comment String nodeValue = node.getNodeValue(); boolean lineDelimiterFoundInComment = StringUtils.containsLineDelimiter(nodeValue); if (lineDelimiterFoundInComment) { // format indentation before node formatIndentationBeforeNode(node, formatContraints); // adjust indentations in multi line comment String lineDelimiter = node.getModel().getStructuredDocument().getLineDelimiter(); String lineIndent = formatContraints.getCurrentIndent(); String singleIndent = getFormatPreferences().getIndent(); String newNodevalue = adjustIndentations(nodeValue, lineDelimiter + lineIndent, singleIndent); if (nodeValue.compareTo(newNodevalue) != 0) node.setNodeValue(newNodevalue); } if (!nodeHasSiblings(node) || (node.getPreviousSibling() != null && node.getPreviousSibling().getNodeType() == Node.TEXT_NODE && !StringUtils.containsLineDelimiter(node.getPreviousSibling().getNodeValue()) && node.getNextSibling() == null)) { // single child // or inline comment after text // do nothing } else // format indentation after node formatIndentationAfterNode(node, formatContraints); } } }
if (parent == null) return; Node next = node.getNextSibling();
if (parent == null) return; Node next = node.getNextSibling();
if (parent == null) return; Node next = node.getNextSibling();
if (parent == null) return; Node next = node.getNextSibling();
while (child != null) { formatNode(child, formatContraints); child = (IDOMNode) child.getNextSibling();
if (child.getParentNode() != node) break; IDOMNode next = (IDOMNode) child.getNextSibling();
if (newNode != null && newNode.getNextSibling() != null)
if (child.getParentNode() != node) break; IDOMNode next = (IDOMNode) child.getNextSibling();
if (child.getParentNode() != node) break; IDOMNode next = (IDOMNode) child.getNextSibling();