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


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?


1 comment
Comment actions Permalink

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


Please sign in to leave a comment.