Skip to content

Commit

Permalink
more specific exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Valerii committed Jan 22, 2024
1 parent 8e4ab53 commit 35d0005
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindow
import com.intellij.openapi.wm.ToolWindowFactory
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiInvalidElementAccessException
import com.intellij.ui.components.JBPanel
import com.intellij.ui.components.JBScrollPane
import com.intellij.ui.table.JBTable
Expand Down Expand Up @@ -75,9 +76,21 @@ class PsiElementCounterPanelFactory : ToolWindowFactory {
psiFile?.let {
val results = mutableListOf<Array<String>>()

// Calculate class and function counts, catching exceptions
val classResult = try { countKtClasses(it).toString() } catch (e: Exception) { "Error" }
val functionResult = try { countKtFunctions(it).toString() } catch (e: Exception) { "Error" }
val classResult = try {
countKtClasses(it).toString()
} catch (e: PsiInvalidElementAccessException) {
"Invalid PSI Element"
} catch (e: NotImplementedError) {
"Not implemented"
}

val functionResult = try {
countKtFunctions(it).toString()
} catch (e: PsiInvalidElementAccessException) {
"Invalid PSI Element"
} catch (e: NotImplementedError) {
"Not implemented"
}

val classAuthorResult = authorCountKtClasses(it).toString()
val functionAuthorResult = authorCountKtFunctions(it).toString()
Expand Down

0 comments on commit 35d0005

Please sign in to comment.