Skip to content

Commit

Permalink
Fix or suppress IdentifierName (and sometimes `ConstantNameForConst…
Browse files Browse the repository at this point in the history
…ants`) warnings.

RELNOTES=n/a
PiperOrigin-RevId: 710073558
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Dec 28, 2024
1 parent 9b05674 commit 4fa6d04
Show file tree
Hide file tree
Showing 44 changed files with 315 additions and 253 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ static class EmptyTestSuite {}

static class Foo {}

@SuppressWarnings("IdentifierName") // We're testing that we ignore classes with underscores.
static class Foo_Bar {}

public static class PublicFoo {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public Object getImpl() {
@Override
ExecutionListWrapper newExecutionList() {
return new ExecutionListWrapper() {
final ExecutionListCAS list = new ExecutionListCAS();
final ExecutionListUsingCompareAndSwap list = new ExecutionListUsingCompareAndSwap();

@Override
public void add(Runnable runnable, Executor executor) {
Expand Down Expand Up @@ -581,8 +581,8 @@ private static final class RunnableExecutorPair {

// A version of the list that uses compare and swap to manage the stack without locks.
@SuppressWarnings({"SunApi", "removal"}) // b/345822163
private static final class ExecutionListCAS {
static final Logger log = Logger.getLogger(ExecutionListCAS.class.getName());
private static final class ExecutionListUsingCompareAndSwap {
static final Logger log = Logger.getLogger(ExecutionListUsingCompareAndSwap.class.getName());

private static final Unsafe UNSAFE;
private static final long HEAD_OFFSET;
Expand All @@ -596,7 +596,9 @@ private static final class ExecutionListCAS {
static {
try {
UNSAFE = getUnsafe();
HEAD_OFFSET = UNSAFE.objectFieldOffset(ExecutionListCAS.class.getDeclaredField("head"));
HEAD_OFFSET =
UNSAFE.objectFieldOffset(
ExecutionListUsingCompareAndSwap.class.getDeclaredField("head"));
} catch (Exception ex) {
throw new Error(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ public void testIn_serialization() {
}

public void testIn_handlesNullPointerException() {
class CollectionThatThrowsNPE<T> extends ArrayList<T> {
class CollectionThatThrowsNullPointerException<T> extends ArrayList<T> {
@J2ktIncompatible // Kotlin doesn't support companions for inner classes
private static final long serialVersionUID = 1L;

Expand All @@ -727,13 +727,13 @@ public boolean contains(@Nullable Object element) {
return super.contains(element);
}
}
Collection<Integer> nums = new CollectionThatThrowsNPE<>();
Collection<Integer> nums = new CollectionThatThrowsNullPointerException<>();
Predicate<@Nullable Integer> isFalse = Predicates.in(nums);
assertFalse(isFalse.apply(null));
}

public void testIn_handlesClassCastException() {
class CollectionThatThrowsCCE<T> extends ArrayList<T> {
class CollectionThatThrowsClassCastException<T> extends ArrayList<T> {
@J2ktIncompatible // Kotlin doesn't support companions for inner classes
private static final long serialVersionUID = 1L;

Expand All @@ -742,7 +742,7 @@ public boolean contains(@Nullable Object element) {
throw new ClassCastException("");
}
}
Collection<Integer> nums = new CollectionThatThrowsCCE<>();
Collection<Integer> nums = new CollectionThatThrowsClassCastException<>();
nums.add(3);
Predicate<Integer> isThree = Predicates.in(nums);
assertFalse(isThree.apply(3));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ private void memoizeTest(CountingSupplier countingSupplier) {
}

public void testMemoize_redudantly() {
memoize_redudantlyTest(new CountingSupplier());
memoize_redudantlyTest(new SerializableCountingSupplier());
memoizeRedudantlyTest(new CountingSupplier());
memoizeRedudantlyTest(new SerializableCountingSupplier());
}

private void memoize_redudantlyTest(CountingSupplier countingSupplier) {
private void memoizeRedudantlyTest(CountingSupplier countingSupplier) {
Supplier<Integer> memoizedSupplier = Suppliers.memoize(countingSupplier);
assertSame(memoizedSupplier, Suppliers.memoize(memoizedSupplier));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public void testReverseOfReverseSameAsForward() {
}

private enum StringLengthFunction implements Function<String, Integer> {
StringLength;
STRING_LENGTH;

@Override
public Integer apply(String string) {
Expand All @@ -370,35 +370,35 @@ public Integer apply(String string) {

public void testOnResultOf_natural() {
Comparator<String> comparator =
Ordering.<Integer>natural().onResultOf(StringLengthFunction.StringLength);
Ordering.<Integer>natural().onResultOf(StringLengthFunction.STRING_LENGTH);
assertTrue(comparator.compare("to", "be") == 0);
assertTrue(comparator.compare("or", "not") < 0);
assertTrue(comparator.compare("that", "to") > 0);

new EqualsTester()
.addEqualityGroup(
comparator, Ordering.<Integer>natural().onResultOf(StringLengthFunction.StringLength))
comparator, Ordering.<Integer>natural().onResultOf(StringLengthFunction.STRING_LENGTH))
.addEqualityGroup(DECREASING_INTEGER)
.testEquals();
reserializeAndAssert(comparator);
assertEquals("Ordering.natural().onResultOf(StringLength)", comparator.toString());
assertEquals("Ordering.natural().onResultOf(STRING_LENGTH)", comparator.toString());
}

public void testOnResultOf_chained() {
Comparator<String> comparator =
DECREASING_INTEGER.onResultOf(StringLengthFunction.StringLength);
DECREASING_INTEGER.onResultOf(StringLengthFunction.STRING_LENGTH);
assertTrue(comparator.compare("to", "be") == 0);
assertTrue(comparator.compare("not", "or") < 0);
assertTrue(comparator.compare("to", "that") > 0);

new EqualsTester()
.addEqualityGroup(
comparator, DECREASING_INTEGER.onResultOf(StringLengthFunction.StringLength))
comparator, DECREASING_INTEGER.onResultOf(StringLengthFunction.STRING_LENGTH))
.addEqualityGroup(DECREASING_INTEGER.onResultOf(Functions.constant(1)))
.addEqualityGroup(Ordering.natural())
.testEquals();
reserializeAndAssert(comparator);
assertEquals("Ordering.natural().reverse().onResultOf(StringLength)", comparator.toString());
assertEquals("Ordering.natural().reverse().onResultOf(STRING_LENGTH)", comparator.toString());
}

public void testLexicographical() {
Expand Down
24 changes: 12 additions & 12 deletions android/guava-tests/test/com/google/common/collect/QueuesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ private void testMultipleProducers(BlockingQueue<Object> q) throws InterruptedEx

public void testDrainTimesOut() throws Exception {
for (BlockingQueue<Object> q : blockingQueues()) {
testDrainTimesOut(q);
checkDrainTimesOut(q);
}
}

private void testDrainTimesOut(BlockingQueue<Object> q) throws Exception {
private void checkDrainTimesOut(BlockingQueue<Object> q) throws Exception {
for (boolean interruptibly : new boolean[] {true, false}) {
assertEquals(0, Queues.drain(q, ImmutableList.of(), 1, 10, MILLISECONDS));

Expand Down Expand Up @@ -157,11 +157,11 @@ private void testDrainTimesOut(BlockingQueue<Object> q) throws Exception {

public void testZeroElements() throws Exception {
for (BlockingQueue<Object> q : blockingQueues()) {
testZeroElements(q);
checkZeroElements(q);
}
}

private void testZeroElements(BlockingQueue<Object> q) throws InterruptedException {
private void checkZeroElements(BlockingQueue<Object> q) throws InterruptedException {
for (boolean interruptibly : new boolean[] {true, false}) {
// asking to drain zero elements
assertEquals(0, drain(q, ImmutableList.of(), 0, 10, MILLISECONDS, interruptibly));
Expand All @@ -170,21 +170,21 @@ private void testZeroElements(BlockingQueue<Object> q) throws InterruptedExcepti

public void testEmpty() throws Exception {
for (BlockingQueue<Object> q : blockingQueues()) {
testEmpty(q);
checkEmpty(q);
}
}

private void testEmpty(BlockingQueue<Object> q) {
private void checkEmpty(BlockingQueue<Object> q) {
assertDrained(q);
}

public void testNegativeMaxElements() throws Exception {
for (BlockingQueue<Object> q : blockingQueues()) {
testNegativeMaxElements(q);
checkNegativeMaxElements(q);
}
}

private void testNegativeMaxElements(BlockingQueue<Object> q) throws InterruptedException {
private void checkNegativeMaxElements(BlockingQueue<Object> q) throws InterruptedException {
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError = threadPool.submit(new Producer(q, 1));

Expand All @@ -199,11 +199,11 @@ private void testNegativeMaxElements(BlockingQueue<Object> q) throws Interrupted

public void testDrain_throws() throws Exception {
for (BlockingQueue<Object> q : blockingQueues()) {
testDrain_throws(q);
checkDrainThrows(q);
}
}

private void testDrain_throws(BlockingQueue<Object> q) {
private void checkDrainThrows(BlockingQueue<Object> q) {
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError = threadPool.submit(new Interrupter(currentThread()));
try {
Expand All @@ -215,11 +215,11 @@ private void testDrain_throws(BlockingQueue<Object> q) {

public void testDrainUninterruptibly_doesNotThrow() throws Exception {
for (BlockingQueue<Object> q : blockingQueues()) {
testDrainUninterruptibly_doesNotThrow(q);
testDrainUninterruptiblyDoesNotThrow(q);
}
}

private void testDrainUninterruptibly_doesNotThrow(final BlockingQueue<Object> q) {
private void testDrainUninterruptiblyDoesNotThrow(final BlockingQueue<Object> q) {
final Thread mainThread = currentThread();
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,15 @@ public void testRoundToDouble_twoToThe54PlusFour() {
}

public void testRoundToDouble_maxDouble() {
BigDecimal maxDoubleAsBD = new BigDecimal(Double.MAX_VALUE);
new RoundToDoubleTester(maxDoubleAsBD).setExpectation(Double.MAX_VALUE, values()).test();
BigDecimal maxDoubleAsBigDecimal = new BigDecimal(Double.MAX_VALUE);
new RoundToDoubleTester(maxDoubleAsBigDecimal)
.setExpectation(Double.MAX_VALUE, values())
.test();
}

public void testRoundToDouble_maxDoublePlusOne() {
BigDecimal maxDoubleAsBD = new BigDecimal(Double.MAX_VALUE).add(BigDecimal.ONE);
new RoundToDoubleTester(maxDoubleAsBD)
BigDecimal maxDoubleAsBigDecimal = new BigDecimal(Double.MAX_VALUE).add(BigDecimal.ONE);
new RoundToDoubleTester(maxDoubleAsBigDecimal)
.setExpectation(Double.MAX_VALUE, DOWN, FLOOR, HALF_EVEN, HALF_UP, HALF_DOWN)
.setExpectation(Double.POSITIVE_INFINITY, UP, CEILING)
.roundUnnecessaryShouldThrow()
Expand Down Expand Up @@ -247,13 +249,15 @@ public void testRoundToDouble_negativeTwoToThe54MinusFour() {
}

public void testRoundToDouble_minDouble() {
BigDecimal minDoubleAsBD = new BigDecimal(-Double.MAX_VALUE);
new RoundToDoubleTester(minDoubleAsBD).setExpectation(-Double.MAX_VALUE, values()).test();
BigDecimal minDoubleAsBigDecimal = new BigDecimal(-Double.MAX_VALUE);
new RoundToDoubleTester(minDoubleAsBigDecimal)
.setExpectation(-Double.MAX_VALUE, values())
.test();
}

public void testRoundToDouble_minDoubleMinusOne() {
BigDecimal minDoubleAsBD = new BigDecimal(-Double.MAX_VALUE).subtract(BigDecimal.ONE);
new RoundToDoubleTester(minDoubleAsBD)
BigDecimal minDoubleAsBigDecimal = new BigDecimal(-Double.MAX_VALUE).subtract(BigDecimal.ONE);
new RoundToDoubleTester(minDoubleAsBigDecimal)
.setExpectation(-Double.MAX_VALUE, DOWN, CEILING, HALF_EVEN, HALF_UP, HALF_DOWN)
.setExpectation(Double.NEGATIVE_INFINITY, UP, FLOOR)
.roundUnnecessaryShouldThrow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,16 +621,18 @@ public void testRoundToDouble_twoToThe54PlusFour() {
@J2ktIncompatible
@GwtIncompatible
public void testRoundToDouble_maxDouble() {
BigInteger maxDoubleAsBI = DoubleMath.roundToBigInteger(Double.MAX_VALUE, UNNECESSARY);
new RoundToDoubleTester(maxDoubleAsBI).setExpectation(Double.MAX_VALUE, values()).test();
BigInteger maxDoubleAsBigInteger = DoubleMath.roundToBigInteger(Double.MAX_VALUE, UNNECESSARY);
new RoundToDoubleTester(maxDoubleAsBigInteger)
.setExpectation(Double.MAX_VALUE, values())
.test();
}

@J2ktIncompatible
@GwtIncompatible
public void testRoundToDouble_maxDoublePlusOne() {
BigInteger maxDoubleAsBI =
BigInteger maxDoubleAsBigInteger =
DoubleMath.roundToBigInteger(Double.MAX_VALUE, UNNECESSARY).add(BigInteger.ONE);
new RoundToDoubleTester(maxDoubleAsBI)
new RoundToDoubleTester(maxDoubleAsBigInteger)
.setExpectation(Double.MAX_VALUE, DOWN, FLOOR, HALF_EVEN, HALF_UP, HALF_DOWN)
.setExpectation(Double.POSITIVE_INFINITY, UP, CEILING)
.roundUnnecessaryShouldThrow()
Expand Down Expand Up @@ -706,16 +708,18 @@ public void testRoundToDouble_negativeTwoToThe54MinusFour() {
@J2ktIncompatible
@GwtIncompatible
public void testRoundToDouble_minDouble() {
BigInteger minDoubleAsBI = DoubleMath.roundToBigInteger(-Double.MAX_VALUE, UNNECESSARY);
new RoundToDoubleTester(minDoubleAsBI).setExpectation(-Double.MAX_VALUE, values()).test();
BigInteger minDoubleAsBigInteger = DoubleMath.roundToBigInteger(-Double.MAX_VALUE, UNNECESSARY);
new RoundToDoubleTester(minDoubleAsBigInteger)
.setExpectation(-Double.MAX_VALUE, values())
.test();
}

@J2ktIncompatible
@GwtIncompatible
public void testRoundToDouble_minDoubleMinusOne() {
BigInteger minDoubleAsBI =
BigInteger minDoubleAsBigInteger =
DoubleMath.roundToBigInteger(-Double.MAX_VALUE, UNNECESSARY).subtract(BigInteger.ONE);
new RoundToDoubleTester(minDoubleAsBI)
new RoundToDoubleTester(minDoubleAsBigInteger)
.setExpectation(-Double.MAX_VALUE, DOWN, CEILING, HALF_EVEN, HALF_UP, HALF_DOWN)
.setExpectation(Double.NEGATIVE_INFINITY, UP, FLOOR)
.roundUnnecessaryShouldThrow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ public void testIsMaximum() throws UnknownHostException {
assertTrue(InetAddresses.isMaximum(address));
}

@SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks
public void testIncrementIPv4() throws UnknownHostException {
InetAddress address_66_0 = InetAddress.getByName("172.24.66.0");
InetAddress address_66_255 = InetAddress.getByName("172.24.66.255");
Expand All @@ -753,6 +754,7 @@ public void testIncrementIPv4() throws UnknownHostException {
assertThrows(IllegalArgumentException.class, () -> InetAddresses.increment(address_ffffff));
}

@SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks
public void testIncrementIPv6() throws UnknownHostException {
InetAddress addressV6_66_0 = InetAddress.getByName("2001:db8::6600");
InetAddress addressV6_66_ff = InetAddress.getByName("2001:db8::66ff");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ interface A {}
interface B {}

public void testEquals() {
class AB implements A, B {}
class BA implements B, A {}
AB ab = new AB();
BA ba = new BA();
new EqualsTester()
.addEqualityGroup(newDelegatingList(LIST1))
// Actually, this violates List#equals contract.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,9 @@ private abstract static class Third<T, D> extends Second<T> {}

private abstract static class Fourth<T, D> extends Third<D, T> {}

private static class ConcreteIS extends Fourth<Integer, String> {}
private static class ConcreteIntegerString extends Fourth<Integer, String> {}

private static class ConcreteSI extends Fourth<String, Integer> {}
private static class ConcreteStringInteger extends Fourth<String, Integer> {}

public void testAssignableClassToClass() {
@SuppressWarnings("rawtypes") // To test TypeToken<List>
Expand Down Expand Up @@ -759,8 +759,8 @@ public void testAssignableClassToType() {
assertFalse(tokenL.isSupertypeOf(List.class));

TypeToken<First<String>> tokenF = new TypeToken<First<String>>() {};
assertTrue(tokenF.isSupertypeOf(ConcreteIS.class));
assertFalse(tokenF.isSupertypeOf(ConcreteSI.class));
assertTrue(tokenF.isSupertypeOf(ConcreteIntegerString.class));
assertFalse(tokenF.isSupertypeOf(ConcreteStringInteger.class));
}

public void testAssignableClassToArrayType() {
Expand All @@ -775,8 +775,8 @@ public void testAssignableParameterizedTypeToType() {
assertFalse(tokenL.isSupertypeOf(IntegerList.class.getGenericInterfaces()[0]));

TypeToken<First<String>> tokenF = new TypeToken<First<String>>() {};
assertTrue(tokenF.isSupertypeOf(ConcreteIS.class.getGenericSuperclass()));
assertFalse(tokenF.isSupertypeOf(ConcreteSI.class.getGenericSuperclass()));
assertTrue(tokenF.isSupertypeOf(ConcreteIntegerString.class.getGenericSuperclass()));
assertFalse(tokenF.isSupertypeOf(ConcreteStringInteger.class.getGenericSuperclass()));
}

public void testGenericArrayTypeToArrayType() {
Expand All @@ -798,8 +798,8 @@ public void testAssignableTokenToType() {
assertFalse(tokenF.isSupertypeOf(new TypeToken<Third<Integer, String>>() {}));
assertTrue(tokenF.isSupertypeOf(new TypeToken<Fourth<Integer, String>>() {}));
assertFalse(tokenF.isSupertypeOf(new TypeToken<Fourth<String, Integer>>() {}));
assertTrue(tokenF.isSupertypeOf(new TypeToken<ConcreteIS>() {}));
assertFalse(tokenF.isSupertypeOf(new TypeToken<ConcreteSI>() {}));
assertTrue(tokenF.isSupertypeOf(new TypeToken<ConcreteIntegerString>() {}));
assertFalse(tokenF.isSupertypeOf(new TypeToken<ConcreteStringInteger>() {}));
}

public void testAssignableWithWildcards() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ class LocalClass<T> {}
}

public void testNewParameterizedType_staticLocalClass() {
doTestNewParameterizedType_staticLocalClass();
doTestNewParameterizedTypeStaticLocalClass();
}

private static void doTestNewParameterizedType_staticLocalClass() {
private static void doTestNewParameterizedTypeStaticLocalClass() {
class LocalClass<T> {}
Type jvmType = new LocalClass<String>() {}.getClass().getGenericSuperclass();
Type ourType = Types.newParameterizedType(LocalClass.class, String.class);
Expand Down
Loading

0 comments on commit 4fa6d04

Please sign in to comment.