Skip to content

Commit

Permalink
Add @CheckReturnValue to mug-guava classes
Browse files Browse the repository at this point in the history
  • Loading branch information
fluentfuture committed Nov 10, 2024
1 parent 1ab7c35 commit b95c6df
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.common.math.DoubleMath;
import com.google.common.math.IntMath;
import com.google.common.math.LongMath;
import com.google.errorprone.annotations.CheckReturnValue;
import com.google.mu.annotations.RequiresGuava;

/**
Expand Down Expand Up @@ -103,6 +104,7 @@
* @since 8.0
*/
@RequiresGuava
@CheckReturnValue
public final class BinarySearch {
/**
* Returns a {@link Table} to search for element indexes in the given sorted {@code list}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.DiscreteDomain;
import com.google.common.collect.Range;
import com.google.errorprone.annotations.CheckReturnValue;
import com.google.errorprone.annotations.Immutable;
import com.google.mu.annotations.RequiresGuava;

Expand Down Expand Up @@ -56,8 +57,9 @@
* @param <C> the domain type
* @since 8.0
*/
@Immutable(containerOf = "C")
@RequiresGuava
@Immutable(containerOf = "C")
@CheckReturnValue
public final class InsertionPoint<C extends Comparable<C>> implements Comparable<InsertionPoint<C>> {
@SuppressWarnings("unchecked") // Curiously recursive generics doesn't play nicely with wildcard.
private static final Comparator<Comparable<?>> NULL_FIRST = (Comparator<Comparable<?>>) Comparator
Expand Down
2 changes: 2 additions & 0 deletions mug-guava/src/main/java/com/google/mu/safesql/GoogleSql.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

import com.google.errorprone.annotations.CheckReturnValue;
import com.google.errorprone.annotations.CompileTimeConstant;
import com.google.mu.annotations.RequiresGuava;
import com.google.mu.annotations.TemplateFormatMethod;
Expand All @@ -33,6 +34,7 @@
* @since 7.0
*/
@RequiresGuava
@CheckReturnValue
public final class GoogleSql {
private static final DateTimeFormatter LOCAL_DATE_TIME_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss[.SSSSSS]");
Expand Down
2 changes: 2 additions & 0 deletions mug-guava/src/main/java/com/google/mu/safesql/SafeQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.common.collect.Iterables;
import com.google.common.primitives.UnsignedInteger;
import com.google.common.primitives.UnsignedLong;
import com.google.errorprone.annotations.CheckReturnValue;
import com.google.errorprone.annotations.CompileTimeConstant;
import com.google.errorprone.annotations.Immutable;
import com.google.mu.annotations.RequiresGuava;
Expand Down Expand Up @@ -72,6 +73,7 @@
*/
@RequiresGuava
@Immutable
@CheckReturnValue
public final class SafeQuery {
/**
* An empty query string.
Expand Down
11 changes: 10 additions & 1 deletion mug-guava/src/main/java/com/google/mu/safesql/SafeSql.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.CheckReturnValue;
import com.google.errorprone.annotations.CompileTimeConstant;
import com.google.errorprone.annotations.MustBeClosed;
import com.google.errorprone.annotations.ThreadSafe;
Expand Down Expand Up @@ -283,8 +285,9 @@
*
* @since 8.2
*/
@ThreadSafe
@RequiresGuava
@ThreadSafe
@CheckReturnValue
public final class SafeSql {
private static final Logger logger = Logger.getLogger(SafeSql.class.getName());
private static final Substring.RepeatingPattern TOKENS =
Expand Down Expand Up @@ -621,6 +624,7 @@ public <T> List<T> query(
*
* @throws UncheckedSqlException wraps {@link SQLException} if failed
*/
@CanIgnoreReturnValue
public int update(Connection connection) {
if (paramValues.isEmpty()) {
try (Statement stmt = connection.createStatement()) {
Expand Down Expand Up @@ -780,6 +784,7 @@ private static void checkMisuse(Substring.Match placeholder, Object value) {
placeholder);
}

@CanIgnoreReturnValue
private static String rejectQuestionMark(String sql) {
checkArgument(sql.indexOf('?') < 0, "please use named {placeholder} instead of '?'");
return sql;
Expand Down Expand Up @@ -898,23 +903,27 @@ private static final class Builder {
private final StringBuilder queryText = new StringBuilder();
private final List<Object> paramValues = new ArrayList<>();

@CanIgnoreReturnValue
Builder appendSql(String snippet) {
queryText.append(rejectQuestionMark(snippet));
return this;
}

@CanIgnoreReturnValue
Builder addParameter(String name, Object value) {
queryText.append("?");
paramValues.add(value);
return this;
}

@CanIgnoreReturnValue
Builder addSubQuery(SafeSql subQuery) {
queryText.append(subQuery.sql);
paramValues.addAll(subQuery.getParameters());
return this;
}

@CanIgnoreReturnValue
Builder delimit(String delim) {
if (queryText.length() > 0) {
queryText.append(delim);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import com.google.common.collect.Tables;
import com.google.common.collect.TreeRangeMap;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.CheckReturnValue;
import com.google.mu.annotations.RequiresGuava;
import com.google.mu.collect.Chain;
import com.google.mu.util.Both;
Expand All @@ -63,6 +64,7 @@
* @since 4.7
*/
@RequiresGuava
@CheckReturnValue
public final class GuavaCollectors {
/**
* Returns a {@link BiCollector} that collects the key-value pairs into an {@link ImmutableMap}.
Expand Down

0 comments on commit b95c6df

Please sign in to comment.