@Override public int getLineNumber(Object impl, int offset) { com.oracle.truffle.api.source.Source source = (com.oracle.truffle.api.source.Source) impl; return source.getLineNumber(offset); }
@Override public int getLineNumber(Object impl, int offset) { com.oracle.truffle.api.source.Source source = (com.oracle.truffle.api.source.Source) impl; return source.getLineNumber(offset); }
public int getEndLine() { return source.getLineNumber(charIndex + charLength - 1); }
@Override public int getStartLine() { if (!isValid()) { return 1; } return source.getLineNumber(getCharIndex()); }
@Override public int getEndLine() { if (!isValid()) { return 1; } return source.getLineNumber(getCharIndex() + Math.max(0, getCharLength() - 1)); }
/** * Returns 1-based line number of the first character in this section (inclusive). Returns * <code>1</code> for out of bounds or {@link #isAvailable() unavailable} source sections. * Please note that calling this method causes the {@link Source#getCharacters() code} of the * {@link #getSource() source} to be loaded if it was not yet loaded. * * @return the starting line number * @since 0.8 or earlier */ public int getStartLine() { if (source == null) { return -1; } if (!isValid()) { return 1; } return source.getLineNumber(getCharIndex()); }
/** * Returns 1-based line number of the last character in this section (inclusive). Returns * <code>1</code> for out of bounds or {@link #isAvailable() unavailable} source sections. * Please note that calling this method causes the {@link Source#getCharacters() code} of the * {@link #getSource() source} to be loaded if it was not yet loaded. * * @return the starting line number * @since 0.8 or earlier */ public int getEndLine() { if (source == null) { return -1; } if (!isValid()) { return 1; } return source.getLineNumber(getCharIndex() + Math.max(0, getCharLength() - 1)); }
/** * Creates a representation of a contiguous region of text in the source. Computes the * {@code (startLine, startColumn)} values by building a {@linkplain TextMap map} of lines in * the source. * <p> * Checks the position arguments for consistency with the source. * <p> * The resulting representation defines hash/equality around equivalent location, presuming that * {@link Source} representations are canonical. * * * @param identifier terse description of the region * @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 either of the arguments are outside the text of the * source * @throws IllegalStateException if the source is one of the "null" instances */ public final SourceSection createSection(String identifier, int charIndex, int length) throws IllegalArgumentException { checkRange(charIndex, length); checkTextMap(); final int startLine = getLineNumber(charIndex); final int startColumn = charIndex - getLineStartOffset(startLine) + 1; return new DefaultSourceSection(this, identifier, startLine, startColumn, charIndex, length); }