Skip to content

Commit 122ae35

Browse files
authored
make generated content consistent by ensuring the same order every time (#218)
1 parent 1e416e6 commit 122ae35

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

codegen/src/main/scala/overflowdb/codegen/CodeGen.scala

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,13 @@ class CodeGen(schema: Schema) {
447447
}.mkString(" ")
448448

449449
def abstractEdgeAccessors(nodeBaseType: NodeBaseType, direction: Direction.Value) = {
450-
nodeBaseType.edges(direction).groupBy(_.viaEdge).map { case (edge, neighbors) =>
450+
val edgeAndNeighbors = nodeBaseType
451+
.edges(direction)
452+
.groupBy(_.viaEdge)
453+
.toSeq
454+
.map { case (edge, neighors) => (edge, neighors.sortBy(_.neighbor.name)) }
455+
.sortBy { case (edge, _) => edge.name }
456+
edgeAndNeighbors.map { case (edge, neighbors) =>
451457
val edgeAccessorName = neighborAccessorNameForEdge(edge, direction)
452458
/** TODO bring this back, but not as direct accessors on the type, but via extension methods
453459
* context: in complex schema hierarchies, type inheritance between base nodes
@@ -590,7 +596,7 @@ class CodeGen(schema: Schema) {
590596
* assigning numbers here must follow the same way as in NodeLayoutInformation, i.e. starting at 0,
591597
* first assign ids to the outEdges based on their order in the list, and then the same for inEdges */
592598
var _currOffsetPos = -1
593-
def nextOffsetPos: Int = { _currOffsetPos += 1; _currOffsetPos }
599+
def nextOffsetPos(): Int = { _currOffsetPos += 1; _currOffsetPos }
594600

595601
case class AjacentNodeWithInheritanceStatus(adjacentNode: AdjacentNode, isInherited: Boolean)
596602

@@ -614,12 +620,19 @@ class CodeGen(schema: Schema) {
614620
}
615621

616622
def createNeighborInfos(neighborContexts: Seq[AjacentNodeWithInheritanceStatus], direction: Direction.Value): Seq[NeighborInfoForEdge] = {
617-
neighborContexts.groupBy(_.adjacentNode.viaEdge).map { case (edge, neighborContexts) =>
618-
val neighborInfoForNodes = neighborContexts.map { case AjacentNodeWithInheritanceStatus(adjacentNode, isInherited) =>
619-
NeighborInfoForNode(adjacentNode.neighbor, edge, direction, adjacentNode.cardinality, isInherited, adjacentNode.customStepName, adjacentNode.customStepDoc)
623+
neighborContexts
624+
.groupBy(_.adjacentNode.viaEdge)
625+
.toSeq
626+
.sortBy { case (edge, _) => edge.name }
627+
.map { case (edge, neighborContexts) =>
628+
val neighborInfoForNodes =
629+
neighborContexts
630+
.sortBy(_.adjacentNode.neighbor.name)
631+
.map { case AjacentNodeWithInheritanceStatus(adjacentNode, isInherited) =>
632+
NeighborInfoForNode(adjacentNode.neighbor, edge, direction, adjacentNode.cardinality, isInherited, adjacentNode.customStepName, adjacentNode.customStepDoc)
633+
}
634+
NeighborInfoForEdge(edge, neighborInfoForNodes, nextOffsetPos())
620635
}
621-
NeighborInfoForEdge(edge, neighborInfoForNodes, nextOffsetPos)
622-
}.toSeq
623636
}
624637

625638
val neighborOutInfos = createNeighborInfos(adjacentNodesWithInheritanceStatus(_.outEdges), Direction.OUT)
@@ -931,7 +944,7 @@ class CodeGen(schema: Schema) {
931944

932945
val neighborAccessorDelegators = neighborInfos.map { case (neighborInfo, direction) =>
933946
val edgeAccessorName = neighborAccessorNameForEdge(neighborInfo.edge, direction)
934-
val nodeDelegators = neighborInfo.nodeInfos.collect {
947+
val nodeDelegators = neighborInfo.nodeInfos.sortBy(_.neighborNode.name).collect {
935948
case neighborNodeInfo if !neighborNodeInfo.isInherited =>
936949
val accessorNameForNode = accessorName(neighborNodeInfo)
937950
s"""/** ${neighborNodeInfo.customStepDoc.getOrElse("")}

codegen/src/main/scala/overflowdb/schema/Schema.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ abstract class AbstractNodeType(val name: String, val comment: Option[String], v
6565
}
6666

6767
def extendz: Seq[NodeBaseType] =
68-
_extendz.toSeq
68+
_extendz.toSeq.sortBy(_.name)
6969

7070
def extendzRecursively: Seq[NodeBaseType] = {
7171
val results = Seq.newBuilder[NodeBaseType]

0 commit comments

Comments
 (0)