Skip to content

Commit 263da38

Browse files
committed
Tweaks
1 parent 48394fe commit 263da38

File tree

6 files changed

+14
-8
lines changed

6 files changed

+14
-8
lines changed

lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ public static FormatterStep create(List<String> addedTypeAnnotations, List<Strin
393393

394394
private FormatAnnotationsStep() {}
395395

396-
// TODO: Enable users to specify more type annotations in `formatAnnotations` in build.gradle.
397396
// TODO: Read from a local .type-annotations file.
398397
private static final class State implements Serializable {
399398
private static final long serialVersionUID = 1L;
@@ -415,13 +414,17 @@ private static final class State implements Serializable {
415414
// Don't move an annotation to the start of a comment line.
416415
private static final Pattern startsWithCommentPattern = Pattern.compile("^[ \t]*(//|/\\*$|/\\*|void\\b)");
417416

417+
/**
418+
* @param addedTypeAnnotations simple names to add to Spotless's default list
419+
* @param removedTypeAnnotations simple names to remove from Spotless's default list
420+
*/
418421
State(List<String> addedTypeAnnotations, List<String> removedTypeAnnotations) {
419422
typeAnnotations.addAll(addedTypeAnnotations);
420423
typeAnnotations.removeAll(removedTypeAnnotations);
421424
}
422425

423426
FormatterFunc toFormatter() {
424-
return unixStr -> fixupFormatAnnotations(unixStr);
427+
return unixStr -> fixupTypeAnnotations(unixStr);
425428
}
426429

427430
/**
@@ -430,7 +433,7 @@ FormatterFunc toFormatter() {
430433
* @param the text of a Java file
431434
* @return corrected text of the Java file
432435
*/
433-
String fixupFormatAnnotations(String unixStr) {
436+
String fixupTypeAnnotations(String unixStr) {
434437
// Each element of `lines` ends with a newline.
435438
String[] lines = unixStr.split("((?<=\n))");
436439
for (int i = 0; i < lines.length - 1; i++) {

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ public FormatAnnotationsConfig formatAnnotations() {
240240
}
241241

242242
public class FormatAnnotationsConfig {
243+
/** Annotations in addition to those in the default list. */
243244
final List<String> addedTypeAnnotations = new ArrayList<>();
245+
/** Annotations that the user doesn't want treated as type annotations. */
244246
final List<String> removedTypeAnnotations = new ArrayList<>();
245247

246248
FormatAnnotationsConfig() {

plugin-maven/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ A type annotation is an annotation that is meta-annotated with `@Target({Element
290290
Because Spotless cannot necessarily examine the annotation definition, it uses a hard-coded
291291
list of well-known type annotations. You can make a pull request to add new ones.
292292
In the future there will be mechanisms to add/remove annotations from the list.
293+
These mechanisms already exist for the Gradle plugin.
293294

294295

295296
## Groovy

plugin-maven/src/main/java/com/diffplug/spotless/maven/java/FormatAnnotations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class FormatAnnotations implements FormatterStepFactory {
2626

2727
@Override
2828
public FormatterStep newFormatterStep(FormatterStepConfig config) {
29-
// TODO: Permit customization in Maven.
29+
// TODO: Permit customization in Maven build files.
3030
return FormatAnnotationsStep.create(Collections.emptyList(), Collections.emptyList());
3131
}
3232
}

testlib/src/main/resources/java/formatannotations/FormatAnnotationsInCommentsInput.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class FormatAnnotationsInComments {
22

3-
// Here is a comment relating to the annotation @Nullable
3+
// Here is a comment
44
@Interned
55
String m1() {}
66

7-
// Here is another comment relating to the annotation @Nullable
7+
// Here is another comment
88
String m2() {}
99

1010
/**

testlib/src/main/resources/java/formatannotations/FormatAnnotationsInCommentsOutput.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
class FormatAnnotationsInComments {
22

3-
// Here is a comment relating to the annotation @Nullable
3+
// Here is a comment
44
@Interned String m1() {}
55

6-
// Here is another comment relating to the annotation @Nullable
6+
// Here is another comment
77
String m2() {}
88

99
/**

0 commit comments

Comments
 (0)