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

io.joern.x2cpg.utils.AstPropertiesUtil.scala Maven / Gradle / Ivy

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

import io.joern.x2cpg.Ast
import io.shiftleft.codepropertygraph.generated.PropertyNames

object AstPropertiesUtil {

  implicit class RootProperties(val ast: Ast) extends AnyVal {

    private def rootProperty(propertyName: String): Option[String] = {
      ast.root.flatMap(_.properties.get(propertyName).map(_.toString))
    }

    def rootType: Option[String] = rootProperty(PropertyNames.TYPE_FULL_NAME)

    def rootCode: Option[String] = rootProperty(PropertyNames.CODE)

    def rootName: Option[String] = rootProperty(PropertyNames.NAME)

    def rootCodeOrEmpty: String = rootCode.getOrElse("")

  }

  implicit class RootPropertiesOnSeq(val asts: Seq[Ast]) extends AnyVal {

    def rootType: Option[String] = asts.headOption.flatMap(_.rootType)

    def rootCode: Option[String] = asts.headOption.flatMap(_.rootCode)

    def rootName: Option[String] = asts.headOption.flatMap(_.rootName)

    def rootCodeOrEmpty: String = asts.rootCode.getOrElse("")
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy