Source:
<code>public static TextSelection calculateSelection(IDocument document, int offset, int length) { Objects.requireNonNull(document, "The given document must not be null"); if (offset == -1 && length == -1) { return TextSelection.EMPTY_SELECTION; } else if (offset < 0 || length < 0) { throw new IllegalArgumentException( "Invalid set of selection parameters given; must either both be -1 or both be >=0. o: " + offset + ", l: " + length); } int endOffset = offset + length; int startLine; int startLineOffset; try { startLine = document.getLineOfOffset(offset); startLineOffset = document.getLineOffset(startLine); } catch (BadLocationException e) { LOG.warn( "Could not calculate the start line or start line offset for the given start offset " + offset + " in the document " + document, e); return TextSelection.EMPTY_SELECTION; } int startInLineOffset = offset - startLineOffset; TextPosition startPosition = new TextPosition(startLine, startInLineOffset); if (endOffset == offset) { return new TextSelection(startPosition, startPosition); } int endLine; int endLineOffset; try { <START> endLine = document.getLineOfOffset(endOffset); <END> if (endLine == startLine) { endLineOffset = startLineOffset; } else { endLineOffset = document.getLineOffset(endLine); } } catch (BadLocationException e) { LOG.warn( "Could not calculate the end line or end line offset for the given end offset " + endOffset + " in the document " + document, e); return TextSelection.EMPTY_SELECTION; } int endInLineOffset = endOffset - endLineOffset; TextPosition endPosition = new TextPosition(endLine, endInLineOffset); return new TextSelection(startPosition, endPosition); }</code><technical_language>ternary</technical_language>

Target:
public static TextSelection calculateSelection(IDocument document, int offset, int length) { Objects.requireNonNull(document, "The given document must not be null"); if (offset == -1 && length == -1) { return TextSelection.EMPTY_SELECTION; } else if (offset < 0 || length < 0) { throw new IllegalArgumentException( "Invalid set of selection parameters given; must either both be -1 or both be >=0. o: " + offset + ", l: " + length); } int endOffset = offset + length; int startLine; int startLineOffset; try { startLine = document.getLineOfOffset(offset); startLineOffset = document.getLineOffset(startLine); } catch (BadLocationException e) { log.warn( "Could not calculate the start line or start line offset for the given start offset " + offset + " in the document " + document, e); return TextSelection.EMPTY_SELECTION; } int startInLineOffset = offset - startLineOffset; TextPosition startPosition = new TextPosition(startLine, startInLineOffset); if (endOffset == offset) { return new TextSelection(startPosition, startPosition); } int endLine; int endLineOffset; try { endLine = document.getLineOfOffset(endOffset); if (endLine == startLine) { endLineOffset = startLineOffset; } else { endLineOffset = document.getLineOffset(endLine); } } catch (BadLocationException e) { log.warn( "Could not calculate the end line or end line offset for the given end offset " + endOffset + " in the document " + document, e); return TextSelection.EMPTY_SELECTION; } int endInLineOffset = endOffset - endLineOffset; TextPosition endPosition = new TextPosition(endLine, endInLineOffset); return new TextSelection(startPosition, endPosition); }