Skip to content

Commit 50b2228

Browse files
authored
Merge pull request #1047 from reimai/stable-class-files
Make format generation idempotent
2 parents 59a9508 + 27c2a35 commit 50b2228

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

play-json/shared/src/main/scala-2/play/api/libs/json/JsMacroImpl.scala

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package play.api.libs.json
66

77
import scala.annotation.tailrec
8+
import scala.collection.mutable
89
import scala.reflect.macros.blackbox
910

1011
/**
@@ -555,25 +556,26 @@ class JsMacroImpl(val c: blackbox.Context) {
555556
val tpeSym = atag.tpe.typeSymbol.asClass
556557

557558
@tailrec
558-
def allSubclasses(path: List[Symbol], subclasses: Set[Type]): Set[Type] = path match {
559-
case (cls: ClassSymbol) :: tail if tpeSym != cls && cls.selfType.baseClasses.contains(tpeSym) => {
560-
if (cls.typeParams.nonEmpty)
561-
c.warning(c.enclosingPosition, s"cannot handle class ${cls.fullName}: type parameter not supported")
562-
val newSub = if (cls.typeParams.isEmpty) Set(cls.selfType) else Set.empty
563-
allSubclasses(tail, subclasses ++ newSub)
564-
}
559+
def allSubclasses(path: List[Symbol], subclasses: mutable.LinkedHashSet[Type]): mutable.LinkedHashSet[Type] =
560+
path match {
561+
case (cls: ClassSymbol) :: tail if tpeSym != cls && cls.selfType.baseClasses.contains(tpeSym) => {
562+
if (cls.typeParams.nonEmpty)
563+
c.warning(c.enclosingPosition, s"cannot handle class ${cls.fullName}: type parameter not supported")
564+
val newSub = if (cls.typeParams.isEmpty) Set(cls.selfType) else Set.empty
565+
allSubclasses(tail, subclasses ++ newSub)
566+
}
565567

566-
case (o: ModuleSymbol) :: tail
567-
if o.companion == NoSymbol // not a companion object
568-
&& o.typeSignature.baseClasses.contains(tpeSym) =>
569-
allSubclasses(tail, subclasses ++ Set(o.typeSignature))
568+
case (o: ModuleSymbol) :: tail
569+
if o.companion == NoSymbol // not a companion object
570+
&& o.typeSignature.baseClasses.contains(tpeSym) =>
571+
allSubclasses(tail, subclasses ++ Set(o.typeSignature))
570572

571-
case _ :: tail => allSubclasses(tail, subclasses)
572-
case _ => subclasses
573-
}
573+
case _ :: tail => allSubclasses(tail, subclasses)
574+
case _ => subclasses
575+
}
574576

575577
if (tpeSym.isSealed && tpeSym.isAbstract) {
576-
Some(allSubclasses(tpeSym.owner.typeSignature.decls.sorted, Set.empty).toList)
578+
Some(allSubclasses(tpeSym.owner.typeSignature.decls.sorted, mutable.LinkedHashSet[Type]()).toList)
577579
} else None
578580
}
579581

0 commit comments

Comments
 (0)