Add an action to EditorPopupMenu when right clicking on a test method name?

Answered

I'm looking to add an action to the dynamic EditorPopupMenu when right-clicking on a test method name. Basically, I am trying to replicate the behavior that already exists in Android Studio when you right click on a method:

Any idea how to invoke this action when right clicking on a method name only? Also, only if that method is in a file that exists in the test sources?

I know I can modify visibility using onUpdate, and I think this is the way you determine if a file is in test sources:

ProjectFileIndex.SERVICE.getInstance(event.project).isInTestSourceContent(psiFile)

Thanks!

1 comment
Comment actions Permalink

Correct, com.intellij.openapi.actionSystem.AnAction#update should determine visibility of your AnAction.

Obtain current/containing PsiMethod via com.intellij.openapi.actionSystem.CommonDataKeys#PSI_ELEMENT

Assuming this is about JVM language, see com.intellij.codeInsight.TestFrameworks as convenient API to check given PsiMethod/Class etc.

0

Please sign in to leave a comment.