io.shiftleft.codepropertygraph.generated.traversal.Declaration.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of codepropertygraph-domain-classes_3 Show documentation
Show all versions of codepropertygraph-domain-classes_3 Show documentation
codepropertygraph-domain-classes
The newest version!
package io.shiftleft.codepropertygraph.generated.traversal
import overflowdb.traversal._
import io.shiftleft.codepropertygraph.generated.nodes._
/** Traversal steps for Declaration */
class DeclarationTraversalExtGen[NodeType <: Declaration](val traversal: Iterator[NodeType]) extends AnyVal {
/** Traverse to name property */
def name: Iterator[String] =
traversal.map(_.name)
/** Traverse to nodes where the name matches the regular expression `value`
*/
def name(pattern: String): Iterator[NodeType] = {
if (!Misc.isRegex(pattern)) {
nameExact(pattern)
} else {
overflowdb.traversal.filter.StringPropertyFilter.regexp(traversal)(_.name, pattern)
}
}
/** Traverse to nodes where the name matches at least one of the regular expressions in `values`
*/
def name(patterns: String*): Iterator[NodeType] =
overflowdb.traversal.filter.StringPropertyFilter.regexpMultiple(traversal)(_.name, patterns)
/** Traverse to nodes where name matches `value` exactly.
*/
def nameExact(value: String): Iterator[NodeType] = {
val fastResult = traversal match {
case init: overflowdb.traversal.InitialTraversal[NodeType] => init.getByIndex("NAME", value).getOrElse(null)
case _ => null
}
if (fastResult != null) fastResult
else traversal.filter { node => node.name == value }
}
/** Traverse to nodes where name matches one of the elements in `values` exactly.
*/
def nameExact(values: String*): Iterator[NodeType] = {
if (values.size == 1)
nameExact(values.head)
else
overflowdb.traversal.filter.StringPropertyFilter
.exactMultiple[NodeType, String](traversal, node => Some(node.name), values, "NAME")
}
/** Traverse to nodes where name does not match the regular expression `value`.
*/
def nameNot(pattern: String): Iterator[NodeType] = {
if (!Misc.isRegex(pattern)) {
traversal.filter { node => node.name != pattern }
} else {
overflowdb.traversal.filter.StringPropertyFilter.regexpNot(traversal)(_.name, pattern)
}
}
/** Traverse to nodes where name does not match any of the regular expressions in `values`.
*/
def nameNot(patterns: String*): Iterator[NodeType] = {
overflowdb.traversal.filter.StringPropertyFilter.regexpNotMultiple(traversal)(_.name, patterns)
}
}