-
Notifications
You must be signed in to change notification settings - Fork 2
Normalizing Imports
Import processing orders imports, removes unused imports, expands wildcards when the required types are available, and shortens unambiguous qualified type names by adding imports.
For example:
import java.util.*;
class Example {
java.time.Duration timeout;
List<String> names;
}becomes:
import java.time.Duration;
import java.util.List;
class Example {
Duration timeout;
List<String> names;
}Type names are resolved with javac before making these changes. This prevents an import from being added when it conflicts with another declaration or import. Pass related source files in the same invocation so their declarations are available to one another:
jfmt dependency/Widget.java application/Example.javaUse the same class path or module path as the build so referenced types can be resolved:
jfmt --class-path build/classes application/Example.java
jfmt --module-path modules --module-source-path srcOther javac options that affect type resolution are also supported. Run jfmt --help for the complete list.
Method bodies are not compiled as part of type resolution. A missing type needed to resolve a declaration causes the command to fail before changing any files, but unrelated errors inside method bodies do not prevent formatting.
If the requirements of a named module are unavailable on the supplied module path, the module is still formatted, but its wildcard imports and qualified type names are left unchanged. Other modules whose requirements are available still receive type-aware import normalization.