@@ -60,7 +60,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui
60
60
- [ ** Quickstart** ] ( #quickstart )
61
61
- [ Requirements] ( #requirements )
62
62
- ** Languages**
63
- - [ Java] ( #java ) ([ google-java-format] ( #google-java-format ) , [ eclipse jdt] ( #eclipse-jdt ) , [ clang-format] ( #clang-format ) , [ prettier] ( #prettier ) , [ palantir-java-format] ( #palantir-java-format ) )
63
+ - [ Java] ( #java ) ([ google-java-format] ( #google-java-format ) , [ eclipse jdt] ( #eclipse-jdt ) , [ clang-format] ( #clang-format ) , [ prettier] ( #prettier ) , [ palantir-java-format] ( #palantir-java-format ) , [ type annotations ] (#Type annotations) )
64
64
- [ Groovy] ( #groovy ) ([ eclipse groovy] ( #eclipse-groovy ) )
65
65
- [ Kotlin] ( #kotlin ) ([ ktfmt] ( #ktfmt ) , [ ktlint] ( #ktlint ) , [ diktat] ( #diktat ) , [ prettier] ( #prettier ) )
66
66
- [ Scala] ( #scala ) ([ scalafmt] ( #scalafmt ) )
@@ -117,6 +117,8 @@ spotless {
117
117
118
118
// apply a specific flavor of google-java-format
119
119
googleJavaFormat('1.8').aosp().reflowLongStrings()
120
+ // fix formatting of type annotations
121
+ typeAnnotations()
120
122
// make sure every file has the following copyright header.
121
123
// optionally, Spotless can set copyright years by digging
122
124
// through git history (see "license" section below)
@@ -162,6 +164,8 @@ spotless {
162
164
prettier() // has its own section below
163
165
clangFormat() // has its own section below
164
166
167
+ typeAnnotations() // has its own section below
168
+
165
169
licenseHeader '/* (C) $YEAR */' // or licenseHeaderFile
166
170
}
167
171
}
@@ -188,6 +192,8 @@ spotless {
188
192
// and/or reflow long strings (requires at least 1.8)
189
193
// and/or use custom group artifact (you probably don't need this)
190
194
googleJavaFormat('1.8').aosp().reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format')
195
+ // optional: fix formatting of type annotations
196
+ typeAnnotations()
191
197
```
192
198
193
199
** ⚠️ Note on using Google Java Format with Java 16+**
@@ -214,6 +220,8 @@ spotless {
214
220
palantirJavaFormat()
215
221
// optional: you can specify a specific version
216
222
palantirJavaFormat('2.9.0')
223
+ // optional: fix formatting of type annotations
224
+ typeAnnotations()
217
225
```
218
226
219
227
** ⚠️ Note on using Palantir Java Format with Java 16+**
@@ -244,6 +252,38 @@ spotless {
244
252
```
245
253
246
254
255
+ ### Type annotations
256
+
257
+ Type annotations should be on the same line as the type that they qualify.
258
+
259
+ ``` java
260
+ @Override
261
+ @Deprecated
262
+ @Nullable @Interned String s;
263
+ ```
264
+
265
+ However, some tools format them incorrectly, like this:
266
+
267
+ ``` java
268
+ @Override
269
+ @Deprecated
270
+ @Nullable
271
+ @Interned
272
+ String s;
273
+ ```
274
+
275
+ To fix the incorrect formatting, add the ` typeAnnotations() ` rule after a Java formatter. For example:
276
+
277
+ ``` gradle
278
+ spotless {
279
+ java {
280
+ googleJavaFormat()
281
+ typeAnnotations()
282
+ }
283
+ }
284
+ ```
285
+
286
+
247
287
<a name =" applying-to-groovy-source " ></a >
248
288
249
289
## Groovy
0 commit comments