/** * Returns an unavailable source section indicating that the source location is not available. * Unavailable source sections have the same characteristics as empty source sections with * character index <code>0</code>, but returns <code>false</code> for * {@link SourceSection#isAvailable()}. * * @see SourceSection#isAvailable() * @since 0.18 */ public final SourceSection createUnavailableSection() { return new SourceSection(this, 0, -1); }
/** * 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; }
throw new IllegalArgumentException("charIndex out of range"); SourceSection section = new SourceSection(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; }