/** * */ protected void setValueForTextContent(List list, String value) { // String oldValue = getValueForTextContent(); // we worry about preserving trimmed text if (list.size() > 0) { IDOMNode first = (IDOMNode) list.get(0); IDOMNode last = (IDOMNode) list.get(list.size() - 1); int start = first.getStartOffset(); int end = last.getEndOffset(); first.getModel().getStructuredDocument().replaceText(this, start, end - start, value); } }
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; }
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; IStructuredDocumentRegion endStructuredDocumentRegion = child.getEndStructuredDocumentRegion(); if (endStructuredDocumentRegion != null) { if (endStructuredDocumentRegion.getStart() <= offset) child = (IDOMNode) parent.getFirstChild(); if (child.getStartOffset() > offset) { child = (IDOMNode) child.getPreviousSibling(); continue; if (child.getEndOffset() <= offset) { break; IStructuredDocumentRegion startStructuredDocumentRegion = child.getStartStructuredDocumentRegion(); if (startStructuredDocumentRegion != null) { if (startStructuredDocumentRegion.getEnd() > offset) return child;
void unlockDeep(IDOMNode node) { if (node == null) { return; } int offset = node.getStartOffset(); int length = node.getEndOffset() - offset; unlock(node.getStructuredDocument(), offset, length); }
public int getLength() { if (this.node.getNodeType() == Node.ELEMENT_NODE) { return ((IDOMElement) this.node).getStartEndOffset() - this.node.getStartOffset(); } return this.node.getLength(); }
/** * lock itself and all descendants */ void lockDeep(IDOMNode node) { if (node == null) { return; } int offset = node.getStartOffset(); int length = node.getEndOffset() - offset; boolean canInsert = true; IDOMNode parent = (IDOMNode) node.getParentNode(); if (parent != null && !parent.isChildEditable()) { canInsert = false; } lock(node.getStructuredDocument(), offset, length, canInsert, canInsert); }
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(); } } }
IStructuredDocumentRegion sdRegionStart = node.getStartStructuredDocumentRegion(); IStructuredDocument document = node.getStructuredDocument(); int lineIndex = document.getLineOfOffset(node.getStartOffset()); int endLineIndex = document.getLineOfOffset(node.getEndOffset()); if (node.hasChildNodes()) { // container IDOMNode child = (IDOMNode) node.getFirstChild(); while (child != null) { formatNode(child, formatContraints); child = (IDOMNode) child.getNextSibling();
if (node == null) return; if (node.getNodeType() == Node.TEXT_NODE) return; int documentLength = node.getStructuredDocument().getLength(); if (documentLength < 1 || (node.getEndOffset() >= (documentLength - 1))) return; Node parent = node.getParentNode(); if (parent == null) return; Node next = node.getNextSibling(); return; replaceSource(node.getModel(), node.getEndOffset(), 0, spaces); setWidth(contraints, spaces);
/** * 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; }
NamedNodeMap attributes = newNode.getAttributes(); int attributesLength = attributes.getLength(); ISourceGenerator generator = node.getModel().getGenerator(); attributes = newNode.getAttributes(); attributesLength = attributes.getLength(); IDOMAttr eachAttr = (IDOMAttr) attributes.item(i); IDOMModel structuredModel = node.getModel(); if (isXMLType(structuredModel)) { newNode = (IDOMNode) structuredModel.getIndexedRegion(node.getStartOffset()); // save int attrValueStartOffset = eachAttr.getValueRegionStartOffset(); int attrValueLength = oldAttrValue.length(); int startTagStartOffset = node.getStartOffset(); IDOMModel structuredModel = node.getModel(); IStructuredDocument structuredDocument = structuredModel.getStructuredDocument(); replaceSource(structuredModel, structuredDocument, attrValueStartOffset, attrValueLength, newAttrValue);
private IDOMNode compressEmptyElementTag(IDOMNode node) { boolean compressEmptyElementTags = getCleanupPreferences().getCompressEmptyElementTags(); IDOMNode newNode = node; IStructuredDocumentRegion startTagStructuredDocumentRegion = newNode.getFirstStructuredDocumentRegion(); IStructuredDocumentRegion endTagStructuredDocumentRegion = newNode.getLastStructuredDocumentRegion(); if (compressEmptyElementTags && startTagStructuredDocumentRegion != endTagStructuredDocumentRegion && startTagStructuredDocumentRegion != null) { ITextRegionList regions = startTagStructuredDocumentRegion.getRegions(); ITextRegion lastRegion = regions.get(regions.size() - 1); // format children and end tag if not empty element tag if (lastRegion.getType() != DOMRegionContext.XML_EMPTY_TAG_CLOSE) { NodeList childNodes = newNode.getChildNodes(); if (childNodes == null || childNodes.getLength() == 0 || (childNodes.getLength() == 1 && (childNodes.item(0)).getNodeType() == Node.TEXT_NODE && ((childNodes.item(0)).getNodeValue().trim().length() == 0))) { IDOMModel structuredModel = newNode.getModel(); IStructuredDocument structuredDocument = structuredModel.getStructuredDocument(); int startTagStartOffset = newNode.getStartOffset(); int offset = endTagStructuredDocumentRegion.getStart(); int length = endTagStructuredDocumentRegion.getLength(); structuredDocument.replaceText(structuredDocument, offset, length, ""); //$NON-NLS-1$ newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save offset = startTagStructuredDocumentRegion.getStart() + lastRegion.getStart(); structuredDocument.replaceText(structuredDocument, offset, 0, "/"); //$NON-NLS-1$ newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save } } } return newNode; }
private String getContentTypeId(Node node) { String contentTypeId = "org.eclipse.core.runtime.xml"; //$NON-NLS-1$ if (node instanceof IDOMNode) { IDOMNode domNode = (IDOMNode) node; contentTypeId = domNode.getModel().getContentTypeIdentifier(); } return contentTypeId; } }
NamedNodeMap attributes = node.getAttributes(); int attributesLength = attributes.getLength(); String oldAttrName = eachAttr.getNodeName(); String newAttrName = oldAttrName; int attrNameStartOffset = eachAttr.getStartOffset(); int attrNameLength = oldAttrName.length(); IDOMModel structuredModel = node.getModel(); IStructuredDocument structuredDocument = structuredModel.getStructuredDocument(); replaceSource(structuredModel, structuredDocument, attrNameStartOffset, attrNameLength, newAttrName);
private IDOMNode insertStartTag(IDOMNode node) { IDOMNode newNode = node; if (isCommentTag(node)) return node; // do nothing String tagName = node.getNodeName(); String startTag = START_TAG_OPEN.concat(tagName).concat(TAG_CLOSE); int startTagStartOffset = node.getStartOffset(); IDOMModel structuredModel = node.getModel(); IStructuredDocument structuredDocument = structuredModel.getStructuredDocument(); structuredDocument.replaceText(structuredDocument, startTagStartOffset, 0, startTag); newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save // new // node return newNode; }
protected void insertAfterNode(IDOMNode node, String string) { IDOMModel structuredModel = node.getModel(); IStructuredDocument structuredDocument = structuredModel.getStructuredDocument(); int offset = node.getEndOffset(); int length = 0; // 261968 - formatting tag without closing bracket: <t1><t1 if (node.getEndStructuredDocumentRegion() != null) { offset = node.getEndStructuredDocumentRegion().getTextEndOffset(); length = node.getEndOffset() - offset; } replace(structuredDocument, offset, length, string); }
private void getInsertRequiredAttrs(List proposals, ISourceViewer viewer, int offset) { IDOMNode node = (IDOMNode) getNodeAt(viewer, offset); if ((node != null) && (node.getNodeType() == Node.ELEMENT_NODE)) { IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion(); if ((startStructuredDocumentRegion != null) && startStructuredDocumentRegion.containsOffset(offset)) { IDOMNode cursorNode = (IDOMNode) getNodeAt(viewer, offset); List requiredAttrs = getRequiredAttrs(cursorNode); if (requiredAttrs.size() > 0) { NamedNodeMap currentAttrs = node.getAttributes(); List insertAttrs = new ArrayList(); if (currentAttrs.getLength() == 0) {
CMDocument jcmdoc = null; if (node instanceof IDOMNode) { IDOMModel model = ((IDOMNode) node).getModel(); String modelPath = model.getBaseLocation(); if (modelPath != null && !IModelManager.UNMANAGED_MODEL.equals(modelPath)) { TLDCMDocumentManager tldmgr = TaglibController.getTLDCMDocumentManager(xmlNode.getStructuredDocument()); if (tldmgr != null) { List documents = tldmgr.getCMDocumentTrackers(node.getPrefix(), xmlNode.getStartOffset());
IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); if ((node.getNodeType() == Node.DOCUMENT_NODE) || (documentPosition >= sdRegion.getEndOffset())) { if ((node == nodeAtOffset) && (node.getParentNode() != null)) { node = (IDOMNode) node.getParentNode(); if ((node.getNodeType() != Node.DOCUMENT_NODE) && (node.getEndStructuredDocumentRegion() == null)) { addEndTagProposals(contentAssistRequest); if ((node.getNodeType() != Node.DOCUMENT_NODE) && (node.getEndStructuredDocumentRegion() != null)) { addTagCloseProposals(contentAssistRequest); if (sdRegion == nodeAtOffset.getFirstStructuredDocumentRegion()) { contentAssistRequest.setReplacementBeginPosition(documentPosition); contentAssistRequest.setReplacementLength(0);
void unlockBoth(IDOMNode node) { if (node == null) { return; } IStructuredDocumentRegion flatNode; // start node flatNode = node.getStartStructuredDocumentRegion(); if (flatNode != null) { unlock(flatNode); } // end node flatNode = node.getEndStructuredDocumentRegion(); if (flatNode != null) { unlock(flatNode); } }