google-java-format
google-java-format copied to clipboard
IntelliJ plugin should sort imports in group alphabetically. But the plugin do not sort.
Google Java Style should sort imports in group alphabetically. But the plugin do not sort.
It is as follows in my IDEA:
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
It should be as follows:
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
I think, the IDEA plugin uses the Formatter.format() entry point, which does not optimize/fix (remove unused and sort) import statements. See #92 for further details.
Any update on this topic? I cannot find any call to Formatter.format() in the idea plugin source.
the command line version sorts import, why can't the Intellij plugin sort import as well?
Hi @plumpy any update on this?
I'd like to create a pull request for this.
Parsing the plugin source code lead to general questions about its architecture. The plugin was "revived" in 2016. Before 2016, the plugin was already extending com.intellij.psi.codeStyle.CodeStyleManager. IntelliJ default implementation of CodeStyleManager abstract class delegates to interfaces FormattingService and PostFormatProcessor.
According to the javadoc, those interfaces are more suited as extension points for formatting plugins. For example, when a plugin wants to provide an import formatting feature, it is expected to implement PostFormatProcessor.
I suppose FormattingService and PostFormatProcessor didn't exist at the time of plugin inception. Unless there is something I missed, wouldn't it make sense to start by restructuring the plugin to implement FormattingService instead of extending com.intellij.psi.codeStyle.CodeStyleManager ? Otherwise, could someone tell me why overriding CodeStyleManager is still the best way to do it?
#821 replaces CodeStyleManager "hack" with FormattingService implementation.
Version 1.16.0.0 includes an import optimizer to fix this issue.