diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 365d25def95..6739d5a1f6a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,7 +42,7 @@ jobs: java-version: ${{ matrix.java }} - name: 'Install' shell: bash - run: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V + run: mvn install -DskipTests=true -B -V - name: 'Test' shell: bash run: mvn test -B diff --git a/annotations/src/main/java/com/google/errorprone/annotations/IncompatibleModifiers.java b/annotations/src/main/java/com/google/errorprone/annotations/IncompatibleModifiers.java index 9af2262ad8a..55ff68c2717 100644 --- a/annotations/src/main/java/com/google/errorprone/annotations/IncompatibleModifiers.java +++ b/annotations/src/main/java/com/google/errorprone/annotations/IncompatibleModifiers.java @@ -27,16 +27,16 @@ * Annotation declaring that the target annotation is incompatible with any one of the provided * modifiers. For example, an annotation declared as: * - *
{@code - * @IncompatibleModifiers(Modifier.PUBLIC) - * @interface MyAnnotation {} - * }+ *
+ * {@literal @}IncompatibleModifiers(Modifier.PUBLIC) + * {@literal @}interface MyAnnotation {} + ** *
will be considered illegal when used as: * - *
{@code - * @MyAnnotation public void foo() {} - * }+ *
+ * {@literal @}MyAnnotation public void foo() {} + ** * @author benyu@google.com (Jige Yu) */ diff --git a/annotations/src/main/java/com/google/errorprone/annotations/RequiredModifiers.java b/annotations/src/main/java/com/google/errorprone/annotations/RequiredModifiers.java index 6a364c5cb2b..ca14b836836 100644 --- a/annotations/src/main/java/com/google/errorprone/annotations/RequiredModifiers.java +++ b/annotations/src/main/java/com/google/errorprone/annotations/RequiredModifiers.java @@ -27,16 +27,16 @@ * Annotation declaring that the target annotation requires all the specified modifiers. For * example, an annotation declared as: * - *
{@code - * @RequiredModifiers(Modifier.PUBLIC) - * @interface MyAnnotation {} - * }+ *
+ * {@literal @}RequiredModifiers(Modifier.PUBLIC) + * {@literal @}interface MyAnnotation {} + ** *
will be considered illegal when used on non-public elements such as: * - *
{@code - * @MyAnnotation void foo() {} - * }+ *
+ * {@literal @}MyAnnotation void foo() {} + ** * @author benyu@google.com (Jige Yu) */ diff --git a/annotations/src/main/java/com/google/errorprone/annotations/RestrictedApi.java b/annotations/src/main/java/com/google/errorprone/annotations/RestrictedApi.java index a8392775369..37157069b72 100644 --- a/annotations/src/main/java/com/google/errorprone/annotations/RestrictedApi.java +++ b/annotations/src/main/java/com/google/errorprone/annotations/RestrictedApi.java @@ -38,15 +38,15 @@ * example through code review, could be marked {@code @ReviewedFooBar}. * *
{@code - * public @interface LegacyUnsafeFooBar{} + * public {@literal @}interface LegacyUnsafeFooBar{} * - * public @interface ReviewedFooBar{ + * public {@literal @}interface ReviewedFooBar{ * public string reviewer(); * public string comments(); * } * * public class Foo { - * @RestrictedApi( + * {@literal @}RestrictedApi( * explanation="You could shoot yourself in the foot with Foo.bar if you aren't careful", * link="http://edsger.dijkstra/foo_bar_consider_harmful.html", * allowedOnPath="testsuite/.*", // Unsafe behavior in tests is ok. @@ -61,7 +61,7 @@ * } * boolean complicatedCondition = true; * - * @ReviewedFooBar( + * {@literal @}ReviewedFooBar( * reviewer="bangert", * comments="Makes sure complicatedCondition isn't true, so bar is safe!" * ) @@ -71,7 +71,7 @@ * } * } * - * @LegacyUnsafeFooBar + * {@literal @}LegacyUnsafeFooBar * public void someOldCode() { * // ... * bar() diff --git a/annotations/src/main/java/com/google/errorprone/annotations/concurrent/LazyInit.java b/annotations/src/main/java/com/google/errorprone/annotations/concurrent/LazyInit.java index b4245a5d475..c264e6aa761 100644 --- a/annotations/src/main/java/com/google/errorprone/annotations/concurrent/LazyInit.java +++ b/annotations/src/main/java/com/google/errorprone/annotations/concurrent/LazyInit.java @@ -33,7 +33,7 @@ * *{@code * private final String source; - * @LazyInit private String data; + * {@literal @}LazyInit private String data; * * public String getData() { * String local = data; diff --git a/check_api/src/main/java/com/google/errorprone/CodeTransformer.java b/check_api/src/main/java/com/google/errorprone/CodeTransformer.java index d340e2315b0..a391222fbe8 100644 --- a/check_api/src/main/java/com/google/errorprone/CodeTransformer.java +++ b/check_api/src/main/java/com/google/errorprone/CodeTransformer.java @@ -37,10 +37,10 @@ public interface CodeTransformer { * applied to it: * *{@code - * @MyCustomAnnotation("value") + * {@literal @}MyCustomAnnotation("value") * public class AnnotatedRefasterRule { - * @BeforeTemplate void before(String x) {...} - * @AfterTemplate void after(String x) {...} + * {@literal @}BeforeTemplate void before(String x) {...} + * {@literal @}AfterTemplate void after(String x) {...} * } * }* diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ThreadSafety.java b/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ThreadSafety.java index 402d3b405d7..d525bf1a94d 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ThreadSafety.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ThreadSafety.java @@ -686,11 +686,11 @@ && isThreadSafeType( *Usually only the immediately enclosing declaration is searched, but it's possible to have * cases like: * - *
{@code - * @MarkerAnnotation(containerOf="T") class C*/ public Set{ - * class Inner extends ThreadSafeCollection {} + * + * {@literal @}MarkerAnnotation(containerOf="T") class C<T> { + * class Inner extends ThreadSafeCollection<T> {} * } - * }+ *threadSafeTypeParametersInScope(Symbol sym) { if (sym == null) { diff --git a/core/src/main/java/com/google/errorprone/refaster/Refaster.java b/core/src/main/java/com/google/errorprone/refaster/Refaster.java index dc22c43e8fa..44776dd461f 100644 --- a/core/src/main/java/com/google/errorprone/refaster/Refaster.java +++ b/core/src/main/java/com/google/errorprone/refaster/Refaster.java @@ -30,11 +30,11 @@ private Refaster() {} * * For example, you might write * - *
{@code - * @BeforeTemplate void something(@Repeated T arg) { - * Stream.of(asVarargs(arg)); // doesn't use the Stream.of(T) overload, but Stream.of(T...) - * } - * }+ **/ public static+ * {@literal @}BeforeTemplate void something(@Repeated T arg) { + * Stream.of(asVarargs(arg)); // doesn't use the Stream.of(T) overload, but Stream.of(T...) + * } + *
T[] asVarargs(T arg) { throw new UnsupportedOperationException(); @@ -48,24 +48,24 @@ public static T[] asVarargs(T arg) { * * For example, instead of writing * - *
{@code - * @BeforeTemplate* *List copyOfSingleton(E element) { + * + *+ * {@literal @}BeforeTemplate <E> List<E> copyOfSingleton(E element) { * return ImmutableList.copyOf(Collections.singletonList(element)); * } - * @BeforeTemplate
List copyOfArrayList(E element) { + * {@literal @}BeforeTemplate <E> List<E> copyOfArrayList(E element) { * return ImmutableList.copyOf(Lists.newArrayList(element)); * } - * } one could alternately write * - *
{@code - * @BeforeTemplate*/ @SafeVarargs public staticList singleton(E element) { + * + *+ * {@literal @}BeforeTemplate <E> List<E> singleton(E element) { * return ImmutableList.copyOf(Refaster.anyOf( * Collections.singletonList(element), * Lists.newArrayList(element))); * } - * }
T anyOf(T... expressions) { @@ -79,19 +79,19 @@ public static T anyOf(T... expressions) { * * For example, instead of writing the broken * - *
{@code - * @AfterTemplate* *boolean instanceOf(Object o) { + * + *+ * {@literal @}AfterTemplate <T> boolean instanceOf(Object o) { * return o instanceof T; // you want to match this, but it won't compile * } - * }
you would instead write * - *
{@code - * @AfterTemplate* * @throws IllegalArgumentException if T is not specified explicitly. */ @@ -106,19 +106,19 @@ public staticboolean instanceOf(Object o) { - * return Refaster. isInstance(o); // generates the replacement "o instanceof T" + * + *+ * {@literal @}AfterTemplate <T> boolean instanceOf(Object o) { + * return Refaster.<T>isInstance(o); // generates the replacement "o instanceof T" * } - * }
boolean isInstance(Object o) { * * For example, instead of writing the broken * - *
{@code - * @AfterTemplate* *T[] newTArray(int size) { + * + *+ * {@literal @}AfterTemplate <T> T[] newTArray(int size) { * return new T[size]; // you want to generate this code, but it won't compile * } - * }
you would instead write * - *
{@code - * @AfterTemplate* * @throws IllegalArgumentException if T is not specified explicitly. */ @@ -132,19 +132,19 @@ public staticT[] newTArray(int size) { - * return Refaster. newArray(size); + * + *+ * {@literal @}AfterTemplate <T> T[] newTArray(int size) { + * return Refaster.<T>newArray(size); * } - * }
T[] newArray(int size) { * * For example, instead of writing the broken * - *
{@code - * @AfterTemplate* * you would instead write * - *T[] getEnumConstants() { + * + *+ * {@literal @}AfterTemplate <T> T[] getEnumConstants() { * return T.class.getEnumConstants(); // you want to inline this, but it won't compile * } - * }
{@code - * @AfterTemplate* * @throws IllegalArgumentException if T is not specified explicitly. */ @@ -158,19 +158,19 @@ public staticT[] getEnumConstants() { - * return Refaster. clazz().getEnumConstants(); + * + *+ * {@literal @}AfterTemplate <T> T[] getEnumConstants() { + * return Refaster.<T>clazz().getEnumConstants(); * } - * }
Class clazz() { * * For example, instead of writing the broken * - *
{@code - * @BeforeTemplate* *> E valueOf(String str) { + * + *+ * {@literal @}BeforeTemplate <E extends Enum<E>> E valueOf(String str) { * return E.valueOf(str); * } - * }
you would instead write * - *
{@code - * @BeforeTemplate* * @throws IllegalArgumentException if E is not specified explicitly. */ @@ -184,19 +184,19 @@ public static> E valueOf(String str) { - * return Refaster. enumValueOf(str); + * + *+ * {@literal @}BeforeTemplate <E extends Enum<E>> E valueOf(String str) { + * return Refaster.<E>enumValueOf(str); * } - * }
> E enumValueOf(String string) { * * For example, instead of writing * - *
{@code - * @AfterTemplate int lengthWithComment(String str) { + ** *+ *+ * {@literal @}AfterTemplate int lengthWithComment(String str) { * return /* comment \*\/ str.length(); * } - * }
you would instead write * - *
{@code - * @AfterTemplate int lengthWithComment(String str) { + **/ public static+ *+ * {@literal @}AfterTemplate int lengthWithComment(String str) { * return Refaster.emitCommentBefore("comment", str.length()); * } - * }
T emitCommentBefore(String literal, T expression) { throw new UnsupportedOperationException(); @@ -208,21 +208,21 @@ public static T emitCommentBefore(String literal, T expression) { * * For example, instead of writing * - *
{@code - * @AfterTemplate void printWithComment(String str) { + ** *+ *+ * {@literal @}AfterTemplate void printWithComment(String str) { * // comment * System.out.println(str); * } - * }
you would instead write * - *
{@code - * @AfterTemplate void printWithComment(String str) { + **/ public static void emitComment(String literal) { throw new UnsupportedOperationException(); diff --git a/core/src/main/java/com/google/errorprone/refaster/annotation/Matches.java b/core/src/main/java/com/google/errorprone/refaster/annotation/Matches.java index 62a8bb2aa45..62942a060e6 100644 --- a/core/src/main/java/com/google/errorprone/refaster/annotation/Matches.java +++ b/core/src/main/java/com/google/errorprone/refaster/annotation/Matches.java @@ -32,12 +32,12 @@ * *+ *+ * {@literal @}AfterTemplate void printWithComment(String str) { * Refaster.emitComment("comment"); * System.out.println(str); * } - * }
{@code * class SingletonList { - * @BeforeTemplate - * publicList before(@Matches(IsNonNullMatcher.class) E e) { + * {@literal @}BeforeTemplate + * public List before({@literal @}Matches(IsNonNullMatcher.class) E e) { * return Collections.singletonList(e); * } * - * @AfterTemplate + * {@literal @}AfterTemplate * public List after(E e) { * return ImmutableList.of(e); * } diff --git a/core/src/main/java/com/google/errorprone/refaster/annotation/MayOptionallyUse.java b/core/src/main/java/com/google/errorprone/refaster/annotation/MayOptionallyUse.java index bd30b737348..29c5dbd7003 100644 --- a/core/src/main/java/com/google/errorprone/refaster/annotation/MayOptionallyUse.java +++ b/core/src/main/java/com/google/errorprone/refaster/annotation/MayOptionallyUse.java @@ -25,23 +25,23 @@ * Indicates that a parameter to a placeholder method is not required to be used in the * placeholder's implementation. For example, the pattern * - * {@code + ** * would match even if the catch statement were empty, or didn't refer to e. */ diff --git a/core/src/main/java/com/google/errorprone/refaster/annotation/Placeholder.java b/core/src/main/java/com/google/errorprone/refaster/annotation/Placeholder.java index 76baaca0039..8dd640c1e51 100644 --- a/core/src/main/java/com/google/errorprone/refaster/annotation/Placeholder.java +++ b/core/src/main/java/com/google/errorprone/refaster/annotation/Placeholder.java @@ -26,22 +26,22 @@ * arbitrary expression (if the return type is nonvoid), or zero or more statements (if the return * type is void), in terms of its arguments. For example, * - *+ ** abstract class Utf8Bytes { - * @Placeholder abstract void handleException( - * @MayOptionallyUse UnsupportedEncodingException e); - * @Placeholder abstract void useString(String str); - * @BeforeTemplate void before(byte[] array) { + * {@literal @}Placeholder abstract void handleException( + * {@literal @}MayOptionallyUse UnsupportedEncodingException e); + * {@literal @}Placeholder abstract void useString(String str); + * {@literal @}BeforeTemplate void before(byte[] array) { * try { * useString(new String(array, "UTF_8")); * } catch (UnsupportedEncodingException e) { * handleException(e); * } * } - * @AfterTemplate void after(byte[] array) { + * {@literal @}AfterTemplate void after(byte[] array) { * useString(new String(array, StandardCharsets.UTF_8)); * } * } - * }
{@code - * abstract class ComputeIfAbsent* *{ - * @Placeholder abstract V computeValue(K key); + * + *+ * abstract class ComputeIfAbsent<K, V> { + * {@literal @}Placeholder abstract V computeValue(K key); * - * @BeforeTemplate void getOrCompute(Map
map, K key) { + * {@literal @}BeforeTemplate void getOrCompute(Map<K, V> map, K key) { * V value = map.get(key); * if (value == null) { * map.put(key, value = computeValue(key)); * } * } * - * @AfterTemplate void computeIfAbsent(Map map, K key) { - * V value = map.computeIfAbsent(key, (K k) -> computeValue(k)); + * {@literal @}AfterTemplate void computeIfAbsent(Map<K, V> map, K key) { + * V value = map.computeIfAbsent(key, (K k) -> computeValue(k)); * } * } - * } Here, {@code computeValue} represents an arbitrary expression in terms of {@code key}, and the * {@code @AfterTemplate} rewrites that same expression in terms of the parameter of a lambda @@ -49,12 +49,12 @@ * *
For a multi-line example, consider * - *
{@code - * abstract class TryWithResources* *{ - * @Placeholder abstract T open(); - * @Placeholder void process(T resource); + * + *+ * abstract class TryWithResources<T extends AutoCloseable> { + * {@literal @}Placeholder abstract T open(); + * {@literal @}Placeholder void process(T resource); * - * @BeforeTemplate void tryFinallyClose() { + * {@literal @}BeforeTemplate void tryFinallyClose() { * T resource = open(); * try { * process(resource); @@ -63,13 +63,13 @@ * } * } * - * @AfterTemplate void tryWithResource() { + * {@literal @}AfterTemplate void tryWithResource() { * try (T resource = open()) { * process(resource); * } * } * } - * }
Here, {@code process} is any block, though it must refer to {@code resource} in some way; it * is not permitted to reassign the contents of {@code resource}.