Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name := "codepropertygraph"

// parsed by project/Versions.scala, updated by updateDependencies.sh
val flatgraphVersion = "0.1.22"
val flatgraphVersion = "0.1.23"

inThisBuild(
List(
Expand Down
34 changes: 6 additions & 28 deletions codepropertygraph/src/main/scala/io/shiftleft/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,23 @@ package io.shiftleft
import org.slf4j.{Logger, LoggerFactory}

object Implicits {

private val logger: Logger = LoggerFactory.getLogger(Implicits.getClass)

implicit class IterableOnceDeco[T](val iterable: IterableOnce[T]) extends AnyVal {
@deprecated(
"please use `.loneElement` from flatgraph (mixed into the generated `language` packages) instead, which has a better name and will throw if the iterable has more than one element (rather than just log.warn)",
since = "1.7.42 (July 2025)"
)
def onlyChecked: T = {
if (iterable.iterator.hasNext) {
val res = iterable.iterator.next()
if (iterable.iterator.hasNext) {
logger.warn("iterator was expected to have exactly one element, but it actually has more")
}
res
} else { throw new NoSuchElementException() }
}
}

/** A wrapper around a Java iterator that throws a proper NoSuchElementException.
*
* Proper in this case means an exception with a stack trace. This is intended to be used as a replacement for next()
* on the iterators returned from TinkerPop since those are missing stack traces.
*/
implicit class JavaIteratorDeco[T](val iterator: java.util.Iterator[T]) extends AnyVal {
def nextChecked: T = {
try {
iterator.next
} catch {
case _: NoSuchElementException =>
throw new NoSuchElementException()
} else {
throw new NoSuchElementException()
}
}

def onlyChecked: T = {
if (iterator.hasNext) {
val res = iterator.next
if (iterator.hasNext) {
logger.warn("iterator was expected to have exactly one element, but it actually has more")
}
res
} else { throw new NoSuchElementException() }
}
}

}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.10.11
sbt.version=1.11.2