/** * A tag is implicit if it has not corresponding region in document. * * @param renamedNode * @return */ private boolean isImplicitTag(IDOMNode renamedNode) { return renamedNode.getStartStructuredDocumentRegion() == null; }
public int getStartTagEndOffset() { if (node.getStartStructuredDocumentRegion() != null) { return node.getStartStructuredDocumentRegion().getEndOffset(); } return -1; }
public int getStartTagStartOffset() { if (node.getStartStructuredDocumentRegion() != null) { return node.getStartStructuredDocumentRegion().getStartOffset(); } return -1; } }
/** * @param eObj * @return the offset character offset in to the XML document of the * XML node that eObj was constructed from or -1 if not * computable */ public static int getStartOffset(EObject eObj) { IDOMNode node = getDomNode(eObj); if (node != null) { return node.getStartStructuredDocumentRegion().getStartOffset(); } return -1; }
protected String getOtherClose(Node notATagNode) { if (notATagNode instanceof IDOMNode) { IStructuredDocumentRegion node = ((IDOMNode) notATagNode).getStartStructuredDocumentRegion(); if ((node != null) && (node.getNumberOfRegions() > 1) && node.getRegions().get(0).getType().equals(DOMJSPRegionContextsPrivateCopy.JSP_DIRECTIVE_OPEN)) { return "%>"; //$NON-NLS-1$ } } return null; }
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);
/** * @see org.eclipse.jface.text.contentassist.IContextInformationValidator#isContextInformationValid(int) */ public boolean isContextInformationValid(int documentPosition) { // determine whether or not this context info should still be // showing... // if cursor still within the element it's valid... boolean result = false; if (fModelUtil != null) { IStructuredDocumentRegion startRegion = fModelUtil.getXMLNode(fDocumentPosition).getStartStructuredDocumentRegion(); int start = startRegion.getStartOffset(); int end = startRegion.getEndOffset(); result = (documentPosition < end) && (documentPosition > start + 1); } return result; }
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); } }
/** */ protected void formatNode(IDOMNode node, HTMLFormatContraints contraints) { if (node == null) return; if (node.hasChildNodes()) { // container formatChildNodes(node, contraints); } else { // leaf IStructuredDocumentRegion flatNode = node.getStartStructuredDocumentRegion(); if (flatNode != null) { String source = flatNode.getText(); if (source != null && source.length() > 0) { setWidth(contraints, source); } } } }
/** * @param eObj * @return the length in characters of the XML node that * eObj was constructed from or -1 if no computable */ public static int getLength(EObject eObj) { IDOMNode node = getDomNode(eObj); if (node != null) { return node.getEndStructuredDocumentRegion().getEndOffset() - node.getStartStructuredDocumentRegion().getStartOffset(); } return -1; }
/** * 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); } }
/** * Apply changes from CSS sub-model to HTML model */ private void replaceData(int offset, int length, String data) { IDOMNode element = (IDOMNode) getElement(); if (element == null) return; IDOMModel ownerModel = element.getModel(); if (ownerModel == null) return; IStructuredDocument structuredDocument = ownerModel.getStructuredDocument(); if (structuredDocument == null) return; IStructuredDocumentRegion flatNode = element.getStartStructuredDocumentRegion(); if (flatNode == null) return; int contentOffset = flatNode.getEndOffset(); if (data == null) data = "";//$NON-NLS-1$ this.ignoreNotification = true; structuredDocument.replaceText(getRequesterC2H(), contentOffset + offset, length, data); this.ignoreNotification = false; }
private IDOMNode insertMissingTags(IDOMNode node) { boolean insertMissingTags = getCleanupPreferences().getInsertMissingTags(); IDOMNode newNode = node; if (insertMissingTags) { IStructuredDocumentRegion startTagStructuredDocumentRegion = node.getStartStructuredDocumentRegion(); if (startTagStructuredDocumentRegion == null) { // implicit start tag; generate tag for it newNode = insertStartTag(node); startTagStructuredDocumentRegion = newNode.getStartStructuredDocumentRegion(); } IStructuredDocumentRegion endTagStructuredDocumentRegion = newNode.getEndStructuredDocumentRegion(); ITextRegionList startStructuredDocumentRegionRegions = startTagStructuredDocumentRegion.getRegions(); if (startTagStructuredDocumentRegion != null && startStructuredDocumentRegionRegions != null && (startStructuredDocumentRegionRegions.get(startStructuredDocumentRegionRegions.size() - 1)).getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) { } else { if (startTagStructuredDocumentRegion == null) { // start tag missing if (isStartTagRequired(newNode)) newNode = insertStartTag(newNode); } else if (endTagStructuredDocumentRegion == null) { // end tag missing if (isEndTagRequired(newNode)) newNode = insertEndTag(newNode); } } } return newNode; }
protected IDOMNode insertMissingTags(IDOMNode node) { boolean insertMissingTags = getCleanupPreferences().getInsertMissingTags(); IDOMNode newNode = node; if (insertMissingTags) { IStructuredDocumentRegion startTagStructuredDocumentRegion = node.getStartStructuredDocumentRegion(); if (startTagStructuredDocumentRegion == null) { // implicit start tag; generate tag for it newNode = insertStartTag(node); startTagStructuredDocumentRegion = newNode.getStartStructuredDocumentRegion(); } IStructuredDocumentRegion endTagStructuredDocumentRegion = newNode.getEndStructuredDocumentRegion(); ITextRegionList regionList = startTagStructuredDocumentRegion.getRegions(); if (startTagStructuredDocumentRegion != null && regionList != null && regionList.get(regionList.size() - 1).getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) { } else { if (startTagStructuredDocumentRegion == null) { // start tag missing if (isStartTagRequired(newNode)) newNode = insertStartTag(newNode); } else if (endTagStructuredDocumentRegion == null) { // end tag missing if (isEndTagRequired(newNode)) newNode = insertEndTag(newNode); } } } return newNode; }
/** * 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; }
private void getLocalRenameQuickAssistProposal(List proposals, ISourceViewer viewer, int offset) { IDOMNode node = (IDOMNode) getNodeAt(viewer, offset); IStructuredDocumentRegion startStructuredDocumentRegion = node == null ? null : node.getStartStructuredDocumentRegion(); IStructuredDocumentRegion endStructuredDocumentRegion = node == null ? null : node.getEndStructuredDocumentRegion(); ITextRegion region = null; int regionTextEndOffset = 0; if ((startStructuredDocumentRegion != null) && startStructuredDocumentRegion.containsOffset(offset)) { region = startStructuredDocumentRegion.getRegionAtCharacterOffset(offset); regionTextEndOffset = startStructuredDocumentRegion.getTextEndOffset(region); } else if ((endStructuredDocumentRegion != null) && endStructuredDocumentRegion.containsOffset(offset)) { region = endStructuredDocumentRegion.getRegionAtCharacterOffset(offset); regionTextEndOffset = endStructuredDocumentRegion.getTextEndOffset(region); } if ((region != null) && ((region.getType() == DOMRegionContext.XML_TAG_NAME) || (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)) && (offset <= regionTextEndOffset)) { proposals.add(new RenameInFileQuickAssistProposal()); } }
/** * @param proposals * @param viewer * @param offset */ protected void getLocalRenameQuickAssistProposal(ArrayList proposals, StructuredTextViewer viewer, int offset) { IDOMNode node = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, offset); IStructuredDocumentRegion startStructuredDocumentRegion = node == null ? null : node.getStartStructuredDocumentRegion(); IStructuredDocumentRegion endStructuredDocumentRegion = node == null ? null : node.getEndStructuredDocumentRegion(); ITextRegion region = null; int regionTextEndOffset = 0; if ((startStructuredDocumentRegion != null) && startStructuredDocumentRegion.containsOffset(offset)) { region = startStructuredDocumentRegion.getRegionAtCharacterOffset(offset); regionTextEndOffset = startStructuredDocumentRegion.getTextEndOffset(region); } else if ((endStructuredDocumentRegion != null) && endStructuredDocumentRegion.containsOffset(offset)) { region = endStructuredDocumentRegion.getRegionAtCharacterOffset(offset); regionTextEndOffset = endStructuredDocumentRegion.getTextEndOffset(region); } if ((region != null) && ((region.getType() == DOMRegionContext.XML_TAG_NAME) || (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)) && (offset <= regionTextEndOffset)) { proposals.add(new RenameInFileQuickAssistProposal()); } }
protected ContentAssistRequest computeEqualsProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { ContentAssistRequest contentAssistRequest = null; IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); ITextRegion valueRegion = node.getStartStructuredDocumentRegion().getRegionAtCharacterOffset(sdRegion.getStartOffset(completionRegion) + completionRegion.getLength()); if ((valueRegion != null) && (valueRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) && (sdRegion.getStartOffset(valueRegion) <= documentPosition)) { // replace the adjacent attribute value contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, valueRegion, sdRegion.getStartOffset(valueRegion), valueRegion.getTextLength(), matchString); } else { // append an attribute value after the '=' contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString); } addAttributeValueProposals(contentAssistRequest); return contentAssistRequest; }
IStructuredDocumentRegion sdRegionStart = node.getStartStructuredDocumentRegion();
flatNode = node.getStartStructuredDocumentRegion(); if (flatNode != null) { if (node.isDataEditable()) {