Skip to content

Commit e6e0259

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
Remove explicit visibilities from effectively private members.
And add `@Keep` to cases in which we don't want that to happen. (When such members already had `@SuppressWarnings("unused")`, I removed the latter.) I have forgotten whether there are reasons to prefer `@Keep` (which is retained all the way to `RUNTIME`) over `@SuppressWarnings` (which has only `SOURCE` retention). (Extra retention could be either good or bad.) I might expect `@SuppressWarnings` to be recognized by _more_ tools (mainly "non-Google" tools like IntelliJ?). Probably part of the reason for `@Keep` is to use it as a _meta-annotation_, and we're not doing that here. I guess "`@Keep`" is shorter :) Probably most relevant here, `@Keep` suggests "Do not touch this at all" (including possibly things like "Don't make it `final`," which may or may not be desirable in our various usages), whereas `@SuppressWarnings("unused")` at least doesn't suggest that quite as much? Prompted by google/error-prone#5156. RELNOTES=n/a PiperOrigin-RevId: 782899232
1 parent 0044cce commit e6e0259

File tree

68 files changed

+214
-148
lines changed

Some content is hidden

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

68 files changed

+214
-148
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private static final class OneSizeTestSuiteBuilder<T, E>
126126
private final List<Class<? extends AbstractTester>> testers;
127127

128128
@SuppressWarnings("rawtypes") // class literals
129-
public OneSizeTestSuiteBuilder(List<Class<? extends AbstractTester>> testers) {
129+
OneSizeTestSuiteBuilder(List<Class<? extends AbstractTester>> testers) {
130130
this.testers = testers;
131131
}
132132

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ private static class AsMapGenerator<K, V, M extends Multimap<K, V>>
314314
implements TestMapGenerator<K, Collection<V>>, DerivedGenerator {
315315
private final OneSizeTestContainerGenerator<M, Entry<K, V>> multimapGenerator;
316316

317-
public AsMapGenerator(OneSizeTestContainerGenerator<M, Entry<K, V>> multimapGenerator) {
317+
AsMapGenerator(OneSizeTestContainerGenerator<M, Entry<K, V>> multimapGenerator) {
318318
this.multimapGenerator = multimapGenerator;
319319
}
320320

@@ -638,8 +638,7 @@ private static class ReserializedMultimapGenerator<K, V, M extends Multimap<K, V
638638
implements TestMultimapGenerator<K, V, M> {
639639
private final OneSizeTestContainerGenerator<M, Entry<K, V>> multimapGenerator;
640640

641-
public ReserializedMultimapGenerator(
642-
OneSizeTestContainerGenerator<M, Entry<K, V>> multimapGenerator) {
641+
ReserializedMultimapGenerator(OneSizeTestContainerGenerator<M, Entry<K, V>> multimapGenerator) {
643642
this.multimapGenerator = multimapGenerator;
644643
}
645644

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ public List<Integer> order(List<Integer> insertionOrder) {
412412

413413
private abstract static class AbstractContiguousSetGenerator
414414
extends TestIntegerSortedSetGenerator {
415-
protected final ContiguousSet<Integer> checkedCreate(SortedSet<Integer> elementsSet) {
415+
final ContiguousSet<Integer> checkedCreate(SortedSet<Integer> elementsSet) {
416416
List<Integer> elements = new ArrayList<>(elementsSet);
417417
/*
418418
* A ContiguousSet can't have holes. If a test demands a hole, it should be changed so that it

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ public boolean isExpectedType(Throwable cause) {
631631
}
632632
};
633633

634-
public abstract boolean isExpectedType(Throwable cause);
634+
abstract boolean isExpectedType(Throwable cause);
635635
}
636636

637637
private static boolean annotatedTypeExists() {

android/guava-testlib/test/com/google/common/collect/testing/features/FeatureUtilTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.google.common.collect.ImmutableSet;
3737
import com.google.common.collect.testing.features.FeatureUtilTest.ExampleFeature.NotTesterAnnotation;
3838
import com.google.common.collect.testing.features.FeatureUtilTest.ExampleFeature.Require;
39+
import com.google.errorprone.annotations.Keep;
3940
import java.lang.annotation.Inherited;
4041
import java.lang.annotation.Retention;
4142
import java.lang.reflect.Method;
@@ -175,6 +176,7 @@ class Tester {}
175176
public void testBuildTesterRequirements_class_present_method_present() throws Exception {
176177
@Require(IMPLIES_BAR)
177178
class Tester {
179+
@Keep
178180
@Require(IMPLIES_IMPLIES_FOO)
179181
public void test() {}
180182
}
@@ -189,6 +191,7 @@ public void test() {}
189191
public void testBuildTesterRequirements_class_absent_method_absent() throws Exception {
190192
@Require(absent = IMPLIES_BAR)
191193
class Tester {
194+
@Keep
192195
@Require(absent = IMPLIES_IMPLIES_FOO)
193196
public void test() {}
194197
}
@@ -202,6 +205,7 @@ public void test() {}
202205
public void testBuildTesterRequirements_class_present_method_absent() throws Exception {
203206
@Require(IMPLIES_IMPLIES_FOO)
204207
class Tester {
208+
@Keep
205209
@Require(absent = IMPLIES_IMPLIES_FOO_AND_IMPLIES_BAR)
206210
public void test() {}
207211
}
@@ -217,6 +221,7 @@ public void test() {}
217221
public void testBuildTesterRequirements_class_absent_method_present() throws Exception {
218222
@Require(absent = IMPLIES_IMPLIES_FOO_AND_IMPLIES_BAR)
219223
class Tester {
224+
@Keep
220225
@Require(IMPLIES_IMPLIES_FOO)
221226
public void test() {}
222227
}
@@ -267,6 +272,7 @@ class Tester {}
267272
public void testBuildTesterRequirements_methodClassConflict() throws Exception {
268273
@Require(IMPLIES_FOO)
269274
class Tester {
275+
@Keep
270276
@Require(absent = FOO)
271277
public void test() {}
272278
}
@@ -301,6 +307,7 @@ class Tester {}
301307

302308
public void testGetTesterAnnotations_method() throws Exception {
303309
class Tester {
310+
@Keep
304311
@Require
305312
@NotTesterAnnotation
306313
public void test() {}

android/guava-testlib/test/com/google/common/testing/anotherpackage/ForwardingWrapperTesterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ private interface Adder {
320320
private static class ForwardingArithmetic implements Arithmetic {
321321
private final Arithmetic arithmetic;
322322

323-
public ForwardingArithmetic(Arithmetic arithmetic) {
323+
ForwardingArithmetic(Arithmetic arithmetic) {
324324
this.arithmetic = arithmetic;
325325
}
326326

@@ -455,7 +455,7 @@ void foo(
455455
private static class ParameterTypesDifferentForwarder implements ParameterTypesDifferent {
456456
private final ParameterTypesDifferent delegate;
457457

458-
public ParameterTypesDifferentForwarder(ParameterTypesDifferent delegate) {
458+
ParameterTypesDifferentForwarder(ParameterTypesDifferent delegate) {
459459
this.delegate = delegate;
460460
}
461461

android/guava-tests/benchmark/com/google/common/collect/ConcurrentHashMultisetBenchmark.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private static final class OldConcurrentHashMultiset<E> extends AbstractMultiset
175175
* Creates a new, empty {@code OldConcurrentHashMultiset} using the default initial capacity,
176176
* load factor, and concurrency settings.
177177
*/
178-
public static <E> OldConcurrentHashMultiset<E> create() {
178+
static <E> OldConcurrentHashMultiset<E> create() {
179179
return new OldConcurrentHashMultiset<E>(new ConcurrentHashMap<E, Integer>());
180180
}
181181

@@ -351,7 +351,7 @@ private int removeAllOccurrences(@Nullable Object element) {
351351
* @param occurrences the number of occurrences of {@code element} to remove
352352
* @return {@code true} if the removal was possible (including if {@code occurrences} is zero)
353353
*/
354-
public boolean removeExactly(@Nullable Object element, int occurrences) {
354+
boolean removeExactly(@Nullable Object element, int occurrences) {
355355
if (occurrences == 0) {
356356
return true;
357357
}

android/guava-tests/benchmark/com/google/common/hash/MessageDigestAlgorithmBenchmark.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public byte[] hash(Algorithm algorithm, byte[] input) {
6969
};
7070
;
7171

72-
public abstract byte[] hash(Algorithm algorithm, byte[] input);
72+
abstract byte[] hash(Algorithm algorithm, byte[] input);
7373
}
7474

7575
private enum Algorithm {
@@ -87,15 +87,15 @@ private enum Algorithm {
8787
this.hashFn = hashFn;
8888
}
8989

90-
public MessageDigest getMessageDigest() {
90+
MessageDigest getMessageDigest() {
9191
try {
9292
return MessageDigest.getInstance(algorithmName);
9393
} catch (NoSuchAlgorithmException e) {
9494
throw new AssertionError(e);
9595
}
9696
}
9797

98-
public HashFunction getHashFunction() {
98+
HashFunction getHashFunction() {
9999
return hashFn;
100100
}
101101
}

android/guava-tests/benchmark/com/google/common/math/ApacheBenchmark.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,21 @@ public boolean noMulOverflow(long a, long b) {
9999
}
100100
};
101101

102-
public abstract double factorialDouble(int n);
102+
abstract double factorialDouble(int n);
103103

104-
public abstract long binomialCoefficient(int n, int k);
104+
abstract long binomialCoefficient(int n, int k);
105105

106-
public abstract int gcdInt(int a, int b);
106+
abstract int gcdInt(int a, int b);
107107

108-
public abstract long gcdLong(long a, long b);
108+
abstract long gcdLong(long a, long b);
109109

110-
public abstract boolean noAddOverflow(int a, int b);
110+
abstract boolean noAddOverflow(int a, int b);
111111

112-
public abstract boolean noAddOverflow(long a, long b);
112+
abstract boolean noAddOverflow(long a, long b);
113113

114-
public abstract boolean noMulOverflow(int a, int b);
114+
abstract boolean noMulOverflow(int a, int b);
115115

116-
public abstract boolean noMulOverflow(long a, long b);
116+
abstract boolean noMulOverflow(long a, long b);
117117
}
118118

119119
private final int[] factorials = new int[ARRAY_SIZE];

android/guava-tests/test/com/google/common/base/ConverterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void testApply() {
112112
private static class StringWrapper {
113113
private final String value;
114114

115-
public StringWrapper(String value) {
115+
StringWrapper(String value) {
116116
this.value = value;
117117
}
118118
}

0 commit comments

Comments
 (0)