### Question:
TreeMetaDataProvider { public TreeMetaData metaData(TextRange textRange) { return new TreeMetaDataImpl(textRange); } TreeMetaDataProvider(List<Comment> comments, List<Token> tokens); List<Comment> allComments(); List<Token> allTokens(); int indexOfFirstToken(TextRange textRange); Optional<Token> firstToken(TextRange textRange); Optional<Token> previousToken(TextRange textRange); Optional<Token> previousToken(TextRange textRange, String expectedTokenValue); Optional<Token> previousToken(TextRange textRange, Predicate<Token> expectedConditionToMatch); void updateTokenType(Token token, Token.Type newType); Token keyword(TextRange textRange); TreeMetaData metaData(TextRange textRange); static final Comparator<HasTextRange> COMPARATOR; }### Answer:
@Test public void lines_of_code() { Token token1 = new TokenImpl(new TextRangeImpl(1, 3, 1, 6), "abc", Token.Type.OTHER); Token token2 = new TokenImpl(new TextRangeImpl(1, 9, 1, 12), "def", Token.Type.OTHER); Token token3 = new TokenImpl(new TextRangeImpl(2, 1, 2, 4), "abc", Token.Type.OTHER); Token token4 = new TokenImpl(new TextRangeImpl(4, 1, 6, 2), "ab\ncd\nef", Token.Type.OTHER); TreeMetaDataProvider provider = new TreeMetaDataProvider(emptyList(), Arrays.asList(token1, token2, token3, token4)); TreeMetaData metaData = provider.metaData(new TextRangeImpl(1, 1, 1, 20)); assertThat(metaData.linesOfCode()).containsExactly(1); assertThat(metaData.linesOfCode()).containsExactly(1); assertThat(metaData.textRange().toString()).isEqualTo("TextRange[1, 1, 1, 20]"); assertThat(provider.metaData(new TextRangeImpl(1, 1, 2, 20)).linesOfCode()).containsExactly(1, 2); assertThat(provider.metaData(new TextRangeImpl(1, 1, 3, 20)).linesOfCode()).containsExactly(1, 2); assertThat(provider.metaData(new TextRangeImpl(1, 1, 6, 20)).linesOfCode()).containsExactly(1, 2, 4, 5, 6); }