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

io.shiftleft.semanticcpg.dotgenerator.AstGenerator.scala Maven / Gradle / Ivy

There is a newer version: 4.0.77
Show newest version
package io.shiftleft.semanticcpg.dotgenerator

import io.shiftleft.codepropertygraph.generated.EdgeTypes
import io.shiftleft.codepropertygraph.generated.nodes.{AstNode, MethodParameterOut}
import io.shiftleft.semanticcpg.dotgenerator.DotSerializer.{Edge, Graph}
import io.shiftleft.semanticcpg.language.*

class AstGenerator {

  private val edgeType = EdgeTypes.AST

  def generate(astRoot: AstNode): Graph = {
    def shouldBeDisplayed(v: AstNode): Boolean = !v.isInstanceOf[MethodParameterOut]
    val vertices                               = astRoot.ast.filter(shouldBeDisplayed).l
    val edges = vertices.flatMap(v =>
      v.astChildren.filter(shouldBeDisplayed).map { child =>
        Edge(v, child, edgeType = edgeType)
      }
    )
    Graph(vertices, edges)
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy