Skip to content

Commit 157b3f7

Browse files
cpovirkGoogle Java Core Libraries
authored and
Google Java Core Libraries
committed
Use Javadoc {@snippet ...} tag.
This CL is mostly just the output of an automated search-and-replace operation: - `<pre>{@code$` -> `{@snippet :` - `[*] }</pre>` -> `* }` But I did touch up `ComparisonChain`, which had a workaround for using "`@Override`" at the beginning of a line of the code snippet. In the process, I discovered that we hadn't carried over the "Java 8" instructions to the backport. Now that we use library desugaring for all our internal builds, we should include these instructions in the backport, too. I've done so. External users may or may not be able to use these features yet. I also touched up `Iterables` and `FluentIterable`, since the `Class` overload of their `filter` methods was using a different style so that it could contain a line that starts with "`@SuppressWarnings`." This CL should be safe now that [the external Guava build uses newer versions of tools like `javadoc`](#6549), even as it continues to target (and test under) older JDKs. The result of the CL is mostly that code snippets appear in a gray box with a copy button and slightly less whitespace. RELNOTES=n/a PiperOrigin-RevId: 737729648
1 parent 6b1a22f commit 157b3f7

File tree

211 files changed

+1073
-1040
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+1073
-1040
lines changed

android/guava-testlib/src/com/google/common/collect/testing/IteratorTester.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
* <p>For example, to test {@link java.util.Collections#unmodifiableList(java.util.List)
5959
* Collections.unmodifiableList}'s iterator:
6060
*
61-
* <pre>{@code
61+
* {@snippet :
6262
* List<String> expectedElements =
6363
* Arrays.asList("a", "b", "c", "d", "e");
6464
* List<String> actualElements =
@@ -77,7 +77,7 @@
7777
* };
7878
* iteratorTester.test();
7979
* iteratorTester.testForEachRemaining();
80-
* }</pre>
80+
* }
8181
*
8282
* <p><b>Note</b>: It is necessary to use {@code IteratorTester.KnownOrder} as shown above, rather
8383
* than {@code KnownOrder} directly, because otherwise the code cannot be compiled.

android/guava-testlib/src/com/google/common/testing/EquivalenceTester.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
* contains objects that are supposed to be equal to each other. Objects of different groups are
3737
* expected to be unequal. For example:
3838
*
39-
* <pre>{@code
39+
* {@snippet :
4040
* EquivalenceTester.of(someStringEquivalence)
4141
* .addEquivalenceGroup("hello", "h" + "ello")
4242
* .addEquivalenceGroup("world", "wor" + "ld")
4343
* .test();
44-
* }</pre>
44+
* }
4545
*
4646
* <p>Note that testing {@link Object#equals(Object)} is more simply done using the {@link
4747
* EqualsTester}. It includes an extra test against an instance of an arbitrary class without having

android/guava-testlib/src/com/google/common/testing/ForwardingWrapperTester.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@
4545
*
4646
* <p>For example:
4747
*
48-
* <pre>{@code
48+
* {@snippet :
4949
* new ForwardingWrapperTester().testForwarding(Foo.class, new Function<Foo, Foo>() {
5050
* public Foo apply(Foo foo) {
5151
* return new ForwardingFoo(foo);
5252
* }
5353
* });
54-
* }</pre>
54+
* }
5555
*
5656
* @author Ben Yu
5757
* @since 14.0

android/guava-testlib/src/com/google/common/testing/GcFinalization.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,32 @@
5656
*
5757
* <p>Here's an example that tests a {@code finalize} method:
5858
*
59-
* <pre>{@code
59+
* {@snippet :
6060
* final CountDownLatch latch = new CountDownLatch(1);
6161
* Object x = new MyClass() {
6262
* ...
6363
* protected void finalize() { latch.countDown(); ... }
6464
* };
6565
* x = null; // Hint to the JIT that x is stack-unreachable
6666
* GcFinalization.await(latch);
67-
* }</pre>
67+
* }
6868
*
6969
* <p>Here's an example that uses a user-defined finalization predicate:
7070
*
71-
* <pre>{@code
71+
* {@snippet :
7272
* final WeakHashMap<Object, Object> map = new WeakHashMap<>();
7373
* map.put(new Object(), Boolean.TRUE);
7474
* GcFinalization.awaitDone(new FinalizationPredicate() {
7575
* public boolean isDone() {
7676
* return map.isEmpty();
7777
* }
7878
* });
79-
* }</pre>
79+
* }
8080
*
8181
* <p>Even if your non-test code does not use finalization, you can use this class to test for
8282
* leaks, by ensuring that objects are no longer strongly referenced:
8383
*
84-
* <pre>{@code
84+
* {@snippet :
8585
* // Helper function keeps victim stack-unreachable.
8686
* private WeakReference<Foo> fooWeakRef() {
8787
* Foo x = ....;
@@ -93,7 +93,7 @@
9393
* public void testFooLeak() {
9494
* GcFinalization.awaitClear(fooWeakRef());
9595
* }
96-
* }</pre>
96+
* }
9797
*
9898
* <p>This class cannot currently be used to test soft references, since this class does not try to
9999
* create the memory pressure required to cause soft references to be cleared.
@@ -261,13 +261,13 @@ public interface FinalizationPredicate {
261261
*
262262
* <p>This is a convenience method, equivalent to:
263263
*
264-
* <pre>{@code
264+
* {@snippet :
265265
* awaitDone(new FinalizationPredicate() {
266266
* public boolean isDone() {
267267
* return ref.get() == null;
268268
* }
269269
* });
270-
* }</pre>
270+
* }
271271
*
272272
* @throws RuntimeException if timed out or interrupted while waiting
273273
*/

android/guava-tests/test/com/google/common/graph/TraverserTest.java

+18-18
Original file line numberDiff line numberDiff line change
@@ -42,40 +42,40 @@ public class TraverserTest {
4242
/**
4343
* The undirected graph in the {@link Traverser#breadthFirst(Object)} javadoc:
4444
*
45-
* <pre>{@code
45+
* {@snippet :
4646
* b ---- a ---- d
4747
* | |
4848
* | |
4949
* e ---- c ---- f
50-
* }</pre>
50+
* }
5151
*/
5252
private static final SuccessorsFunction<Character> JAVADOC_GRAPH =
5353
createUndirectedGraph("ba", "ad", "be", "ac", "ec", "cf");
5454

5555
/**
5656
* A diamond shaped directed graph (arrows going down):
5757
*
58-
* <pre>{@code
58+
* {@snippet :
5959
* a
6060
* / \
6161
* b c
6262
* \ /
6363
* d
64-
* }</pre>
64+
* }
6565
*/
6666
private static final SuccessorsFunction<Character> DIAMOND_GRAPH =
6767
createDirectedGraph("ab", "ac", "bd", "cd");
6868

6969
/**
7070
* Same as {@link #DIAMOND_GRAPH}, but with an extra c->a edge and some self edges:
7171
*
72-
* <pre>{@code
72+
* {@snippet :
7373
* a<>
7474
* / \\
7575
* b c
7676
* \ /
7777
* d<>
78-
* }</pre>
78+
* }
7979
*
8080
* {@code <>} indicates a self-loop
8181
*/
@@ -89,21 +89,21 @@ public class TraverserTest {
8989
/**
9090
* Same as {@link #CYCLE_GRAPH}, but with an extra a->c edge.
9191
*
92-
* <pre>{@code
92+
* {@snippet :
9393
* |--------------|
9494
* v |
9595
* a -> b -> c -> d
9696
* | ^
9797
* |---------|
98-
* }</pre>
98+
* }
9999
*/
100100
private static final SuccessorsFunction<Character> TWO_CYCLES_GRAPH =
101101
createDirectedGraph("ab", "ac", "bc", "cd", "da");
102102

103103
/**
104104
* A tree-shaped graph that looks as follows (all edges are directed facing downwards):
105105
*
106-
* <pre>{@code
106+
* {@snippet :
107107
* h
108108
* /|\
109109
* / | \
@@ -112,29 +112,29 @@ public class TraverserTest {
112112
* /|\ |
113113
* / | \ |
114114
* a b c f
115-
* }</pre>
115+
* }
116116
*/
117117
private static final SuccessorsFunction<Character> TREE =
118118
createDirectedGraph("hd", "he", "hg", "da", "db", "dc", "gf");
119119

120120
/**
121121
* Two disjoint tree-shaped graphs that look as follows (all edges are directed facing downwards):
122122
*
123-
* <pre>{@code
123+
* {@snippet :
124124
* a c
125125
* | |
126126
* | |
127127
* b d
128-
* }</pre>
128+
* }
129129
*/
130130
private static final SuccessorsFunction<Character> TWO_TREES = createDirectedGraph("ab", "cd");
131131

132132
/**
133133
* A graph consisting of a single root {@code a}:
134134
*
135-
* <pre>{@code
135+
* {@snippet :
136136
* a
137-
* }</pre>
137+
* }
138138
*/
139139
private static final SuccessorsFunction<Character> SINGLE_ROOT = createSingleRootGraph();
140140

@@ -143,13 +143,13 @@ public class TraverserTest {
143143
* {@code f} and thus has a cycle) but is a valid input to {@link Traverser#forTree} when starting
144144
* e.g. at node {@code a} (all edges without an arrow are directed facing downwards):
145145
*
146-
* <pre>{@code
146+
* {@snippet :
147147
* a
148148
* /
149149
* b e <----> f
150150
* / \ /
151151
* c d
152-
* }</pre>
152+
* }
153153
*/
154154
private static final SuccessorsFunction<Character> CYCLIC_GRAPH_CONTAINING_TREE =
155155
createDirectedGraph("ab", "bc", "bd", "ed", "ef", "fe");
@@ -159,13 +159,13 @@ public class TraverserTest {
159159
* e} and {@code g}) but is a valid input to {@link Traverser#forTree} when starting e.g. at node
160160
* {@code a} (all edges are directed facing downwards):
161161
*
162-
* <pre>{@code
162+
* {@snippet :
163163
* a f
164164
* / / \
165165
* b e g
166166
* / \ / \ /
167167
* c d h
168-
* }</pre>
168+
* }
169169
*/
170170
private static final SuccessorsFunction<Character> GRAPH_CONTAINING_TREE_AND_DIAMOND =
171171
createDirectedGraph("ab", "fe", "fg", "bc", "bd", "ed", "eh", "gh");

android/guava-tests/test/com/google/common/reflect/SubtypeTester.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* <p>These declaration methods rely on Java static type checking to make sure what we want to
4343
* assert as subtypes are really subtypes according to javac. For example:
4444
*
45-
* <pre>{@code
45+
* {@snippet :
4646
* class MySubtypeTests extends SubtypeTester {
4747
* @TestSubtype(suppressGetSubtype = true, suppressGetSupertype = true)
4848
* public <T> Iterable<? extends T> listIsSubtypeOfIterable(List<T> list) {
@@ -58,7 +58,7 @@
5858
* public void testMySubtypes() throws Exception {
5959
* new MySubtypeTests().testAllDeclarations();
6060
* }
61-
* }</pre>
61+
* }
6262
*
6363
* The calls to {@link #isSubtype} and {@link #notSubtype} tells the framework what assertions need
6464
* to be made.

android/guava/src/com/google/common/base/Ascii.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,10 @@ public static boolean isUpperCase(char c) {
523523
*
524524
* <p>Examples:
525525
*
526-
* <pre>{@code
526+
* {@snippet :
527527
* Ascii.truncate("foobar", 7, "..."); // returns "foobar"
528528
* Ascii.truncate("foobar", 5, "..."); // returns "fo..."
529-
* }</pre>
529+
* }
530530
*
531531
* <p><b>Note:</b> This method <i>may</i> work with certain non-ASCII text but is not safe for use
532532
* with arbitrary Unicode text. It is mostly intended for use with text that is known to be safe

android/guava/src/com/google/common/base/CharMatcher.java

+18-18
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,9 @@ public int countIn(CharSequence sequence) {
609609
* Returns a string containing all non-matching characters of a character sequence, in order. For
610610
* example:
611611
*
612-
* <pre>{@code
612+
* {@snippet :
613613
* CharMatcher.is('a').removeFrom("bazaar")
614-
* }</pre>
614+
* }
615615
*
616616
* ... returns {@code "bzr"}.
617617
*/
@@ -648,9 +648,9 @@ public String removeFrom(CharSequence sequence) {
648648
* Returns a string containing all matching BMP characters of a character sequence, in order. For
649649
* example:
650650
*
651-
* <pre>{@code
651+
* {@snippet :
652652
* CharMatcher.is('a').retainFrom("bazaar")
653-
* }</pre>
653+
* }
654654
*
655655
* ... returns {@code "aaa"}.
656656
*/
@@ -662,9 +662,9 @@ public String retainFrom(CharSequence sequence) {
662662
* Returns a string copy of the input character sequence, with each matching BMP character
663663
* replaced by a given replacement character. For example:
664664
*
665-
* <pre>{@code
665+
* {@snippet :
666666
* CharMatcher.is('a').replaceFrom("radar", 'o')
667-
* }</pre>
667+
* }
668668
*
669669
* ... returns {@code "rodor"}.
670670
*
@@ -697,9 +697,9 @@ public String replaceFrom(CharSequence sequence, char replacement) {
697697
* Returns a string copy of the input character sequence, with each matching BMP character
698698
* replaced by a given replacement sequence. For example:
699699
*
700-
* <pre>{@code
700+
* {@snippet :
701701
* CharMatcher.is('a').replaceFrom("yaha", "oo")
702-
* }</pre>
702+
* }
703703
*
704704
* ... returns {@code "yoohoo"}.
705705
*
@@ -745,17 +745,17 @@ public String replaceFrom(CharSequence sequence, CharSequence replacement) {
745745
* Returns a substring of the input character sequence that omits all matching BMP characters from
746746
* the beginning and from the end of the string. For example:
747747
*
748-
* <pre>{@code
748+
* {@snippet :
749749
* CharMatcher.anyOf("ab").trimFrom("abacatbab")
750-
* }</pre>
750+
* }
751751
*
752752
* ... returns {@code "cat"}.
753753
*
754754
* <p>Note that:
755755
*
756-
* <pre>{@code
756+
* {@snippet :
757757
* CharMatcher.inRange('\0', ' ').trimFrom(str)
758-
* }</pre>
758+
* }
759759
*
760760
* ... is equivalent to {@link String#trim()}.
761761
*/
@@ -782,9 +782,9 @@ public String trimFrom(CharSequence sequence) {
782782
* Returns a substring of the input character sequence that omits all matching BMP characters from
783783
* the beginning of the string. For example:
784784
*
785-
* <pre>{@code
785+
* {@snippet :
786786
* CharMatcher.anyOf("ab").trimLeadingFrom("abacatbab")
787-
* }</pre>
787+
* }
788788
*
789789
* ... returns {@code "catbab"}.
790790
*/
@@ -802,9 +802,9 @@ public String trimLeadingFrom(CharSequence sequence) {
802802
* Returns a substring of the input character sequence that omits all matching BMP characters from
803803
* the end of the string. For example:
804804
*
805-
* <pre>{@code
805+
* {@snippet :
806806
* CharMatcher.anyOf("ab").trimTrailingFrom("abacatbab")
807-
* }</pre>
807+
* }
808808
*
809809
* ... returns {@code "abacat"}.
810810
*/
@@ -822,9 +822,9 @@ public String trimTrailingFrom(CharSequence sequence) {
822822
* Returns a string copy of the input character sequence, with each group of consecutive matching
823823
* BMP characters replaced by a single replacement character. For example:
824824
*
825-
* <pre>{@code
825+
* {@snippet :
826826
* CharMatcher.anyOf("eko").collapseFrom("bookkeeper", '-')
827-
* }</pre>
827+
* }
828828
*
829829
* ... returns {@code "b-p-r"}.
830830
*

0 commit comments

Comments
 (0)