Java Eclipse (ctrl+shift+f) 什么都不做
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24809536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse (ctrl+shift+f) does nothing
提问by Reggie
I made a new Java file in Gedit.
我在 Gedit 中创建了一个新的 Java 文件。
When I open it in Eclipse (CTRL+ SHIFT+ F), it does not format the code.
当我在Eclipse(打开CTRL+ SHIFT+ F),它不格式化代码。
(CTRL+ SHIFT+ F) still formats other Java files (which I also did not create in Eclipse), and it even formats individual lines of code in this particular file when I press (enter) at the beginning of a line.
( CTRL+ SHIFT+ F) 仍然格式化其他 Java 文件(我也没有在 Eclipse 中创建),当我在一行的开头按 (enter) 时,它甚至会格式化这个特定文件中的各个代码行。
It just will not format the entire file with (CTRL+ SHIFT+ F). I restored defaults in:
它只是不会用(CTRL+ SHIFT+ F)格式化整个文件。我恢复了默认值:
Window > Preferences > General > Keys
Window > Preferences > General > Keys
But still nothing. I have installed no plugins.
但还是什么都没有。我没有安装插件。
Any idea why Eclipse isn't recognizing the file as something that should be formatted when I use
CTRL+ SHIFT+ F?
Any idea why Eclipse isn't recognizing the file as something that should be formatted when I use
CTRL+ SHIFT+F?
回答by nitind
Eclipse can only format a Java file when it is in a Java Source Folder
of a Java Project
. It won't do random ones you just Open from the File menu.
当它在一个Java的Eclipse只能格式化的Java文件Source Folder
的Java Project
。它不会随机执行您从“文件”菜单中打开的操作。
回答by codewiz
I don't understand why it wouldn't format the code with CTRL+ SHIFT+ Fby try selecting the whole document with CTRL+ A) and then using CTRL+ Ito format the document. You may have the same problem though.
我不明白为什么它不会与格式化代码CTRL+ SHIFT+F通过尝试选择整个文档与CTRL+ A),然后使用CTRL+I的文档格式。你可能有同样的问题。
回答by Kacy
I had this exact same problem just now. The auto formatter seemed to not work for only a single file. I even deleted and recreated the file but no luck. I eventually decided to keep working and all of a sudden it worked again.
我刚才遇到了完全相同的问题。自动格式化程序似乎不适用于单个文件。我什至删除并重新创建了该文件,但没有运气。我最终决定继续工作,突然之间它又起作用了。
The problem was I had a syntax error (a random comma laying around) that the auto formatter did not know how to format. Fixing the syntax error allowed the auto formatter to do its thing again.
问题是我有一个语法错误(一个随机的逗号),自动格式化程序不知道如何格式化。修复语法错误允许自动格式化程序再次执行它的操作。
回答by Lee Duhem
I also encountered this problem. And I figured out the reason by luck.
我也遇到了这个问题。我靠运气找出了原因。
I am using IBus input method, and when IBus in Chinese mode, Ctrl+Shift+Fdoes not format Java source code in Eclipse Java project. When I changed IBus to English mode, that shortcut works just fine.
我使用下iBus输入法,并在中IBus中国模式,Ctrl+ Shift+F不格式化在Eclipse Java项目的Java源代码。当我将 IBus 更改为英语模式时,该快捷方式工作正常。
回答by Arash moradabadi
Check the followings:
检查以下各项:
- The chosen active formatter profile is exactly what you want(You can find it in Preferences->Java->Code Style->Formatter)
- The code lines which needs to format is selected correctly
- And the most important oneis not to have any syntax errorin the file which is formatting
- 所选的活动格式化程序配置文件正是您想要的(您可以在Preferences->Java->Code Style->Formatter 中找到它)
- 正确选择需要格式化的代码行
- 最重要的是在格式化的文件中没有任何语法错误
回答by sffc
Check for weird syntax in your file. In my case, I had a method with an underscore parameter name:
检查文件中的奇怪语法。就我而言,我有一个带有下划线参数名称的方法:
@Deprecated
public synchronized void setParseMaxDigits(int _) {}
I had to delete sections of my file until I pinpointed that this was the function causing SHIFT+CTRL+Fto not format the file. As soon as I changed the above method to,
我不得不删除我的文件的部分,直到我精确定位,这是导致功能SHIFT+ CTRL+F不格式化文件。一旦我将上述方法更改为,
@Deprecated
public synchronized void setParseMaxDigits(int unused) {}
then SHIFT+CTRL+Fstarted working again.
然后SHIFT+ CTRL+F又开始工作。
回答by henriquefalc
The following is the solution that worked for me:
以下是对我有用的解决方案:
In Window -> Preferences -> General -> Keys, look for all commands using the Ctrl+Shift+F shortcut. To do so, click on the Bindingcolumn, so the commands will be sorted by shortcut, then scroll down the grid.
在Window -> Preferences -> General -> Keys 中,使用 Ctrl+Shift+F 快捷键查找所有命令。为此,单击“绑定”列,命令将按快捷方式排序,然后向下滚动网格。
In my case, there was another command using this shortcut, that probably had higher priority than the format source command. So I just cleared the Bindingfield for it, and leave only the "Format" commands using Ctrl+Shift+F.
就我而言,还有另一个使用此快捷方式的命令,它的优先级可能高于格式源命令。所以我只是清除了它的绑定字段,只留下使用 Ctrl+Shift+F 的“格式”命令。