How to get package name of the file on which an action has been performed?
Answered
I have an Action class that is triggered on rt click in the project tree or in the editor. I want to extract the java module and java package name for .java files from the AnActionEvent in this case. I cant seem to figure out how.
I have tired,
actionEvent.getDataContext() but that doesnt have the package name and module name
Please sign in to leave a comment.
Use
LangDataKeys.PSI_FILEto obtainPsiFile, when it’s a Java file you can obtain package name viacom.intellij.psi.PsiJavaFile#getPackageName.PlatformCoreDataKeys#MODULEforModule.Trying to get the base package for my project i.e. “com.android.example”. I've tried the above but it seems to just give the full directory for wherever I am for example: “com.android.example.account.a”.
I'm trying to get just the base package as I need it for my own template for specific imports in Fragments. I am also trying to use `actionEvent.getDataContext()`.
Thanks.
Sorry, your post is a bit unclear. What is “base package”? Please always share your code.