override fun extract()

in src/main/kotlin/com/github/mkartashev/hserr/miner/artifact/Threads.kt [76:104]


    override fun extract(log: HsErrLog): ThreadsArtifact {
        val javaThreadsSelection = log.start.moveToLineWith("Java Threads:").selectUpToFirstEmptyLine()
        val otherThreadsSelection = log.start.moveToLineWith("Other Threads:").selectUpToFirstEmptyLine()

        val locations = mutableSetOf<TextRange>()
        if (!javaThreadsSelection.isEmpty()) locations.add(javaThreadsSelection)
        if (!otherThreadsSelection.isEmpty()) locations.add(otherThreadsSelection)

        if (locations.isEmpty()) fail("Couldn't find any threads information")

        val threadsLocations = mutableListOf<TextRange>()
        var lineStart = javaThreadsSelection.start.moveToNextLine()
        while (lineStart.isValid() && !lineStart.isAtEnd()) {
            val fullLine = lineStart.selectUpToEOL()
            if (fullLine.toString().isBlank()) break
            threadsLocations.add(fullLine)
            lineStart = lineStart.moveToNextLine()
        }

        lineStart = otherThreadsSelection.start.moveToNextLine()
        while (lineStart.isValid() && !lineStart.isAtEnd()) {
            val fullLine = lineStart.selectUpToEOL()
            if (fullLine.toString().isBlank()) break
            threadsLocations.add(fullLine)
            lineStart = lineStart.moveToNextLine()
        }

        return ThreadsArtifact(log, locations, threadsLocations)
    }