@Test public void positive_offset() { assertThat(lineNumber(node, 4)).isEqualTo(1); assertThat(lineNumber(node, 6)).isEqualTo(2); assertThat(lineNumber(node, 8)).isEqualTo(3); assertThat(lineNumber(node, node.getCode().length())).isEqualTo(3); }
static int lineNumber(CommentNode node, int offset) { String content = node.getCode(); if (offset < 0 || offset > content.length()) { throw new IllegalArgumentException("Out of range offset: " + offset + " for comment content (size: " + content.length() + ")"); } int lineFeedCountBeforeOffset = (int) content.substring(0, offset).chars().filter(c -> c == '\n').count(); return node.getStartLinePosition() + lineFeedCountBeforeOffset; }
CommentUtils { static int lineNumber(CommentNode node, int offset) { String content = node.getCode(); if (offset < 0 || offset > content.length()) { throw new IllegalArgumentException("Out of range offset: " + offset + " for comment content (size: " + content.length() + ")"); } int lineFeedCountBeforeOffset = (int) content.substring(0, offset).chars().filter(c -> c == '\n').count(); return node.getStartLinePosition() + lineFeedCountBeforeOffset; } }
CommentUtils { static int lineNumber(CommentNode node, int offset) { String content = node.getCode(); if (offset < 0 || offset > content.length()) { throw new IllegalArgumentException("Out of range offset: " + offset + " for comment content (size: " + content.length() + ")"); } int lineFeedCountBeforeOffset = (int) content.substring(0, offset).chars().filter(c -> c == '\n').count(); return node.getStartLinePosition() + lineFeedCountBeforeOffset; } private  CommentUtils(); }
CommentUtils { static int lineNumber(CommentNode node, int offset) { String content = node.getCode(); if (offset < 0 || offset > content.length()) { throw new IllegalArgumentException("Out of range offset: " + offset + " for comment content (size: " + content.length() + ")"); } int lineFeedCountBeforeOffset = (int) content.substring(0, offset).chars().filter(c -> c == '\n').count(); return node.getStartLinePosition() + lineFeedCountBeforeOffset; } private  CommentUtils();  }
CommentUtils { static int lineNumber(CommentNode node, int offset) { String content = node.getCode(); if (offset < 0 || offset > content.length()) { throw new IllegalArgumentException("Out of range offset: " + offset + " for comment content (size: " + content.length() + ")"); } int lineFeedCountBeforeOffset = (int) content.substring(0, offset).chars().filter(c -> c == '\n').count(); return node.getStartLinePosition() + lineFeedCountBeforeOffset; } private  CommentUtils();   }