/** * Creates a representation of a contiguous region of text in the source. Please note that * calling this method does only cause the {@link Source#getCharacters() code} of this source to * be loaded if assertions enabled. The bounds of the source section are only verified if * assertions (-ea) are enabled in the host system. An {@link IllegalArgumentException} is * thrown if the given indices are out of bounds of the source bounds. * * @param charIndex 0-based position of the first character in the section * @param length the number of characters in the section * @return newly created object representing the specified region * @throws IllegalArgumentException if charIndex < 0 or length < 0; in case assertions are * enabled also if the given bounds are out of the source bounds. * @since 0.17 */ public final SourceSection createSection(int charIndex, int length) { if (charIndex < 0) { throw new IllegalArgumentException("charIndex < 0"); } else if (length < 0) { throw new IllegalArgumentException("length < 0"); } SourceSection section = new SourceSection(this, charIndex, length); assert assertValid(section); return section; }
if (hasCharacters()) { section = new SourceSectionLoaded(this, charIndex, length); assert assertValid(section); } else { section = new SourceSectionUnloaded.Indexed(this, charIndex, length);
assert assertValid(section); return section;
/** * 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; }
assert assertValid(section); return section;
assert assertValid(section); return section; } else {
final int length = getTextMap().lineLength(lineNumber); section = new SourceSectionLoaded(this, charIndex, length); assert assertValid(section); } else { section = new SourceSectionUnloaded.Lines(this, lineNumber, lineNumber);