You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
or use the https://repo.spring.io/javaformat-eclipse-update-site/[update site].
197
210
211
+
212
+
198
213
=== IntelliJ IDEA
199
214
The IntelliJ IDEA plugin provides custom formatter support for IntelliJ IDEA.
200
215
The plugin is automatically activated whenever the Maven or Gradle plugins are discovered in a project build script.
@@ -204,15 +219,21 @@ You can use the standard `code` -> `reformat code` action to format the code.
204
219
To install the plugin use the `spring-javaformat-intellij-idea-plugin` jar file.
205
220
You can download the latest version from https://repo.spring.io/release/io/spring/javaformat/spring-javaformat-intellij-idea-plugin/{release-version}[repo.spring.io].
206
221
207
-
=== About the conventions
222
+
223
+
224
+
=== About the Conventions
208
225
Most of the coding conventions and style comes from the Spring Framework and Spring Boot projects.
209
226
Spring Framework manually formats code, where as Spring Boot uses automatic formatting.
210
227
228
+
229
+
211
230
=== Tips
212
231
Formatting and Checkstyle alone are not enough to produce truly consistent code.
213
232
Here are some tips that we've found useful when developing Spring Boot.
214
233
215
-
==== Excluding specific checks
234
+
235
+
236
+
==== Excluding Specific Checks
216
237
If you want most `SpringChecks` but need to exclude one or two, you can do something like this in your `checkstyle.xml`:
217
238
218
239
[source,xml,indent=0]
@@ -228,7 +249,9 @@ If you want most `SpringChecks` but need to exclude one or two, you can do somet
228
249
</module>
229
250
----
230
251
231
-
==== Disabling formatting for blocks of code
252
+
253
+
254
+
==== Disabling Formatting For Blocks of Code
232
255
Some code isn't particularly amenable to automatic formatting.
233
256
For example, Spring Security configurations often work better when manually formatted.
234
257
@@ -243,6 +266,8 @@ If you need to disable formatting for a specific block of code you can enclose i
243
266
// @formatter:on
244
267
----
245
268
269
+
270
+
246
271
==== Wrapping
247
272
The source formatter uses 120 chars for wrapping. This aims to strike a balance between
248
273
making use of available horizontal space in your IDE and avoiding unwanted additional
@@ -254,23 +279,31 @@ code bunched up to the right of your screen you should take that as a signal to
254
279
"`extract method`" refactor. Extracting small private methods will improve formatting and
255
280
it helps when reading the code and debugging.
256
281
282
+
283
+
257
284
==== Whitespace
258
285
Keeping whitespace lines out of method bodies can help make the code easier to scan.
259
286
If blank lines are only included between methods it becomes easier to see the overall structure of the class.
260
287
If you find you need whitespace inside your method, consider if extracting a private method might give a better result.
261
288
289
+
290
+
262
291
==== Comments
263
292
Try to add javadoc for each public method and constant.
264
293
Private methods shouldn't generally need javadoc, unless it provides a natural place to document unusual behavior.
265
294
266
295
The checkstyle rules will enforce that all public classes have javadoc.
267
296
They will also ensure that `@author` tags are well formed.
268
297
298
+
299
+
269
300
==== Final
270
301
Private members should be `final` whenever possible.
271
302
Local variable and parameters should generally not be explicitly declared as final since it adds so much noise.
272
303
273
-
==== Read-down methods, fields and parameters
304
+
305
+
306
+
==== Read-down Methods, Fields and Parameters
274
307
Methods don't need to be organized by scope.
275
308
There's no need to group all `private`, `protected` and `public` methods together.
276
309
Instead try to make your code easy to read when scanning the file from top to bottom.
0 commit comments