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

Plugin isn't organizing Java Imports (Google Java Code Formatter/Code Style Google) #215

Closed
jonathanpoulin9 opened this issue Jun 8, 2022 · 5 comments

Comments

@jonathanpoulin9
Copy link
Contributor

Bug

When Format is called on the code editor, the plugin isn't organizing the Java Imports statements when it's using the Google Java Code Formatter with the Code Style Google.

That's important in order to comply with the Google Java Style, for the 3.3 Import statements definition.

Workaround

Right now the NetBeans' Organize Imports functionality can be use for that, but must be configured according to the rules found in the link above.

Note

Additionally, perhaps an plugin option can be made available to determine if we want to organize Imports or not when reformatting files. It can be useful in some situations.

@funfried
Copy link
Owner

funfried commented Jun 8, 2022

@jonathanpoulin9

I'll have a(nother) look into this, but I'm not sure if I can add this functionality in the formatter as NetBeans separates formatting from organizing the imports. I'm just handling format requests, but reorganizing the imports is a completely different thing in NetBeans. But as said, I'll have a look and check what I can do, maybe there is a way of triggering the organize import action from the formatter or something like this.

@jonathanpoulin9
Copy link
Contributor Author

@funfried

Great! :) I understand that it is 2 things now. So is it the case for all the formatters, Google but Eclipse and etc as well?

If I have time, I'll take a look also. I have already a fork of your plugin.

@funfried
Copy link
Owner

@jonathanpoulin9

Yes, none of the formatters is organizing the imports right now and as said for NetBeans those are two different things and it also makes sense as the are no imports when formatting e.g. HTML.

@funfried funfried self-assigned this Jul 21, 2022
@funfried funfried added this to the 1.15.2 milestone Jul 21, 2022
@funfried
Copy link
Owner

I found actions to sort the imports inside some of the formatters and try to add that functionality. Actually, I already did implement that, but - as formatting and sorting the imports are two different things (at least for the NetBeans Editor) - I found no way to skip the On-Save-Sort-Imports-Action from NetBeans so far, I'll try to find a solution for that and if it is not possible, I'll show a warning to manually disable it if the import sorting is activated for an external formatter.

funfried added a commit that referenced this issue Aug 2, 2022
Added possibility to organize imports with Google and Palantir Formatter instead of NetBeans
funfried added a commit that referenced this issue Aug 2, 2022
Some cosmetics and JavaDoc improvements
@funfried
Copy link
Owner

funfried commented Aug 3, 2022

@jonathanpoulin9
This feature will be added in the next SNAPSHOT version and later in the 1.15.2 release, it took some time, but I finally got it to work. Unfortunately, it's not possible to sort the imports with the Eclipse Formatter as it seems to need some OSGi/Eclipse Equinox Runtime related stuff to initialize the related classes, but it can be used with the Google and Palantir Formatter.

@funfried funfried closed this as completed Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants