srinannapa
srinannapa

Reputation: 3207

Warning in eclipse for code formatting

Is there an option for Eclipse to issue a warning when code formatting does not match the current settings?

Also, how to can I find the best standards for formatting Java code?

Upvotes: 1

Views: 1923

Answers (6)

Janfy
Janfy

Reputation: 2786

You can also setup eclipse to automatically format your code when saving files:

Window > Preferences > Java > Editor > Save Actions

Check Perform the selected actions on save, then check Format source code and choose to format all lines, or edited lines

Upvotes: 1

TrueDub
TrueDub

Reputation: 5070

Something like Checkstyle should suit your needs - you can configure the rules if required.

Upvotes: 1

Ted Hopp
Ted Hopp

Reputation: 234857

You might take a look at the HTML Tidy Plug-in. Normally, Eclipse only displays compiler warnings and errors, and the compiler couldn't care less about style. However, you can set certain style warnings under Windows -> Preferences -> Java -> Compiler -> Errors/Warnings.

As far as guidelines go, there's this fairly comprehensive one published many years ago by Sun.

Upvotes: 0

muddybruin
muddybruin

Reputation: 845

I'm not sure that it'll show a warning. However, Eclipse can automatically format your code for you. You can select all using Ctrl+A, then hit Ctrl+Shift+F to auto-format your code.

Also, to see the Java conventions, you can go to Window, Preferences, Java, Code Style, Formatter. Then, under Active Profile, select "Java Conventions," which I think is the same as "Eclipse (built-in)". You can see a short example of what properly-formatted code should look like.

You can also see the document in its full gory detail at: http://www.oracle.com/technetwork/java/codeconv-138413.html

Upvotes: 1

卢声远 Shengyuan Lu
卢声远 Shengyuan Lu

Reputation: 32014

View: “Window” -> “Show View” -> “Problems”

Configuration: “Preferences” -> “Java” -> “Compiler” -> “Errors/Warnings”

Upvotes: 0

Related Questions