Getting Eclipse Java Organize Imports to work with Google checkstyle

huangapple go评论73阅读模式
英文:

Getting Eclipse Java Organize Imports to work with Google checkstyle

问题

使用Ctrl+Shift+O快捷键来整理我的Java导入时,会在以不同根包开头的包之间插入空格。例如:

import java.util.Map;
import java.util.Set;

import work.enumeration.Generation;

这与Google的checkstyle不兼容,我想修复这个问题。我尝试过去窗口 > 首选项 > Java > 代码样式 > 格式化器 > 编辑 > 空白行 > 编译单元内的空白行 > 导入组之间,将其设置为0,但这没有修复“整理导入”操作。

所以我想知道如何解决这个问题。我还想设置“整理导入”在静态导入和常规导入之间插入一行。

英文:

So when I use the Ctrl+Shift+O shortcut to organize my Java imports it puts a space between packages that begin with a different root package. For example:

import java.util.Map;
import java.util.Set;

import work.enumeration.Generation;

This is incompatible with Google's checkstyle and I would like to fix this. I have tried going to Window > Preferences > Java > Code Style > Formatter > Edit > Blank Lines > Blank lines within compilation unit > Between import groups and setting it to 0, but this has not fixed the Organize Imports action.

So I'm wondering how I go about resolving this. I would also like to set up Organize Imports to put a line between static and regular imports.

答案1

得分: 4

正如@greg-449在评论中所说,将单个“*”导入组添加到“组织导入”首选项中,并删除现有的导入(java,javax,com,org),将消除包之间的单行间距。

正如我在以下评论中所说,将单个“*”静态导入组添加到“组织导入”首选项中,并将其放置在常规导入组之上,应该通过一行将静态导入和普通导入分开。

“组织导入”首选项位于窗口 > 首选项 > Java > 代码样式 > 组织导入

英文:

As @greg-449 said in a comment on the question, adding a single "*" import group in the Organize Imports preference and deleting the existing ones (java, javax, com, org) will eliminate the single line spaces between packages.

As I said in the following comment, adding a single "*" static import group in the Organize Imports preference and placing it above the regular import group should keep the static imports and imports separated by one line.

The Organize Imports preference can be found at Window > Preferences > Java > Code Style > Organize Imports.

huangapple
  • 本文由 发表于 2020年10月4日 08:30:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/64190170.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定