Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prerequisite changes to fix #3695 #3731

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name := "joern"
ThisBuild / organization := "io.joern"
ThisBuild / scalaVersion := "3.3.1"

val cpgVersion = "1.4.23"
val cpgVersion = "1.4.24"

lazy val joerncli = Projects.joerncli
lazy val querydb = Projects.querydb
Expand Down Expand Up @@ -64,7 +64,7 @@ ThisBuild / compile / javacOptions ++= Seq(
ThisBuild / scalacOptions ++= Seq(
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"--release",
"11",
"11"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid unrelated change

Suggested change
"11"
"11",

Copy link
Contributor Author

@pandurangpatil pandurangpatil Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is formatter change. It has removed the unwanted last ,

)

lazy val createDistribution = taskKey[File]("Create a complete Joern distribution")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.shiftleft.codepropertygraph.Cpg
import io.shiftleft.codepropertygraph.generated.nodes.StoredNode
import io.shiftleft.codepropertygraph.generated.{EdgeTypes, NodeTypes}
import io.shiftleft.passes.CpgPass
import io.shiftleft.semanticcpg.language._
import io.shiftleft.semanticcpg.language.*

class AstLinkerPass(cpg: Cpg) extends CpgPass(cpg) with LinkingUtil {

Expand All @@ -16,6 +16,9 @@ class AstLinkerPass(cpg: Cpg) extends CpgPass(cpg) with LinkingUtil {
cpg.typeDecl.whereNot(_.astParent).foreach { typeDecl =>
addAstParent(typeDecl, typeDecl.fullName, typeDecl.astParentType, typeDecl.astParentFullName, dstGraph)
}
cpg.member.whereNot(_.astParent).foreach { member =>
addAstParent(member, member.typeFullName, member.astParentType, member.astParentFullName, dstGraph)
pandurangpatil marked this conversation as resolved.
Show resolved Hide resolved
}
}

/** For the given method or type declaration, determine its parent in the AST via the AST_PARENT_TYPE and
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.joern.x2cpg.passes

import io.joern.x2cpg.layers.Base
import io.joern.x2cpg.passes.base.AstLinkerPass
import io.joern.x2cpg.{Ast, ValidationMode}
import io.shiftleft.codepropertygraph.generated.*
import io.shiftleft.codepropertygraph.generated.nodes.{NewCall, NewMember, NewTypeDecl}
import io.shiftleft.semanticcpg.language.*
import io.shiftleft.semanticcpg.layers.LayerCreatorContext
import io.shiftleft.semanticcpg.testing.MockCpg
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

class AstLinkerPassTest extends AnyWordSpec with Matchers {

"Check member node is child of TypeDecl node" in {
val cpg = MockCpg().withCustom { (graph, _) =>
implicit val withSchemaValidation: ValidationMode = ValidationMode.Disabled
val typeDecl = NewTypeDecl().name("Sample").fullName("namespace.Sample")
Ast.storeInDiffGraph(Ast(typeDecl), graph)
val memberNode = NewMember()
.name("test")
.typeFullName("String")
.astParentType(NodeTypes.TYPE_DECL)
.astParentFullName("namespace.Sample")
Ast.storeInDiffGraph(Ast(memberNode), graph)
}.cpg

val context = new LayerCreatorContext(cpg)
new Base().run(context)
val List(typeDecl) = cpg.typeDecl("Sample").l
val List(member) = typeDecl.member.l
member.typeFullName shouldBe "String"
member.name shouldBe "test"
}
}