aboutsummaryrefslogtreecommitdiff
path: root/jgvariant-core/src/main
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2022-10-17 19:38:56 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2022-10-17 19:38:56 +0200
commit91dbd7474041880d2babc7124fcce20fe61493c1 (patch)
treedba559a9f4b9b604f035e27fd4d4dc7207a74bcd /jgvariant-core/src/main
parenteac6ed704e7fa059488848c5d52cc4c8102d7ac5 (diff)
Remove Checker Framework; add NullAway, Picnic Error Prone Support.
Change-Id: I6558f0b4db0f9a192c18bbe45e2eaf10595bc666
Diffstat (limited to 'jgvariant-core/src/main')
-rw-r--r--jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java16
-rw-r--r--jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Signature.java10
2 files changed, 17 insertions, 9 deletions
diff --git a/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java b/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java
index 2cb36c6..4538900 100644
--- a/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java
+++ b/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java
@@ -5,15 +5,16 @@
package eu.mulk.jgvariant.core;
import static java.nio.ByteOrder.LITTLE_ENDIAN;
+import static java.util.Objects.requireNonNullElse;
import static java.util.stream.Collectors.toMap;
+import com.google.errorprone.annotations.Immutable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.RecordComponent;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import java.text.ParseException;
-import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -56,8 +57,9 @@ import org.jetbrains.annotations.Nullable;
*
* @param <T> the type that the {@link Decoder} can decode.
*/
-@SuppressWarnings("java:S1610")
@API(status = Status.EXPERIMENTAL)
+@Immutable
+@SuppressWarnings({"ImmutableListOf", "InvalidInlineTag", "java:S1610", "UnescapedEntity"})
public abstract class Decoder<T> {
private Decoder() {}
@@ -523,6 +525,7 @@ public abstract class Decoder<T> {
}
}
+ @SuppressWarnings("Immutable")
private static class TupleDecoder extends Decoder<Object[]> {
private final Decoder<?>[] componentDecoders;
@@ -625,7 +628,7 @@ public abstract class Decoder<T> {
@SuppressWarnings("unchecked")
public Map.@NotNull Entry<K, V> decode(ByteBuffer byteSlice) {
Object[] components = tupleDecoder.decode(byteSlice);
- return new SimpleImmutableEntry<>((K) components[0], (V) components[1]);
+ return Map.entry((K) components[0], (V) components[1]);
}
}
@@ -800,6 +803,7 @@ public abstract class Decoder<T> {
}
}
+ @SuppressWarnings("Immutable")
private class MappingDecoder<U> extends Decoder<U> {
private final Function<@NotNull T, @NotNull U> function;
@@ -824,6 +828,7 @@ public abstract class Decoder<T> {
}
}
+ @SuppressWarnings("Immutable")
private class ContramappingDecoder extends Decoder<T> {
private final UnaryOperator<ByteBuffer> function;
@@ -879,6 +884,7 @@ public abstract class Decoder<T> {
return byteSlice.slice(index, length).order(byteSlice.order());
}
+ @SuppressWarnings("Immutable")
private static class PredicateDecoder<U> extends Decoder<U> {
private final Predicate<ByteBuffer> selector;
@@ -900,8 +906,8 @@ public abstract class Decoder<T> {
throw new IllegalArgumentException(
"incompatible sizes in predicate branches: then=%s, else=%s"
.formatted(
- Objects.requireNonNullElse(thenDecoder.fixedSize(), "(null)"),
- Objects.requireNonNullElse(elseDecoder.fixedSize(), "(null)")));
+ requireNonNullElse(thenDecoder.fixedSize(), "(null)"),
+ requireNonNullElse(elseDecoder.fixedSize(), "(null)")));
}
}
diff --git a/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Signature.java b/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Signature.java
index cc9674d..4c8cd65 100644
--- a/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Signature.java
+++ b/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Signature.java
@@ -4,8 +4,10 @@
package eu.mulk.jgvariant.core;
+import static java.nio.charset.StandardCharsets.US_ASCII;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
@@ -41,7 +43,7 @@ public final class Signature {
this.decoder = parseSignature(signatureBytes);
signatureBytes.rewind();
- this.signatureString = StandardCharsets.US_ASCII.decode(signatureBytes).toString();
+ this.signatureString = US_ASCII.decode(signatureBytes).toString();
}
static Signature parse(ByteBuffer signatureBytes) throws ParseException {
@@ -49,7 +51,7 @@ public final class Signature {
}
public static Signature parse(String signatureString) throws ParseException {
- var signatureBytes = ByteBuffer.wrap(signatureString.getBytes(StandardCharsets.US_ASCII));
+ var signatureBytes = ByteBuffer.wrap(signatureString.getBytes(US_ASCII));
return parse(signatureBytes);
}
@@ -93,7 +95,7 @@ public final class Signature {
case 'i', 'u' -> Decoder.ofInt();
case 'x', 't' -> Decoder.ofLong();
case 'd' -> Decoder.ofDouble();
- case 's', 'o', 'g' -> Decoder.ofString(StandardCharsets.UTF_8);
+ case 's', 'o', 'g' -> Decoder.ofString(UTF_8);
case 'v' -> Decoder.ofVariant();
case 'm' -> Decoder.ofMaybe(parseSignature(signature));
case '(' -> Decoder.ofStructure(parseTupleTypes(signature).toArray(new Decoder<?>[0]));