/** * Given a 1-based line number, return the 0-based offset of the first character in the line. * * @throws UnsupportedOperationException if this source cannot contain {@link #hasCharacters() * characters}. * @throws IllegalArgumentException if there is no such line in the text * @since 0.8 or earlier */ public final int getLineStartOffset(int lineNumber) throws IllegalArgumentException { return getTextMap().lineStartOffset(lineNumber); }
/** * Given a 0-based character offset, return the 1-based number of the line that includes the * position. Causes the contents of this source to be loaded if they are loaded lazily. * * @throws IllegalArgumentException if the offset is outside the text contents * @since 0.8 or earlier */ public final int getLineNumber(int offset) throws IllegalArgumentException { return getTextMap().offsetToLine(offset); }
/** * Given a 0-based character offset, return the 1-based number of the line that includes the * position. Causes the contents of this source to be loaded if they are loaded lazily. * * @throws UnsupportedOperationException if this source cannot contain {@link #hasCharacters() * characters}. * @throws IllegalArgumentException if the offset is outside the text contents * @since 0.8 or earlier */ public final int getLineNumber(int offset) throws IllegalArgumentException { return getTextMap().offsetToLine(offset); }
/** * The number of characters (not counting a possible terminating newline) in a (1-based) * numbered line. Causes the contents of this source to be loaded if they are loaded lazily. * * @throws UnsupportedOperationException if this source cannot contain {@link #hasCharacters() * characters}. * @throws IllegalArgumentException if there is no such line in the text * @since 0.8 or earlier */ public final int getLineLength(int lineNumber) throws IllegalArgumentException { return getTextMap().lineLength(lineNumber); }
/** * The number of text lines in the source, including empty lines; characters at the end of the * source without a terminating newline count as a line. Causes the contents of this source to * be loaded if they are loaded lazily. * * @since 0.8 or earlier */ public final int getLineCount() { return getTextMap().lineCount(); }
/** * The number of characters (not counting a possible terminating newline) in a (1-based) * numbered line. Causes the contents of this source to be loaded if they are loaded lazily. * * @throws IllegalArgumentException if there is no such line in the text * @since 0.8 or earlier */ public final int getLineLength(int lineNumber) throws IllegalArgumentException { return getTextMap().lineLength(lineNumber); }
/** * The number of text lines in the source, including empty lines; characters at the end of the * source without a terminating newline count as a line. Causes the contents of this source to * be loaded if they are loaded lazily. * * @throws UnsupportedOperationException if this source cannot contain {@link #hasCharacters() * characters}. * @since 0.8 or earlier */ public final int getLineCount() { return getTextMap().lineCount(); }
/** * Given a 0-based character offset, return the 1-based number of the column at the position. * Causes the contents of this source to be loaded if they are loaded lazily. * * @throws UnsupportedOperationException if this source cannot contain {@link #hasCharacters() * characters}. * @throws IllegalArgumentException if the offset is outside the text contents * @since 0.8 or earlier */ public final int getColumnNumber(int offset) throws IllegalArgumentException { return getTextMap().offsetToCol(offset); }
/** * Gets the number of characters in the source. Causes the contents of this source to be loaded * if they are loaded lazily. * * @since 0.8 or earlier */ public final int getLength() { return getTextMap().length(); }
/** * Given a 0-based character offset, return the 1-based number of the column at the position. * Causes the contents of this source to be loaded if they are loaded lazily. * * @throws IllegalArgumentException if the offset is outside the text contents * @since 0.8 or earlier */ public final int getColumnNumber(int offset) throws IllegalArgumentException { return getTextMap().offsetToCol(offset); }
/** * Given a 1-based line number, return the 0-based offset of the first character in the line. * * @throws IllegalArgumentException if there is no such line in the text * @since 0.8 or earlier */ public final int getLineStartOffset(int lineNumber) throws IllegalArgumentException { return getTextMap().lineStartOffset(lineNumber); }
/** * Gets the text (not including a possible terminating newline) in a (1-based) numbered line. * Causes the contents of this source to be loaded if they are loaded lazily. * * @since 0.28 */ public final CharSequence getCharacters(int lineNumber) { final int offset = getTextMap().lineStartOffset(lineNumber); final int length = getTextMap().lineLength(lineNumber); return getCharacters().subSequence(offset, offset + length); }
/** * Gets the text (not including a possible terminating newline) in a (1-based) numbered line. * Causes the contents of this source to be loaded if they are loaded lazily. * * @throws UnsupportedOperationException if this source cannot contain {@link #hasCharacters() * characters}. * @since 0.28 */ public final CharSequence getCharacters(int lineNumber) { final int offset = getTextMap().lineStartOffset(lineNumber); final int length = getTextMap().lineLength(lineNumber); return getCharacters().subSequence(offset, offset + length); }
/** * Creates a representation of a line of text in the source identified only by line number, from * which the character information will be computed. Please note that calling this method does * cause the {@link Source#getCharacters() code} of this source to be loaded. * * @param lineNumber 1-based line number of the first character in the section * @return newly created object representing the specified line * @throws IllegalArgumentException if the given lineNumber does not exist the source * @since 0.17 */ public final SourceSection createSection(int lineNumber) { if (lineNumber < 1) { throw new IllegalArgumentException("lineNumber < 1"); } final int charIndex = getTextMap().lineStartOffset(lineNumber); final int length = getTextMap().lineLength(lineNumber); SourceSection section = new SourceSection(this, charIndex, length); assert assertValid(section); return section; }
final int lineStartOffset = getTextMap().lineStartOffset(startLine); if (startColumn > getTextMap().lineLength(startLine)) { throw new IllegalArgumentException("column out of range");
throw new IllegalArgumentException("length < 0"); final int lineStartOffset = getTextMap().lineStartOffset(startLine); final int lineLength = getTextMap().lineLength(startLine); if (startColumn > (lineLength + 1)) { throw new IllegalArgumentException("column out of range");
throw new IllegalArgumentException("columnNumber < 1"); final int charIndex = getTextMap().lineColumnToOffset(startLine, startColumn); final int endIndex = getTextMap().lineColumnToOffset(endLine, endColumn); assert charIndex <= endIndex : charIndex + " > " + endIndex; int length = endIndex + 1 - charIndex; int sourceLength = getTextMap().length(); if (length == 1 && charIndex + length > sourceLength) {
/** * Gets the number of characters or bytes of the source. * * @throws UnsupportedOperationException if this source does not contain {@link #hasCharacters() * characters}, nor {@link #hasBytes() bytes}. * @since 0.8 */ public final int getLength() { if (hasCharacters()) { return getTextMap().length(); } else if (hasBytes()) { return getBytes().length(); } else { throw new UnsupportedOperationException("Operation is only enabled for sources with character or byte content."); } }
final int charIndex = getTextMap().lineStartOffset(lineNumber); final int length = getTextMap().lineLength(lineNumber); section = new SourceSectionLoaded(this, charIndex, length); assert assertValid(section);