-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11232 from BarkingBad/scala3doc/sealed-classes
Add sealed keyword to nodes in graphs"
- Loading branch information
Showing
34 changed files
with
99 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package tests | ||
package sealedClasses | ||
|
||
sealed trait A | ||
|
||
sealed trait B1 extends A | ||
case class B2(a: Int) extends A | ||
case object B3 extends A | ||
class B4 extends A | ||
object B4 extends A | ||
object B5 extends A | ||
case class B6(a: Int) extends A | ||
case object B6 extends A | ||
|
||
sealed trait C1 extends B1 | ||
case class C2(a: Int) extends B1 | ||
case object C3 extends B1 | ||
class C4 extends B1 | ||
object C4 extends B1 | ||
object C5 extends B1 | ||
case class C6(a: Int) extends B1 | ||
case object C6 extends B1 | ||
sealed trait C7 extends B1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ class S: | |
class R: | ||
def findThisDeclaration = 1 | ||
|
||
given R: A[B] with {} | ||
given R: A[B] with {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
scaladoc/src/dotty/tools/scaladoc/transformers/SealedMarksGraphTransformer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dotty.tools.scaladoc | ||
package transformers | ||
|
||
|
||
class SealedMarksGraphTransformer(using context: DocContext) extends (Module => Module): | ||
override def apply(original: Module): Module = | ||
val sealedRelations = getSealedRelations(original.rootPackage) | ||
original.updateMembers { m => | ||
m.copy(graph = m.graph.copy(sealedNodes = m.graph.vertecies.filter { v => | ||
sealedRelations.contains(v.dri) | ||
}.toSet)) | ||
} | ||
|
||
private def getSealedRelations(c: Member): Set[DRI] = | ||
val selfMapping = if c.modifiers.contains(Modifier.Sealed) then Set(c.dri) else Set.empty | ||
selfMapping ++ c.members.flatMap(getSealedRelations) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
scaladoc/test/dotty/tools/scaladoc/diagram/SealedHierarchyTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package dotty.tools.scaladoc | ||
package diagram | ||
|
||
import dotty.tools.scaladoc.ScaladocTest | ||
import scala.jdk.CollectionConverters.{ListHasAsScala, SeqHasAsJava} | ||
import org.junit.Assert.{assertSame, assertTrue, assertEquals} | ||
|
||
class SealedHierarchyTest extends ScaladocTest("sealedClasses"): | ||
override def runTest = withModule(_.visitMembers(checkMember)) | ||
|
||
def checkMember(x: Member) = x.name match | ||
case "A" => | ||
assertEquals(4, x.graph.sealedNodes.size) | ||
assertEquals( | ||
Set("A", "B1", "C1", "C7"), | ||
x.graph.sealedNodes.map(_.signature.getName) | ||
) | ||
case "B1" => | ||
assertEquals(4, x.graph.sealedNodes.size) | ||
assertEquals( | ||
Set("A", "B1", "C1", "C7"), | ||
x.graph.sealedNodes.map(_.signature.getName) | ||
) | ||
case "C1" => | ||
assertEquals(3, x.graph.sealedNodes.size) | ||
assertEquals( | ||
Set("A", "B1", "C1"), | ||
x.graph.sealedNodes.map(_.signature.getName) | ||
) | ||
case _ => |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.