From 15456c86a45c7871d8a217e985d099c02149aa7a Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sat, 20 Jul 2024 10:52:54 +0200 Subject: Switch from JetBrains annotations to JSpecify. Change-Id: Ia04b52c36f9779ab15e688e0dd7434644b3a3f7f --- .../main/java/eu/mulk/jgvariant/core/Decoder.java | 73 +++++++++++----------- .../java/eu/mulk/jgvariant/core/Signature.java | 2 +- .../java/eu/mulk/jgvariant/core/package-info.java | 3 + 3 files changed, 42 insertions(+), 36 deletions(-) (limited to 'jgvariant-core/src/main/java/eu') 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 74d569d..4f2ae10 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 @@ -4,12 +4,13 @@ package eu.mulk.jgvariant.core; -import com.google.errorprone.annotations.Immutable; -import org.apiguardian.api.API; -import org.apiguardian.api.API.Status; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import static java.lang.Math.max; +import static java.nio.ByteOrder.BIG_ENDIAN; +import static java.nio.ByteOrder.LITTLE_ENDIAN; +import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.Objects.requireNonNullElse; +import com.google.errorprone.annotations.Immutable; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -24,12 +25,10 @@ import java.util.Map.Entry; import java.util.function.Function; import java.util.function.Predicate; import java.util.function.UnaryOperator; - -import static java.lang.Math.max; -import static java.nio.ByteOrder.BIG_ENDIAN; -import static java.nio.ByteOrder.LITTLE_ENDIAN; -import static java.nio.charset.StandardCharsets.UTF_8; -import static java.util.Objects.requireNonNullElse; +import org.apiguardian.api.API; +import org.apiguardian.api.API.Status; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; /** * Type class for decodable types. @@ -79,7 +78,7 @@ public abstract class Decoder { * data. * @throws IllegalArgumentException if the serialized GVariant is ill-formed */ - public abstract @NotNull T decode(ByteBuffer byteSlice); + public abstract @NonNull T decode(ByteBuffer byteSlice); /** * Encodes a value of type {@code T} into a {@link ByteBuffer} holding a serialized GVariant. @@ -121,7 +120,9 @@ public abstract class Decoder { * @return a new, decorated {@link Decoder}. * @see java.util.stream.Stream#map */ - public final Decoder map(Function<@NotNull T, @NotNull U> decodingFunction, Function<@NotNull U, @NotNull T> encodingFunction) { + public final Decoder map( + Function<@NonNull T, @NonNull U> decodingFunction, + Function<@NonNull U, @NonNull T> encodingFunction) { return new MappingDecoder<>(decodingFunction, encodingFunction); } @@ -396,7 +397,7 @@ public abstract class Decoder { } @Override - public @NotNull List decode(ByteBuffer byteSlice) { + public @NonNull List decode(ByteBuffer byteSlice) { List elements; var elementSize = elementDecoder.fixedSize(); @@ -486,7 +487,7 @@ public abstract class Decoder { } @Override - public @NotNull Map decode(ByteBuffer byteSlice) { + public @NonNull Map decode(ByteBuffer byteSlice) { List> entries = entryArrayDecoder.decode(byteSlice); Map result = new LinkedHashMap<>(); for (var entry : entries) { @@ -517,7 +518,7 @@ public abstract class Decoder { } @Override - public byte @NotNull [] decode(ByteBuffer byteSlice) { + public byte @NonNull [] decode(ByteBuffer byteSlice) { // A simple C-style array. byte[] elements = new byte[byteSlice.limit() / ELEMENT_SIZE]; byteSlice.get(elements); @@ -550,7 +551,7 @@ public abstract class Decoder { } @Override - public @NotNull Optional decode(ByteBuffer byteSlice) { + public @NonNull Optional decode(ByteBuffer byteSlice) { if (!byteSlice.hasRemaining()) { return Optional.empty(); } else { @@ -604,7 +605,7 @@ public abstract class Decoder { } @Override - public @NotNull U decode(ByteBuffer byteSlice) { + public @NonNull U decode(ByteBuffer byteSlice) { Object[] recordConstructorArguments = tupleDecoder.decode(byteSlice); try { @@ -674,7 +675,7 @@ public abstract class Decoder { } @Override - public Object @NotNull [] decode(ByteBuffer byteSlice) { + public Object @NonNull [] decode(ByteBuffer byteSlice) { int framingOffsetSize = byteCount(byteSlice.limit()); var objects = new Object[componentDecoders.length]; @@ -782,7 +783,7 @@ public abstract class Decoder { @Override @SuppressWarnings("unchecked") - public Map.@NotNull Entry decode(ByteBuffer byteSlice) { + public Map.@NonNull Entry decode(ByteBuffer byteSlice) { Object[] components = tupleDecoder.decode(byteSlice); return Map.entry((K) components[0], (V) components[1]); } @@ -807,7 +808,7 @@ public abstract class Decoder { } @Override - public @NotNull Variant decode(ByteBuffer byteSlice) { + public @NonNull Variant decode(ByteBuffer byteSlice) { for (int i = byteSlice.limit() - 1; i >= 0; --i) { if (byteSlice.get(i) != 0) { continue; @@ -850,7 +851,7 @@ public abstract class Decoder { } @Override - public @NotNull Boolean decode(ByteBuffer byteSlice) { + public @NonNull Boolean decode(ByteBuffer byteSlice) { return byteSlice.get() != 0; } @@ -873,7 +874,7 @@ public abstract class Decoder { } @Override - public @NotNull Byte decode(ByteBuffer byteSlice) { + public @NonNull Byte decode(ByteBuffer byteSlice) { return byteSlice.get(); } @@ -896,7 +897,7 @@ public abstract class Decoder { } @Override - public @NotNull Short decode(ByteBuffer byteSlice) { + public @NonNull Short decode(ByteBuffer byteSlice) { return byteSlice.getShort(); } @@ -919,7 +920,7 @@ public abstract class Decoder { } @Override - public @NotNull Integer decode(ByteBuffer byteSlice) { + public @NonNull Integer decode(ByteBuffer byteSlice) { return byteSlice.getInt(); } @@ -942,7 +943,7 @@ public abstract class Decoder { } @Override - public @NotNull Long decode(ByteBuffer byteSlice) { + public @NonNull Long decode(ByteBuffer byteSlice) { return byteSlice.getLong(); } @@ -965,7 +966,7 @@ public abstract class Decoder { } @Override - public @NotNull Double decode(ByteBuffer byteSlice) { + public @NonNull Double decode(ByteBuffer byteSlice) { return byteSlice.getDouble(); } @@ -995,7 +996,7 @@ public abstract class Decoder { } @Override - public @NotNull String decode(ByteBuffer byteSlice) { + public @NonNull String decode(ByteBuffer byteSlice) { byteSlice.limit(byteSlice.limit() - 1); return charset.decode(byteSlice).toString(); } @@ -1010,10 +1011,12 @@ public abstract class Decoder { @SuppressWarnings("Immutable") private class MappingDecoder extends Decoder { - private final Function<@NotNull T, @NotNull U> decodingFunction; - private final Function<@NotNull U, @NotNull T> encodingFunction; + private final Function<@NonNull T, @NonNull U> decodingFunction; + private final Function<@NonNull U, @NonNull T> encodingFunction; - MappingDecoder(Function<@NotNull T, @NotNull U> decodingFunction, Function<@NotNull U, @NotNull T> encodingFunction) { + MappingDecoder( + Function<@NonNull T, @NonNull U> decodingFunction, + Function<@NonNull U, @NonNull T> encodingFunction) { this.decodingFunction = decodingFunction; this.encodingFunction = encodingFunction; } @@ -1029,7 +1032,7 @@ public abstract class Decoder { } @Override - public @NotNull U decode(ByteBuffer byteSlice) { + public @NonNull U decode(ByteBuffer byteSlice) { return decodingFunction.apply(Decoder.this.decode(byteSlice)); } @@ -1061,7 +1064,7 @@ public abstract class Decoder { } @Override - public @NotNull T decode(ByteBuffer byteSlice) { + public @NonNull T decode(ByteBuffer byteSlice) { var transformedBuffer = decodingFunction.apply(byteSlice.asReadOnlyBuffer().order(byteSlice.order())); return Decoder.this.decode(transformedBuffer); } @@ -1094,7 +1097,7 @@ public abstract class Decoder { } @Override - public @NotNull T decode(ByteBuffer byteSlice) { + public @NonNull T decode(ByteBuffer byteSlice) { var newByteSlice = byteSlice.duplicate(); newByteSlice.order(byteOrder); return Decoder.this.decode(newByteSlice); @@ -1150,7 +1153,7 @@ public abstract class Decoder { } @Override - public @NotNull U decode(ByteBuffer byteSlice) { + public @NonNull U decode(ByteBuffer byteSlice) { var b = selector.test(byteSlice); byteSlice.rewind(); return b ? thenDecoder.decode(byteSlice) : elseDecoder.decode(byteSlice); 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 f59b267..1b33151 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 @@ -14,7 +14,7 @@ import java.util.List; import java.util.Objects; import org.apiguardian.api.API; import org.apiguardian.api.API.Status; -import org.jetbrains.annotations.Nullable; +import org.jspecify.annotations.Nullable; /** * A GVariant signature string. diff --git a/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/package-info.java b/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/package-info.java index e2e8143..e51c9c4 100644 --- a/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/package-info.java +++ b/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/package-info.java @@ -28,4 +28,7 @@ * List example = decoder.decode(ByteBuffer.wrap(bytes)); * } */ +@NullMarked package eu.mulk.jgvariant.core; + +import org.jspecify.annotations.NullMarked; -- cgit v1.2.3