image provider

Import Tidier


Disclaimer

This essay does not describe an existing computer program, just one that should exist. This essay is about a suggested student project in Java programming. This essay gives a rough overview of how it might work. I have no source, object, specifications, file layouts or anything else useful to implementing this project. Everything I have prepared to help you is right here.

This project outline is not like the artificial, tidy little problems you are spoon-fed in school, when all the facts you need are included, nothing extraneous is mentioned, the answer is fully specified, along with hints to nudge you toward a single expected canonical solution. This project is much more like the real world of messy problems where it is up to you to fully the define the end point, or a series of ever more difficult versions of this project and research the information yourself to solve them.

Everything I have to say to help you with this project is written below. I am not prepared to help you implement it; or give you any additional materials. I have too many other projects of my own.

Though I am a programmer by profession, I don’t do people’s homework for them. That just robs them of an education.

You have my full permission to implement this project in any way you please and to keep all the profits from your endeavour.

Please do not email me about this project without reading the disclaimer above.

This project is no longer much of a priority now that Eclipse and Intellij both do an excellent job of import tidying.

There are two questions a maintenance programmer commonly asks:

  1. What classes does this defined class use?
  2. What package is this referenced class in?
Java’s import gives only rough clues because:
  1. Some classes may be used in fully qualified form in the code bodies, hence don’t need to be mentioned in the import. You can’t tell from looking at the import statements all the classes used.
  2. Imports don’t need to mention java.lang classes.
  3. Imports can contain packages and classes never used.
  4. Imports can contain wildcards without ever mentioning the specific classes used.
Further, programmers like to have rwars or just how imports and qualification should be organised.

When I am maintaining other people’s programs, I prefer explicit imports rather than wildcard import on demand. Further, I prefer all variable declarations to be fully qualified in the code body. When I am writing new code, I prefer to use wildcard imports, and unqualified declarations. This makes it easy to use new classes in my code. It takes fewer keystrokes. Others wildly disagree. It would be nice if there were some automatic way to convert my new code style to my maintenance style and back.

These problems could be rectified by a tool that tidied the Java source code to do the following things:

  1. List the fully qualified imports for each class used.
  2. List them in alphabetical order.
  3. Optionally include or exclude java.lang classes.
  4. Optionally remove any imports not used.
  5. Optionally remove any wildcard imports.
  6. Optionally remove individual imports where there is a wildcard covering them.
  7. Optionally list imports in wildcard form for packages with n or more classes, where n is an integer > 1,
  8. Optionally convert to fully qualified class names in the source code bodies.
  9. Optionally convert to unqualified class names in the source code bodies.
You might think you would have to parse the Java source code with a miniature compiler to handle this project. There is an easier way to tackle it, however, it requires a clean compile first. You look in the class file to get the list of fully qualified class names and regenerate the needed import list from that, ignoring what the programmer originally used as imports.
decompiler
disassembler
JASM
There is a catch, the class file does not list the classes of finals. You will have to find these yourself.

This page is posted
on the web at:

http://mindprod.com/project/importtidier.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\project\importtidier.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[18.227.190.231]
You are visitor number