Skip to content

Commit

Permalink
Merge pull request #539 from olafurpg/prev
Browse files Browse the repository at this point in the history
Add docstring explaning next/prev special behavior.
  • Loading branch information
olafurpg authored Jan 4, 2018
2 parents 4b15fcd + 1c857f3 commit 9b24be3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions scalafix-core/shared/src/main/scala/scalafix/util/TokenList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ final class TokenList private (tokens: Tokens) {
def slice(from: Token, to: Token): Seq[Token] =
tokens.view(tok2idx(from), tok2idx(to))

/** Returns the next/trailing token or the original token if none exists.
*
* @note You need to guard against infinite recursion if iterating through
* a list of tokens using this method. This method does not fail
* with an exception.
*/
def next(token: Token): Token = {
tok2idx.get(token) match {
case Some(i) if tokens.length > i + 1 =>
Expand All @@ -40,6 +46,12 @@ final class TokenList private (tokens: Tokens) {
}
}

/** Returns the previous/leading token or the original token if none exists.
*
* @note You need to guard against infinite recursion if iterating through
* a list of tokens using this method. This method does not fail
* with an exception.
*/
def prev(token: Token): Token = {
tok2idx.get(token) match {
case Some(i) if i > 0 =>
Expand Down

0 comments on commit 9b24be3

Please sign in to comment.