Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort imports and remove unused imports #11

Closed
tbroyer opened this issue Apr 25, 2017 · 4 comments
Closed

Sort imports and remove unused imports #11

tbroyer opened this issue Apr 25, 2017 · 4 comments

Comments

@tbroyer
Copy link
Contributor

tbroyer commented Apr 25, 2017

The Formatter class won't sort imports or remove unused imports. This can be done using the ImportOrderer and RemoveUnusedImports classes respectively.

See google/google-java-format#96 which adds this as a default behavior in the Formatter class.

(note that java -jar google-java-format-1.3-all-deps.jar uses FormatFileCallable instead of directly calling the Formatter; FormatFileCallable sort and cleans up imports in addition to formatting the code; actually, this is probably what this plugin should use too)

tbroyer added a commit to tbroyer/jaxrs-utils that referenced this issue Apr 25, 2017
Note that fmt-maven-plugin doesn't look at imports
(see spotify/fmt-maven-plugin#11).

Files here have been formatted using:

    java -jar google-java-format-1.3-all-deps.jar -i \
        $(find . -name '*.java')

rather than 'mvn fmt:format'.
tbroyer added a commit to tbroyer/jaxrs-utils that referenced this issue Apr 25, 2017
Note that fmt-maven-plugin doesn't look at imports
(see spotify/fmt-maven-plugin#11).

Files here have been formatted using:

    java -jar google-java-format-1.3-all-deps.jar -i \
        $(find . -name '*.java')

rather than 'mvn fmt:format'.
tbroyer added a commit to tbroyer/jaxrs-utils that referenced this issue Apr 25, 2017
Note that fmt-maven-plugin doesn't look at imports
(see spotify/fmt-maven-plugin#11).

Files here have been formatted using:

    java -jar google-java-format-1.3-all-deps.jar -i \
        $(find . -name '*.java')

rather than 'mvn fmt:format'.
@jbduncan
Copy link

For Spotless, we effectively call the following lines one after another.

String source = ...;
String formatted = new Formatter().formatSource(...);
formatted = RemoveUnusedImports.removeUnusedImports(formatted);
formatted = ImportOrderer.reorderImports(formatted);

Using FormatFileCallable would be tricky if not impossible without reflection AFAICT, because it requires an instance of CommandLineOptions, which is a default-visibility class.

@jbduncan
Copy link

On a somewhat different note, I'm interested in seeing this issue resolved as well, as it would make implementing jrtom/jung#86 easier for us.

philipp-paland pushed a commit to philipp-paland/fmt-maven-plugin that referenced this issue Jul 5, 2017
pastjean added a commit that referenced this issue Jul 5, 2017
@pastjean
Copy link
Contributor

pastjean commented Jul 5, 2017

Fixed by #13

@pastjean pastjean closed this as completed Jul 5, 2017
@jbduncan
Copy link

jbduncan commented Jul 5, 2017

Great to see that this issue is resolved now. Thank you very much @pastjean and @therealppa. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants