title: How to match calls to particular methods in Wart Remover?
body: <p>I am writing a Wart Remover plugin. I want to detect calls to certain methods that may return <code>null</code>, such as <code>System.getProperty</code>. However, all the ways I have tried to match them, have failed. Here is my latest attempt:</p>
  
  <pre><code>import org.brianmckenna.wartremover.{WartTraverser, WartUniverse}
  import scala.language.{implicitConversions,reflectiveCalls}
  
  object LegacyJavaAPIs extends WartTraverser {
  
    def apply(u: WartUniverse): u.Traverser = {
      import u.universe._
  
      @SuppressWarnings(Array("org.brianmckenna.wartremover.warts.AsInstanceOf",
        "com.example.wart.LegacyJavaAPIs"))
      val getProperty = reify(System.getProperty("x")).tree match {
        case Apply(a,b) =&gt; a.toString
      }
  
      new u.Traverser {
        override def traverse(tree: Tree): Unit = {
          if(tree.toString == getProperty)
            u.error(tree.pos,
              """|Do not use System.getProperty - it may return null.
                 |Use sys.props instead.""".stripMargin)
          else
            super.traverse(tree)
        }
      }
    }
  }
  </code></pre>
  
  <p>Most ways I have tried result in no error for the line that should have an error - although when I tried <code>.symbol</code> instead of <code>.toString</code>, top-level trees started matching everywhere. I'm guessing <code>.symbol</code> is <code>null</code> in these contexts...</p>
  
  <p>I also tried using <code>showRaw</code> and copying and pasting the relevant constructors out of that, but that didn't work because it wasn't valid Scala code - <code>java.lang</code> appeared as an identifier in the output of <code>showRaw</code>, instead of wrapped in whatever constructor it is actually wrapped in.</p>