From 5be405391d793194195d14031841e189b3b29302 Mon Sep 17 00:00:00 2001 From: Octavia Togami Date: Tue, 25 Jun 2024 19:18:52 -0700 Subject: [PATCH] Switch to jspecify --- common/build.gradle.kts | 4 +- common/src/main/java/module-info.java | 5 +- .../enginehub/linbus/common/IOFunction.java | 4 +- .../common/internal/AbstractIterator.java | 4 +- format-snbt/build.gradle.kts | 4 +- format-snbt/src/main/java/module-info.java | 5 +- .../linbus/format/snbt/LinStringIO.java | 13 ++- .../format/snbt/impl/LinSnbtWriter.java | 3 +- .../snbt/impl/reader/LinSnbtReader.java | 11 ++- .../snbt/impl/reader/LinSnbtTokenizer.java | 8 +- .../linbus/format/snbt/impl/package-info.java | 22 +++++ .../format/snbt/impl/reader/package-info.java | 22 +++++ .../linbus/format/snbt/package-info.java | 22 +++++ .../linbus/format/snbt/util/TracedReader.java | 8 +- .../linbus/format/snbt/util/package-info.java | 22 +++++ gradle/libs.versions.toml | 10 +-- stream/build.gradle.kts | 7 +- stream/src/main/java/module-info.java | 5 +- .../enginehub/linbus/stream/LinBinaryIO.java | 10 +-- .../enginehub/linbus/stream/LinStream.java | 9 +- .../linbus/stream/LinStreamable.java | 4 +- .../linbus/stream/impl/LinNbtReader.java | 2 +- .../stream/impl/OptionalInfoCalculator.java | 11 ++- .../stream/internal/FlatteningLinStream.java | 4 +- .../stream/internal/SurroundingLinStream.java | 10 +-- tree/build.gradle.kts | 4 +- tree/src/main/java/module-info.java | 5 +- .../linbus/tree/LinByteArrayTag.java | 21 +++-- .../org/enginehub/linbus/tree/LinByteTag.java | 13 ++- .../enginehub/linbus/tree/LinCompoundTag.java | 84 ++++++++----------- .../enginehub/linbus/tree/LinDoubleTag.java | 11 ++- .../org/enginehub/linbus/tree/LinEndTag.java | 7 +- .../enginehub/linbus/tree/LinFloatTag.java | 11 ++- .../enginehub/linbus/tree/LinIntArrayTag.java | 17 ++-- .../org/enginehub/linbus/tree/LinIntTag.java | 11 ++- .../org/enginehub/linbus/tree/LinListTag.java | 36 ++++---- .../linbus/tree/LinLongArrayTag.java | 19 ++--- .../org/enginehub/linbus/tree/LinLongTag.java | 11 ++- .../enginehub/linbus/tree/LinRootEntry.java | 7 +- .../enginehub/linbus/tree/LinShortTag.java | 11 ++- .../enginehub/linbus/tree/LinStringTag.java | 13 ++- .../org/enginehub/linbus/tree/LinTag.java | 10 +-- .../org/enginehub/linbus/tree/LinTagType.java | 63 +++++++------- .../org/enginehub/linbus/tree/ToLinTag.java | 4 +- .../linbus/tree/impl/LinTagReader.java | 13 ++- .../enginehub/linbus/tree/TagTestUtil.java | 3 +- .../linbus/tree/impl/package-info.java | 22 +++++ .../enginehub/linbus/tree/package-info.java | 22 +++++ .../linbus/tree/truth/LinTagSubject.java | 20 ++++- .../linbus/tree/truth/package-info.java | 22 +++++ 50 files changed, 409 insertions(+), 280 deletions(-) create mode 100644 format-snbt/src/test/java/org/enginehub/linbus/format/snbt/impl/package-info.java create mode 100644 format-snbt/src/test/java/org/enginehub/linbus/format/snbt/impl/reader/package-info.java create mode 100644 format-snbt/src/test/java/org/enginehub/linbus/format/snbt/package-info.java create mode 100644 format-snbt/src/test/java/org/enginehub/linbus/format/snbt/util/package-info.java create mode 100644 tree/src/test/java/org/enginehub/linbus/tree/impl/package-info.java create mode 100644 tree/src/test/java/org/enginehub/linbus/tree/package-info.java create mode 100644 tree/src/test/java/org/enginehub/linbus/tree/truth/package-info.java diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 742321a..d119c63 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -6,13 +6,13 @@ plugins { } dependencies { - compileOnlyApi(libs.jetbrains.annotations) + compileOnlyApi(libs.jspecify.annotations) testImplementation(platform(libs.junit.bom)) testImplementation(libs.junit.jupiter.api) testRuntimeOnly(libs.junit.jupiter.engine) - testImplementation(libs.truth.asProvider()) { + testImplementation(libs.truth) { exclude(group = "junit") } } diff --git a/common/src/main/java/module-info.java b/common/src/main/java/module-info.java index 5a5688f..dab727b 100644 --- a/common/src/main/java/module-info.java +++ b/common/src/main/java/module-info.java @@ -16,12 +16,15 @@ * along with this program. If not, see . */ +import org.jspecify.annotations.NullMarked; + /** * The common module of lin-bus, shared between the streaming and tree modules. */ +@NullMarked module org.enginehub.linbus.common { exports org.enginehub.linbus.common; exports org.enginehub.linbus.common.internal to org.enginehub.linbus.stream, org.enginehub.linbus.tree, org.enginehub.linbus.format.snbt; - requires static org.jetbrains.annotations; + requires static transitive org.jspecify; } diff --git a/common/src/main/java/org/enginehub/linbus/common/IOFunction.java b/common/src/main/java/org/enginehub/linbus/common/IOFunction.java index 5fbccfe..1815234 100644 --- a/common/src/main/java/org/enginehub/linbus/common/IOFunction.java +++ b/common/src/main/java/org/enginehub/linbus/common/IOFunction.java @@ -18,6 +18,8 @@ package org.enginehub.linbus.common; +import org.jspecify.annotations.Nullable; + import java.io.IOException; import java.util.function.Function; @@ -27,7 +29,7 @@ * @param the input type * @param the output type */ -public interface IOFunction { +public interface IOFunction { /** * Applies this function to the given argument. * diff --git a/common/src/main/java/org/enginehub/linbus/common/internal/AbstractIterator.java b/common/src/main/java/org/enginehub/linbus/common/internal/AbstractIterator.java index 365dafa..cae7353 100644 --- a/common/src/main/java/org/enginehub/linbus/common/internal/AbstractIterator.java +++ b/common/src/main/java/org/enginehub/linbus/common/internal/AbstractIterator.java @@ -18,7 +18,7 @@ package org.enginehub.linbus.common.internal; -import org.jetbrains.annotations.Nullable; +import org.jspecify.annotations.Nullable; import java.util.Iterator; import java.util.NoSuchElementException; @@ -30,7 +30,7 @@ * * @param the type of items returned by this iterator */ -public abstract class AbstractIterator implements Iterator { +public abstract class AbstractIterator implements Iterator { private boolean needNext = true; private boolean end; private T next; diff --git a/format-snbt/build.gradle.kts b/format-snbt/build.gradle.kts index ab45523..e52498d 100644 --- a/format-snbt/build.gradle.kts +++ b/format-snbt/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } dependencies { - compileOnlyApi(libs.jetbrains.annotations) + compileOnlyApi(libs.jspecify.annotations) api(project(":common")) api(project(":stream")) @@ -17,7 +17,7 @@ dependencies { testImplementation(libs.junit.jupiter.api) testRuntimeOnly(libs.junit.jupiter.engine) - testImplementation(libs.truth.asProvider()) { + testImplementation(libs.truth) { exclude(group = "junit") } } diff --git a/format-snbt/src/main/java/module-info.java b/format-snbt/src/main/java/module-info.java index 53f2787..b16fb39 100644 --- a/format-snbt/src/main/java/module-info.java +++ b/format-snbt/src/main/java/module-info.java @@ -16,13 +16,16 @@ * along with this program. If not, see . */ +import org.jspecify.annotations.NullMarked; + /** * The tree module of lin-bus. Presents a standard tree structure of NBT. Internally, everything is parsed using the * streaming module. */ +@NullMarked module org.enginehub.linbus.format.snbt { exports org.enginehub.linbus.format.snbt; - requires static transitive org.jetbrains.annotations; + requires static transitive org.jspecify; requires transitive org.enginehub.linbus.common; requires transitive org.enginehub.linbus.stream; } diff --git a/format-snbt/src/main/java/org/enginehub/linbus/format/snbt/LinStringIO.java b/format-snbt/src/main/java/org/enginehub/linbus/format/snbt/LinStringIO.java index 960273f..4a41edd 100644 --- a/format-snbt/src/main/java/org/enginehub/linbus/format/snbt/LinStringIO.java +++ b/format-snbt/src/main/java/org/enginehub/linbus/format/snbt/LinStringIO.java @@ -24,7 +24,6 @@ import org.enginehub.linbus.format.snbt.impl.reader.LinSnbtTokenizer; import org.enginehub.linbus.stream.LinStream; import org.enginehub.linbus.stream.LinStreamable; -import org.jetbrains.annotations.NotNull; import java.io.IOException; import java.io.Reader; @@ -54,7 +53,7 @@ public class LinStringIO { * @param input the input to read from * @return the stream of NBT tokens */ - public static @NotNull LinStream read(@NotNull Reader input) { + public static LinStream read(Reader input) { return new LinSnbtReader(new LinSnbtTokenizer(input)); } @@ -64,7 +63,7 @@ public class LinStringIO { * @param input the input to read from * @return the stream of NBT tokens */ - public static @NotNull LinStream readFromString(@NotNull String input) { + public static LinStream readFromString(String input) { return read(new StringReader(input)); } @@ -86,7 +85,7 @@ public class LinStringIO { * @return the result * @throws IOException if an I/O error occurs */ - public static R readUsing(@NotNull Reader input, @NotNull IOFunction transform) throws IOException { + public static R readUsing(Reader input, IOFunction transform) throws IOException { return transform.apply(read(input)); } @@ -98,7 +97,7 @@ public static R readUsing(@NotNull Reader input, @NotNull IOFunction the type of the result * @return the stream of NBT tokens */ - public static R readFromStringUsing(@NotNull String input, @NotNull IOFunction transform) { + public static R readFromStringUsing(String input, IOFunction transform) { try { return transform.apply(readFromString(input)); } catch (IOException e) { @@ -117,7 +116,7 @@ public static R readFromStringUsing(@NotNull String input, @NotNull IOFuncti * @param tokens the stream of NBT tokens * @throws IOException if an I/O error occurs */ - public static void write(@NotNull Appendable output, @NotNull LinStreamable tokens) throws IOException { + public static void write(Appendable output, LinStreamable tokens) throws IOException { new LinSnbtWriter().write(output, tokens.linStream()); } @@ -131,7 +130,7 @@ public static void write(@NotNull Appendable output, @NotNull LinStreamable toke * @param tokens the stream of NBT tokens * @return the string */ - public static String writeToString(@NotNull LinStreamable tokens) { + public static String writeToString(LinStreamable tokens) { var builder = new StringBuilder(); try { write(builder, tokens); diff --git a/format-snbt/src/main/java/org/enginehub/linbus/format/snbt/impl/LinSnbtWriter.java b/format-snbt/src/main/java/org/enginehub/linbus/format/snbt/impl/LinSnbtWriter.java index efa3ab3..c269cad 100644 --- a/format-snbt/src/main/java/org/enginehub/linbus/format/snbt/impl/LinSnbtWriter.java +++ b/format-snbt/src/main/java/org/enginehub/linbus/format/snbt/impl/LinSnbtWriter.java @@ -23,7 +23,6 @@ import org.enginehub.linbus.stream.LinStreamable; import org.enginehub.linbus.stream.exception.NbtWriteException; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.NotNull; import java.io.IOException; import java.nio.ByteBuffer; @@ -55,7 +54,7 @@ record WritingArray() implements WriteState { * @param tokens the tokens * @throws IOException if an I/O error occurs */ - public void write(@NotNull Appendable output, @NotNull LinStream tokens) throws IOException { + public void write(Appendable output, LinStream tokens) throws IOException { while (true) { var state = stateStack.peekLast(); LinToken token = tokens.nextOrNull(); diff --git a/format-snbt/src/main/java/org/enginehub/linbus/format/snbt/impl/reader/LinSnbtReader.java b/format-snbt/src/main/java/org/enginehub/linbus/format/snbt/impl/reader/LinSnbtReader.java index 701fb08..e0a4c27 100644 --- a/format-snbt/src/main/java/org/enginehub/linbus/format/snbt/impl/reader/LinSnbtReader.java +++ b/format-snbt/src/main/java/org/enginehub/linbus/format/snbt/impl/reader/LinSnbtReader.java @@ -21,8 +21,7 @@ import org.enginehub.linbus.stream.LinStream; import org.enginehub.linbus.stream.exception.NbtParseException; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import org.jspecify.annotations.Nullable; import java.io.DataInput; import java.nio.Buffer; @@ -114,7 +113,7 @@ record ReadValue(boolean mustBeCompound) implements State { private static final int BUFFER_SIZE = 4096; - private final Iterator input; + private final Iterator input; /** * The state stack. We're currently on the one that's LAST. */ @@ -126,7 +125,7 @@ record ReadValue(boolean mustBeCompound) implements State { /** * The pushback token stack, which is used to push back tokens that we've read. */ - private final Deque<@NotNull SnbtTokenWithMetadata> readAgainStack; + private final Deque readAgainStack; private int charIndex; /** @@ -134,14 +133,14 @@ record ReadValue(boolean mustBeCompound) implements State { * * @param input the input to read from */ - public LinSnbtReader(Iterator input) { + public LinSnbtReader(Iterator input) { this.input = input; this.stateStack = new ArrayDeque<>(List.of(new State.ReadValue(true))); this.tokenQueue = new ArrayDeque<>(); this.readAgainStack = new ArrayDeque<>(); } - private @NotNull SnbtTokenWithMetadata read() { + private SnbtTokenWithMetadata read() { var token = readAgainStack.pollFirst(); if (token != null) { return token; diff --git a/format-snbt/src/main/java/org/enginehub/linbus/format/snbt/impl/reader/LinSnbtTokenizer.java b/format-snbt/src/main/java/org/enginehub/linbus/format/snbt/impl/reader/LinSnbtTokenizer.java index 3edf0d8..d4dfefe 100644 --- a/format-snbt/src/main/java/org/enginehub/linbus/format/snbt/impl/reader/LinSnbtTokenizer.java +++ b/format-snbt/src/main/java/org/enginehub/linbus/format/snbt/impl/reader/LinSnbtTokenizer.java @@ -22,7 +22,7 @@ import org.enginehub.linbus.format.snbt.impl.Elusion; import org.enginehub.linbus.stream.exception.NbtParseException; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.NotNull; +import org.jspecify.annotations.Nullable; import java.io.BufferedReader; import java.io.IOException; @@ -32,7 +32,7 @@ /** * But not like, a tokenizer into {@link LinToken}s. But like our own internal {@link SnbtToken}. Sigh. */ -public class LinSnbtTokenizer extends AbstractIterator<@NotNull SnbtTokenWithMetadata> { +public class LinSnbtTokenizer extends AbstractIterator { private final Reader input; private int charIndex = -1; private boolean eatAllWhitespaceAfter; @@ -42,7 +42,7 @@ public class LinSnbtTokenizer extends AbstractIterator<@NotNull SnbtTokenWithMet * * @param input the input to read from */ - public LinSnbtTokenizer(@NotNull Reader input) { + public LinSnbtTokenizer(Reader input) { this.input = input.markSupported() ? input : new BufferedReader(input); } @@ -67,7 +67,7 @@ private void skipWhitespace() throws IOException { } @Override - protected SnbtTokenWithMetadata computeNext() { + protected @Nullable SnbtTokenWithMetadata computeNext() { try { skipWhitespace(); input.mark(1); diff --git a/format-snbt/src/test/java/org/enginehub/linbus/format/snbt/impl/package-info.java b/format-snbt/src/test/java/org/enginehub/linbus/format/snbt/impl/package-info.java new file mode 100644 index 0000000..27b5cf5 --- /dev/null +++ b/format-snbt/src/test/java/org/enginehub/linbus/format/snbt/impl/package-info.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) EngineHub + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +@NullMarked +package org.enginehub.linbus.format.snbt.impl; + +import org.jspecify.annotations.NullMarked; diff --git a/format-snbt/src/test/java/org/enginehub/linbus/format/snbt/impl/reader/package-info.java b/format-snbt/src/test/java/org/enginehub/linbus/format/snbt/impl/reader/package-info.java new file mode 100644 index 0000000..5d31e8a --- /dev/null +++ b/format-snbt/src/test/java/org/enginehub/linbus/format/snbt/impl/reader/package-info.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) EngineHub + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +@NullMarked +package org.enginehub.linbus.format.snbt.impl.reader; + +import org.jspecify.annotations.NullMarked; diff --git a/format-snbt/src/test/java/org/enginehub/linbus/format/snbt/package-info.java b/format-snbt/src/test/java/org/enginehub/linbus/format/snbt/package-info.java new file mode 100644 index 0000000..58eb193 --- /dev/null +++ b/format-snbt/src/test/java/org/enginehub/linbus/format/snbt/package-info.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) EngineHub + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +@NullMarked +package org.enginehub.linbus.format.snbt; + +import org.jspecify.annotations.NullMarked; diff --git a/format-snbt/src/test/java/org/enginehub/linbus/format/snbt/util/TracedReader.java b/format-snbt/src/test/java/org/enginehub/linbus/format/snbt/util/TracedReader.java index 67ae0e1..c93bcee 100644 --- a/format-snbt/src/test/java/org/enginehub/linbus/format/snbt/util/TracedReader.java +++ b/format-snbt/src/test/java/org/enginehub/linbus/format/snbt/util/TracedReader.java @@ -18,8 +18,6 @@ package org.enginehub.linbus.format.snbt.util; -import org.jetbrains.annotations.NotNull; - import java.io.IOException; import java.io.Reader; import java.io.Writer; @@ -55,7 +53,7 @@ private boolean isRelevantStackFrame(StackWalker.StackFrame frame) { } @Override - public int read(@NotNull CharBuffer target) throws IOException { + public int read(CharBuffer target) throws IOException { int result = delegate.read(target); System.err.println("read(" + target + "): " + result); printRelevantStack(); @@ -75,7 +73,7 @@ public int read() throws IOException { } @Override - public int read(char @NotNull [] cbuf) throws IOException { + public int read(char[] cbuf) throws IOException { int result = delegate.read(cbuf); System.err.println("read(char[].length = " + cbuf.length + "): " + result); printRelevantStack(); @@ -83,7 +81,7 @@ public int read(char @NotNull [] cbuf) throws IOException { } @Override - public int read(char @NotNull [] cbuf, int off, int len) throws IOException { + public int read(char[] cbuf, int off, int len) throws IOException { int result = delegate.read(cbuf, off, len); System.err.println("read(char[].length = " + cbuf.length + ", off = " + off + ", len = " + len + "): " + result); printRelevantStack(); diff --git a/format-snbt/src/test/java/org/enginehub/linbus/format/snbt/util/package-info.java b/format-snbt/src/test/java/org/enginehub/linbus/format/snbt/util/package-info.java new file mode 100644 index 0000000..64f58e7 --- /dev/null +++ b/format-snbt/src/test/java/org/enginehub/linbus/format/snbt/util/package-info.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) EngineHub + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +@NullMarked +package org.enginehub.linbus.format.snbt.util; + +import org.jspecify.annotations.NullMarked; diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 733622f..638e7ce 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,13 +1,7 @@ -[versions] -truth = "1.4.2" - [libraries] -jetbrains-annotations = "org.jetbrains:annotations:24.1.0" +jspecify-annotations = "org.jspecify:jspecify:0.3.0" guava = "com.google.guava:guava:31.0.1-jre" junit-bom = "org.junit:junit-bom:5.10.2" junit-jupiter-api.module = "org.junit.jupiter:junit-jupiter-api" junit-jupiter-engine.module = "org.junit.jupiter:junit-jupiter-engine" -truth.module = "com.google.truth:truth" -truth.version.ref = "truth" -truth-extensions-java8.module = "com.google.truth.extensions:truth-java8-extension" -truth-extensions-java8.version.ref = "truth" +truth = "com.google.truth:truth:1.4.2" diff --git a/stream/build.gradle.kts b/stream/build.gradle.kts index 384e0b8..a319030 100644 --- a/stream/build.gradle.kts +++ b/stream/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } dependencies { - compileOnlyApi(libs.jetbrains.annotations) + compileOnlyApi(libs.jspecify.annotations) api(project(":common")) @@ -14,10 +14,7 @@ dependencies { testImplementation(libs.junit.jupiter.api) testRuntimeOnly(libs.junit.jupiter.engine) - testImplementation(libs.truth.asProvider()) { - exclude(group = "junit") - } - testImplementation(libs.truth.extensions.java8) { + testImplementation(libs.truth) { exclude(group = "junit") } } diff --git a/stream/src/main/java/module-info.java b/stream/src/main/java/module-info.java index 3e41e3f..c6deab8 100644 --- a/stream/src/main/java/module-info.java +++ b/stream/src/main/java/module-info.java @@ -16,14 +16,17 @@ * along with this program. If not, see . */ +import org.jspecify.annotations.NullMarked; + /** * The streaming module of lin-bus. Features a Jackson-like API for decoding and encoding NBT. */ +@NullMarked module org.enginehub.linbus.stream { exports org.enginehub.linbus.stream; exports org.enginehub.linbus.stream.exception; exports org.enginehub.linbus.stream.token; exports org.enginehub.linbus.stream.internal to org.enginehub.linbus.tree; - requires static transitive org.jetbrains.annotations; + requires static transitive org.jspecify; requires transitive org.enginehub.linbus.common; } diff --git a/stream/src/main/java/org/enginehub/linbus/stream/LinBinaryIO.java b/stream/src/main/java/org/enginehub/linbus/stream/LinBinaryIO.java index cfc41f9..d56076c 100644 --- a/stream/src/main/java/org/enginehub/linbus/stream/LinBinaryIO.java +++ b/stream/src/main/java/org/enginehub/linbus/stream/LinBinaryIO.java @@ -23,7 +23,7 @@ import org.enginehub.linbus.stream.exception.NbtWriteException; import org.enginehub.linbus.stream.impl.LinNbtReader; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.NotNull; +import org.jspecify.annotations.Nullable; import java.io.DataInput; import java.io.DataOutput; @@ -46,7 +46,7 @@ public class LinBinaryIO { * @param input the input to read from * @return the stream of NBT tokens */ - public static LinStream read(@NotNull DataInput input) { + public static LinStream read(DataInput input) { return new LinNbtReader(input); } @@ -63,7 +63,7 @@ public static LinStream read(@NotNull DataInput input) { * @return the result * @throws IOException if an I/O error occurs ({@link UncheckedIOException} is unwrapped) */ - public static R readUsing(@NotNull DataInput input, @NotNull IOFunction transform) + public static R readUsing(DataInput input, IOFunction transform) throws IOException { return transform.apply(read(input)); } @@ -84,7 +84,7 @@ public static R readUsing(@NotNull DataInput input, @NotNull IOFunction asIterator() { + default Iterator asIterator() { return new AbstractIterator<>() { @Override protected @Nullable LinToken computeNext() { diff --git a/stream/src/main/java/org/enginehub/linbus/stream/LinStreamable.java b/stream/src/main/java/org/enginehub/linbus/stream/LinStreamable.java index 62bfbbe..0bfad0a 100644 --- a/stream/src/main/java/org/enginehub/linbus/stream/LinStreamable.java +++ b/stream/src/main/java/org/enginehub/linbus/stream/LinStreamable.java @@ -18,8 +18,6 @@ package org.enginehub.linbus.stream; -import org.jetbrains.annotations.NotNull; - /** * Represents something that can provide a {@link LinStream}. */ @@ -27,5 +25,5 @@ public interface LinStreamable { /** * {@return a {@link LinStream} for this object} */ - @NotNull LinStream linStream(); + LinStream linStream(); } diff --git a/stream/src/main/java/org/enginehub/linbus/stream/impl/LinNbtReader.java b/stream/src/main/java/org/enginehub/linbus/stream/impl/LinNbtReader.java index ca67795..0ec0c2e 100644 --- a/stream/src/main/java/org/enginehub/linbus/stream/impl/LinNbtReader.java +++ b/stream/src/main/java/org/enginehub/linbus/stream/impl/LinNbtReader.java @@ -22,7 +22,7 @@ import org.enginehub.linbus.stream.LinStream; import org.enginehub.linbus.stream.exception.NbtParseException; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.Nullable; +import org.jspecify.annotations.Nullable; import java.io.DataInput; import java.io.IOException; diff --git a/stream/src/main/java/org/enginehub/linbus/stream/impl/OptionalInfoCalculator.java b/stream/src/main/java/org/enginehub/linbus/stream/impl/OptionalInfoCalculator.java index 78db59c..6b8d458 100644 --- a/stream/src/main/java/org/enginehub/linbus/stream/impl/OptionalInfoCalculator.java +++ b/stream/src/main/java/org/enginehub/linbus/stream/impl/OptionalInfoCalculator.java @@ -22,8 +22,7 @@ import org.enginehub.linbus.stream.LinStream; import org.enginehub.linbus.stream.exception.NbtParseException; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import org.jspecify.annotations.Nullable; import java.io.IOException; import java.util.ArrayDeque; @@ -43,7 +42,7 @@ private interface OptionalFill { } private final LinStream original; - private Deque tokenBuffer; + private @Nullable Deque tokenBuffer; /** * Create a new {@link OptionalInfoCalculator}. @@ -81,7 +80,7 @@ public LinStream calculateOptionalInfo() { return this; } - private record TokenAndBuffer(@NotNull LinToken token, @Nullable Deque buffer) { + private record TokenAndBuffer(LinToken token, @Nullable Deque buffer) { } private TokenAndBuffer fillIfNeeded(LinToken token) throws IOException { @@ -134,8 +133,8 @@ private TokenAndBuffer getFilled(OptionalFill fill) throws IOException { private static final class ListStartFill implements OptionalFill { private final int knownSize; - private final ValueCounter counter; - private LinTagId elementId; + private final @Nullable ValueCounter counter; + private @Nullable LinTagId elementId; public ListStartFill(LinToken.ListStart listStart) { if (listStart.size().isPresent()) { diff --git a/stream/src/main/java/org/enginehub/linbus/stream/internal/FlatteningLinStream.java b/stream/src/main/java/org/enginehub/linbus/stream/internal/FlatteningLinStream.java index e881b8c..d44eab2 100644 --- a/stream/src/main/java/org/enginehub/linbus/stream/internal/FlatteningLinStream.java +++ b/stream/src/main/java/org/enginehub/linbus/stream/internal/FlatteningLinStream.java @@ -21,7 +21,7 @@ import org.enginehub.linbus.stream.LinStream; import org.enginehub.linbus.stream.LinStreamable; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.Nullable; +import org.jspecify.annotations.Nullable; import java.io.IOException; import java.util.Iterator; @@ -31,7 +31,7 @@ */ public class FlatteningLinStream implements LinStream { private final Iterator streamables; - private LinStream current; + private @Nullable LinStream current; /** * Create a new flattening stream. diff --git a/stream/src/main/java/org/enginehub/linbus/stream/internal/SurroundingLinStream.java b/stream/src/main/java/org/enginehub/linbus/stream/internal/SurroundingLinStream.java index 0251815..3a513f4 100644 --- a/stream/src/main/java/org/enginehub/linbus/stream/internal/SurroundingLinStream.java +++ b/stream/src/main/java/org/enginehub/linbus/stream/internal/SurroundingLinStream.java @@ -20,7 +20,7 @@ import org.enginehub.linbus.stream.LinStream; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.Nullable; +import org.jspecify.annotations.Nullable; import java.io.IOException; @@ -28,9 +28,9 @@ * A {@link LinStream} that wraps another {@link LinStream} and adds a token to the beginning and end of the stream. */ public class SurroundingLinStream implements LinStream { - private LinToken prefix; - private LinStream stream; - private LinToken suffix; + private @Nullable LinToken prefix; + private @Nullable LinStream stream; + private @Nullable LinToken suffix; /** * Creates a new {@link SurroundingLinStream} with the given prefix and suffix. @@ -39,7 +39,7 @@ public class SurroundingLinStream implements LinStream { * @param stream the stream to wrap * @param suffix the suffix token, may be null */ - public SurroundingLinStream(LinToken prefix, LinStream stream, LinToken suffix) { + public SurroundingLinStream(@Nullable LinToken prefix, LinStream stream, @Nullable LinToken suffix) { this.prefix = prefix; this.stream = stream; this.suffix = suffix; diff --git a/tree/build.gradle.kts b/tree/build.gradle.kts index 3f029a9..9fd3436 100644 --- a/tree/build.gradle.kts +++ b/tree/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } dependencies { - compileOnlyApi(libs.jetbrains.annotations) + compileOnlyApi(libs.jspecify.annotations) api(project(":common")) api(project(":stream")) @@ -15,7 +15,7 @@ dependencies { testImplementation(libs.junit.jupiter.api) testRuntimeOnly(libs.junit.jupiter.engine) - testImplementation(libs.truth.asProvider()) { + testImplementation(libs.truth) { exclude(group = "junit") } } diff --git a/tree/src/main/java/module-info.java b/tree/src/main/java/module-info.java index 3864262..d8f11e8 100644 --- a/tree/src/main/java/module-info.java +++ b/tree/src/main/java/module-info.java @@ -16,13 +16,16 @@ * along with this program. If not, see . */ +import org.jspecify.annotations.NullMarked; + /** * The tree module of lin-bus. Presents a standard tree structure of NBT. Internally, everything is parsed using the * streaming module. */ +@NullMarked module org.enginehub.linbus.tree { exports org.enginehub.linbus.tree; - requires static transitive org.jetbrains.annotations; + requires static transitive org.jspecify; requires transitive org.enginehub.linbus.common; requires transitive org.enginehub.linbus.stream; } diff --git a/tree/src/main/java/org/enginehub/linbus/tree/LinByteArrayTag.java b/tree/src/main/java/org/enginehub/linbus/tree/LinByteArrayTag.java index 423806e..cbd09f0 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/LinByteArrayTag.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/LinByteArrayTag.java @@ -21,8 +21,7 @@ import org.enginehub.linbus.stream.LinStream; import org.enginehub.linbus.stream.internal.SurroundingLinStream; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import org.jspecify.annotations.Nullable; import java.nio.ByteBuffer; import java.util.Arrays; @@ -30,30 +29,30 @@ /** * Represents a byte array tag. */ -public final class LinByteArrayTag extends LinTag { +public final class LinByteArrayTag extends LinTag { /** * Creates a new byte array tag from the given byte array. The array will be {@linkplain Object#clone() cloned}. * * @param value the value * @return the tag */ - public static @NotNull LinByteArrayTag of(byte @NotNull ... value) { + public static LinByteArrayTag of(byte... value) { return new LinByteArrayTag(value.clone()); } private final byte[] value; - private LinByteArrayTag(byte @NotNull [] value) { + private LinByteArrayTag(byte[] value) { this.value = value; } @Override - public @NotNull LinTagType<@NotNull LinByteArrayTag> type() { + public LinTagType type() { return LinTagType.byteArrayTag(); } @Override - public byte @NotNull [] value() { + public byte[] value() { return value.clone(); } @@ -63,12 +62,12 @@ private LinByteArrayTag(byte @NotNull [] value) { * * @return a read-only {@link ByteBuffer} providing view access to the contents of this tag */ - public @NotNull ByteBuffer view() { + public ByteBuffer view() { return ByteBuffer.wrap(value).asReadOnlyBuffer(); } @Override - public @NotNull LinStream linStream() { + public LinStream linStream() { return new SurroundingLinStream( new LinToken.ByteArrayStart(value.length), new LinStream() { @@ -91,7 +90,7 @@ private LinByteArrayTag(byte @NotNull [] value) { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; LinByteArrayTag that = (LinByteArrayTag) o; @@ -106,7 +105,7 @@ public int hashCode() { } @Override - public @NotNull String toString() { + public String toString() { return getClass().getSimpleName() + Arrays.toString(value()); } } diff --git a/tree/src/main/java/org/enginehub/linbus/tree/LinByteTag.java b/tree/src/main/java/org/enginehub/linbus/tree/LinByteTag.java index 1399e5d..8546715 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/LinByteTag.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/LinByteTag.java @@ -20,12 +20,11 @@ import org.enginehub.linbus.stream.LinStream; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.NotNull; /** * Represents a byte tag. */ -public final class LinByteTag extends LinNumberTag<@NotNull Byte> { +public final class LinByteTag extends LinNumberTag { /** * Creates a new byte tag from the given integer, which will be cast to a byte. @@ -33,7 +32,7 @@ public final class LinByteTag extends LinNumberTag<@NotNull Byte> { * @param value the value * @return the tag */ - public static @NotNull LinByteTag fromInt(int value) { + public static LinByteTag fromInt(int value) { return of((byte) value); } @@ -43,7 +42,7 @@ public final class LinByteTag extends LinNumberTag<@NotNull Byte> { * @param value the value * @return the tag */ - public static @NotNull LinByteTag of(byte value) { + public static LinByteTag of(byte value) { return new LinByteTag(value); } @@ -54,12 +53,12 @@ private LinByteTag(byte value) { } @Override - public @NotNull LinTagType<@NotNull LinByteTag> type() { + public LinTagType type() { return LinTagType.byteTag(); } @Override - public @NotNull Byte value() { + public Byte value() { return value; } @@ -73,7 +72,7 @@ public byte valueAsByte() { } @Override - public @NotNull LinStream linStream() { + public LinStream linStream() { return LinStream.of(new LinToken.Byte(value)); } } diff --git a/tree/src/main/java/org/enginehub/linbus/tree/LinCompoundTag.java b/tree/src/main/java/org/enginehub/linbus/tree/LinCompoundTag.java index 64ac2ce..ec86807 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/LinCompoundTag.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/LinCompoundTag.java @@ -25,9 +25,7 @@ import org.enginehub.linbus.stream.internal.SurroundingLinStream; import org.enginehub.linbus.stream.token.LinToken; import org.enginehub.linbus.tree.impl.LinTagReader; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import org.jspecify.annotations.Nullable; import java.io.IOException; import java.util.Collections; @@ -40,7 +38,7 @@ /** * Represents a compound tag. */ -public final class LinCompoundTag extends LinTag<@NotNull Map<@NotNull String, ? extends @NotNull LinTag>> { +public final class LinCompoundTag extends LinTag>> { /** * Creates a new compound tag. @@ -53,7 +51,7 @@ public final class LinCompoundTag extends LinTag<@NotNull Map<@NotNull String, ? * @param value the value * @return the tag */ - public static @NotNull LinCompoundTag of(@NotNull Map<@NotNull String, ? extends @NotNull LinTag> value) { + public static LinCompoundTag of(Map> value) { return new LinCompoundTag(copyImmutable(value), true); } @@ -70,7 +68,7 @@ public static Builder builder() { * A builder for {@link LinCompoundTag LinCompoundTags}. */ public static final class Builder { - private final LinkedHashMap<@NotNull String, @NotNull LinTag> collector; + private final LinkedHashMap> collector; private Builder() { this.collector = new LinkedHashMap<>(); @@ -87,8 +85,7 @@ private Builder(LinCompoundTag base) { * @param value the value of the tag * @return this builder */ - @Contract("_, _ -> this") - public @NotNull Builder put(@NotNull String name, @NotNull LinTag value) { + public Builder put(String name, LinTag value) { if (value.type().id() == LinTagId.END) { throw new IllegalArgumentException("Cannot add END tag to compound tag"); } @@ -102,8 +99,7 @@ private Builder(LinCompoundTag base) { * @param map the tags to add * @return this builder */ - @Contract("_ -> this") - public @NotNull Builder putAll(@NotNull Map> map) { + public Builder putAll(Map> map) { map.forEach(this::put); return this; } @@ -114,8 +110,7 @@ private Builder(LinCompoundTag base) { * @param name the name of the tag * @return this builder */ - @Contract("_ -> this") - public @NotNull Builder remove(@NotNull String name) { + public Builder remove(String name) { this.collector.remove(name); return this; } @@ -127,8 +122,7 @@ private Builder(LinCompoundTag base) { * @param value the value to add * @return this builder */ - @Contract("_, _ -> this") - public @NotNull Builder putByteArray(@NotNull String name, byte @NotNull [] value) { + public Builder putByteArray(String name, byte[] value) { return put(name, LinByteArrayTag.of(value)); } @@ -139,8 +133,7 @@ private Builder(LinCompoundTag base) { * @param value the value to add * @return this builder */ - @Contract("_, _ -> this") - public @NotNull Builder putByte(@NotNull String name, byte value) { + public Builder putByte(String name, byte value) { return put(name, LinByteTag.of(value)); } @@ -151,8 +144,7 @@ private Builder(LinCompoundTag base) { * @param value the value to add * @return this builder */ - @Contract("_, _ -> this") - public @NotNull Builder putCompound(@NotNull String name, @NotNull Map> value) { + public Builder putCompound(String name, Map> value) { return put(name, new LinCompoundTag(value, true)); } @@ -163,8 +155,7 @@ private Builder(LinCompoundTag base) { * @param value the value to add * @return this builder */ - @Contract("_, _ -> this") - public @NotNull Builder putDouble(@NotNull String name, double value) { + public Builder putDouble(String name, double value) { return put(name, LinDoubleTag.of(value)); } @@ -175,8 +166,7 @@ private Builder(LinCompoundTag base) { * @param value the value to add * @return this builder */ - @Contract("_, _ -> this") - public @NotNull Builder putFloat(@NotNull String name, float value) { + public Builder putFloat(String name, float value) { return put(name, LinFloatTag.of(value)); } @@ -187,8 +177,7 @@ private Builder(LinCompoundTag base) { * @param value the value to add * @return this builder */ - @Contract("_, _ -> this") - public @NotNull Builder putIntArray(@NotNull String name, int @NotNull [] value) { + public Builder putIntArray(String name, int[] value) { return put(name, LinIntArrayTag.of(value)); } @@ -199,8 +188,7 @@ private Builder(LinCompoundTag base) { * @param value the value to add * @return this builder */ - @Contract("_, _ -> this") - public @NotNull Builder putInt(@NotNull String name, int value) { + public Builder putInt(String name, int value) { return put(name, LinIntTag.of(value)); } @@ -211,8 +199,7 @@ private Builder(LinCompoundTag base) { * @param value the value to add * @return this builder */ - @Contract("_, _ -> this") - public @NotNull Builder putLongArray(@NotNull String name, long @NotNull [] value) { + public Builder putLongArray(String name, long[] value) { return put(name, LinLongArrayTag.of(value)); } @@ -223,8 +210,7 @@ private Builder(LinCompoundTag base) { * @param value the value to add * @return this builder */ - @Contract("_, _ -> this") - public @NotNull Builder putLong(@NotNull String name, long value) { + public Builder putLong(String name, long value) { return put(name, LinLongTag.of(value)); } @@ -235,8 +221,7 @@ private Builder(LinCompoundTag base) { * @param value the value to add * @return this builder */ - @Contract("_, _ -> this") - public @NotNull Builder putShort(@NotNull String name, short value) { + public Builder putShort(String name, short value) { return put(name, LinShortTag.of(value)); } @@ -247,8 +232,7 @@ private Builder(LinCompoundTag base) { * @param value the value to add * @return this builder */ - @Contract("_, _ -> this") - public @NotNull Builder putString(@NotNull String name, @NotNull String value) { + public Builder putString(String name, String value) { return put(name, LinStringTag.of(value)); } @@ -257,7 +241,7 @@ private Builder(LinCompoundTag base) { * * @return the built tag */ - public @NotNull LinCompoundTag build() { + public LinCompoundTag build() { return new LinCompoundTag(copyImmutable(this.collector), false); } } @@ -269,19 +253,19 @@ private Builder(LinCompoundTag base) { * @return the compound tag * @throws IOException if an I/O error occurs */ - public static @NotNull LinCompoundTag readFrom(@NotNull LinStream tokens) throws IOException { + public static LinCompoundTag readFrom(LinStream tokens) throws IOException { return LinTagReader.readCompound(tokens); } - private static @NotNull Map<@NotNull String, @NotNull LinTag> copyImmutable( - @NotNull Map<@NotNull String, ? extends @NotNull LinTag> value + private static Map> copyImmutable( + Map> value ) { return Collections.unmodifiableMap(new LinkedHashMap<>(value)); } - private final Map<@NotNull String, ? extends @NotNull LinTag> value; + private final Map> value; - private LinCompoundTag(@NotNull Map<@NotNull String, ? extends @NotNull LinTag> value, boolean check) { + private LinCompoundTag(Map> value, boolean check) { if (check) { for (LinTag tag : value.values()) { if (tag.type().id() == LinTagId.END) { @@ -293,17 +277,17 @@ private LinCompoundTag(@NotNull Map<@NotNull String, ? extends @NotNull LinTag type() { + public LinTagType type() { return LinTagType.compoundTag(); } @Override - public @NotNull Map<@NotNull String, ? extends @NotNull LinTag> value() { + public Map> value() { return value; } @Override - public @NotNull LinStream linStream() { + public LinStream linStream() { return new SurroundingLinStream( new LinToken.CompoundStart(), new FlatteningLinStream(new EntryTokenIterator()), @@ -338,7 +322,7 @@ public LinStreamable next() { * @param the type of the tag * @return the tag, or {@code null} if not found */ - public > @Nullable T findTag(@NotNull String name, @NotNull LinTagType type) { + public > @Nullable T findTag(String name, LinTagType type) { LinTag tag = value.get(name); return tag != null && type == tag.type() ? type.cast(tag) : null; } @@ -351,8 +335,8 @@ public LinStreamable next() { * @param the element type of the tag * @return the tag, or {@code null} if not found */ - public > @Nullable LinListTag findListTag( - @NotNull String name, @NotNull LinTagType elementType + public > @Nullable LinListTag findListTag( + String name, LinTagType elementType ) { var listTag = findTag(name, LinTagType.listTag()); if (listTag == null || listTag.elementType() != elementType) { @@ -373,7 +357,7 @@ public LinStreamable next() { * @throws NoSuchElementException if there is no tag under the given name * @throws IllegalStateException if the tag exists but is of a different type */ - public > @NotNull T getTag(@NotNull String name, @NotNull LinTagType type) { + public > T getTag(String name, LinTagType type) { LinTag tag = value.get(name); if (tag == null) { @@ -398,8 +382,8 @@ public LinStreamable next() { * @throws NoSuchElementException if there is no tag under the given name * @throws IllegalStateException if the tag exists but is of a different type */ - public > @NotNull LinListTag getListTag( - @NotNull String name, @NotNull LinTagType elementType + public > LinListTag getListTag( + String name, LinTagType elementType ) { var listTag = getTag(name, LinTagType.listTag()); if (listTag.elementType() != elementType) { @@ -421,7 +405,7 @@ public Builder toBuilder() { } @Override - public @NotNull String toString() { + public String toString() { return getClass().getSimpleName() + value; } } diff --git a/tree/src/main/java/org/enginehub/linbus/tree/LinDoubleTag.java b/tree/src/main/java/org/enginehub/linbus/tree/LinDoubleTag.java index abb14df..5da4677 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/LinDoubleTag.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/LinDoubleTag.java @@ -20,12 +20,11 @@ import org.enginehub.linbus.stream.LinStream; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.NotNull; /** * Represents a double tag. */ -public final class LinDoubleTag extends LinNumberTag<@NotNull Double> { +public final class LinDoubleTag extends LinNumberTag { /** * Creates a new double tag. @@ -33,7 +32,7 @@ public final class LinDoubleTag extends LinNumberTag<@NotNull Double> { * @param value the value * @return the tag */ - public static @NotNull LinDoubleTag of(double value) { + public static LinDoubleTag of(double value) { return new LinDoubleTag(value); } @@ -44,12 +43,12 @@ private LinDoubleTag(double value) { } @Override - public @NotNull LinTagType<@NotNull LinDoubleTag> type() { + public LinTagType type() { return LinTagType.doubleTag(); } @Override - public @NotNull Double value() { + public Double value() { return value; } @@ -63,7 +62,7 @@ public double valueAsDouble() { } @Override - public @NotNull LinStream linStream() { + public LinStream linStream() { return LinStream.of(new LinToken.Double(value)); } } diff --git a/tree/src/main/java/org/enginehub/linbus/tree/LinEndTag.java b/tree/src/main/java/org/enginehub/linbus/tree/LinEndTag.java index ba2596d..c0762c6 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/LinEndTag.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/LinEndTag.java @@ -19,7 +19,6 @@ package org.enginehub.linbus.tree; import org.enginehub.linbus.stream.LinStream; -import org.jetbrains.annotations.NotNull; /** * Represents an end tag. @@ -40,7 +39,7 @@ private LinEndTag() { } @Override - public @NotNull LinTagType<@NotNull LinEndTag> type() { + public LinTagType type() { return LinTagType.endTag(); } @@ -50,7 +49,7 @@ public Void value() { } @Override - public @NotNull LinStream linStream() { + public LinStream linStream() { return LinStream.of(); } @@ -60,7 +59,7 @@ public int hashCode() { } @Override - public @NotNull String toString() { + public String toString() { return getClass().getSimpleName(); } } diff --git a/tree/src/main/java/org/enginehub/linbus/tree/LinFloatTag.java b/tree/src/main/java/org/enginehub/linbus/tree/LinFloatTag.java index b9befe2..3d465fa 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/LinFloatTag.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/LinFloatTag.java @@ -20,12 +20,11 @@ import org.enginehub.linbus.stream.LinStream; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.NotNull; /** * Represents a float tag. */ -public final class LinFloatTag extends LinNumberTag<@NotNull Float> { +public final class LinFloatTag extends LinNumberTag { /** * Create a new float tag. @@ -33,7 +32,7 @@ public final class LinFloatTag extends LinNumberTag<@NotNull Float> { * @param value the value * @return the tag */ - public static @NotNull LinFloatTag of(float value) { + public static LinFloatTag of(float value) { return new LinFloatTag(value); } @@ -44,12 +43,12 @@ private LinFloatTag(float value) { } @Override - public @NotNull LinTagType<@NotNull LinFloatTag> type() { + public LinTagType type() { return LinTagType.floatTag(); } @Override - public @NotNull Float value() { + public Float value() { return value; } @@ -63,7 +62,7 @@ public float valueAsFloat() { } @Override - public @NotNull LinStream linStream() { + public LinStream linStream() { return LinStream.of(new LinToken.Float(value)); } } diff --git a/tree/src/main/java/org/enginehub/linbus/tree/LinIntArrayTag.java b/tree/src/main/java/org/enginehub/linbus/tree/LinIntArrayTag.java index 644c91e..fac785d 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/LinIntArrayTag.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/LinIntArrayTag.java @@ -21,8 +21,7 @@ import org.enginehub.linbus.stream.LinStream; import org.enginehub.linbus.stream.internal.SurroundingLinStream; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import org.jspecify.annotations.Nullable; import java.nio.IntBuffer; import java.util.Arrays; @@ -30,7 +29,7 @@ /** * Represents an int array tag. */ -public final class LinIntArrayTag extends LinTag { +public final class LinIntArrayTag extends LinTag { /** * Creates a new int array tag from the given int array. The array will be {@linkplain Object#clone() cloned}. @@ -38,23 +37,23 @@ public final class LinIntArrayTag extends LinTag { * @param value the value * @return the tag */ - public static @NotNull LinIntArrayTag of(int @NotNull ... value) { + public static LinIntArrayTag of(int... value) { return new LinIntArrayTag(value.clone()); } private final int[] value; - private LinIntArrayTag(int @NotNull [] value) { + private LinIntArrayTag(int[] value) { this.value = value; } @Override - public @NotNull LinTagType<@NotNull LinIntArrayTag> type() { + public LinTagType type() { return LinTagType.intArrayTag(); } @Override - public int @NotNull [] value() { + public int[] value() { return value.clone(); } @@ -69,7 +68,7 @@ public IntBuffer view() { } @Override - public @NotNull LinStream linStream() { + public LinStream linStream() { return new SurroundingLinStream( new LinToken.IntArrayStart(value.length), new LinStream() { @@ -107,7 +106,7 @@ public int hashCode() { } @Override - public @NotNull String toString() { + public String toString() { return getClass().getSimpleName() + Arrays.toString(value()); } } diff --git a/tree/src/main/java/org/enginehub/linbus/tree/LinIntTag.java b/tree/src/main/java/org/enginehub/linbus/tree/LinIntTag.java index fa5a956..7aa4bf4 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/LinIntTag.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/LinIntTag.java @@ -20,12 +20,11 @@ import org.enginehub.linbus.stream.LinStream; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.NotNull; /** * Represents an int tag. */ -public final class LinIntTag extends LinNumberTag<@NotNull Integer> { +public final class LinIntTag extends LinNumberTag { /** * Create a new int tag. @@ -33,7 +32,7 @@ public final class LinIntTag extends LinNumberTag<@NotNull Integer> { * @param value the value * @return the tag */ - public static @NotNull LinIntTag of(int value) { + public static LinIntTag of(int value) { return new LinIntTag(value); } @@ -44,12 +43,12 @@ private LinIntTag(int value) { } @Override - public @NotNull LinTagType<@NotNull LinIntTag> type() { + public LinTagType type() { return LinTagType.intTag(); } @Override - public @NotNull Integer value() { + public Integer value() { return value; } @@ -63,7 +62,7 @@ public int valueAsInt() { } @Override - public @NotNull LinStream linStream() { + public LinStream linStream() { return LinStream.of(new LinToken.Int(value)); } } diff --git a/tree/src/main/java/org/enginehub/linbus/tree/LinListTag.java b/tree/src/main/java/org/enginehub/linbus/tree/LinListTag.java index f1c5ff6..e5c3479 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/LinListTag.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/LinListTag.java @@ -22,8 +22,6 @@ import org.enginehub.linbus.stream.internal.FlatteningLinStream; import org.enginehub.linbus.stream.internal.SurroundingLinStream; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collection; @@ -35,7 +33,7 @@ * * @param the type of the elements in the list */ -public final class LinListTag> extends LinTag<@NotNull List> { +public final class LinListTag> extends LinTag> { /** * Creates a new list tag. @@ -49,8 +47,8 @@ public final class LinListTag> extends LinTag<@NotN * @param the type of the elements in the list * @return the tag */ - public static > @NotNull LinListTag of( - @NotNull LinTagType elementType, @NotNull List value + public static > LinListTag of( + LinTagType elementType, List value ) { for (T t : value) { if (t.type() != elementType) { @@ -68,7 +66,7 @@ public final class LinListTag> extends LinTag<@NotN * @param the type of the elements in the list * @return an empty list */ - public static > @NotNull LinListTag empty(@NotNull LinTagType elementType) { + public static > LinListTag empty(LinTagType elementType) { return builder(elementType).build(); } @@ -79,7 +77,7 @@ public final class LinListTag> extends LinTag<@NotN * @param the type of the elements in the list * @return a new builder */ - public static > @NotNull Builder builder(@NotNull LinTagType elementType) { + public static > Builder builder(LinTagType elementType) { return new Builder<>(elementType); } @@ -88,7 +86,7 @@ public final class LinListTag> extends LinTag<@NotN * * @param the type of the elements in the list */ - public static final class Builder> { + public static final class Builder> { private final LinTagType elementType; private final List collector; @@ -108,8 +106,7 @@ private Builder(LinListTag base) { * @param tag the element * @return this builder */ - @Contract("_ -> this") - public @NotNull Builder add(T tag) { + public Builder add(T tag) { if (tag.type() != elementType) { throw new IllegalArgumentException("Element is not of type " + elementType.name() + " but " + tag.type().name()); @@ -124,8 +121,7 @@ private Builder(LinListTag base) { * @param tags the elements * @return this builder */ - @Contract("_ -> this") - public @NotNull Builder addAll(@NotNull Collection tags) { + public Builder addAll(Collection tags) { tags.forEach(this::add); return this; } @@ -135,7 +131,7 @@ private Builder(LinListTag base) { * * @return the built tag */ - public @NotNull LinListTag build() { + public LinListTag build() { return new LinListTag<>(this.elementType, List.copyOf(this.collector)); } } @@ -153,14 +149,14 @@ private LinListTag(LinTagType elementType, List value) { } @Override - public @NotNull LinTagType<@NotNull LinListTag> type() { + public LinTagType> type() { return LinTagType.listTag(); } /** * {@return the element type of this list} */ - public @NotNull LinTagType elementType() { + public LinTagType elementType() { return elementType; } @@ -172,7 +168,7 @@ private LinListTag(LinTagType elementType, List value) { * @return the converted list * @throws IllegalStateException if the {@link #elementType()} is not the same as the given type */ - public > LinListTag asTypeChecked(@NotNull LinTagType elementType) { + public > LinListTag asTypeChecked(LinTagType elementType) { if (elementType != this.elementType) { throw new IllegalStateException( "List is of type " + this.elementType.name() + ", not " + elementType.name() @@ -184,12 +180,12 @@ private LinListTag(LinTagType elementType, List value) { } @Override - public @NotNull List value() { + public List value() { return value; } @Override - public @NotNull LinStream linStream() { + public LinStream linStream() { return new SurroundingLinStream( new LinToken.ListStart(value.size(), elementType.id()), new FlatteningLinStream(value.iterator()), @@ -212,12 +208,12 @@ public T get(int index) { * * @return a new builder */ - public @NotNull Builder toBuilder() { + public Builder toBuilder() { return new Builder<>(this); } @Override - public @NotNull String toString() { + public String toString() { return getClass().getSimpleName() + value; } } diff --git a/tree/src/main/java/org/enginehub/linbus/tree/LinLongArrayTag.java b/tree/src/main/java/org/enginehub/linbus/tree/LinLongArrayTag.java index 045df22..7b7a93f 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/LinLongArrayTag.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/LinLongArrayTag.java @@ -22,8 +22,7 @@ import org.enginehub.linbus.stream.LinStream; import org.enginehub.linbus.stream.internal.SurroundingLinStream; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import org.jspecify.annotations.Nullable; import java.nio.LongBuffer; import java.util.Arrays; @@ -31,7 +30,7 @@ /** * Represents a long array tag. */ -public final class LinLongArrayTag extends LinTag { +public final class LinLongArrayTag extends LinTag { /** * Creates a new long array tag from the given long array. The array will be {@linkplain Object#clone() cloned}. @@ -39,23 +38,23 @@ public final class LinLongArrayTag extends LinTag { * @param value the value * @return the tag */ - public static @NotNull LinLongArrayTag of(long @NotNull ... value) { + public static LinLongArrayTag of(long... value) { return new LinLongArrayTag(value.clone()); } private final long[] value; - private LinLongArrayTag(long @NotNull [] value) { + private LinLongArrayTag(long[] value) { this.value = value; } @Override - public @NotNull LinTagType<@NotNull LinLongArrayTag> type() { + public LinTagType type() { return LinTagType.longArrayTag(); } @Override - public long @NotNull [] value() { + public long[] value() { return value.clone(); } @@ -65,12 +64,12 @@ private LinLongArrayTag(long @NotNull [] value) { * * @return a read-only {@link LongBuffer} providing view access to the contents of this tag */ - public @NotNull LongBuffer view() { + public LongBuffer view() { return LongBuffer.wrap(value).asReadOnlyBuffer(); } @Override - public @NotNull LinStream linStream() { + public LinStream linStream() { return new SurroundingLinStream( new LinToken.LongArrayStart(value.length), new LinStream() { @@ -108,7 +107,7 @@ public int hashCode() { } @Override - public @NotNull String toString() { + public String toString() { return getClass().getSimpleName() + Arrays.toString(value()); } } diff --git a/tree/src/main/java/org/enginehub/linbus/tree/LinLongTag.java b/tree/src/main/java/org/enginehub/linbus/tree/LinLongTag.java index 0427475..2728886 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/LinLongTag.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/LinLongTag.java @@ -20,12 +20,11 @@ import org.enginehub.linbus.stream.LinStream; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.NotNull; /** * Represents a long tag. */ -public final class LinLongTag extends LinNumberTag<@NotNull Long> { +public final class LinLongTag extends LinNumberTag { /** * Create a new long tag. @@ -33,7 +32,7 @@ public final class LinLongTag extends LinNumberTag<@NotNull Long> { * @param value the value * @return the tag */ - public static @NotNull LinLongTag of(long value) { + public static LinLongTag of(long value) { return new LinLongTag(value); } @@ -44,12 +43,12 @@ private LinLongTag(long value) { } @Override - public @NotNull LinTagType<@NotNull LinLongTag> type() { + public LinTagType type() { return LinTagType.longTag(); } @Override - public @NotNull Long value() { + public Long value() { return value; } @@ -63,7 +62,7 @@ public long valueAsLong() { } @Override - public @NotNull LinStream linStream() { + public LinStream linStream() { return LinStream.of(new LinToken.Long(value)); } } diff --git a/tree/src/main/java/org/enginehub/linbus/tree/LinRootEntry.java b/tree/src/main/java/org/enginehub/linbus/tree/LinRootEntry.java index fe8f772..3c0df2f 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/LinRootEntry.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/LinRootEntry.java @@ -25,7 +25,6 @@ import org.enginehub.linbus.stream.internal.SurroundingLinStream; import org.enginehub.linbus.stream.token.LinToken; import org.enginehub.linbus.tree.impl.LinTagReader; -import org.jetbrains.annotations.NotNull; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; @@ -48,7 +47,7 @@ public record LinRootEntry( * @return the root entry * @throws IOException if an I/O error occurs */ - public static LinRootEntry readFrom(@NotNull LinStream tokens) throws IOException { + public static LinRootEntry readFrom(LinStream tokens) throws IOException { return LinTagReader.readRoot(tokens); } @@ -84,12 +83,12 @@ public byte[] writeToArray() { * Note that the tag returned is not the same as {@link #value()}. */ @Override - public @NotNull LinCompoundTag toLinTag() { + public LinCompoundTag toLinTag() { return LinCompoundTag.of(Map.of(name, value)); } @Override - public @NotNull LinStream linStream() { + public LinStream linStream() { return new SurroundingLinStream( new LinToken.Name(name, LinTagId.COMPOUND), value.linStream(), diff --git a/tree/src/main/java/org/enginehub/linbus/tree/LinShortTag.java b/tree/src/main/java/org/enginehub/linbus/tree/LinShortTag.java index 9086e10..d3dd735 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/LinShortTag.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/LinShortTag.java @@ -20,12 +20,11 @@ import org.enginehub.linbus.stream.LinStream; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.NotNull; /** * Represents a short tag. */ -public final class LinShortTag extends LinNumberTag<@NotNull Short> { +public final class LinShortTag extends LinNumberTag { /** * Create a new short tag. @@ -33,7 +32,7 @@ public final class LinShortTag extends LinNumberTag<@NotNull Short> { * @param value the value * @return the tag */ - public static @NotNull LinShortTag of(short value) { + public static LinShortTag of(short value) { return new LinShortTag(value); } @@ -44,12 +43,12 @@ private LinShortTag(short value) { } @Override - public @NotNull LinTagType<@NotNull LinShortTag> type() { + public LinTagType type() { return LinTagType.shortTag(); } @Override - public @NotNull Short value() { + public Short value() { return value; } @@ -63,7 +62,7 @@ public short valueAsShort() { } @Override - public @NotNull LinStream linStream() { + public LinStream linStream() { return LinStream.of(new LinToken.Short(value)); } } diff --git a/tree/src/main/java/org/enginehub/linbus/tree/LinStringTag.java b/tree/src/main/java/org/enginehub/linbus/tree/LinStringTag.java index 6c5a7e6..e88fa6b 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/LinStringTag.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/LinStringTag.java @@ -20,14 +20,13 @@ import org.enginehub.linbus.stream.LinStream; import org.enginehub.linbus.stream.token.LinToken; -import org.jetbrains.annotations.NotNull; import java.util.Objects; /** * Represents a string tag. */ -public final class LinStringTag extends LinTag<@NotNull String> { +public final class LinStringTag extends LinTag { /** * Creates a new string tag. @@ -35,28 +34,28 @@ public final class LinStringTag extends LinTag<@NotNull String> { * @param value the value * @return the tag */ - public static @NotNull LinStringTag of(@NotNull String value) { + public static LinStringTag of(String value) { return new LinStringTag(value); } private final String value; - private LinStringTag(@NotNull String value) { + private LinStringTag(String value) { this.value = Objects.requireNonNull(value, "value is null"); } @Override - public @NotNull LinTagType<@NotNull LinStringTag> type() { + public LinTagType type() { return LinTagType.stringTag(); } @Override - public @NotNull String value() { + public String value() { return value; } @Override - public @NotNull LinStream linStream() { + public LinStream linStream() { return LinStream.of(new LinToken.String(value)); } } diff --git a/tree/src/main/java/org/enginehub/linbus/tree/LinTag.java b/tree/src/main/java/org/enginehub/linbus/tree/LinTag.java index 9e16ed5..968b926 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/LinTag.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/LinTag.java @@ -19,7 +19,7 @@ package org.enginehub.linbus.tree; import org.enginehub.linbus.stream.LinStreamable; -import org.jetbrains.annotations.NotNull; +import org.jspecify.annotations.Nullable; import java.util.Objects; @@ -43,7 +43,7 @@ protected LinTag() { * @return the type of this tag */ // This is to be overriden directly to save memory in the tag itself - public abstract @NotNull LinTagType> type(); + public abstract LinTagType> type(); /** * Gets the value of this tag. @@ -53,14 +53,14 @@ protected LinTag() { public abstract T value(); @Override - public final @NotNull LinTag toLinTag() { + public final LinTag toLinTag() { // This could be overriden by subclasses to provide a sharper return type. I didn't do this because it's // a lot of work, but please ask / PR if you want it. return this; } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; LinTag that = (LinTag) o; @@ -73,7 +73,7 @@ public int hashCode() { } @Override - public @NotNull String toString() { + public String toString() { return getClass().getSimpleName() + "[" + value() + ']'; } } diff --git a/tree/src/main/java/org/enginehub/linbus/tree/LinTagType.java b/tree/src/main/java/org/enginehub/linbus/tree/LinTagType.java index c94b3ad..fe28a30 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/LinTagType.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/LinTagType.java @@ -19,7 +19,6 @@ package org.enginehub.linbus.tree; import org.enginehub.linbus.common.LinTagId; -import org.jetbrains.annotations.NotNull; import java.util.Comparator; import java.util.stream.Stream; @@ -31,103 +30,103 @@ * This is different from the plain {@link LinTagId}, because it offers generic methods for casting to tag types. *

*/ -public final class LinTagType> { - private static final LinTagType<@NotNull LinEndTag> END_TAG = new LinTagType<>( +public final class LinTagType> { + private static final LinTagType END_TAG = new LinTagType<>( LinTagId.END, LinEndTag.class ); /** * {@return the {@link LinTagType} for the end tag} */ - public static @NotNull LinTagType<@NotNull LinEndTag> endTag() { + public static LinTagType endTag() { return END_TAG; } - private static final LinTagType<@NotNull LinByteTag> BYTE_TAG = new LinTagType<>( + private static final LinTagType BYTE_TAG = new LinTagType<>( LinTagId.BYTE, LinByteTag.class ); /** * {@return the {@link LinTagType} for the byte tag} */ - public static @NotNull LinTagType<@NotNull LinByteTag> byteTag() { + public static LinTagType byteTag() { return BYTE_TAG; } - private static final LinTagType<@NotNull LinShortTag> SHORT_TAG = new LinTagType<>( + private static final LinTagType SHORT_TAG = new LinTagType<>( LinTagId.SHORT, LinShortTag.class ); /** * {@return the {@link LinTagType} for the short tag} */ - public static @NotNull LinTagType<@NotNull LinShortTag> shortTag() { + public static LinTagType shortTag() { return SHORT_TAG; } - private static final LinTagType<@NotNull LinIntTag> INT_TAG = new LinTagType<>( + private static final LinTagType INT_TAG = new LinTagType<>( LinTagId.INT, LinIntTag.class ); /** * {@return the {@link LinTagType} for the int tag} */ - public static @NotNull LinTagType<@NotNull LinIntTag> intTag() { + public static LinTagType intTag() { return INT_TAG; } - private static final LinTagType<@NotNull LinLongTag> LONG_TAG = new LinTagType<>( + private static final LinTagType LONG_TAG = new LinTagType<>( LinTagId.LONG, LinLongTag.class ); /** * {@return the {@link LinTagType} for the long tag} */ - public static @NotNull LinTagType<@NotNull LinLongTag> longTag() { + public static LinTagType longTag() { return LONG_TAG; } - private static final LinTagType<@NotNull LinFloatTag> FLOAT_TAG = new LinTagType<>( + private static final LinTagType FLOAT_TAG = new LinTagType<>( LinTagId.FLOAT, LinFloatTag.class ); /** * {@return the {@link LinTagType} for the float tag} */ - public static @NotNull LinTagType<@NotNull LinFloatTag> floatTag() { + public static LinTagType floatTag() { return FLOAT_TAG; } - private static final LinTagType<@NotNull LinDoubleTag> DOUBLE_TAG = new LinTagType<>( + private static final LinTagType DOUBLE_TAG = new LinTagType<>( LinTagId.DOUBLE, LinDoubleTag.class ); /** * {@return the {@link LinTagType} for the double tag} */ - public static @NotNull LinTagType<@NotNull LinDoubleTag> doubleTag() { + public static LinTagType doubleTag() { return DOUBLE_TAG; } - private static final LinTagType<@NotNull LinByteArrayTag> BYTE_ARRAY_TAG = new LinTagType<>( + private static final LinTagType BYTE_ARRAY_TAG = new LinTagType<>( LinTagId.BYTE_ARRAY, LinByteArrayTag.class ); /** * {@return the {@link LinTagType} for the byte array tag} */ - public static @NotNull LinTagType<@NotNull LinByteArrayTag> byteArrayTag() { + public static LinTagType byteArrayTag() { return BYTE_ARRAY_TAG; } - private static final LinTagType<@NotNull LinStringTag> STRING_TAG = new LinTagType<>( + private static final LinTagType STRING_TAG = new LinTagType<>( LinTagId.STRING, LinStringTag.class ); /** * {@return the {@link LinTagType} for the string tag} */ - public static @NotNull LinTagType<@NotNull LinStringTag> stringTag() { + public static LinTagType stringTag() { return STRING_TAG; } @@ -141,47 +140,47 @@ public final class LinTagType> { * * @param the type of the list elements */ - public static > @NotNull LinTagType<@NotNull LinListTag> listTag() { + public static > LinTagType> listTag() { @SuppressWarnings("unchecked") - var cast = (LinTagType<@NotNull LinListTag>) LIST_TAG; + var cast = (LinTagType>) LIST_TAG; return cast; } - private static final LinTagType<@NotNull LinCompoundTag> COMPOUND_TAG = new LinTagType<>( + private static final LinTagType COMPOUND_TAG = new LinTagType<>( LinTagId.COMPOUND, LinCompoundTag.class ); /** * {@return the {@link LinTagType} for the compound tag} */ - public static @NotNull LinTagType<@NotNull LinCompoundTag> compoundTag() { + public static LinTagType compoundTag() { return COMPOUND_TAG; } - private static final LinTagType<@NotNull LinIntArrayTag> INT_ARRAY_TAG = new LinTagType<>( + private static final LinTagType INT_ARRAY_TAG = new LinTagType<>( LinTagId.INT_ARRAY, LinIntArrayTag.class ); /** * {@return the {@link LinTagType} for the int array tag} */ - public static @NotNull LinTagType<@NotNull LinIntArrayTag> intArrayTag() { + public static LinTagType intArrayTag() { return INT_ARRAY_TAG; } - private static final LinTagType<@NotNull LinLongArrayTag> LONG_ARRAY_TAG = new LinTagType<>( + private static final LinTagType LONG_ARRAY_TAG = new LinTagType<>( LinTagId.LONG_ARRAY, LinLongArrayTag.class ); /** * {@return the {@link LinTagType} for the long array tag} */ - public static @NotNull LinTagType<@NotNull LinLongArrayTag> longArrayTag() { + public static LinTagType longArrayTag() { return LONG_ARRAY_TAG; } @SuppressWarnings("rawtypes") - private static final @NotNull LinTagType[] LIN_TAG_TYPES = + private static final LinTagType[] LIN_TAG_TYPES = Stream.of( END_TAG, BYTE_TAG, @@ -207,7 +206,7 @@ public final class LinTagType> { * @param the type of the tag * @return the {@link LinTagType} for the given {@link LinTagId} */ - public static > @NotNull LinTagType fromId(LinTagId id) { + public static > LinTagType fromId(LinTagId id) { @SuppressWarnings("unchecked") var cast = (LinTagType) LIN_TAG_TYPES[id.id()]; return cast; @@ -224,14 +223,14 @@ private LinTagType(LinTagId id, Class javaType) { /** * {@return the name of this tag type} */ - public @NotNull String name() { + public String name() { return id.name(); } /** * {@return the id of this tag type} */ - public @NotNull LinTagId id() { + public LinTagId id() { return id; } diff --git a/tree/src/main/java/org/enginehub/linbus/tree/ToLinTag.java b/tree/src/main/java/org/enginehub/linbus/tree/ToLinTag.java index 4575036..cb091b7 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/ToLinTag.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/ToLinTag.java @@ -18,8 +18,6 @@ package org.enginehub.linbus.tree; -import org.jetbrains.annotations.NotNull; - /** * Interface for things that can be converted to a {@link LinTag}. * @@ -31,5 +29,5 @@ public interface ToLinTag> { * * @return the {@link LinTag} */ - @NotNull T toLinTag(); + T toLinTag(); } diff --git a/tree/src/main/java/org/enginehub/linbus/tree/impl/LinTagReader.java b/tree/src/main/java/org/enginehub/linbus/tree/impl/LinTagReader.java index b6f804e..46fab71 100644 --- a/tree/src/main/java/org/enginehub/linbus/tree/impl/LinTagReader.java +++ b/tree/src/main/java/org/enginehub/linbus/tree/impl/LinTagReader.java @@ -38,8 +38,7 @@ import org.enginehub.linbus.tree.LinStringTag; import org.enginehub.linbus.tree.LinTag; import org.enginehub.linbus.tree.LinTagType; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import org.jspecify.annotations.Nullable; import java.io.IOException; import java.nio.ByteBuffer; @@ -61,7 +60,7 @@ public class LinTagReader { * @return the root entry * @throws IOException if an I/O error occurs */ - public static LinRootEntry readRoot(@NotNull LinStream tokens) throws IOException { + public static LinRootEntry readRoot(LinStream tokens) throws IOException { tokens = tokens.calculateOptionalInfo(); if (!(tokens.nextOrNull() instanceof LinToken.Name name)) { throw new NbtParseException("Expected root name"); @@ -84,7 +83,7 @@ public static LinRootEntry readRoot(@NotNull LinStream tokens) throws IOExceptio * @return the compound tag * @throws IOException if an I/O error occurs */ - public static LinCompoundTag readCompound(@NotNull LinStream tokens) throws IOException { + public static LinCompoundTag readCompound(LinStream tokens) throws IOException { tokens = tokens.calculateOptionalInfo(); if (!(tokens.nextOrNull() instanceof LinToken.CompoundStart)) { throw new NbtParseException("Expected compound start"); @@ -179,7 +178,7 @@ private static LinLongArrayTag readLongArray(LinStream tokens) throws IOExceptio throw new NbtParseException("Expected long array end"); } - private static > LinListTag readList(LinStream tokens) throws IOException { + private static > LinListTag readList(LinStream tokens) throws IOException { if (!(tokens.nextOrNull() instanceof LinToken.ListStart start)) { throw new NbtParseException("Expected list start"); } @@ -195,7 +194,7 @@ private static LinLongArrayTag readLongArray(LinStream tokens) throws IOExceptio return builder.build(); } - private static > T readValue(@NotNull LinStream tokens, @Nullable LinTagType id) throws IOException { + private static > T readValue(LinStream tokens, @Nullable LinTagType id) throws IOException { if (id == null) { var next = tokens.nextOrNull(); if (next == null) { @@ -221,7 +220,7 @@ private static LinLongArrayTag readLongArray(LinStream tokens) throws IOExceptio }); } - private static LinToken requireNextToken(@NotNull LinStream tokens) throws IOException { + private static LinToken requireNextToken(LinStream tokens) throws IOException { LinToken linToken = tokens.nextOrNull(); if (linToken == null) { throw new NbtParseException("Unexpected end of stream"); diff --git a/tree/src/test/java/org/enginehub/linbus/tree/TagTestUtil.java b/tree/src/test/java/org/enginehub/linbus/tree/TagTestUtil.java index e7f8a6b..3c62b92 100644 --- a/tree/src/test/java/org/enginehub/linbus/tree/TagTestUtil.java +++ b/tree/src/test/java/org/enginehub/linbus/tree/TagTestUtil.java @@ -21,7 +21,6 @@ import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import org.enginehub.linbus.stream.LinBinaryIO; -import org.jetbrains.annotations.NotNull; import java.io.IOException; import java.util.Map; @@ -31,7 +30,7 @@ class TagTestUtil { private static final String NESTING_KEY = "inner"; - static > void assertRoundTrip(T input) throws IOException { + static > void assertRoundTrip(T input) throws IOException { ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(); // It's not legal to use bare streams, so we wrap in a root entry and compound. LinBinaryIO.write( diff --git a/tree/src/test/java/org/enginehub/linbus/tree/impl/package-info.java b/tree/src/test/java/org/enginehub/linbus/tree/impl/package-info.java new file mode 100644 index 0000000..32d941e --- /dev/null +++ b/tree/src/test/java/org/enginehub/linbus/tree/impl/package-info.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) EngineHub + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +@NullMarked +package org.enginehub.linbus.tree.impl; + +import org.jspecify.annotations.NullMarked; diff --git a/tree/src/test/java/org/enginehub/linbus/tree/package-info.java b/tree/src/test/java/org/enginehub/linbus/tree/package-info.java new file mode 100644 index 0000000..3df33e5 --- /dev/null +++ b/tree/src/test/java/org/enginehub/linbus/tree/package-info.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) EngineHub + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +@NullMarked +package org.enginehub.linbus.tree; + +import org.jspecify.annotations.NullMarked; diff --git a/tree/src/test/java/org/enginehub/linbus/tree/truth/LinTagSubject.java b/tree/src/test/java/org/enginehub/linbus/tree/truth/LinTagSubject.java index 6f0b8be..c217163 100644 --- a/tree/src/test/java/org/enginehub/linbus/tree/truth/LinTagSubject.java +++ b/tree/src/test/java/org/enginehub/linbus/tree/truth/LinTagSubject.java @@ -32,7 +32,6 @@ import com.google.common.truth.PrimitiveLongArraySubject; import com.google.common.truth.StringSubject; import com.google.common.truth.Subject; -import org.checkerframework.checker.nullness.qual.Nullable; import org.enginehub.linbus.tree.LinByteArrayTag; import org.enginehub.linbus.tree.LinByteTag; import org.enginehub.linbus.tree.LinCompoundTag; @@ -48,6 +47,7 @@ import org.enginehub.linbus.tree.LinStringTag; import org.enginehub.linbus.tree.LinTag; import org.enginehub.linbus.tree.LinTagType; +import org.jspecify.annotations.Nullable; import static com.google.common.truth.Truth.assertAbout; @@ -60,7 +60,7 @@ public static LinTagSubject assertThat(@Nullable LinTag tag) { return assertAbout(linTags()).that(tag); } - private final LinTag tag; + private final @Nullable LinTag tag; protected LinTagSubject(FailureMetadata metadata, @Nullable LinTag actual) { super(metadata, actual); @@ -69,6 +69,7 @@ protected LinTagSubject(FailureMetadata metadata, @Nullable LinTag actual) { public void isOfType(LinTagType type) { isNotNull(); + assert tag != null : "checked by isNotNull()"; if (this.tag.type() != type) { failWithActual( Fact.fact("expected", type), @@ -79,71 +80,85 @@ public void isOfType(LinTagType type) { public PrimitiveByteArraySubject byteArrayValue() { isOfType(LinTagType.byteArrayTag()); + assert tag != null : "checked by isOfType()"; return check("byteArrayValue()").that(((LinByteArrayTag) tag).value()); } public ComparableSubject byteValue() { isOfType(LinTagType.byteTag()); + assert tag != null : "checked by isOfType()"; return check("byteValue()").that(((LinByteTag) tag).value()); } public MapSubject compoundValue() { isOfType(LinTagType.compoundTag()); + assert tag != null : "checked by isOfType()"; return check("compoundValue()").that(((LinCompoundTag) tag).value()); } public DoubleSubject doubleValue() { isOfType(LinTagType.doubleTag()); + assert tag != null : "checked by isOfType()"; return check("doubleValue()").that(((LinDoubleTag) tag).value()); } public Subject endValue() { isOfType(LinTagType.endTag()); + assert tag != null : "checked by isOfType()"; return check("endValue()").that(((LinEndTag) tag).value()); } public FloatSubject floatValue() { isOfType(LinTagType.floatTag()); + assert tag != null : "checked by isOfType()"; return check("floatValue()").that(((LinFloatTag) tag).value()); } public PrimitiveIntArraySubject intArrayValue() { isOfType(LinTagType.intArrayTag()); + assert tag != null : "checked by isOfType()"; return check("intArrayValue()").that(((LinIntArrayTag) tag).value()); } public IntegerSubject intValue() { isOfType(LinTagType.intTag()); + assert tag != null : "checked by isOfType()"; return check("intValue()").that(((LinIntTag) tag).value()); } public IterableSubject listValue() { isOfType(LinTagType.listTag()); + assert tag != null : "checked by isOfType()"; return check("listValue()").that(((LinListTag) tag).value()); } public PrimitiveLongArraySubject longArrayValue() { isOfType(LinTagType.longArrayTag()); + assert tag != null : "checked by isOfType()"; return check("longArrayValue()").that(((LinLongArrayTag) tag).value()); } public LongSubject longValue() { isOfType(LinTagType.longTag()); + assert tag != null : "checked by isOfType()"; return check("longValue()").that(((LinLongTag) tag).value()); } public ComparableSubject shortValue() { isOfType(LinTagType.shortTag()); + assert tag != null : "checked by isOfType()"; return check("shortValue()").that(((LinShortTag) tag).value()); } public StringSubject stringValue() { isOfType(LinTagType.stringTag()); + assert tag != null : "checked by isOfType()"; return check("stringValue()").that(((LinStringTag) tag).value()); } public LinTagSubject getTagByKey(String key) { isOfType(LinTagType.compoundTag()); + assert tag != null : "checked by isOfType()"; return check("[%s]", key) .about(linTags()) .that(((LinCompoundTag) tag).value().get(key)); @@ -151,6 +166,7 @@ public LinTagSubject getTagByKey(String key) { public LinTagSubject getTagByIndex(int index) { isOfType(LinTagType.listTag()); + assert tag != null : "checked by isOfType()"; return check("[%s]", index) .about(linTags()) .that(((LinListTag) tag).value().get(index)); diff --git a/tree/src/test/java/org/enginehub/linbus/tree/truth/package-info.java b/tree/src/test/java/org/enginehub/linbus/tree/truth/package-info.java new file mode 100644 index 0000000..c89f1a0 --- /dev/null +++ b/tree/src/test/java/org/enginehub/linbus/tree/truth/package-info.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) EngineHub + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +@NullMarked +package org.enginehub.linbus.tree.truth; + +import org.jspecify.annotations.NullMarked;