public int getNameRegionTextEndOffset() { 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.getTextEndOffset(this.nameRegion); }
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); } }
static public boolean canHandleAsLetterOrDigit(ITextRegion region, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) { if (parent == null) return canHandleAsLetterOrDigit(region, changes, requestStart, lengthToReplace); boolean result = false; // Make sure we are in a non-white space area if ((requestStart <= (parent.getTextEndOffset(region))) && (allLetterOrDigit(changes))) { result = true; } return result; }
protected String getRegionName(IStructuredDocumentRegion sdRegion) { String nameStr = ""; //$NON-NLS-1$ ITextRegionList regions = sdRegion.getRegions(); for (int i = 0; i < regions.size(); i++) { ITextRegion r = regions.get(i); if (r.getType() == DOMRegionContext.XML_TAG_NAME) { nameStr = fTextToParse.substring(sdRegion.getStartOffset(r), sdRegion.getTextEndOffset(r)); break; } } return nameStr.trim(); }
protected String getRegionName(IStructuredDocumentRegion sdRegion) { ITextRegion nameRegion = null; String nameStr = ""; //$NON-NLS-1$ int size = sdRegion.getRegions().size(); if (size > 1) { // presumably XML-JSP <jsp:scriptlet> | <jsp:expression> | <jsp:declaration> nameRegion = sdRegion.getRegions().get(1); } else if (size == 1) { // presumably JSP open <% | <%= | <%! nameRegion = sdRegion.getRegions().get(0); } if (nameRegion != null) nameStr = fTextToParse.substring(sdRegion.getStartOffset(nameRegion), sdRegion.getTextEndOffset(nameRegion)); return nameStr.trim(); }
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()); } }
static public boolean canHandleAsWhiteSpace(ITextRegion region, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) { // we don't explect a null parent, but just in case! // (in which case, we must be dealing with regions that are // structuredDocumentRegions). if (parent == null) return canHandleAsWhiteSpace(region, changes, requestStart, lengthToReplace); boolean result = false; // if we are in the "white space" area of a region, then // we don't want to handle, a reparse is needed. // the white space region is consider anywhere that would // leave whitespace between this character and the text part. // and of course, we can insert whitespace in whitespace region // // if there is no whitespace in this region, no need to look further if (region.getEnd() > region.getTextEnd()) { // no need to add one to end of text, as we used to, since we // change definition of length to equate to offset plus one. if (requestStart > parent.getTextEndOffset(region)) { // ok, we are in the whitespace region, so we can't handle, // unless // we are just inserting whitespace. if (allWhiteSpace(changes)) { result = true; } else { result = false; } } } return result; }
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 insertTagClose(IDOMModel structuredModel, IStructuredDocumentRegion flatNode) { if (flatNode != null) { ITextRegionList flatnodeRegions = flatNode.getRegions(); if (flatnodeRegions != null) { ITextRegion lastRegion = flatnodeRegions.get(flatnodeRegions.size() - 1); if (lastRegion != null) { String regionType = lastRegion.getType(); if ((regionType != DOMRegionContext.XML_EMPTY_TAG_CLOSE) && (regionType != DOMRegionContext.XML_TAG_CLOSE)) { IStructuredDocument structuredDocument = structuredModel.getStructuredDocument(); // insert ">" after lastRegion of flatNode // as in "<a</a>" if flatNode is for start tag, or in // "<a></a" if flatNode is for end tag structuredDocument.replaceText(structuredDocument, flatNode.getTextEndOffset(lastRegion), 0, ">"); //$NON-NLS-1$ } } } } }
protected void insertTagClose(IDOMModel structuredModel, IStructuredDocumentRegion flatNode) { if ((flatNode != null) && (flatNode.getRegions() != null)) { ITextRegionList regionList = flatNode.getRegions(); ITextRegion lastRegion = regionList.get(regionList.size() - 1); if (lastRegion != null) { String regionType = lastRegion.getType(); if ((regionType != DOMRegionContext.XML_EMPTY_TAG_CLOSE) && (regionType != DOMRegionContext.XML_TAG_CLOSE)) { IStructuredDocument structuredDocument = structuredModel.getStructuredDocument(); // insert ">" after lastRegion of flatNode // as in "<a</a>" if flatNode is for start tag, or in // "<a></a" if flatNode is for end tag replaceSource(structuredModel, structuredDocument, flatNode.getTextEndOffset(lastRegion), 0, ">"); //$NON-NLS-1$ } } } }
private String getNamedStyleAtOffset(int offset) { // ensure the offset is clean if (offset >= fDocument.getLength()) return getNamedStyleAtOffset(fDocument.getLength() - 1); else if (offset < 0) return getNamedStyleAtOffset(0); IStructuredDocumentRegion documentRegion = fDocument.getFirstStructuredDocumentRegion(); while (documentRegion != null && !documentRegion.containsOffset(offset)) { documentRegion = documentRegion.getNext(); } if (documentRegion != null) { // find the ITextRegion's Context at this offset ITextRegion interest = documentRegion.getRegionAtCharacterOffset(offset); if (interest == null) return null; if (offset > documentRegion.getTextEndOffset(interest)) return null; String regionContext = interest.getType(); if (regionContext == null) return null; // find the named style (internal/selectable name) for that // context String namedStyle = (String) fContextToStyleMap.get(regionContext); if (namedStyle != null) { return namedStyle; } } return null; }
contentAssistRequest = computeEqualsProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); else if ((regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) && (documentPosition == sdRegion.getTextEndOffset()) && (sdRegion.getText(completionRegion).endsWith("\"") || sdRegion.getText(completionRegion).endsWith("\'"))) //$NON-NLS-1$ //$NON-NLS-2$ contentAssistRequest = newContentAssistRequest(treeNode, xmlnode.getParentNode(), sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion) + completionRegion.getLength(), 0, matchString); addStartDocumentProposals(contentAssistRequest); if (documentPosition >= sdRegion.getTextEndOffset(completionRegion)) { addTagInsertionProposals(contentAssistRequest, getElementPositionForModelQuery(treeNode) + 1);
ITextRegion startTagNameRegion = regions.get(1); int startTagNameStartOffset = startTagStructuredDocumentRegion.getStartOffset(startTagNameRegion); int startTagNameLength = startTagStructuredDocumentRegion.getTextEndOffset(startTagNameRegion) - startTagNameStartOffset; ITextRegion endTagNameRegion = regions.get(1); int endTagNameStartOffset = endTagStructuredDocumentRegion.getStartOffset(endTagNameRegion); int endTagNameLength = endTagStructuredDocumentRegion.getTextEndOffset(endTagNameRegion) - endTagNameStartOffset;
IStructuredDocumentRegion endRegion = previousSibling.getEndStructuredDocumentRegion(); if (endRegion != null) { prevEndRegionOffset = endRegion.getTextEndOffset();
int insertOffset = structuredDocumentRegion.getTextEndOffset(equalsRegion) - end; Object[] additionalFixInfo = {structuredDocumentRegion.getText(nameRegion), new Integer(insertOffset)};
int pos = (found ? it.getStructuredDocumentRegion().getStartOffset(region) : it.getStructuredDocumentRegion().getTextEndOffset(region)) - insertPos; return (pos >= 0) ? pos : 0;
if (offset < flatNode.getTextEndOffset(region)) { return new Region(flatNode.getStartOffset(region), region.getTextLength());
int pos = insertPos - (found ? it.getStructuredDocumentRegion().getTextEndOffset(region) : it.getStructuredDocumentRegion().getStartOffset(region));
if (offset < flatNode.getTextEndOffset(region)) { return new Region(flatNode.getStartOffset(region), region.getTextLength());