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

fix.AddLambdaParamParentheses.scala Maven / Gradle / Ivy

The newest version!
package fix

import scala.meta.Term
import scala.meta.Token
import scala.meta.XtensionClassifiable
import scala.meta.XtensionCollectionLikeUI
import scalafix.Patch
import scalafix.v1.SyntacticDocument
import scalafix.v1.SyntacticRule
import scalafix.v1.XtensionSeqPatch

class AddLambdaParamParentheses extends SyntacticRule("AddLambdaParamParentheses") {
  override def fix(implicit doc: SyntacticDocument): Patch = {
    doc.tree.collect {
      case t1 @ Term.ParamClause(param :: Nil, _) if param.decltpe.nonEmpty && param.mods.isEmpty =>
        if (t1.tokens.find(_.is[Token.LeftParen]).exists(_.pos.start <= param.pos.start)) {
          Patch.empty
        } else {
          Seq(
            Patch.addLeft(param, "("),
            Patch.addRight(param, ")")
          ).asPatch
        }
    }.asPatch
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy