public void equatePositions(ITextRegion region) { fStart = region.getStart(); fLength = (short) region.getLength(); fTextLength = (short) region.getTextLength(); }
public void equatePositions(ITextRegion region) { fStart = region.getStart(); fLength = region.getLength(); fTextLength = region.getTextLength(); }
public void equatePositions(ITextRegion region) { fStart = region.getStart(); fLength = region.getLength(); fTextLength = region.getTextLength(); }
public void equatePositions(ITextRegion region) { fStart = region.getStart(); fLength = region.getLength(); fTextLength = region.getTextLength(); }
public void equatePositions(ITextRegion region) { fStart = region.getStart(); fLength = region.getLength(); fTextLength = region.getTextLength(); }
public void equatePositions(ITextRegion region) { fStart = region.getStart(); fLength = region.getLength(); fTextLength = region.getTextLength(); }
public void equatePositions(ITextRegion region) { fStart = region.getStart(); fLength = region.getLength(); fTextLength = region.getTextLength(); }
/** * This method is just to equate positions. clients may (will probably) * still need to make calls to equate regions, parent, etc. */ public void equatePositions(ITextRegion region) { start = region.getStart(); length = region.getLength(); textLength = region.getTextLength(); }
/** * Returns next word after the cursor position * * @throws BadLocationException */ public String getNextWord() throws BadLocationException { ITextRegion nextTwigToken = getNextTwigToken(); return document.get(regionCollection.getStartOffset() + twigScriptRegion.getStart() + nextTwigToken.getStart(), nextTwigToken.getTextLength()); }
public String getNextWord(int times) throws BadLocationException { ITextRegion nextTwigToken = getNextTwigToken(times); return document.get(regionCollection.getStartOffset() + twigScriptRegion.getStart() + nextTwigToken.getStart(), nextTwigToken.getTextLength()); }
/** * * @param jspReferenceRegion * @return */ private boolean isUsebeanTag(ITextRegionCollection jspReferenceRegion) { ITextRegionList regions = jspReferenceRegion.getRegions(); ITextRegion r = null; boolean isUseBean = false; for (int i = 0; i < regions.size(); i++) { r = regions.get(i); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=128490 // length of 11 is the length of jsp:useBean // and saves the expensive getText.equals call if (r.getType() == DOMRegionContext.XML_TAG_NAME) { if (r.getTextLength() == 11 && jspReferenceRegion.getText(r).equals("jsp:useBean")) { //$NON-NLS-1$ isUseBean = true; } // break no matter what if you hit tagname break; } } return isUseBean; }
protected String getMatchString(IStructuredDocumentRegion parent, ITextRegion aRegion, int offset) { if ((aRegion == null) || isCloseRegion(aRegion)) { return ""; //$NON-NLS-1$ } String matchString = null; String regionType = aRegion.getType(); if ((regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) || (regionType == DOMRegionContext.XML_TAG_OPEN) || (offset > parent.getStartOffset(aRegion) + aRegion.getTextLength())) { matchString = ""; //$NON-NLS-1$ } else if (regionType == DOMRegionContext.XML_CONTENT) { matchString = ""; //$NON-NLS-1$ } else { if ((parent.getText(aRegion).length() > 0) && (parent.getStartOffset(aRegion) < offset)) { matchString = parent.getText(aRegion).substring(0, offset - parent.getStartOffset(aRegion)); } else { matchString = ""; //$NON-NLS-1$ } } return matchString; }
public void nodeParsed(IStructuredDocumentRegion aCoreStructuredDocumentRegion) { // could test > 1, but since we only care if there are 8 (<%@, // taglib, uri, =, where, prefix, =, what) if (aCoreStructuredDocumentRegion.getNumberOfRegions() > 1 && aCoreStructuredDocumentRegion.getRegions().get(1).getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) { ITextRegion name = aCoreStructuredDocumentRegion.getRegions().get(1); try { String directiveName = fLocalParser.getText(aCoreStructuredDocumentRegion.getStartOffset(name), name.getTextLength()); if (directiveName.equals(JSP12TLDNames.TAGLIB) || directiveName.equals(JSP12Namespace.ElementName.DIRECTIVE_TAGLIB)) { processTaglib(aCoreStructuredDocumentRegion, fAnchor, fLocalParser); } if (directiveName.equals(JSP12TLDNames.INCLUDE) || directiveName.equals(JSP12Namespace.ElementName.DIRECTIVE_INCLUDE)) { processInclude(aCoreStructuredDocumentRegion, fAnchor, fLocalParser); } } catch (StringIndexOutOfBoundsException sioobExc) { // do nothing } } // could test > 1, but since we only care if there are 5 (<, // jsp:root, xmlns:prefix, =, where) else if (aCoreStructuredDocumentRegion.getNumberOfRegions() > 4 && aCoreStructuredDocumentRegion.getRegions().get(1).getType() == DOMJSPRegionContexts.JSP_ROOT_TAG_NAME) { processJSPRoot(aCoreStructuredDocumentRegion, fAnchor, fLocalParser); } }
private IRegion getHyperlinkRegion(Node node) { IRegion hyperRegion = null; if (node != null) { short nodeType = node.getNodeType(); if (nodeType == Node.DOCUMENT_TYPE_NODE) { // handle doc type node IDOMNode docNode = (IDOMNode) node; hyperRegion = new Region(docNode.getStartOffset(), docNode.getEndOffset() - docNode.getStartOffset()); } else if (nodeType == Node.ATTRIBUTE_NODE) { // handle attribute nodes IDOMAttr att = (IDOMAttr) node; // do not include quotes in attribute value region int regOffset = att.getValueRegionStartOffset(); ITextRegion valueRegion = att.getValueRegion(); if (valueRegion != null) { int regLength = valueRegion.getTextLength(); String attValue = att.getValueRegionText(); if (StringUtils.isQuoted(attValue)) { ++regOffset; regLength = regLength - 2; } hyperRegion = new Region(regOffset, regLength); } } } return hyperRegion; }
/** * */ private int getFirstChildRegionLength(ICSSNode node) { ICSSNode firstChild = node.getFirstChild(); if (firstChild == null) return 1; int start = ((IndexedRegion) firstChild).getStartOffset(); RegionIterator itr = new RegionIterator(node.getOwnerDocument().getModel().getStructuredDocument(), start); while (itr.hasNext()) { ITextRegion reg = itr.next(); if (reg != null && reg.getType() != CSSRegionContexts.CSS_S) return reg.getTextLength(); } return 1; }
protected ContentAssistRequest computeAttributeValueProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { ContentAssistRequest contentAssistRequest = null; IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); if ((documentPosition > sdRegion.getStartOffset(completionRegion) + completionRegion.getTextLength()) && (sdRegion.getStartOffset(completionRegion) + completionRegion.getTextLength() != sdRegion.getStartOffset(completionRegion) + completionRegion.getLength())) { // setup to add a new attribute at the documentPosition IDOMNode actualNode = (IDOMNode) node.getModel().getIndexedRegion(sdRegion.getStartOffset(completionRegion)); contentAssistRequest = newContentAssistRequest(actualNode, actualNode, sdRegion, completionRegion, documentPosition, 0, matchString); addAttributeNameProposals(contentAssistRequest); if ((actualNode.getFirstStructuredDocumentRegion() != null) && !actualNode.getFirstStructuredDocumentRegion().isEnded()) { addTagCloseProposals(contentAssistRequest); } } else { // setup to replace the existing value if (!nodeAtOffset.getFirstStructuredDocumentRegion().isEnded() && (documentPosition < sdRegion.getStartOffset(completionRegion))) { // if the IStructuredDocumentRegion isn't closed and the // cursor is in front of the value, add contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString); addAttributeNameProposals(contentAssistRequest); } else { contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString); addAttributeValueProposals(contentAssistRequest); } } return contentAssistRequest; }
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; }
protected ContentAssistRequest computeAttributeProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { ContentAssistRequest contentAssistRequest = null; IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition); if (documentPosition < sdRegion.getStartOffset(completionRegion)) { // setup to insert new attributes contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, documentPosition, 0, matchString); } else { // Setup to replace an existing attribute name contentAssistRequest = newContentAssistRequest(nodeAtOffset, node, sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString); } addAttributeNameProposals(contentAssistRequest); contentAssistRequest.setReplacementBeginPosition(documentPosition); contentAssistRequest.setReplacementLength(0); if ((node.getFirstStructuredDocumentRegion() != null) && (!node.getFirstStructuredDocumentRegion().isEnded())) { addTagCloseProposals(contentAssistRequest); } return contentAssistRequest; }
/** * Color the text in the sample area according to the current preferences */ void applyStyles() { if (fText == null || fText.isDisposed()) return; IStructuredDocumentRegion documentRegion = fDocument.getFirstStructuredDocumentRegion(); while (documentRegion != null) { ITextRegionList regions = documentRegion.getRegions(); for (int i = 0; i < regions.size(); i++) { ITextRegion currentRegion = regions.get(i); // lookup the local coloring type and apply it String namedStyle = (String) fContextToStyleMap.get(currentRegion.getType()); if (namedStyle == null) continue; TextAttribute attribute = getAttributeFor(namedStyle); if (attribute == null) continue; StyleRange style = new StyleRange(documentRegion.getStartOffset(currentRegion), currentRegion.getTextLength(), attribute.getForeground(), attribute.getBackground(), attribute.getStyle()); style.strikeout = (attribute.getStyle() & TextAttribute.STRIKETHROUGH) != 0; style.underline = (attribute.getStyle() & TextAttribute.UNDERLINE) != 0; fText.setStyleRange(style); } documentRegion = documentRegion.getNext(); } }
protected void processElementDoubleClicked() { if (fTextRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) { processElementAttrValueDoubleClicked(); // special handling for } else { if (fDoubleClickCount == 1) { fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStart() + fTextRegion.getStart(), fTextRegion.getTextLength()); } else if (fDoubleClickCount == 2) { if (fTextRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) { processElementAttrNameDoubleClicked2Times(); } else if (fTextRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) { processElementAttrEqualsDoubleClicked2Times(); } else { fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStart(), fStructuredDocumentRegion.getLength()); fDoubleClickCount = 0; } } else { // fDoubleClickCount == 3 fStructuredTextViewer.setSelectedRange(fStructuredDocumentRegion.getStart(), fStructuredDocumentRegion.getLength()); fDoubleClickCount = 0; } } }