@Test public void negative_offset() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Out of range offset: -1 for comment content (size: 12)"); lineNumber(node, -1); }
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();   }