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

com.sksamuel.scapegoat.inspections.string.ArraysToString.scala Maven / Gradle / Ivy

package com.sksamuel.scapegoat.inspections.string

import com.sksamuel.scapegoat._

/**
 * @author Stephen Samuel
 */
class ArraysToString
    extends Inspection(
      text = "Use of Array.toString",
      defaultLevel = Levels.Warning,
      description = "Checks for explicit toString calls on arrays.",
      explanation = "Calling toString on an array does not perform a deep toString."
    ) {

  def inspector(context: InspectionContext): Inspector =
    new Inspector(context) {
      override def postTyperTraverser =
        new context.Traverser {

          import context.global._

          private val ToString = TermName("toString")

          override def inspect(tree: Tree): Unit = {
            tree match {
              case Apply(Select(lhs, ToString), Nil) if isArray(lhs) =>
                context.warn(tree.pos, self, tree.toString.take(500))
              case _ => continue(tree)
            }
          }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy