Reputation: 523
I made a new Java file in Gedit.
When I open it in Eclipse (CTRL + SHIFT + F), it does not format the code.
(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.
It just will not format the entire file with (CTRL + SHIFT + F). I restored defaults in:
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?
Upvotes: 5
Views: 17947
Reputation: 13496
My solution:
I had to right-click the project -> Properties -> Java Code Style -> Formatter. The Active profile said "Unmanaged project from ..." (I can't recall the exact wording because it's gone now ha). I changed that to the formatter I wanted and now it works.
Upvotes: 0
Reputation: 421
Lee Duhem's answer let me realize where the issue is.The key CTRL + SHIFT + F
may be conflicted by other apps,in my case,it's language input method.
System: Windows 10
Upvotes: 0
Reputation: 1
This is an issue caused by the Razer Cortex application. Its keybind for enabling/disabling its in-game FPS monitor is the same as Eclipse's keybind for formatting a highlighted block of code (Ctrl + Shift + F). This program takes precedence over Eclipse in that regard.
Circumventing this issue is extremely simple:
Your formatting keybind will work in Eclipse now :)
Upvotes: 0
Reputation: 361
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 Binding column, so the commands will be sorted by shortcut, then scroll down the grid.
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 Binding field for it, and leave only the "Format" commands using Ctrl+Shift+F.
Upvotes: 0
Reputation: 196
I don't understand why it wouldn't format the code with CTRL + SHIFT + F by try selecting the whole document with CTRL + A) and then using CTRL + I to format the document. You may have the same problem though.
Upvotes: 4
Reputation: 6424
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+F to not format the file. As soon as I changed the above method to,
@Deprecated
public synchronized void setParseMaxDigits(int unused) {}
then SHIFT+CTRL+F started working again.
Upvotes: 1
Reputation: 365
Check the followings:
Upvotes: 1
Reputation: 15121
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+F does not format Java source code in Eclipse Java project. When I changed IBus to English mode, that shortcut works just fine.
Upvotes: 2
Reputation: 3430
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.
Upvotes: 0
Reputation: 20013
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.
Upvotes: 0