Home > Software engineering >  Create full package path instead of one-by-one in IntelliJ
Create full package path instead of one-by-one in IntelliJ

Time:06-01

Background

Say you have a Java project, and you have a somewhat deep package structure. And one of the classes, under the src/java folder is

com.example.projectname.more.packages.Class

Now, I want to create a test for this class, so I have to create, under src/test, the class

com.example.projectname.more.packages.ClassTest

But I have to create the packages one by one, which can get tedious.

Question

Is there a way, either in IntelliJ, or by some other tool, to say "create the class with this package path, and auto-create whatever is missing along that path"?

For instance, it could be that I already have the com.example package in my test root, in which case it would detect this, and create the rest of the path.

CodePudding user response:

In IntellIJ, when you create a class, its packages will automatically be created.

Just right click the src/java directory, and go "New -> Java Class". Enter the package-qualified name of the new class, and all the missing packages will be created:

enter image description here

For example, assuming I don't have the folders a, b, c, d, e, this will create all of them, in addition to the file Foo.java.

  • Related