diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Node.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Node.kt index a2322d695f..bbef42e957 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Node.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Node.kt @@ -37,7 +37,7 @@ import de.fraunhofer.aisec.cpg.graph.declarations.RecordDeclaration import de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration import de.fraunhofer.aisec.cpg.graph.edges.ast.astEdgesOf import de.fraunhofer.aisec.cpg.graph.edges.flows.* -import de.fraunhofer.aisec.cpg.graph.edges.overlay.OverlaySingleEdge +import de.fraunhofer.aisec.cpg.graph.edges.overlay.* import de.fraunhofer.aisec.cpg.graph.edges.unwrapping import de.fraunhofer.aisec.cpg.graph.scopes.GlobalScope import de.fraunhofer.aisec.cpg.graph.scopes.RecordScope @@ -279,14 +279,9 @@ abstract class Node : val additionalProblems: MutableSet = mutableSetOf() @Relationship(value = "OVERLAY", direction = Relationship.Direction.OUTGOING) - val overlayNodeEdge: OverlaySingleEdge = - OverlaySingleEdge( - this, - of = null, - mirrorProperty = OverlayNode::underlyingNodeEdge, - outgoing = true - ) - var overlayNode by unwrapping(Node::overlayNodeEdge) + val overlayEdges: Overlays = + Overlays(this, mirrorProperty = OverlayNode::underlyingNodeEdge, outgoing = true) + var overlays by unwrapping(Node::overlayEdges) /** * If a node should be removed from the graph, just removing it from the AST is not enough (see diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/OverlayNode.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/OverlayNode.kt index c8cc0f888a..22a0ad2c3e 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/OverlayNode.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/OverlayNode.kt @@ -40,7 +40,7 @@ abstract class OverlayNode() : Node() { OverlaySingleEdge( this, of = null, - mirrorProperty = Node::overlayNodeEdge, + mirrorProperty = Node::overlayEdges, outgoing = false, ) var underlyingNode by unwrapping(OverlayNode::underlyingNodeEdge) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/overlay/Overlay.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/overlay/Overlay.kt index aa2d607720..1b39368ab2 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/overlay/Overlay.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/overlay/Overlay.kt @@ -27,6 +27,7 @@ package de.fraunhofer.aisec.cpg.graph.edges.overlay import de.fraunhofer.aisec.cpg.graph.Node import de.fraunhofer.aisec.cpg.graph.edges.Edge +import de.fraunhofer.aisec.cpg.graph.edges.collections.EdgeSet import de.fraunhofer.aisec.cpg.graph.edges.collections.EdgeSingletonList import de.fraunhofer.aisec.cpg.graph.edges.collections.MirroredEdgeCollection import kotlin.reflect.KProperty @@ -48,3 +49,11 @@ class OverlaySingleEdge( of = of, ), MirroredEdgeCollection + +class Overlays( + thisRef: Node, + override var mirrorProperty: KProperty>, + outgoing: Boolean, +) : + EdgeSet(thisRef = thisRef, init = ::OverlayEdge, outgoing = outgoing), + MirroredEdgeCollection diff --git a/cpg-neo4j/src/test/kotlin/de/fraunhofer/aisec/cpg_vis_neo4j/Neo4JTest.kt b/cpg-neo4j/src/test/kotlin/de/fraunhofer/aisec/cpg_vis_neo4j/Neo4JTest.kt index a623d5c1bc..40d64eb9c8 100644 --- a/cpg-neo4j/src/test/kotlin/de/fraunhofer/aisec/cpg_vis_neo4j/Neo4JTest.kt +++ b/cpg-neo4j/src/test/kotlin/de/fraunhofer/aisec/cpg_vis_neo4j/Neo4JTest.kt @@ -33,6 +33,7 @@ import java.math.BigInteger import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertIs +import kotlin.test.assertNotNull import org.junit.jupiter.api.Tag @Tag("integration") @@ -64,7 +65,11 @@ class Neo4JTest { fun testPushConcepts() { val (application, result) = createTranslationResult() + val tu = result.translationUnits.firstOrNull() + assertNotNull(tu) + val connectCall = result.calls["connect"] + assertNotNull(connectCall) abstract class NetworkingOperation( concept: Concept, @@ -72,15 +77,26 @@ class Neo4JTest { class Connect(concept: Concept) : NetworkingOperation(concept) class Networking() : Concept() + abstract class FileOperation( + concept: Concept, + ) : Operation(concept) + class FileHandling() : Concept() + val nw = Networking() - nw.underlyingNode = result.translationUnits.first() + nw.name = Name("Networking") + nw.underlyingNode = tu val connect = Connect(concept = nw) connect.underlyingNode = connectCall connect.name = Name("connect") nw.ops += connect - assertEquals(connect, connectCall?.overlayNode) + val f = FileHandling() + f.name = Name("FileHandling") + f.underlyingNode = tu + + assertEquals(setOf(connect), connectCall.overlays) + assertEquals(setOf(nw, f), tu.overlays) application.pushToNeo4j(result) }