All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.joern.x2cpg.passes.frontend.XImportsPass.scala Maven / Gradle / Ivy

There is a newer version: 4.0.131
Show newest version
package io.joern.x2cpg.passes.frontend

import io.joern.x2cpg.Imports.createImportNodeAndLink
import io.shiftleft.codepropertygraph.generated.Cpg
import io.shiftleft.codepropertygraph.generated.nodes.Call
import io.shiftleft.passes.ForkJoinParallelCpgPass
import io.shiftleft.semanticcpg.language.*
import io.shiftleft.semanticcpg.language.operatorextension.OpNodes.Assignment

abstract class XImportsPass(cpg: Cpg) extends ForkJoinParallelCpgPass[(Call, Assignment)](cpg) {

  protected val importCallName: String

  override def generateParts(): Array[(Call, Assignment)] = cpg
    .call(importCallName)
    .flatMap(importCallToPart)
    .toArray

  protected def importCallToPart(x: Call): Iterator[(Call, Assignment)]

  override def runOnPart(diffGraph: DiffGraphBuilder, part: (Call, Assignment)): Unit = {
    val (call, assignment) = part
    val importedEntity     = importedEntityFromCall(call)
    val importedAs         = assignment.target.code
    createImportNodeAndLink(importedEntity, importedAs, Some(call), diffGraph)
  }

  protected def importedEntityFromCall(call: Call): String

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy