Auto guessing package name (for source folder) when adding a content root

Hello,

We have a custom project creation plugin and that sets contents roots and the package name. Our current logic of generating package name for source folders fails to guess the correct name in some cases. Since IntelliJ already parses Java files, is there a way of auto guessing the package name from a Java file and then setting the appropriate package name in content roots?

thanks
siddharth

1 comment
Comment actions Permalink

Sure. You can use PsiJavaFile.getPackageName() to get the package name declared in a .java file.

0

Please sign in to leave a comment.