public Segment(IStructuredDocumentRegion region) { super(); this.offset = region.getStartOffset(); this.length = region.getLength(); }
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); }
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(); }
/** * Returns the previous php structured document. Special cases : 1) previous * is null - returns null 2) previous is not PHP region - returns the last * region of the last php block * * @param currentStructuredDocumentRegion */ public static IStructuredDocumentRegion getLastTwigStructuredDocumentRegion( IStructuredDocumentRegion currentStructuredDocumentRegion) { assert currentStructuredDocumentRegion != null; // get last region currentStructuredDocumentRegion = currentStructuredDocumentRegion.getPrevious(); // search for last php block (then returns the last region) while (currentStructuredDocumentRegion != null && currentStructuredDocumentRegion.getType() != TwigRegionContext.TWIG_CONTENT) { currentStructuredDocumentRegion = currentStructuredDocumentRegion.getPrevious(); } return currentStructuredDocumentRegion; }
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; } } }
private void checkStartingSpaceForPI(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) { if (structuredDocumentRegion.isDeleted()) { return; IStructuredDocumentRegion prev = structuredDocumentRegion.getPrevious(); if ((prev != null) && !prev.isDeleted()) { String prevText = prev.getFullText(); if ((prev.getType() == DOMRegionContext.XML_CONTENT) && prevText.endsWith(" ")) { //$NON-NLS-1$ String messageText = XMLUIMessages.ReconcileStepForMarkup_5; int start = prev.getStartOffset(); int length = prev.getLength();
private String getParentName(IStructuredDocumentRegion sdRegion) { String result = "UNKNOWN"; //$NON-NLS-1$ while (sdRegion != null && isValidJspActionRegionType(sdRegion.getType())) sdRegion = sdRegion.getPrevious(); if (sdRegion != null) { ITextRegionList regions = sdRegion.getRegions(); // only find parent names from a start tag if (regions.size() > 1) { ITextRegion r = regions.get(1); if (regions.get(0).getType().equals(DOMRegionContext.XML_TAG_OPEN) && r.getType().equals(DOMRegionContext.XML_TAG_NAME)) { result = sdRegion.getText(r); } } } return result; }
private ReparseRange getUpdateRangeForDelimiter(int start, int end) { if (dirtyStart != null && dirtyStart.getStart() < start) { start = dirtyStart.getStart(); } IStructuredDocumentRegion docRegion = fStructuredDocument.getRegionAtCharacterOffset(start); if (docRegion == null) { return null; } if (docRegion.getType() == CSSRegionContexts.CSS_DELIMITER) { IStructuredDocumentRegion prevRegion = docRegion.getPrevious(); if (prevRegion != null) { return new ReparseRange(prevRegion.getStart(), end); } } return null; }
protected void handleTaglib() { // get/create TLDCMDocument TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(fStructuredDocument); if (mgr != null) { List trackers = mgr.getCMDocumentTrackers(getCurrentNode().getEnd()); Iterator it = trackers.iterator(); CMDocumentTracker tracker = null; Iterator taglibRegions = null; IStructuredDocumentRegion sdRegion = null; ITextRegion r = null; while (it.hasNext()) { tracker = (CMDocumentTracker) it.next(); sdRegion = tracker.getStructuredDocumentRegion(); // since may be call from another thread (like a background // job) // this check is to be safer if (sdRegion != null && !sdRegion.isDeleted()) { taglibRegions = sdRegion.getRegions().iterator(); while (sdRegion != null && !sdRegion.isDeleted() && taglibRegions.hasNext()) { r = (ITextRegion) taglibRegions.next(); if (r.getType().equals(DOMJSPRegionContexts.JSP_DIRECTIVE_NAME)) { if (sdRegion.getText(r).equals(JSP12TLDNames.TAGLIB)) { addBlockMarkers(tracker.getDocument()); } } } } } } }
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()); } }
private void checkEmptyTag(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) { if (structuredDocumentRegion.isDeleted()) { return; } // navigate to name ITextRegionList regions = structuredDocumentRegion.getRegions(); if (regions.size() == 2) { // missing name region if ((regions.get(0).getType() == DOMRegionContext.XML_TAG_OPEN) && (regions.get(1).getType() == DOMRegionContext.XML_TAG_CLOSE)) { String messageText = XMLUIMessages.ReconcileStepForMarkup_3; int start = structuredDocumentRegion.getStartOffset(); int length = structuredDocumentRegion.getLength(); int lineNo = getLineNumber(start); LocalizedMessage message = new LocalizedMessage(IMessage.HIGH_SEVERITY, messageText); message.setOffset(start); message.setLength(length); message.setLineNo(lineNo); MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor(); processor.setProblemId(ProblemIDsXML.EmptyTag); message.setAttribute(QUICKASSISTPROCESSOR, processor); AnnotationInfo info = new AnnotationInfo(message); ((IncrementalReporter) reporter).addAnnotationInfo(this, info); } } }
/** */ public String getSource() { if (this.flatNode == null) return new String(); return this.flatNode.getText(); }
static private void unlock(IStructuredDocumentRegion node) { if (node == null) { return; } IStructuredDocument doc = node.getParentDocument(); if (doc == null) { return; } doc.clearReadOnly(node.getStart(), node.getLength()); }
/** * */ public static IStructuredDocumentRegion findNodeForward(IStructuredDocumentRegion startNode, IStructuredDocumentRegion endNode, String type) { IStructuredDocumentRegion node; for (node = startNode; node != null; node = node.getNext()) { if (endNode.getStartOffset() < node.getStartOffset()) { node = null; break; } else if (getStructuredDocumentRegionType(node) == type) { break; } } return node; }
/** * */ public ITextRegion next() { if (documentRegion == null) return null; if (current < 0 || documentRegion.getRegions() == null || documentRegion.getRegions().size() <= current) return null; ITextRegion region = documentRegion.getRegions().get(current); curDocumentRegion = documentRegion; if (current >= documentRegion.getRegions().size() - 1) { documentRegion = documentRegion.getNext(); current = -1; } current++; return region; }
/** * @param sdRegion * */ private boolean isEndTag(IStructuredDocumentRegion sdRegion) { ITextRegionList regions = sdRegion.getRegions(); return regions.get(0).getType() == DOMRegionContext.XML_END_TAG_OPEN; } }
/** * Returns true if potentially could be a jsp embedded region. Things like * JSP Declaration can't be embedded. */ private boolean isJSPEmbeddedStartOrEnd(IStructuredDocumentRegion flatNode) { boolean result = false; String type = flatNode.getType(); result = ((type == DOMJSPRegionContexts.JSP_SCRIPTLET_OPEN) || (type == DOMJSPRegionContexts.JSP_EXPRESSION_OPEN) || (type == DOMJSPRegionContexts.JSP_DECLARATION_OPEN)); return result; }
/** * */ public static IStructuredDocumentRegion findNodeBackward(IStructuredDocumentRegion startNode, IStructuredDocumentRegion endNode, String type) { IStructuredDocumentRegion node; for (node = startNode; node != null; node = node.getPrevious()) { if (node.getStartOffset() < endNode.getStartOffset()) { node = null; break; } else if (getStructuredDocumentRegionType(node) == type) { break; } } return node; }
static private String getTagName(IStructuredDocumentRegion tag) { ITextRegionList regions = tag.getRegions(); Iterator iter = regions.iterator(); while (iter.hasNext()) { ITextRegion rgn = (ITextRegion) iter.next(); if (rgn.getType() == DOMRegionContext.XML_TAG_NAME) return tag.getText(rgn); } return "";//$NON-NLS-1$ }