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

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

There is a newer version: 3.2.1
Show newest version
package org.wartremover
package warts

object GetOrElseNull extends WartTraverser {

  def apply(u: WartUniverse): u.Traverser = {
    import u.universe._
    val opt = rootMirror.staticClass("scala.Option").toTypeConstructor
    new u.Traverser {
      override def traverse(tree: Tree): Unit = {
        tree match {
          case _ if hasWartAnnotation(u)(tree) =>
          case Apply(
                TypeApply(
                  Select(left, TermName("getOrElse")),
                  _ :: Nil
                ),
                Literal(Constant(null)) :: Nil
              ) if left.tpe.typeConstructor <:< opt =>
            error(u)(tree.pos, "you can use orNull instead of getOrElse(null)")
          case _ =>
            super.traverse(tree)
        }
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy