Skip to content

Instantly share code, notes, and snippets.

@ysnrkdm
Created October 4, 2014 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysnrkdm/f949058d9039de56b121 to your computer and use it in GitHub Desktop.
Save ysnrkdm/f949058d9039de56b121 to your computer and use it in GitHub Desktop.
fun getResultFromScan(psiFile: PsiFile,
baseDir: VirtualFile,
file: VirtualFile): List<ErrorMessage> {
ApplicationManager.getApplication()!!.invokeAndWait(object : Runnable {
override fun run() {
FileDocumentManager.getInstance()!!.saveAllDocuments()
}
}, ModalityState.any())
val scan = psiFile.getProject().getComponent(javaClass<Scan>())!!
val absolutePath = file.getCanonicalPath()!!
val result = scan.runCommand(absolutePath)
val errors = ArrayList<ErrorMessage>()
for (resultLine in result) {
val matcher = Pattern.compile("(.*):(\\d*):(\\d*):(.*)").matcher(resultLine)
if (matcher.find()) {
val path = matcher.group(1)!!
val line = Integer.parseInt(matcher.group(2)!!)
val col = Integer.parseInt(matcher.group(3)!!)
val msg = matcher.group(4)!!.replace("\u0000", "\n")
val severity = ErrorMessage.Severity.Warning
if (absolutePath == path) {
errors.add(ErrorMessage(msg, path, severity, line, col, line, col))
}
}
}
return errors
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment