/** * getEndOffset method * * @return int */ public int getEndOffset() { if (this.ownerElement == null) return 0; int offset = this.ownerElement.getStartOffset(); if (this.valueRegion != null) { return (offset + this.valueRegion.getEnd()); } if (this.equalRegion != null) { return (offset + this.equalRegion.getEnd()); } if (this.nameRegion != null) { return (offset + this.nameRegion.getEnd()); } return 0; }
protected final void checkBadLocation(int offset) throws BadLocationException { ITextRegion lastRegion = getLastToken(); if (offset < 0 || lastRegion.getEnd() < offset) { throw new BadLocationException("offset " + offset + " is out of [0, " + lastRegion.getEnd() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } }
private final boolean isInside(ITextRegion region, int offset) { return region != null && region.getStart() <= offset && offset < region.getEnd(); }
public synchronized ITextRegion[] getTokens(final int offset, final int length) throws BadLocationException { assert length >= 0; List<ITextRegion> result = new ArrayList<ITextRegion>(); // list of // ITextRegion ITextRegion token = getToken(offset); if (token != null) { result.add(token); } while (tokensIterator.hasNext() && token != null && token.getEnd() <= offset + length) { token = tokensIterator.next(); result.add(token); } return result.toArray(new ITextRegion[result.size()]); }
/** * Returns offset where the current partition ends * * @param region * Region containing current offset * @param offset * Current position relative to the containing region * @return Ending offset of the current partition * @throws BadLocationException */ public static final int getPartitionEnd(IPHPScriptRegion region, int offset) throws BadLocationException { ITextRegion endRegion = getPartitionEndRegion(region, offset); return endRegion.getEnd(); }
static public String toString(ITextRegion region) { String className = region.getClass().getName(); String shortClassName = className.substring(className.lastIndexOf(".") + 1); //$NON-NLS-1$ String result = shortClassName + "--> " + region.getType() + ": " + region.getStart() + "-" + region.getTextEnd() + (region.getTextEnd() != region.getEnd() ? ("/" + region.getEnd()) : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ // NOTE: if the document held by any region has been updated and the // region offsets have not // yet been updated, the output from this method invalid. return result; }
public void adjustWhitespace(String yylex, int start, int yylengthLength, int yylength, Object lexerState) { assert (twigTokens.size() == 0 || getLastToken().getEnd() == start) && tokensIterator == null; // if state was change - we add a new token and add state if (lexerStateChanges.size() != 0 && getLastChange().state.equals(lexerState)) { final ITextRegion last = twigTokens.getLast(); last.adjustLength(yylength); } }
/** */ private void removeTailingSpaces(IStructuredDocumentRegion flatNode, ITextRegion region) { int offset = region.getTextEnd(); int count = region.getEnd() - offset; if (count <= 0) return; replaceSource(flatNode, offset, count, null); }
/** */ private void replaceTailingSpaces(IStructuredDocumentRegion flatNode, ITextRegion region, String spaces) { int offset = region.getTextEnd(); int count = region.getEnd() - offset; if (count == spaces.length()) { String source = flatNode.getFullText(region); if (source != null && source.endsWith(spaces)) { // nothing to do return; } } replaceSource(flatNode, offset, count, spaces); } }
public synchronized void addLast(String yylex, int start, int yylengthLength, int yylength, Object lexerState) { assert (twigTokens.size() == 0 || getLastToken().getEnd() == start) && tokensIterator == null; // if state was change - we add a new token and add state if (lexerStateChanges.size() == 0 || !getLastChange().state.equals(lexerState)) { int textLength = (AbstractTwigLexer.WHITESPACE.equals(yylex)) ? 0 : yylengthLength; final ContextRegion contextRegion = new ContextRegion(yylex, start, textLength, yylength); twigTokens.addLast(contextRegion); lexerStateChanges.addLast(new LexerStateChange((LexerState) lexerState, contextRegion)); return; } assert twigTokens.size() > 0; // if we can only adjust the previous token size if (yylex == AbstractTwigLexer.WHITESPACE) { final ITextRegion last = twigTokens.getLast(); last.adjustLength(yylength); } else { // else - add as a new token final ContextRegion contextRegion = new ContextRegion(yylex, start, yylengthLength, yylength); twigTokens.addLast(contextRegion); } }
if (result != null && offset >= result.getEnd()) { // if the offset is
public String getFullText(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion aRegion) { // Must be proxied here since aRegion should always be a child of // *this* container and indexed from // this container's offset return parent.getFullText().substring(start + aRegion.getStart(), start + aRegion.getEnd()); }
/** */ private void compressTailingSpaces(IStructuredDocumentRegion flatNode, ITextRegion region) { int offset = region.getTextEnd(); int count = region.getEnd() - offset; if (count == 1) { String source = flatNode.getFullText(region); int start = region.getStart(); if (source != null && source.charAt(offset - start) == ' ') { // nothing to do return; } } replaceSource(flatNode, offset, count, " ");//$NON-NLS-1$ }
public ITextRegion getNextTwigToken(int times) throws BadLocationException { ITextRegion twigToken = null; int offset = this.offset; while (times-- > 0) { twigToken = getTwigToken(offset); do { twigToken = twigScriptRegion.getTwigToken(twigToken.getEnd()); if (!PHPPartitionTypes.isPHPCommentState(twigToken.getType()) && twigToken.getType() != PHPRegionTypes.WHITESPACE) { break; } } while (twigToken.getEnd() < twigScriptRegion.getLength()); if (twigToken == null) { return null; } else { offset = regionCollection.getStartOffset() + twigScriptRegion.getStart() + twigToken.getEnd(); } } return twigToken; }
/** * Returns next PHP token after offset * * @return PHP token * @throws BadLocationException */ public ITextRegion getNextTwigToken() throws BadLocationException { ITextRegion twigToken = getTwigToken(); do { twigToken = twigScriptRegion.getTwigToken(twigToken.getEnd()); if (!PHPPartitionTypes.isPHPCommentState(twigToken.getType()) && twigToken.getType() != PHPRegionTypes.WHITESPACE) { break; } } while (twigToken.getEnd() < twigScriptRegion.getLength()); return twigToken; }
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); }
/** * Returns region current partition ends on * * @param region * Region containing current offset * @param offset * Current position relative to the containing region * @return Ending region of the current partition * @throws BadLocationException */ public static final ITextRegion getPartitionEndRegion(IPHPScriptRegion region, int offset) throws BadLocationException { String partitionType = region.getPartition(offset); ITextRegion internalRegion = region.getPHPToken(offset); ITextRegion endRegion = internalRegion; while (internalRegion.getEnd() != region.getLength()) { internalRegion = region.getPHPToken(internalRegion.getEnd()); if (region.getPartition(internalRegion.getStart()) != partitionType) { break; } endRegion = internalRegion; } return endRegion; }
static public boolean canHandleAsWhiteSpace(ITextRegion region, String changes, int requestStart, int 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 > region.getTextEnd()) { // 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; }
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; }
String type = region.getType(); if (type == startType) { startOffset = region.getEnd(); } else if (type == endType && prevRegion != null) { endOffset = prevRegion.getTextEnd();