Skip to content

Commit

Permalink
feat: check for a class or method/func in `KotlinPsiHelper.availableF…
Browse files Browse the repository at this point in the history
…orGeneration`
  • Loading branch information
Vladislav Artiukhov committed Oct 4, 2024
1 parent 1cd70d1 commit 3079173
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,19 @@ class KotlinPsiHelper(private val psiFile: PsiFile) : PsiHelper {

override val language: SupportedLanguage get() = SupportedLanguage.Kotlin

override fun availableForGeneration(e: AnActionEvent): Boolean = getCurrentListOfCodeTypes(e).isNotEmpty()
/**
* When dealing with Kotlin PSI files, we expect that only classes, their methods,
* top-level functions are tested.
* Therefore, we expect either a class or a method (top-level function) to surround a cursor offset.
*
* This requirement ensures that the user is not trying
* to generate tests for a line of code outside the aforementioned scopes.
*
* @param e `AnActionEvent` representing the current action event.
* @return `true` if the cursor is inside a class or method, `false` otherwise.
*/
override fun availableForGeneration(e: AnActionEvent): Boolean =
getCurrentListOfCodeTypes(e).any { (it.first == CodeType.CLASS) || (it.first == CodeType.METHOD) }

private val log = Logger.getInstance(this::class.java)

Expand Down

0 comments on commit 3079173

Please sign in to comment.