Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,13 @@ class DomainClassesGenerator(schema: Schema) {

case class NeighborContext(adjacentNode: AdjacentNode, scaladoc: String, defaultMethodName: String, customStepName: Option[String])
case class NeighborContextsByEdge(direction: Direction.Value, edge: EdgeType, neighborContexts: Seq[NeighborContext]) {
lazy val edgeAccessorName = camelCase(edge.name + "_" + direction)
lazy val edgeAccessorName = {
val namePart = edge.defaultAccessorName.getOrElse(edge.name)
camelCase(namePart + "_" + direction)
}

lazy val edgeAccessorNameOnRootType =
camelCase(edge.name + "_" + direction)

/** common root type across neighbors via this edge */
lazy val commonNeighborClassName =
Expand Down Expand Up @@ -1253,7 +1259,7 @@ class DomainClassesGenerator(schema: Schema) {
val stepImplementations = Seq.newBuilder[String]
neighborContextsByEdge.foreach { case context @ NeighborContextsByEdge(direction, edge, neighborContexts) =>
stepImplementations.addOne(
s"def ${context.edgeAccessorName}: Iterator[nodes.${context.commonNeighborClassName}] = node._${context.edgeAccessorName}.cast[nodes.${context.commonNeighborClassName}]"
s"def ${context.edgeAccessorName}: Iterator[nodes.${context.commonNeighborClassName}] = node._${context.edgeAccessorNameOnRootType}.cast[nodes.${context.commonNeighborClassName}]"
)

neighborContexts.foreach { case NeighborContext(adjacentNode, scaladoc, defaultMethodName, customStepName) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,23 @@ class EdgeType(val name: String, val comment: Option[String], val schemaInfo: Sc
extends HasClassName
with HasOptionalProtoId
with HasSchemaInfo {
protected var _property: Option[Property[?]] = None
protected var _property: Option[Property[?]] = None
protected var _defaultAccessorName: Option[String] = None

override def toString = s"EdgeType($name)"

def property: Option[Property[?]] = _property
def property: Option[Property[?]] = _property
def defaultAccessorName: Option[String] = _defaultAccessorName

def withProperty(property: Property[?]): this.type = {
_property = Option(property)
this
}

@deprecated("use `withProperty` instead, edges can only have one property max", since = "0.0.49")
def addProperty(property: Property[?]): this.type =
withProperty(property)
def withDefaultAccessorName(value: String): this.type = {
_defaultAccessorName = Option(value)
this
}
}

object EdgeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
public class EdgeTypes {


public static final String ANOTHER_EDGE = "another_edge";


public static final String CONNECTED_TO = "connected_to";

public static Set<String> ALL = new HashSet<String>() {{
add(ANOTHER_EDGE);
add(CONNECTED_TO);
}};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package testdomains.generic
import flatgraph.FormalQtyType

object GraphSchema extends flatgraph.Schema {
private val nodeLabels = IndexedSeq("node_a", "node_b")
val nodeKindByLabel = nodeLabels.zipWithIndex.toMap
val edgeLabels: Array[String] = Array("connected_to")
val edgeKindByLabel = edgeLabels.zipWithIndex.toMap
val edgePropertyAllocators: Array[Int => Array[?]] = Array(size => Array.fill(size)("<empty>") /* label = connected_to, id = 0 */ )
private val nodeLabels = IndexedSeq("node_a", "node_b")
val nodeKindByLabel = nodeLabels.zipWithIndex.toMap
val edgeLabels: Array[String] = Array("another_edge", "connected_to")
val edgeKindByLabel = edgeLabels.zipWithIndex.toMap
val edgePropertyAllocators: Array[Int => Array[?]] =
Array(size => null, size => Array.fill(size)("<empty>") /* label = connected_to, id = 1 */ )
val nodeFactories: Array[(flatgraph.Graph, Int) => nodes.StoredNode] =
Array((g, seq) => new nodes.NodeA(g, seq), (g, seq) => new nodes.NodeB(g, seq))
val edgeFactories: Array[(flatgraph.GNode, flatgraph.GNode, Int, Any) => flatgraph.Edge] =
Array((s, d, subseq, p) => new edges.ConnectedTo(s, d, subseq, p))
Array((s, d, subseq, p) => new edges.AnotherEdge(s, d, subseq, p), (s, d, subseq, p) => new edges.ConnectedTo(s, d, subseq, p))
val nodePropertyAllocators: Array[Int => Array[?]] = Array(
size => new Array[Int](size),
size => new Array[Int](size),
Expand Down Expand Up @@ -63,7 +64,7 @@ object GraphSchema extends flatgraph.Schema {
_newNodeInserters
}
override def getNumberOfNodeKinds: Int = 2
override def getNumberOfEdgeKinds: Int = 1
override def getNumberOfEdgeKinds: Int = 2
override def getNodeLabel(nodeKind: Int): String = nodeLabels(nodeKind)
override def getNodeKindByLabel(label: String): Int = nodeKindByLabel.getOrElse(label, flatgraph.Schema.UndefinedKind)
override def getEdgeLabel(nodeKind: Int, edgeKind: Int): String = edgeLabels(edgeKind)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package testdomains.generic.edges

object AnotherEdge {
val Label = "another_edge"

}

class AnotherEdge(src_4762: flatgraph.GNode, dst_4762: flatgraph.GNode, subSeq_4862: Int, property_4862: Any)
extends flatgraph.Edge(src_4762, dst_4762, 0, subSeq_4862, property_4862) {}

object ConnectedTo {
val Label = "connected_to"
val propertyName: Option[String] = Some("string_mandatory")
}

class ConnectedTo(src_4762: flatgraph.GNode, dst_4762: flatgraph.GNode, subSeq_4862: Int, property_4862: Any)
extends flatgraph.Edge(src_4762, dst_4762, 0, subSeq_4862, property_4862) {
extends flatgraph.Edge(src_4762, dst_4762, 1, subSeq_4862, property_4862) {
override def propertyName: Option[String] = ConnectedTo.propertyName
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ final class AccessNeighborsForNodeA(val node: nodes.NodeA) extends AnyVal {
*/
def _nodeAViaConnectedToIn: Iterator[nodes.NodeA] = connectedToIn.collectAll[nodes.NodeA]

/** Traverse to node_b via another_edge OUT edge.
*/
def _nodeBViaAnotherEdgeOut: Iterator[nodes.NodeB] = defaultStepNameOut.collectAll[nodes.NodeB]

/** Connected neighbor node Traverse to node_a via connected_to OUT edge.
*/
@deprecated("please use connectedTo instead")
Expand All @@ -21,6 +25,8 @@ final class AccessNeighborsForNodeA(val node: nodes.NodeA) extends AnyVal {
def connectedToIn: Iterator[nodes.NodeA] = node._connectedToIn.cast[nodes.NodeA]

def connectedToOut: Iterator[nodes.NodeA] = node._connectedToOut.cast[nodes.NodeA]

def defaultStepNameOut: Iterator[nodes.NodeB] = node._anotherEdgeOut.cast[nodes.NodeB]
}

final class AccessNeighborsForNodeATraversal(val traversal: Iterator[nodes.NodeA]) extends AnyVal {
Expand All @@ -29,6 +35,10 @@ final class AccessNeighborsForNodeATraversal(val traversal: Iterator[nodes.NodeA
*/
def _nodeAViaConnectedToIn: Iterator[nodes.NodeA] = traversal.flatMap(_._nodeAViaConnectedToIn)

/** Traverse to node_b via another_edge OUT edge.
*/
def _nodeBViaAnotherEdgeOut: Iterator[nodes.NodeB] = traversal.flatMap(_._nodeBViaAnotherEdgeOut)

/** Connected neighbor node Traverse to node_a via connected_to OUT edge.
*/
def connectedTo: Iterator[nodes.NodeA] = traversal.flatMap(_.connectedTo)
Expand All @@ -41,4 +51,6 @@ final class AccessNeighborsForNodeATraversal(val traversal: Iterator[nodes.NodeA
def connectedToIn: Iterator[nodes.NodeA] = traversal.flatMap(_.connectedToIn)

def connectedToOut: Iterator[nodes.NodeA] = traversal.flatMap(_.connectedToOut)

def defaultStepNameOut: Iterator[nodes.NodeB] = traversal.flatMap(_.defaultStepNameOut)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package testdomains.generic.neighboraccessors

import testdomains.generic.nodes
import testdomains.generic.language.*

final class AccessNeighborsForNodeB(val node: nodes.NodeB) extends AnyVal {

/** Traverse to node_a via another_edge IN edge.
*/
def _nodeAViaAnotherEdgeIn: Iterator[nodes.NodeA] = defaultStepNameIn.collectAll[nodes.NodeA]

def defaultStepNameIn: Iterator[nodes.NodeA] = node._anotherEdgeIn.cast[nodes.NodeA]
}

final class AccessNeighborsForNodeBTraversal(val traversal: Iterator[nodes.NodeB]) extends AnyVal {

/** Traverse to node_a via another_edge IN edge.
*/
def _nodeAViaAnotherEdgeIn: Iterator[nodes.NodeA] = traversal.flatMap(_._nodeAViaAnotherEdgeIn)

def defaultStepNameIn: Iterator[nodes.NodeA] = traversal.flatMap(_.defaultStepNameIn)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@ package object neighboraccessors {

implicit def accessNeighborsForNodeATraversal(traversal: IterableOnce[nodes.NodeA]): AccessNeighborsForNodeATraversal =
new AccessNeighborsForNodeATraversal(traversal.iterator)

implicit def accessNeighborsForNodeB(node: nodes.NodeB): AccessNeighborsForNodeB =
new AccessNeighborsForNodeB(node)

implicit def accessNeighborsForNodeBTraversal(traversal: IterableOnce[nodes.NodeB]): AccessNeighborsForNodeBTraversal =
new AccessNeighborsForNodeBTraversal(traversal.iterator)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scala.collection.mutable

object NewNodeA {
def apply(): NewNodeA = new NewNodeA
private val outNeighbors: Map[String, Set[String]] = Map("connected_to" -> Set("node_a"))
private val outNeighbors: Map[String, Set[String]] = Map("another_edge" -> Set("node_b"), "connected_to" -> Set("node_a"))
private val inNeighbors: Map[String, Set[String]] = Map("connected_to" -> Set("node_a"))

object InsertionHelpers {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import scala.collection.mutable
object NewNodeB {
def apply(): NewNodeB = new NewNodeB
private val outNeighbors: Map[String, Set[String]] = Map()
private val inNeighbors: Map[String, Set[String]] = Map()
private val inNeighbors: Map[String, Set[String]] = Map("another_edge" -> Set("node_a"))

object InsertionHelpers {
object NewNodeInserter_NodeB_stringOptional extends flatgraph.NewNodePropertyInsertionHelper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,28 @@ abstract class StoredNode(graph_4762: flatgraph.Graph, kind_4762: Short, seq_476
extends flatgraph.GNode(graph_4762, kind_4762, seq_4762)
with AbstractNode {

final def _connectedToOut: Iterator[StoredNode] = {
final def _anotherEdgeOut: Iterator[StoredNode] = {
flatgraph.Accessors
.getNeighborsOut(this.graph, nodeKind = this.nodeKind, seq = this.seq, edgeKind = 0)
.asInstanceOf[Iterator[StoredNode]]
}
final def _connectedToIn: Iterator[StoredNode] = {
final def _anotherEdgeIn: Iterator[StoredNode] = {
flatgraph.Accessors
.getNeighborsIn(this.graph, nodeKind = this.nodeKind, seq = this.seq, edgeKind = 0)
.asInstanceOf[Iterator[StoredNode]]
}

final def _connectedToOut: Iterator[StoredNode] = {
flatgraph.Accessors
.getNeighborsOut(this.graph, nodeKind = this.nodeKind, seq = this.seq, edgeKind = 1)
.asInstanceOf[Iterator[StoredNode]]
}
final def _connectedToIn: Iterator[StoredNode] = {
flatgraph.Accessors
.getNeighborsIn(this.graph, nodeKind = this.nodeKind, seq = this.seq, edgeKind = 1)
.asInstanceOf[Iterator[StoredNode]]
}

}

abstract class NewNode(val nodeKind: Short) extends AbstractNode with flatgraph.DNode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package testdomains.generic.nodes

extension (iterator: Iterator[StoredNode]) {

final def _anotherEdgeOut: Iterator[StoredNode] = iterator.flatMap(_._anotherEdgeOut)
final def _anotherEdgeIn: Iterator[StoredNode] = iterator.flatMap(_._anotherEdgeIn)

final def _connectedToOut: Iterator[StoredNode] = iterator.flatMap(_._connectedToOut)
final def _connectedToIn: Iterator[StoredNode] = iterator.flatMap(_._connectedToIn)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ object Generic {
val connectedTo = builder.addEdgeType("connected_to").withProperty(stringMandatory)
nodeA.addOutEdge(connectedTo, nodeA, stepNameOut = "connectedTo", stepNameOutDoc = "Connected neighbor node")

val anotherEdge = builder.addEdgeType("another_edge").withDefaultAccessorName("default_step_name")
nodeA.addOutEdge(anotherEdge, nodeB)

builder.build
}
}