All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wartremover.warts.ReverseFind.scala Maven / Gradle / Ivy

package org.wartremover
package warts

object ReverseFind extends WartTraverser {

  def apply(u: WartUniverse): u.Traverser = {
    import u.universe._
    val iterable = rootMirror.staticClass("scala.collection.Iterable").toTypeConstructor
    val function = rootMirror.staticClass("scala.Function1").toTypeConstructor
    new u.Traverser {
      override def traverse(tree: Tree): Unit = {
        tree match {
          case _ if hasWartAnnotation(u)(tree) =>
          case Apply(Select(Select(left, TermName("reverse")), TermName("find")), f1 :: Nil)
              if left.tpe.typeConstructor <:< iterable && f1.tpe.typeConstructor <:< function =>
            error(u)(tree.pos, "you can use findLast instead of reverse.find")
          case _ =>
            super.traverse(tree)
        }
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy