user967491
user967491

Reputation: 121

Eclipse formatter behaving insane to me

I am facing a very stupid problem lately. I was working on a project and there is a particular file I was editing. In the beginning my eclipse formatter was working. But now its not working. If I open some other file from the same project, it works there, but for this particular file it does not work. Is there any key strokes that I have pressed which has made eclipse turned off? How can I get the formatter back for my file? Please help. This problem is driving me crazy..

I am working on Java file. All other things are working on it like warnings, errors. Its just that I was editing my code in the file, initially my formatter was working. And then I made more changes and pressed Ctrl+Shift+F, it dint work. its not working since then for me on that file. its working fine on other files of same project. also if I copy my code and paste in other file of same project and do Ctrl+Shift+F it does not work there as well, so I am guessing that may be I accidentally pressed some short-cut to turn off eclipse on that code. How can I restore that?

Upvotes: 3

Views: 2218

Answers (2)

Stephan Branczyk
Stephan Branczyk

Reputation: 9375

It can't be a shortcut, since you've replicated the same issue with the same content in another file. Look for a misplaced curly brace { or /**

Also, the static analyzer findbugs may be able to pinpoint this issue. You can use the Java applet first to see if it will catch it, but then I recommend you install its Eclipse plugin so that findbugs is always available to you.

It's located here: http://findbugs.sourceforge.net/demo.html

Just click on the link located in the first paragraph: run findbugs That will download a findbugs.jnlp file, then you just need to double-click on that file to run the applet (since you obviously already have Java on your computer).

Upvotes: 0

mliebelt
mliebelt

Reputation: 15525

As you told some of the following things are not the case:

  • Formatting is done on the whole file or section, and there is no shortcut to stop that.
  • The shortcut is in place and is working. If your are unsure about that, press twice CTRL-SHIFT-L to get the preferences for keyboard shortcuts, and search there for formatting.

So the reason should be the code itself. What the formatter has to do is the following:

  • Parse the code partially, so that an AST (abstract syntax tree) can be deduced.
  • Reformat the code by using the AST.

If the formatter has no chance to get an AST, it will just abort. Make a short experiment to see if that is the reason:

  1. Take the top of the file without any errors or warnings in it. Move the rest of the file to another editor (perhaps outside eclipse).
  2. See if the formatter is working now.
  3. If yes, take one more methods from your tmp editor and move it to the open file, and repeat the step 2.
  4. Stop when the formatter is not working any more. The reason should be in the code you have just added. Look at the errors and warnings, and try to fix them.

I cannot think of any other reason, so I wanted to try that answer. Hope it helps :-)

Upvotes: 3

Related Questions