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

io.shiftleft.codepropertygraph.generated.traversals.TraversalImportBase.scala Maven / Gradle / Ivy

The newest version!
package io.shiftleft.codepropertygraph.generated.traversals

import io.shiftleft.codepropertygraph.generated.nodes
import io.shiftleft.codepropertygraph.generated.accessors.languagebootstrap.*

final class TraversalImportBase[NodeType <: nodes.ImportBase](val traversal: Iterator[NodeType]) extends AnyVal {

  /** Traverse to explicitAs property */
  def explicitAs: Iterator[Boolean] =
    traversal.flatMap(_.explicitAs)

  /** Traverse to nodes where the explicitAs equals the given `value`
    */
  def explicitAs(value: Boolean): Iterator[NodeType] =
    traversal.filter { node => node.explicitAs.isDefined && node.explicitAs.get == value }

  /** Traverse to importedAs property */
  def importedAs: Iterator[String] =
    traversal.flatMap(_.importedAs)

  /** Traverse to nodes where the importedAs matches the regular expression `value`
    */
  def importedAs(pattern: String): Iterator[NodeType] = {
    if (!flatgraph.misc.Regex.isRegex(pattern)) {
      importedAsExact(pattern)
    } else {
      val matcher = flatgraph.misc.Regex.multilineMatcher(pattern)
      traversal.filter { item =>
        val tmp = item.importedAs; tmp.isDefined && matcher.reset(tmp.get).matches
      }
    }
  }

  /** Traverse to nodes where the importedAs matches at least one of the regular expressions in `values`
    */
  def importedAs(patterns: String*): Iterator[NodeType] = {
    val matchers = patterns.map(flatgraph.misc.Regex.multilineMatcher)
    traversal.filter { item =>
      val tmp = item.importedAs; tmp.isDefined && matchers.exists { _.reset(tmp.get).matches }
    }
  }

  /** Traverse to nodes where importedAs matches `value` exactly.
    */
  def importedAsExact(value: String): Iterator[NodeType] = traversal match {
    case init: flatgraph.misc.InitNodeIterator[flatgraph.GNode @unchecked] if init.isVirgin && init.hasNext =>
      val someNode = init.next
      flatgraph.Accessors
        .getWithInverseIndex(someNode.graph, someNode.nodeKind, 24, value)
        .asInstanceOf[Iterator[NodeType]]
    case _ =>
      traversal.filter { node =>
        val tmp = node.importedAs; tmp.isDefined && tmp.get == value
      }
  }

  /** Traverse to nodes where importedAs matches one of the elements in `values` exactly.
    */
  def importedAsExact(values: String*): Iterator[NodeType] =
    if (values.length == 1) importedAsExact(values.head)
    else {
      val valueSet = values.toSet
      traversal.filter { item =>
        val tmp = item.importedAs; tmp.isDefined && valueSet.contains(tmp.get)
      }
    }

  /** Traverse to nodes where importedAs does not match the regular expression `value`.
    */
  def importedAsNot(pattern: String): Iterator[NodeType] = {
    if (!flatgraph.misc.Regex.isRegex(pattern)) {
      traversal.filter { node => node.importedAs.isEmpty || node.importedAs.get != pattern }
    } else {
      val matcher = flatgraph.misc.Regex.multilineMatcher(pattern)
      traversal.filterNot { item =>
        val tmp = item.importedAs; tmp.isDefined && matcher.reset(tmp.get).matches
      }
    }
  }

  /** Traverse to nodes where importedAs does not match any of the regular expressions in `values`.
    */
  def importedAsNot(patterns: String*): Iterator[NodeType] = {
    val matchers = patterns.map(flatgraph.misc.Regex.multilineMatcher)
    traversal.filterNot { item =>
      val tmp = item.importedAs; tmp.isDefined && matchers.exists { _.reset(tmp.get).matches }
    }
  }

  /** Traverse to importedEntity property */
  def importedEntity: Iterator[String] =
    traversal.flatMap(_.importedEntity)

  /** Traverse to nodes where the importedEntity matches the regular expression `value`
    */
  def importedEntity(pattern: String): Iterator[NodeType] = {
    if (!flatgraph.misc.Regex.isRegex(pattern)) {
      importedEntityExact(pattern)
    } else {
      val matcher = flatgraph.misc.Regex.multilineMatcher(pattern)
      traversal.filter { item =>
        val tmp = item.importedEntity; tmp.isDefined && matcher.reset(tmp.get).matches
      }
    }
  }

  /** Traverse to nodes where the importedEntity matches at least one of the regular expressions in `values`
    */
  def importedEntity(patterns: String*): Iterator[NodeType] = {
    val matchers = patterns.map(flatgraph.misc.Regex.multilineMatcher)
    traversal.filter { item =>
      val tmp = item.importedEntity; tmp.isDefined && matchers.exists { _.reset(tmp.get).matches }
    }
  }

  /** Traverse to nodes where importedEntity matches `value` exactly.
    */
  def importedEntityExact(value: String): Iterator[NodeType] = traversal match {
    case init: flatgraph.misc.InitNodeIterator[flatgraph.GNode @unchecked] if init.isVirgin && init.hasNext =>
      val someNode = init.next
      flatgraph.Accessors
        .getWithInverseIndex(someNode.graph, someNode.nodeKind, 25, value)
        .asInstanceOf[Iterator[NodeType]]
    case _ =>
      traversal.filter { node =>
        val tmp = node.importedEntity; tmp.isDefined && tmp.get == value
      }
  }

  /** Traverse to nodes where importedEntity matches one of the elements in `values` exactly.
    */
  def importedEntityExact(values: String*): Iterator[NodeType] =
    if (values.length == 1) importedEntityExact(values.head)
    else {
      val valueSet = values.toSet
      traversal.filter { item =>
        val tmp = item.importedEntity; tmp.isDefined && valueSet.contains(tmp.get)
      }
    }

  /** Traverse to nodes where importedEntity does not match the regular expression `value`.
    */
  def importedEntityNot(pattern: String): Iterator[NodeType] = {
    if (!flatgraph.misc.Regex.isRegex(pattern)) {
      traversal.filter { node => node.importedEntity.isEmpty || node.importedEntity.get != pattern }
    } else {
      val matcher = flatgraph.misc.Regex.multilineMatcher(pattern)
      traversal.filterNot { item =>
        val tmp = item.importedEntity; tmp.isDefined && matcher.reset(tmp.get).matches
      }
    }
  }

  /** Traverse to nodes where importedEntity does not match any of the regular expressions in `values`.
    */
  def importedEntityNot(patterns: String*): Iterator[NodeType] = {
    val matchers = patterns.map(flatgraph.misc.Regex.multilineMatcher)
    traversal.filterNot { item =>
      val tmp = item.importedEntity; tmp.isDefined && matchers.exists { _.reset(tmp.get).matches }
    }
  }

  /** Traverse to isExplicit property */
  def isExplicit: Iterator[Boolean] =
    traversal.flatMap(_.isExplicit)

  /** Traverse to nodes where the isExplicit equals the given `value`
    */
  def isExplicit(value: Boolean): Iterator[NodeType] =
    traversal.filter { node => node.isExplicit.isDefined && node.isExplicit.get == value }

  /** Traverse to isWildcard property */
  def isWildcard: Iterator[Boolean] =
    traversal.flatMap(_.isWildcard)

  /** Traverse to nodes where the isWildcard equals the given `value`
    */
  def isWildcard(value: Boolean): Iterator[NodeType] =
    traversal.filter { node => node.isWildcard.isDefined && node.isWildcard.get == value }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy