int getEndOffset() { return fDocumentRegion.getEndOffset(fTextRegion); }
/** * NOTE: 'start' and 'end' must be the start and end of the contiguous regions. * Otherwise, this class cannot work correctly. */ public Segment(IStructuredDocumentRegion start, IStructuredDocumentRegion end) { super(); this.offset = start.getStartOffset(); int endOffset = (end == null) ? start.getEndOffset() : end.getEndOffset(); this.length = endOffset - this.offset; }
private boolean intersects(IStructuredDocumentRegion node, ITextRegion region, int low, int high) { int start = node.getStartOffset(region); int end = node.getEndOffset(region); return (end >= low && start <= high) || (start <= low && end >= low) || (start <= high && end >= high); }
public int getNameRegionEndOffset() { if (this.ownerElement == null) return 0; // assuming the firstStructuredDocumentRegion is the one that contains // attributes IStructuredDocumentRegion flatNode = this.ownerElement.getFirstStructuredDocumentRegion(); if (flatNode == null) return 0; return flatNode.getEndOffset(this.nameRegion); }
/** * @return int */ public int getEndOffset() { int result = -1; ITextRegion region = getLastRegion(); if (!(region == null || fParentRegion == null)) { result = fParentRegion.getEndOffset(region); } return result; }
public int getEndTagEndOffset() { if (node.getEndStructuredDocumentRegion() != null) { return node.getEndStructuredDocumentRegion().getEndOffset(); } return -1; }
public int getStartTagEndOffset() { if (node.getStartStructuredDocumentRegion() != null) { return node.getStartStructuredDocumentRegion().getEndOffset(); } return -1; }
protected void prepareText(IStructuredDocumentRegion sdRegion) { fTextBefore = fTextToParse.substring(sdRegion.getStartOffset(), sdRegion.getEndOffset()); fUnescapedText = EscapedTextUtil.getUnescapedText(fTextBefore); fStrippedText = this.fTranslator.stripCDATA(fUnescapedText); }
protected void removeRegionSpaces(IDOMNode node, IStructuredDocumentRegion flatNode, ITextRegion region) { if ((region != null) && (region instanceof ContextRegion || region instanceof TagNameRegion) && (flatNode.getEndOffset(region) > flatNode.getTextEndOffset(region))) { IDOMModel structuredModel = node.getModel(); IStructuredDocument structuredDocument = structuredModel.getStructuredDocument(); replace(structuredDocument, flatNode.getTextEndOffset(region), flatNode.getEndOffset(region) - flatNode.getTextEndOffset(region), EMPTY_STRING); } }
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; }
/** * @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; }
protected String getAttributeValue(String attrName, IStructuredDocumentRegion sdRegion) { String sdRegionText = fTextToParse.substring(sdRegion.getStartOffset(), sdRegion.getEndOffset()); String textRegionText, attrValue = ""; //$NON-NLS-1$ Iterator it = sdRegion.getRegions().iterator(); ITextRegion nameRegion, valueRegion = null; while (it.hasNext()) { nameRegion = (ITextRegion) it.next(); if (nameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) { textRegionText = sdRegionText.substring(nameRegion.getStart(), nameRegion.getTextEnd()); if (textRegionText.equalsIgnoreCase(attrName)) { while (it.hasNext()) { valueRegion = (ITextRegion) it.next(); if (valueRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) { attrValue = sdRegionText.substring(valueRegion.getStart(), valueRegion.getEnd()); break; // inner } } break; // outer } } } return StringUtils.stripQuotes(attrValue); }
protected boolean doParserSpecificCheck(int offset, boolean partitionFound, IStructuredDocumentRegion sdRegion, IStructuredDocumentRegion previousStructuredDocumentRegion, ITextRegion next, ITextRegion previousStart) { // this was moved down to subclass of StructuredTextPartioner // for quick fix to transition problems. Heirarchy needs lots of // cleanup. if (previousStart != null && previousStart.getType() == DOMRegionContext.XML_TAG_OPEN && next.getType() == DOMRegionContext.XML_END_TAG_OPEN) { ITextRegion previousName = previousStructuredDocumentRegion.getRegionAtCharacterOffset(previousStructuredDocumentRegion.getEndOffset(previousStart)); ITextRegion nextName = sdRegion.getRegionAtCharacterOffset(sdRegion.getEndOffset(next)); if (previousName != null && nextName != null && previousName.getType() == DOMRegionContext.XML_TAG_NAME && nextName.getType() == DOMRegionContext.XML_TAG_NAME) { setInternalPartition(offset, 0, getPartitionTypeBetween(previousStructuredDocumentRegion, sdRegion)); partitionFound = true; } } return partitionFound; } }
/** * @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; }
int end = sdr.getEndOffset(); String sdrText = ""; //$NON-NLS-1$ end = sdr.getEndOffset() - 3; // ]]> sdrText = sdrText.substring(9, sdrText.length() - 3); writeToBuffer(type, sdrText, start, end); end = sdr.getEndOffset(); writeToBuffer(type, sdrText, start, end);
private void checkCursorInRegion(IStructuredDocumentRegion sdRegion) { // if cursor is in this region... if (this.fTranslator.getSourcePosition() >= fStartOfTextToParse + sdRegion.getStartOffset() && this.fTranslator.getSourcePosition() <= fStartOfTextToParse + sdRegion.getEndOffset()) { int endOfNameTag = sdRegion.getStartOffset(); int offset = fTextBefore.length() - fStrippedText.length(); // offset in addtion to what's already in the buffer this.fTranslator.setRelativeOffset(this.fTranslator.getSourcePosition() - (fStartOfTextToParse + endOfNameTag) - offset); // outer class method this.fTranslator.setCursorOwner(fPossibleOwner); // add length of what's already in the buffer this.fTranslator.setRelativeOffset(this.fTranslator.getRelativeOffset() + this.fTranslator.getCursorOwner().length()); if (fPossibleOwner == JSPTranslator.EXPRESSION) { // add length of expression prefix if necessary... this.fTranslator.setRelativeOffset(this.fTranslator.getRelativeOffset() + JSPTranslator.EXPRESSION_PREFIX.length()); } } }
protected void processElementAttrNameDoubleClicked2Times() { int nextRegionOffset = fStructuredDocumentRegion.getEndOffset(fTextRegion); ITextRegion nextRegion = fStructuredDocumentRegion.getRegionAtCharacterOffset(nextRegionOffset); if (nextRegion != null) { nextRegionOffset = fStructuredDocumentRegion.getEndOffset(nextRegion); nextRegion = fStructuredDocumentRegion.getRegionAtCharacterOffset(nextRegionOffset); if ((nextRegion != null) && (nextRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)) { fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStartOffset(fTextRegion), nextRegion.getTextEnd() - fTextRegion.getStart()); } else { // attribute has no value fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStart(), fStructuredDocumentRegion.getLength()); fDoubleClickCount = 0; } } }
/** * 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; }
protected void processElementAttrEqualsDoubleClicked2Times() { int prevRegionOffset = fStructuredDocumentRegion.getStartOffset(fTextRegion) - 1; ITextRegion prevRegion = fStructuredDocumentRegion.getRegionAtCharacterOffset(prevRegionOffset); int nextRegionOffset = fStructuredDocumentRegion.getEndOffset(fTextRegion); ITextRegion nextRegion = fStructuredDocumentRegion.getRegionAtCharacterOffset(nextRegionOffset); if ((prevRegion != null) && (prevRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) && (nextRegion != null) && (nextRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)) { fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStartOffset(prevRegion), nextRegion.getTextEnd() - prevRegion.getStart()); } }
/** * */ public int getAttrInsertPos(ICSSNode node, String attrName) { if (node == null || attrName == null || attrName.length() == 0) return -1; if (!ICSSPageRule.SELECTOR.equalsIgnoreCase(attrName)) return -1; ICSSAttr attr = (ICSSAttr) node.getAttributes().getNamedItem(ICSSPageRule.SELECTOR); if (attr != null && ((IndexedRegion) attr).getEndOffset() > 0) return ((IndexedRegion) attr).getStartOffset(); else if (((IndexedRegion) node).getEndOffset() > 0) { IStructuredDocumentRegion flatNode = node.getOwnerDocument().getModel().getStructuredDocument().getRegionAtCharacterOffset(((IndexedRegion) node).getStartOffset()); ITextRegion region = flatNode.getRegionAtCharacterOffset(((IndexedRegion) node).getStartOffset()); RegionIterator it = new RegionIterator(flatNode, region); while (it.hasNext()) { region = it.next(); if (region.getType() == CSSRegionContexts.CSS_LBRACE) { return it.getStructuredDocumentRegion().getStartOffset(region); } if (it.getStructuredDocumentRegion().getEndOffset(region) >= ((IndexedRegion) node).getEndOffset()) break; } } return ((IndexedRegion) node).getStartOffset(); }