aboutsummaryrefslogtreecommitdiff
path: root/jgvariant-core/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'jgvariant-core/src/main/java')
-rw-r--r--jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java73
-rw-r--r--jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Signature.java2
-rw-r--r--jgvariant-core/src/main/java/eu/mulk/jgvariant/core/package-info.java3
-rw-r--r--jgvariant-core/src/main/java/module-info.java4
4 files changed, 46 insertions, 36 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 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<T> {
* 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<T> {
* @return a new, decorated {@link Decoder}.
* @see java.util.stream.Stream#map
*/
- public final <U> Decoder<U> map(Function<@NotNull T, @NotNull U> decodingFunction, Function<@NotNull U, @NotNull T> encodingFunction) {
+ public final <U> Decoder<U> 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<T> {
}
@Override
- public @NotNull List<U> decode(ByteBuffer byteSlice) {
+ public @NonNull List<U> decode(ByteBuffer byteSlice) {
List<U> elements;
var elementSize = elementDecoder.fixedSize();
@@ -486,7 +487,7 @@ public abstract class Decoder<T> {
}
@Override
- public @NotNull Map<K, V> decode(ByteBuffer byteSlice) {
+ public @NonNull Map<K, V> decode(ByteBuffer byteSlice) {
List<Map.Entry<K, V>> entries = entryArrayDecoder.decode(byteSlice);
Map<K, V> result = new LinkedHashMap<>();
for (var entry : entries) {
@@ -517,7 +518,7 @@ public abstract class Decoder<T> {
}
@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<T> {
}
@Override
- public @NotNull Optional<U> decode(ByteBuffer byteSlice) {
+ public @NonNull Optional<U> decode(ByteBuffer byteSlice) {
if (!byteSlice.hasRemaining()) {
return Optional.empty();
} else {
@@ -604,7 +605,7 @@ public abstract class Decoder<T> {
}
@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<T> {
}
@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<T> {
@Override
@SuppressWarnings("unchecked")
- public Map.@NotNull Entry<K, V> decode(ByteBuffer byteSlice) {
+ public Map.@NonNull Entry<K, V> 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<T> {
}
@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<T> {
}
@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<T> {
}
@Override
- public @NotNull Byte decode(ByteBuffer byteSlice) {
+ public @NonNull Byte decode(ByteBuffer byteSlice) {
return byteSlice.get();
}
@@ -896,7 +897,7 @@ public abstract class Decoder<T> {
}
@Override
- public @NotNull Short decode(ByteBuffer byteSlice) {
+ public @NonNull Short decode(ByteBuffer byteSlice) {
return byteSlice.getShort();
}
@@ -919,7 +920,7 @@ public abstract class Decoder<T> {
}
@Override
- public @NotNull Integer decode(ByteBuffer byteSlice) {
+ public @NonNull Integer decode(ByteBuffer byteSlice) {
return byteSlice.getInt();
}
@@ -942,7 +943,7 @@ public abstract class Decoder<T> {
}
@Override
- public @NotNull Long decode(ByteBuffer byteSlice) {
+ public @NonNull Long decode(ByteBuffer byteSlice) {
return byteSlice.getLong();
}
@@ -965,7 +966,7 @@ public abstract class Decoder<T> {
}
@Override
- public @NotNull Double decode(ByteBuffer byteSlice) {
+ public @NonNull Double decode(ByteBuffer byteSlice) {
return byteSlice.getDouble();
}
@@ -995,7 +996,7 @@ public abstract class Decoder<T> {
}
@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<T> {
@SuppressWarnings("Immutable")
private class MappingDecoder<U> extends Decoder<U> {
- 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<T> {
}
@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<T> {
}
@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<T> {
}
@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<T> {
}
@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<ExampleRecord> example = decoder.decode(ByteBuffer.wrap(bytes));
* }
*/
+@NullMarked
package eu.mulk.jgvariant.core;
+
+import org.jspecify.annotations.NullMarked;
diff --git a/jgvariant-core/src/main/java/module-info.java b/jgvariant-core/src/main/java/module-info.java
index 51c7252..b0b61a7 100644
--- a/jgvariant-core/src/main/java/module-info.java
+++ b/jgvariant-core/src/main/java/module-info.java
@@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later
+import org.jspecify.annotations.NullMarked;
+
/**
* Provides a parser for the <a href="https://docs.gtk.org/glib/struct.Variant.html">GVariant</a>
* serialization format.
@@ -79,10 +81,12 @@
* }
* }
*/
+@NullMarked
module eu.mulk.jgvariant.core {
requires static com.google.errorprone.annotations;
requires static org.apiguardian.api;
requires static org.jetbrains.annotations;
+ requires static org.jspecify;
exports eu.mulk.jgvariant.core;
}