This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
It would be nice if the "Import management tool" and the "Fast import" tool could sort the import statements, so that imports to the same package appear next to each other. The package imports should also be "grouped": when an import to a different package starts, a blank line should be inserted. The threshold when a new "package" starts should be user configurable, so the user can define the package "level" (java.util would be 2 levels, javax.swing.border would 3 levels) on which the grouping should occur. Example: package level set to 2, the following import sorting should be generated. import java.sql.ResultSet; import java.sql.Statement; import java.util.HashMap; import java.util.Map; If the "threshold" was set to level 3 the above 4 lines would be "grouped" together without the blank line.
*** This issue has been marked as a duplicate of 19167 ***
Created attachment 5080 [details] Patch to make Fast Import insert new statements in Alphabetic order
I reopened this because the supposedly duplicate issue makes no reference to the Fast Import tool. Also, the patch I just submitted only fixes (to some degree) the Fast Import part of the issue. Note, the FI patch does not respect whitespace. It will always insert a new statement in the first correct alphabetic location, but it will not respect blank lines separating package groups. I'd love to know how to do that.
Created attachment 5151 [details] patch in jar form
Just drop the importPatch.jar in \netbeans\modules\patches\org-netbeans-modules- java\importPatch.jar
I'll try a little if I can make the code generator a little smarter with the blank separating lines...
Patch applied; I've added a little of code, which separates imports from different package by a blank line... but the package level is not configurable yet. Anyway, a simple level won't do, IMHO. Different libraries (with different package nesting depth) may reuqire different grouping. See in tomorrow dev-build. Thanks! /cvs/java/src/org/netbeans/modules/java/codegen/ImportB.java,v <-- ImportB.java new revision: 1.6; previous revision: 1.5 /cvs/java/src/org/netbeans/modules/java/model/ImportCollection.java,v <-- ImportCollection.java new revision: 1.10; previous revision: 1.9
VERIFIED
Resolved for 3.4.x or earlier, no new info since then -> closing.