@Test public void error_when_updating_token_type() { Token token1 = new TokenImpl(range(1, 1, 1, 3), "ab", Token.Type.OTHER); TreeMetaDataProvider provider = new TreeMetaDataProvider(emptyList(), Arrays.asList(token1)); Token tokenNotInMetaData1 = new TokenImpl(range(1, 0, 1, 3), "xyz", Token.Type.OTHER); assertThatThrownBy(() -> provider.updateTokenType(tokenNotInMetaData1, Token.Type.KEYWORD)) .hasMessage("token 'xyz' not found in metadata, TextRange[1, 0, 1, 3]"); Token tokenNotInMetaData2 = new TokenImpl(range(1, 20, 1, 23), "xyz", Token.Type.OTHER); assertThatThrownBy(() -> provider.updateTokenType(tokenNotInMetaData2, Token.Type.KEYWORD)) .hasMessage("token 'xyz' not found in metadata, TextRange[1, 20, 1, 23]"); }
public void updateTokenType(Token token, Token.Type newType) { int tokenIndex = indexOfFirstToken(token.textRange()); if (!isExistingToken(token, tokenIndex)) { throw new IllegalArgumentException("token '" + token.text() + "' not found in metadata, " + token.textRange()); } this.sortedTokens.set(tokenIndex, new TokenImpl(token.textRange(), token.text(), newType)); }
TreeMetaDataProvider { public void updateTokenType(Token token, Token.Type newType) { int tokenIndex = indexOfFirstToken(token.textRange()); if (!isExistingToken(token, tokenIndex)) { throw new IllegalArgumentException("token '" + token.text() + "' not found in metadata, " + token.textRange()); } this.sortedTokens.set(tokenIndex, new TokenImpl(token.textRange(), token.text(), newType)); } }
TreeMetaDataProvider { public void updateTokenType(Token token, Token.Type newType) { int tokenIndex = indexOfFirstToken(token.textRange()); if (!isExistingToken(token, tokenIndex)) { throw new IllegalArgumentException("token '" + token.text() + "' not found in metadata, " + token.textRange()); } this.sortedTokens.set(tokenIndex, new TokenImpl(token.textRange(), token.text(), newType)); } TreeMetaDataProvider(List<Comment> comments, List<Token> tokens); }
TreeMetaDataProvider { public void updateTokenType(Token token, Token.Type newType) { int tokenIndex = indexOfFirstToken(token.textRange()); if (!isExistingToken(token, tokenIndex)) { throw new IllegalArgumentException("token '" + token.text() + "' not found in metadata, " + token.textRange()); } this.sortedTokens.set(tokenIndex, new TokenImpl(token.textRange(), token.text(), newType)); } 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); }
TreeMetaDataProvider { public void updateTokenType(Token token, Token.Type newType) { int tokenIndex = indexOfFirstToken(token.textRange()); if (!isExistingToken(token, tokenIndex)) { throw new IllegalArgumentException("token '" + token.text() + "' not found in metadata, " + token.textRange()); } this.sortedTokens.set(tokenIndex, new TokenImpl(token.textRange(), token.text(), newType)); } 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; }