Skip to content

Commit

Permalink
use WithParamClauseGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k authored Apr 23, 2024
1 parent 8b2b04c commit 2d43104
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions rules/src/main/scala/fix/SameParamOverloading.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package fix

import scala.meta.Decl
import scala.meta.Defn
import scala.meta.Member
import scala.meta.Mod
import scala.meta.Stat
import scala.meta.Template
import scala.meta.Tree.WithParamClauseGroup
import scala.meta.XtensionClassifiable
import scala.meta.XtensionCollectionLikeUI
import scala.meta.XtensionStructure
Expand All @@ -17,11 +16,9 @@ import scalafix.v1.SyntacticRule
import scalafix.v1.XtensionSeqPatch

object SameParamOverloading {
private sealed abstract class Method extends Product with Serializable {
def value: Stat
def paramClauseGroups: List[Member.ParamClauseGroup]
private case class Method(value: WithParamClauseGroup) {
def noImplicitParams: Option[List[Method.Param]] =
paramClauseGroups.headOption.map(_.paramClauses).filter(!_.forall(_.mod.exists(_.is[Mod.Implicit]))).map { a =>
value.paramClauseGroup.map(_.paramClauses).filter(!_.forall(_.mod.exists(_.is[Mod.Implicit]))).map { a =>
a.flatMap(_.values).map { x =>
Method.Param(
paramType = x.decltpe.map(_.structure)
Expand All @@ -31,13 +28,6 @@ object SameParamOverloading {
}
private object Method {
case class Param(paramType: Option[String])

final case class Defn(value: scala.meta.Defn.Def) extends Method {
def paramClauseGroups = value.paramClauseGroups
}
final case class Decl(value: scala.meta.Decl.Def) extends Method {
def paramClauseGroups = value.paramClauseGroups
}
}
}

Expand All @@ -47,9 +37,9 @@ class SameParamOverloading extends SyntacticRule("SameParamOverloading") {
doc.tree.collect { case t: Template =>
val overloadMethods = t.stats.collect {
case a: Defn.Def =>
a.name -> Method.Defn(a)
a.name -> Method(a)
case a: Decl.Def =>
a.name -> Method.Decl(a)
a.name -> Method(a)
}.groupBy(a => (a._1.value, a._2.noImplicitParams)).values.map(_.map(_._2)).filter(_.size > 1)

overloadMethods.flatMap {
Expand Down

0 comments on commit 2d43104

Please sign in to comment.