From 8ab01552d5f23b6f0c850cc5309b52c8e39c0198 Mon Sep 17 00:00:00 2001 From: powercas_gamer Date: Thu, 12 Oct 2023 22:51:28 +0200 Subject: [PATCH] chore(api): more api migrations to jspecify --- .../net/kyori/adventure/inventory/Book.java | 37 ++++++------- .../kyori/adventure/inventory/BookImpl.java | 31 +++++------ .../adventure/nbt/api/BinaryTagHolder.java | 13 ++--- .../nbt/api/BinaryTagHolderImpl.java | 7 +-- .../permission/PermissionChecker.java | 9 ++-- .../permission/PermissionCheckers.java | 5 +- .../net/kyori/adventure/pointer/Pointer.java | 11 ++-- .../kyori/adventure/pointer/PointerImpl.java | 7 +-- .../kyori/adventure/pointer/Pointered.java | 12 ++--- .../net/kyori/adventure/pointer/Pointers.java | 20 +++---- .../kyori/adventure/pointer/PointersImpl.java | 23 ++++---- .../java/net/kyori/adventure/sound/Sound.java | 53 ++++++++++--------- .../net/kyori/adventure/sound/SoundImpl.java | 41 +++++++------- .../net/kyori/adventure/sound/SoundStop.java | 29 +++++----- .../kyori/adventure/sound/SoundStopImpl.java | 5 +- .../net/kyori/adventure/util/Buildable.java | 9 ++-- .../java/net/kyori/adventure/util/Codec.java | 23 ++++---- .../adventure/util/ForwardingIterator.java | 9 ++-- .../net/kyori/adventure/util/HSVLike.java | 11 ++-- .../java/net/kyori/adventure/util/Index.java | 35 ++++++------ .../net/kyori/adventure/util/Listenable.java | 9 ++-- .../net/kyori/adventure/util/MonkeyBars.java | 7 +-- .../java/net/kyori/adventure/util/Nag.java | 5 +- .../net/kyori/adventure/util/RGBLike.java | 5 +- .../net/kyori/adventure/util/Services.java | 7 +-- .../net/kyori/adventure/util/ShadyPines.java | 5 +- .../java/net/kyori/adventure/util/Ticks.java | 5 +- .../net/kyori/adventure/util/TriState.java | 9 ++-- .../util/UTF8ResourceBundleControl.java | 5 +- 29 files changed, 237 insertions(+), 210 deletions(-) diff --git a/api/src/main/java/net/kyori/adventure/inventory/Book.java b/api/src/main/java/net/kyori/adventure/inventory/Book.java index 3ad29c706..096c0ad0f 100644 --- a/api/src/main/java/net/kyori/adventure/inventory/Book.java +++ b/api/src/main/java/net/kyori/adventure/inventory/Book.java @@ -35,7 +35,7 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Unmodifiable; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; /** * Represents the in-game interface of a book. @@ -48,6 +48,7 @@ * @since 4.0.0 */ @ApiStatus.NonExtendable +@NullMarked public interface Book extends Buildable, Examinable { /** * Creates a book. @@ -58,7 +59,7 @@ public interface Book extends Buildable, Examinable { * @return a book * @since 4.0.0 */ - static @NonNull Book book(final @NonNull Component title, final @NonNull Component author, final @NonNull Collection pages) { + static Book book(final Component title, final Component author, final Collection pages) { return new BookImpl(title, author, new ArrayList<>(pages)); } @@ -71,7 +72,7 @@ public interface Book extends Buildable, Examinable { * @return a book * @since 4.0.0 */ - static @NonNull Book book(final @NonNull Component title, final @NonNull Component author, final @NonNull Component@NonNull... pages) { + static Book book(final Component title, final Component author, final Component... pages) { return book(title, author, Arrays.asList(pages)); } @@ -81,7 +82,7 @@ public interface Book extends Buildable, Examinable { * @return a builder * @since 4.0.0 */ - static @NonNull Builder builder() { + static Builder builder() { return new BookImpl.BuilderImpl(); } @@ -91,7 +92,7 @@ public interface Book extends Buildable, Examinable { * @return the title * @since 4.0.0 */ - @NonNull Component title(); + Component title(); /** * Changes the book's title. @@ -101,7 +102,7 @@ public interface Book extends Buildable, Examinable { * @since 4.0.0 */ @Contract(value = "_ -> new", pure = true) - @NonNull Book title(final @NonNull Component title); + Book title(final Component title); /** * Gets the author. @@ -109,7 +110,7 @@ public interface Book extends Buildable, Examinable { * @return the author * @since 4.0.0 */ - @NonNull Component author(); + Component author(); /** * Changes the book's author. @@ -119,7 +120,7 @@ public interface Book extends Buildable, Examinable { * @since 4.0.0 */ @Contract(value = "_ -> new", pure = true) - @NonNull Book author(final @NonNull Component author); + Book author(final Component author); /** * Gets the list of pages. @@ -129,7 +130,7 @@ public interface Book extends Buildable, Examinable { * @return the list of pages * @since 4.0.0 */ - @Unmodifiable @NonNull List pages(); + @Unmodifiable List pages(); /** * Returns an updated book with the provided pages. @@ -139,7 +140,7 @@ public interface Book extends Buildable, Examinable { * @since 4.0.0 */ @Contract(value = "_ -> new", pure = true) - default @NonNull Book pages(final @NonNull Component@NonNull... pages) { + default Book pages(final Component... pages) { return this.pages(Arrays.asList(pages)); } @@ -151,7 +152,7 @@ public interface Book extends Buildable, Examinable { * @since 4.0.0 */ @Contract(value = "_ -> new", pure = true) - @NonNull Book pages(final @NonNull List pages); + Book pages(final List pages); /** * Create a new builder initialized with the attributes of this book. @@ -159,7 +160,7 @@ public interface Book extends Buildable, Examinable { * @return the builder */ @Override - default @NonNull Builder toBuilder() { + default Builder toBuilder() { return builder() .title(this.title()) .author(this.author()) @@ -180,7 +181,7 @@ interface Builder extends AbstractBuilder, Buildable.Builder { * @since 4.0.0 */ @Contract("_ -> this") - @NonNull Builder title(final @NonNull Component title); + Builder title(final Component title); /** * Set the author. @@ -190,7 +191,7 @@ interface Builder extends AbstractBuilder, Buildable.Builder { * @since 4.0.0 */ @Contract("_ -> this") - @NonNull Builder author(final @NonNull Component author); + Builder author(final Component author); /** * Add a page to the book. @@ -203,7 +204,7 @@ interface Builder extends AbstractBuilder, Buildable.Builder { * @since 4.0.0 */ @Contract("_ -> this") - @NonNull Builder addPage(final @NonNull Component page); + Builder addPage(final Component page); /** * Add pages to the book. @@ -214,7 +215,7 @@ interface Builder extends AbstractBuilder, Buildable.Builder { * @since 4.0.0 */ @Contract("_ -> this") - @NonNull Builder pages(final @NonNull Component@NonNull... pages); + Builder pages(final Component... pages); /** * Add pages to the book. @@ -225,7 +226,7 @@ interface Builder extends AbstractBuilder, Buildable.Builder { * @since 4.0.0 */ @Contract("_ -> this") - @NonNull Builder pages(final @NonNull Collection pages); + Builder pages(final Collection pages); /** * Builds. @@ -233,6 +234,6 @@ interface Builder extends AbstractBuilder, Buildable.Builder { * @return a new book */ @Override - @NonNull Book build(); + Book build(); } } diff --git a/api/src/main/java/net/kyori/adventure/inventory/BookImpl.java b/api/src/main/java/net/kyori/adventure/inventory/BookImpl.java index 52cd65cab..ec62637ca 100644 --- a/api/src/main/java/net/kyori/adventure/inventory/BookImpl.java +++ b/api/src/main/java/net/kyori/adventure/inventory/BookImpl.java @@ -31,53 +31,54 @@ import net.kyori.adventure.internal.Internals; import net.kyori.adventure.text.Component; import net.kyori.examination.ExaminableProperty; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; import static java.util.Objects.requireNonNull; +@NullMarked final class BookImpl implements Book { private final Component title; private final Component author; private final List pages; - BookImpl(final @NonNull Component title, final @NonNull Component author, final @NonNull List pages) { + BookImpl(final Component title, final Component author, final List pages) { this.title = requireNonNull(title, "title"); this.author = requireNonNull(author, "author"); this.pages = Collections.unmodifiableList(requireNonNull(pages, "pages")); } @Override - public @NonNull Component title() { + public Component title() { return this.title; } @Override - public @NonNull Book title(final @NonNull Component title) { + public Book title(final Component title) { return new BookImpl(requireNonNull(title, "title"), this.author, this.pages); } @Override - public @NonNull Component author() { + public Component author() { return this.author; } @Override - public @NonNull Book author(final @NonNull Component author) { + public Book author(final Component author) { return new BookImpl(this.title, requireNonNull(author, "author"), this.pages); } @Override - public @NonNull List pages() { + public List pages() { return this.pages; } @Override - public @NonNull Book pages(final @NonNull List pages) { + public Book pages(final List pages) { return new BookImpl(this.title, this.author, new ArrayList<>(requireNonNull(pages, "pages"))); } @Override - public @NonNull Stream examinableProperties() { + public Stream examinableProperties() { return Stream.of( ExaminableProperty.of("title", this.title), ExaminableProperty.of("author", this.author), @@ -114,37 +115,37 @@ static final class BuilderImpl implements Book.Builder { private final List pages = new ArrayList<>(); @Override - public @NonNull Builder title(final @NonNull Component title) { + public Builder title(final Component title) { this.title = requireNonNull(title, "title"); return this; } @Override - public @NonNull Builder author(final @NonNull Component author) { + public Builder author(final Component author) { this.author = requireNonNull(author, "author"); return this; } @Override - public @NonNull Builder addPage(final @NonNull Component page) { + public Builder addPage(final Component page) { this.pages.add(requireNonNull(page, "page")); return this; } @Override - public @NonNull Builder pages(final @NonNull Collection pages) { + public Builder pages(final Collection pages) { this.pages.addAll(requireNonNull(pages, "pages")); return this; } @Override - public @NonNull Builder pages(final @NonNull Component@NonNull... pages) { + public Builder pages(final Component... pages) { Collections.addAll(this.pages, pages); return this; } @Override - public @NonNull Book build() { + public Book build() { return new BookImpl(this.title, this.author, new ArrayList<>(this.pages)); } } diff --git a/api/src/main/java/net/kyori/adventure/nbt/api/BinaryTagHolder.java b/api/src/main/java/net/kyori/adventure/nbt/api/BinaryTagHolder.java index 7e6ead9a7..25b79a3b9 100644 --- a/api/src/main/java/net/kyori/adventure/nbt/api/BinaryTagHolder.java +++ b/api/src/main/java/net/kyori/adventure/nbt/api/BinaryTagHolder.java @@ -25,7 +25,7 @@ import net.kyori.adventure.util.Codec; import org.jetbrains.annotations.ApiStatus; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; /** * Holds a compound binary tag. @@ -37,6 +37,7 @@ * * @since 4.0.0 */ +@NullMarked public interface BinaryTagHolder { /** * Encodes {@code nbt} using {@code codec}. @@ -49,7 +50,7 @@ public interface BinaryTagHolder { * @throws EX if an error occurred while encoding the binary tag * @since 4.0.0 */ - static @NonNull BinaryTagHolder encode(final @NonNull T nbt, final @NonNull Codec codec) throws EX { + static BinaryTagHolder encode(final T nbt, final Codec codec) throws EX { return new BinaryTagHolderImpl(codec.encode(nbt)); } @@ -60,7 +61,7 @@ public interface BinaryTagHolder { * @return the encoded binary tag * @since 4.10.0 */ - static @NonNull BinaryTagHolder binaryTagHolder(final @NonNull String string) { + static BinaryTagHolder binaryTagHolder(final String string) { return new BinaryTagHolderImpl(string); } @@ -74,7 +75,7 @@ public interface BinaryTagHolder { */ @Deprecated @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") - static @NonNull BinaryTagHolder of(final @NonNull String string) { + static BinaryTagHolder of(final String string) { return new BinaryTagHolderImpl(string); } @@ -84,7 +85,7 @@ public interface BinaryTagHolder { * @return the raw string value * @since 4.0.0 */ - @NonNull String string(); + String string(); /** * Gets the held value as a binary tag. @@ -96,5 +97,5 @@ public interface BinaryTagHolder { * @throws DX if an error occurred while retrieving the binary tag * @since 4.0.0 */ - @NonNull T get(final @NonNull Codec codec) throws DX; + T get(final Codec codec) throws DX; } diff --git a/api/src/main/java/net/kyori/adventure/nbt/api/BinaryTagHolderImpl.java b/api/src/main/java/net/kyori/adventure/nbt/api/BinaryTagHolderImpl.java index d9214cd1e..f7443e16e 100644 --- a/api/src/main/java/net/kyori/adventure/nbt/api/BinaryTagHolderImpl.java +++ b/api/src/main/java/net/kyori/adventure/nbt/api/BinaryTagHolderImpl.java @@ -24,10 +24,11 @@ package net.kyori.adventure.nbt.api; import net.kyori.adventure.util.Codec; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; import static java.util.Objects.requireNonNull; +@NullMarked final class BinaryTagHolderImpl implements BinaryTagHolder { private final String string; @@ -36,12 +37,12 @@ final class BinaryTagHolderImpl implements BinaryTagHolder { } @Override - public @NonNull String string() { + public String string() { return this.string; } @Override - public @NonNull T get(final @NonNull Codec codec) throws DX { + public T get(final Codec codec) throws DX { return codec.decode(this.string); } diff --git a/api/src/main/java/net/kyori/adventure/permission/PermissionChecker.java b/api/src/main/java/net/kyori/adventure/permission/PermissionChecker.java index 9bea4c939..20eed2ee5 100644 --- a/api/src/main/java/net/kyori/adventure/permission/PermissionChecker.java +++ b/api/src/main/java/net/kyori/adventure/permission/PermissionChecker.java @@ -28,7 +28,7 @@ import net.kyori.adventure.key.Key; import net.kyori.adventure.pointer.Pointer; import net.kyori.adventure.util.TriState; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; import static java.util.Objects.requireNonNull; @@ -37,6 +37,7 @@ * * @since 4.8.0 */ +@NullMarked public interface PermissionChecker extends Predicate { /** * A pointer to a permission predicate. @@ -52,7 +53,7 @@ public interface PermissionChecker extends Predicate { * @return a {@link PermissionChecker} * @since 4.8.0 */ - static @NonNull PermissionChecker always(final @NonNull TriState state) { + static PermissionChecker always(final TriState state) { requireNonNull(state); if (state == TriState.TRUE) return PermissionCheckers.TRUE; if (state == TriState.FALSE) return PermissionCheckers.FALSE; @@ -66,10 +67,10 @@ public interface PermissionChecker extends Predicate { * @return a tri-state result * @since 4.8.0 */ - @NonNull TriState value(final @NonNull String permission); + TriState value(final String permission); @Override - default boolean test(final @NonNull String permission) { + default boolean test(final String permission) { return this.value(permission) == TriState.TRUE; } } diff --git a/api/src/main/java/net/kyori/adventure/permission/PermissionCheckers.java b/api/src/main/java/net/kyori/adventure/permission/PermissionCheckers.java index 72853b9bc..d9920f559 100644 --- a/api/src/main/java/net/kyori/adventure/permission/PermissionCheckers.java +++ b/api/src/main/java/net/kyori/adventure/permission/PermissionCheckers.java @@ -24,9 +24,10 @@ package net.kyori.adventure.permission; import net.kyori.adventure.util.TriState; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; +@NullMarked final class PermissionCheckers { static final PermissionChecker NOT_SET = new Always(TriState.NOT_SET); static final PermissionChecker FALSE = new Always(TriState.FALSE); @@ -43,7 +44,7 @@ private Always(final TriState value) { } @Override - public @NonNull TriState value(final @NonNull String permission) { + public TriState value(final String permission) { return this.value; } diff --git a/api/src/main/java/net/kyori/adventure/pointer/Pointer.java b/api/src/main/java/net/kyori/adventure/pointer/Pointer.java index f6fd2fe47..b493c5324 100644 --- a/api/src/main/java/net/kyori/adventure/pointer/Pointer.java +++ b/api/src/main/java/net/kyori/adventure/pointer/Pointer.java @@ -27,7 +27,7 @@ import net.kyori.adventure.key.Key; import net.kyori.examination.Examinable; import net.kyori.examination.ExaminableProperty; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; /** * A pointer to a resource. @@ -35,6 +35,7 @@ * @param the value type * @since 4.8.0 */ +@NullMarked public interface Pointer extends Examinable { /** * Creates a pointer. @@ -45,7 +46,7 @@ public interface Pointer extends Examinable { * @return the pointer * @since 4.8.0 */ - static @NonNull Pointer pointer(final @NonNull Class type, final @NonNull Key key) { + static Pointer pointer(final Class type, final Key key) { return new PointerImpl<>(type, key); } @@ -55,7 +56,7 @@ public interface Pointer extends Examinable { * @return the value type * @since 4.8.0 */ - @NonNull Class type(); + Class type(); /** * Gets the key. @@ -63,10 +64,10 @@ public interface Pointer extends Examinable { * @return the key * @since 4.8.0 */ - @NonNull Key key(); + Key key(); @Override - default @NonNull Stream examinableProperties() { + default Stream examinableProperties() { return Stream.of( ExaminableProperty.of("type", this.type()), ExaminableProperty.of("key", this.key()) diff --git a/api/src/main/java/net/kyori/adventure/pointer/PointerImpl.java b/api/src/main/java/net/kyori/adventure/pointer/PointerImpl.java index 08cf075a8..cb35a3a44 100644 --- a/api/src/main/java/net/kyori/adventure/pointer/PointerImpl.java +++ b/api/src/main/java/net/kyori/adventure/pointer/PointerImpl.java @@ -25,9 +25,10 @@ import net.kyori.adventure.internal.Internals; import net.kyori.adventure.key.Key; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; +@NullMarked final class PointerImpl implements Pointer { private final Class type; private final Key key; @@ -38,12 +39,12 @@ final class PointerImpl implements Pointer { } @Override - public @NonNull Class type() { + public Class type() { return this.type; } @Override - public @NonNull Key key() { + public Key key() { return this.key; } diff --git a/api/src/main/java/net/kyori/adventure/pointer/Pointered.java b/api/src/main/java/net/kyori/adventure/pointer/Pointered.java index 8007bb905..0d0d6ee6f 100644 --- a/api/src/main/java/net/kyori/adventure/pointer/Pointered.java +++ b/api/src/main/java/net/kyori/adventure/pointer/Pointered.java @@ -26,8 +26,7 @@ import java.util.Optional; import java.util.function.Supplier; import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.UnknownNullability; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; /** @@ -35,6 +34,7 @@ * * @since 4.8.0 */ +@NullMarked public interface Pointered { /** * Gets the value of {@code pointer}. @@ -44,7 +44,7 @@ public interface Pointered { * @return the value * @since 4.8.0 */ - default @NonNull Optional get(final @NonNull Pointer pointer) { + default Optional get(final Pointer pointer) { return this.pointers().get(pointer); } @@ -61,7 +61,7 @@ public interface Pointered { */ @Contract("_, null -> _; _, !null -> !null") @SuppressWarnings("checkstyle:MethodName") - default @Nullable T getOrDefault(final @NonNull Pointer pointer, final @Nullable T defaultValue) { + default @Nullable T getOrDefault(final Pointer pointer, final @Nullable T defaultValue) { return this.pointers().getOrDefault(pointer, defaultValue); } @@ -77,7 +77,7 @@ public interface Pointered { * @since 4.8.0 */ @SuppressWarnings("checkstyle:MethodName") - default @UnknownNullability T getOrDefaultFrom(final @NonNull Pointer pointer, final @NonNull Supplier defaultValue) { + default @Nullable T getOrDefaultFrom(final Pointer pointer, final Supplier defaultValue) { return this.pointers().getOrDefaultFrom(pointer, defaultValue); } @@ -87,7 +87,7 @@ public interface Pointered { * @return the pointers * @since 4.8.0 */ - default @NonNull Pointers pointers() { + default Pointers pointers() { return Pointers.empty(); } } diff --git a/api/src/main/java/net/kyori/adventure/pointer/Pointers.java b/api/src/main/java/net/kyori/adventure/pointer/Pointers.java index 9ce6a8f89..38e615015 100644 --- a/api/src/main/java/net/kyori/adventure/pointer/Pointers.java +++ b/api/src/main/java/net/kyori/adventure/pointer/Pointers.java @@ -28,8 +28,7 @@ import net.kyori.adventure.builder.AbstractBuilder; import net.kyori.adventure.util.Buildable; import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.UnknownNullability; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; /** @@ -37,6 +36,7 @@ * * @since 4.8.0 */ +@NullMarked public interface Pointers extends Buildable { /** * Gets an empty pointers collection. @@ -45,7 +45,7 @@ public interface Pointers extends Buildable { * @since 4.8.0 */ @Contract(pure = true) - static @NonNull Pointers empty() { + static Pointers empty() { return PointersImpl.EMPTY; } @@ -57,7 +57,7 @@ public interface Pointers extends Buildable { * @since 4.8.0 */ @Contract(pure = true) - static @NonNull Builder builder() { + static Builder builder() { return new PointersImpl.BuilderImpl(); } @@ -69,7 +69,7 @@ public interface Pointers extends Buildable { * @return the value * @since 4.8.0 */ - @NonNull Optional get(final @NonNull Pointer pointer); + Optional get(final Pointer pointer); /** * Gets the value of {@code pointer}. @@ -84,7 +84,7 @@ public interface Pointers extends Buildable { */ @Contract("_, null -> _; _, !null -> !null") @SuppressWarnings("checkstyle:MethodName") - default @Nullable T getOrDefault(final @NonNull Pointer pointer, final @Nullable T defaultValue) { + default @Nullable T getOrDefault(final Pointer pointer, final @Nullable T defaultValue) { return this.get(pointer).orElse(defaultValue); } @@ -100,7 +100,7 @@ public interface Pointers extends Buildable { * @since 4.8.0 */ @SuppressWarnings("checkstyle:MethodName") - default @UnknownNullability T getOrDefaultFrom(final @NonNull Pointer pointer, final @NonNull Supplier defaultValue) { + default @Nullable T getOrDefaultFrom(final Pointer pointer, final Supplier defaultValue) { return this.get(pointer).orElseGet(defaultValue); } @@ -114,7 +114,7 @@ public interface Pointers extends Buildable { * @return if the pointer is supported * @since 4.8.0 */ - boolean supports(final @NonNull Pointer pointer); + boolean supports(final Pointer pointer); /** * A builder of pointers. @@ -133,7 +133,7 @@ interface Builder extends AbstractBuilder, Buildable.Builder * @since 4.8.0 */ @Contract("_, _ -> this") - default @NonNull Builder withStatic(final @NonNull Pointer pointer, final @Nullable T value) { + default Builder withStatic(final Pointer pointer, final @Nullable T value) { return this.withDynamic(pointer, () -> value); } @@ -147,6 +147,6 @@ interface Builder extends AbstractBuilder, Buildable.Builder * @since 4.8.0 */ @Contract("_, _ -> this") - @NonNull Builder withDynamic(final @NonNull Pointer pointer, @NonNull Supplier<@Nullable T> value); + Builder withDynamic(final Pointer pointer, Supplier<@Nullable T> value); } } diff --git a/api/src/main/java/net/kyori/adventure/pointer/PointersImpl.java b/api/src/main/java/net/kyori/adventure/pointer/PointersImpl.java index e07b60e19..af27ad1eb 100644 --- a/api/src/main/java/net/kyori/adventure/pointer/PointersImpl.java +++ b/api/src/main/java/net/kyori/adventure/pointer/PointersImpl.java @@ -28,23 +28,24 @@ import java.util.Objects; import java.util.Optional; import java.util.function.Supplier; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; +@NullMarked final class PointersImpl implements Pointers { static final Pointers EMPTY = new Pointers() { @Override - public @NonNull Optional get(final @NonNull Pointer pointer) { + public Optional get(final Pointer pointer) { return Optional.empty(); } @Override - public boolean supports(final @NonNull Pointer pointer) { + public boolean supports(final Pointer pointer) { return false; } @Override - public Pointers.@NonNull Builder toBuilder() { + public Pointers.Builder toBuilder() { return new PointersImpl.BuilderImpl(); } @@ -56,13 +57,13 @@ public String toString() { private final Map, Supplier> pointers; - PointersImpl(final @NonNull BuilderImpl builder) { + PointersImpl(final BuilderImpl builder) { this.pointers = new HashMap<>(builder.pointers); } @Override @SuppressWarnings("unchecked") // all values are checked on entry - public @NonNull Optional get(final @NonNull Pointer pointer) { + public Optional get(final Pointer pointer) { Objects.requireNonNull(pointer, "pointer"); final Supplier supplier = this.pointers.get(pointer); if (supplier == null) { @@ -73,13 +74,13 @@ public String toString() { } @Override - public boolean supports(final @NonNull Pointer pointer) { + public boolean supports(final Pointer pointer) { Objects.requireNonNull(pointer, "pointer"); return this.pointers.containsKey(pointer); } @Override - public Pointers.@NonNull Builder toBuilder() { + public Pointers.Builder toBuilder() { return new BuilderImpl(this); } @@ -90,18 +91,18 @@ static final class BuilderImpl implements Builder { this.pointers = new HashMap<>(); } - BuilderImpl(final @NonNull PointersImpl pointers) { + BuilderImpl(final PointersImpl pointers) { this.pointers = new HashMap<>(pointers.pointers); } @Override - public @NonNull Builder withDynamic(final @NonNull Pointer pointer, final @NonNull Supplier<@Nullable T> value) { + public Builder withDynamic(final Pointer pointer, final Supplier<@Nullable T> value) { this.pointers.put(Objects.requireNonNull(pointer, "pointer"), Objects.requireNonNull(value, "value")); return this; } @Override - public @NonNull Pointers build() { + public Pointers build() { return new PointersImpl(this); } } diff --git a/api/src/main/java/net/kyori/adventure/sound/Sound.java b/api/src/main/java/net/kyori/adventure/sound/Sound.java index d58eb5a2a..73aa09da5 100644 --- a/api/src/main/java/net/kyori/adventure/sound/Sound.java +++ b/api/src/main/java/net/kyori/adventure/sound/Sound.java @@ -33,7 +33,7 @@ import net.kyori.examination.Examinable; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Range; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; import static java.util.Objects.requireNonNull; @@ -58,6 +58,7 @@ * @since 4.0.0 */ @ApiStatus.NonExtendable +@NullMarked public interface Sound extends Examinable { /** * Create a new builder for {@link Sound} instances. @@ -65,7 +66,7 @@ public interface Sound extends Examinable { * @return a new builder * @since 4.12.0 */ - static @NonNull Builder sound() { + static Builder sound() { return new SoundImpl.BuilderImpl(); } @@ -76,7 +77,7 @@ public interface Sound extends Examinable { * @return a new builder * @since 4.12.0 */ - static @NonNull Builder sound(final @NonNull Sound existing) { + static Builder sound(final Sound existing) { return new SoundImpl.BuilderImpl(existing); } @@ -87,7 +88,7 @@ public interface Sound extends Examinable { * @return a new builder * @since 4.12.0 */ - static @NonNull Sound sound(final @NonNull Consumer configurer) { + static Sound sound(final Consumer configurer) { return AbstractBuilder.configureAndBuild(sound(), configurer); } @@ -101,7 +102,7 @@ public interface Sound extends Examinable { * @return the sound * @since 4.0.0 */ - static @NonNull Sound sound(final @NonNull Key name, final @NonNull Source source, final float volume, final float pitch) { + static Sound sound(final Key name, final Source source, final float volume, final float pitch) { return sound().type(name).source(source).volume(volume).pitch(pitch).build(); } @@ -115,7 +116,7 @@ public interface Sound extends Examinable { * @return the sound * @since 4.0.0 */ - static @NonNull Sound sound(final @NonNull Type type, final @NonNull Source source, final float volume, final float pitch) { + static Sound sound(final Type type, final Source source, final float volume, final float pitch) { requireNonNull(type, "type"); return sound(type.key(), source, volume, pitch); } @@ -130,7 +131,7 @@ public interface Sound extends Examinable { * @return the sound * @since 4.0.0 */ - static @NonNull Sound sound(final @NonNull Supplier type, final @NonNull Source source, final float volume, final float pitch) { + static Sound sound(final Supplier type, final Source source, final float volume, final float pitch) { return sound().type(type).source(source).volume(volume).pitch(pitch).build(); } @@ -144,7 +145,7 @@ public interface Sound extends Examinable { * @return the sound * @since 4.8.0 */ - static @NonNull Sound sound(final @NonNull Key name, final Source.@NonNull Provider source, final float volume, final float pitch) { + static Sound sound(final Key name, final Source.Provider source, final float volume, final float pitch) { return sound(name, source.soundSource(), volume, pitch); } @@ -158,7 +159,7 @@ public interface Sound extends Examinable { * @return the sound * @since 4.8.0 */ - static @NonNull Sound sound(final @NonNull Type type, final Source.@NonNull Provider source, final float volume, final float pitch) { + static Sound sound(final Type type, final Source.Provider source, final float volume, final float pitch) { return sound(type, source.soundSource(), volume, pitch); } @@ -172,7 +173,7 @@ public interface Sound extends Examinable { * @return the sound * @since 4.8.0 */ - static @NonNull Sound sound(final @NonNull Supplier type, final Source.@NonNull Provider source, final float volume, final float pitch) { + static Sound sound(final Supplier type, final Source.Provider source, final float volume, final float pitch) { return sound(type, source.soundSource(), volume, pitch); } @@ -182,7 +183,7 @@ public interface Sound extends Examinable { * @return the name * @since 4.0.0 */ - @NonNull Key name(); + Key name(); /** * Gets the source. @@ -190,7 +191,7 @@ public interface Sound extends Examinable { * @return the source * @since 4.0.0 */ - @NonNull Source source(); + Source source(); /** * Gets the volume. @@ -216,7 +217,7 @@ public interface Sound extends Examinable { * @return the seed to use * @since 4.12.0 */ - @NonNull OptionalLong seed(); + OptionalLong seed(); /** * Gets the {@link SoundStop} that will stop this specific sound. @@ -224,7 +225,7 @@ public interface Sound extends Examinable { * @return the sound stop * @since 4.8.0 */ - @NonNull SoundStop asStop(); + SoundStop asStop(); /** * The sound source. @@ -267,7 +268,7 @@ public interface Provider { * @return the source * @since 4.8.0 */ - @NonNull Source soundSource(); + Source soundSource(); } } @@ -284,7 +285,7 @@ interface Type extends Keyed { * @since 4.0.0 */ @Override - @NonNull Key key(); + Key key(); } /** @@ -302,7 +303,7 @@ interface Emitter { * @return the emitter * @since 4.8.0 */ - static @NonNull Emitter self() { + static Emitter self() { return SoundImpl.EMITTER_SELF; } } @@ -324,7 +325,7 @@ interface Builder extends AbstractBuilder { * @return this builder * @since 4.12.0 */ - @NonNull Builder type(final @NonNull Key type); + Builder type(final Key type); /** * Set the type of this sound. @@ -335,7 +336,7 @@ interface Builder extends AbstractBuilder { * @return this builder * @since 4.12.0 */ - @NonNull Builder type(final @NonNull Type type); + Builder type(final Type type); /** * Set the type of this sound. @@ -346,7 +347,7 @@ interface Builder extends AbstractBuilder { * @return this builder * @since 4.12.0 */ - @NonNull Builder type(final @NonNull Supplier typeSupplier); + Builder type(final Supplier typeSupplier); /** * A {@link Source} to tell the game where the sound is coming from. @@ -357,7 +358,7 @@ interface Builder extends AbstractBuilder { * @return this builder * @since 4.12.0 */ - @NonNull Builder source(final @NonNull Source source); + Builder source(final Source source); /** * A {@link Source} to tell the game where the sound is coming from. @@ -368,7 +369,7 @@ interface Builder extends AbstractBuilder { * @return this builder * @since 4.12.0 */ - @NonNull Builder source(final Source.@NonNull Provider source); + Builder source(final Source.Provider source); /** * The volume for this sound, indicating how far away it can be heard. @@ -379,7 +380,7 @@ interface Builder extends AbstractBuilder { * @return this builder * @since 4.12.0 */ - @NonNull Builder volume(final @Range(from = 0, to = Integer.MAX_VALUE) float volume); + Builder volume(final @Range(from = 0, to = Integer.MAX_VALUE) float volume); /** * The pitch for this sound, indicating how high or low the sound can be heard. @@ -390,7 +391,7 @@ interface Builder extends AbstractBuilder { * @return this builder * @since 4.12.0 */ - @NonNull Builder pitch(final @Range(from = -1, to = 1) float pitch); + Builder pitch(final @Range(from = -1, to = 1) float pitch); /** * The seed for this sound, used for weighted choices. @@ -401,7 +402,7 @@ interface Builder extends AbstractBuilder { * @return this builder * @since 4.12.0 */ - @NonNull Builder seed(final long seed); + Builder seed(final long seed); /** * The seed for this sound, used for weighted choices. @@ -412,6 +413,6 @@ interface Builder extends AbstractBuilder { * @return this builder * @since 4.12.0 */ - @NonNull Builder seed(final @NonNull OptionalLong seed); + Builder seed(final OptionalLong seed); } } diff --git a/api/src/main/java/net/kyori/adventure/sound/SoundImpl.java b/api/src/main/java/net/kyori/adventure/sound/SoundImpl.java index b55fad179..fc908592c 100644 --- a/api/src/main/java/net/kyori/adventure/sound/SoundImpl.java +++ b/api/src/main/java/net/kyori/adventure/sound/SoundImpl.java @@ -31,11 +31,12 @@ import net.kyori.adventure.util.ShadyPines; import net.kyori.examination.ExaminableProperty; import org.jetbrains.annotations.Range; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; import static java.util.Objects.requireNonNull; +@NullMarked abstract class SoundImpl implements Sound { static final Emitter EMITTER_SELF = new Emitter() { @Override @@ -50,7 +51,7 @@ public String toString() { private final OptionalLong seed; private SoundStop stop; - SoundImpl(final @NonNull Source source, final float volume, final float pitch, final OptionalLong seed) { + SoundImpl(final Source source, final float volume, final float pitch, final OptionalLong seed) { this.source = source; this.volume = volume; this.pitch = pitch; @@ -58,7 +59,7 @@ public String toString() { } @Override - public @NonNull Source source() { + public Source source() { return this.source; } @@ -78,7 +79,7 @@ public OptionalLong seed() { } @Override - public @NonNull SoundStop asStop() { + public SoundStop asStop() { if (this.stop == null) this.stop = SoundStop.namedOnSource(this.name(), this.source()); return this.stop; } @@ -106,7 +107,7 @@ public int hashCode() { } @Override - public @NonNull Stream examinableProperties() { + public Stream examinableProperties() { return Stream.of( ExaminableProperty.of("name", this.name()), ExaminableProperty.of("source", this.source), @@ -134,7 +135,7 @@ static final class BuilderImpl implements Builder { BuilderImpl() { } - BuilderImpl(final @NonNull Sound existing) { + BuilderImpl(final Sound existing) { if (existing instanceof Eager) { this.type(((Eager) existing).name); } else if (existing instanceof Lazy) { @@ -150,63 +151,63 @@ static final class BuilderImpl implements Builder { } @Override - public @NonNull Builder type(final @NonNull Key type) { + public Builder type(final Key type) { this.eagerType = requireNonNull(type, "type"); this.lazyType = null; return this; } @Override - public @NonNull Builder type(final @NonNull Type type) { + public Builder type(final Type type) { this.eagerType = requireNonNull(requireNonNull(type, "type").key(), "type.key()"); this.lazyType = null; return this; } @Override - public @NonNull Builder type(final @NonNull Supplier typeSupplier) { + public Builder type(final Supplier typeSupplier) { this.lazyType = requireNonNull(typeSupplier, "typeSupplier"); this.eagerType = null; return this; } @Override - public @NonNull Builder source(final @NonNull Source source) { + public Builder source(final Source source) { this.source = requireNonNull(source, "source"); return this; } @Override - public @NonNull Builder source(final Source.@NonNull Provider source) { + public Builder source(final Source.Provider source) { return this.source(source.soundSource()); } @Override - public @NonNull Builder volume(final @Range(from = 0, to = Integer.MAX_VALUE) float volume) { + public Builder volume(final @Range(from = 0, to = Integer.MAX_VALUE) float volume) { this.volume = volume; return this; } @Override - public @NonNull Builder pitch(final @Range(from = -1, to = 1) float pitch) { + public Builder pitch(final @Range(from = -1, to = 1) float pitch) { this.pitch = pitch; return this; } @Override - public @NonNull Builder seed(final long seed) { + public Builder seed(final long seed) { this.seed = OptionalLong.of(seed); return this; } @Override - public @NonNull Builder seed(final @NonNull OptionalLong seed) { + public Builder seed(final OptionalLong seed) { this.seed = requireNonNull(seed, "seed"); return this; } @Override - public @NonNull Sound build() { + public Sound build() { if (this.eagerType != null) { return new Eager(this.eagerType, this.source, this.volume, this.pitch, this.seed); } else if (this.lazyType != null) { @@ -220,13 +221,13 @@ static final class BuilderImpl implements Builder { static final class Eager extends SoundImpl { final Key name; - Eager(final @NonNull Key name, final @NonNull Source source, final float volume, final float pitch, final OptionalLong seed) { + Eager(final Key name, final Source source, final float volume, final float pitch, final OptionalLong seed) { super(source, volume, pitch, seed); this.name = name; } @Override - public @NonNull Key name() { + public Key name() { return this.name; } } @@ -234,13 +235,13 @@ static final class Eager extends SoundImpl { static final class Lazy extends SoundImpl { final Supplier supplier; - Lazy(final @NonNull Supplier supplier, final @NonNull Source source, final float volume, final float pitch, final OptionalLong seed) { + Lazy(final Supplier supplier, final Source source, final float volume, final float pitch, final OptionalLong seed) { super(source, volume, pitch, seed); this.supplier = supplier; } @Override - public @NonNull Key name() { + public Key name() { return this.supplier.get().key(); } } diff --git a/api/src/main/java/net/kyori/adventure/sound/SoundStop.java b/api/src/main/java/net/kyori/adventure/sound/SoundStop.java index cba590967..1f870526a 100644 --- a/api/src/main/java/net/kyori/adventure/sound/SoundStop.java +++ b/api/src/main/java/net/kyori/adventure/sound/SoundStop.java @@ -28,7 +28,7 @@ import net.kyori.adventure.key.Key; import net.kyori.examination.Examinable; import org.jetbrains.annotations.ApiStatus; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; import static java.util.Objects.requireNonNull; @@ -45,6 +45,7 @@ * @since 4.0.0 */ @ApiStatus.NonExtendable +@NullMarked public interface SoundStop extends Examinable { /** * Stops all sounds. @@ -52,7 +53,7 @@ public interface SoundStop extends Examinable { * @return a sound stopper * @since 4.0.0 */ - static @NonNull SoundStop all() { + static SoundStop all() { return SoundStopImpl.ALL; } @@ -63,11 +64,11 @@ public interface SoundStop extends Examinable { * @return a sound stopper * @since 4.0.0 */ - static @NonNull SoundStop named(final @NonNull Key sound) { + static SoundStop named(final Key sound) { requireNonNull(sound, "sound"); return new SoundStopImpl(null) { @Override - public @NonNull Key sound() { + public Key sound() { return sound; } }; @@ -80,11 +81,11 @@ public interface SoundStop extends Examinable { * @return a sound stopper * @since 4.0.0 */ - static @NonNull SoundStop named(final Sound.@NonNull Type sound) { + static SoundStop named(final Sound.Type sound) { requireNonNull(sound, "sound"); return new SoundStopImpl(null) { @Override - public @NonNull Key sound() { + public Key sound() { return sound.key(); } }; @@ -97,11 +98,11 @@ public interface SoundStop extends Examinable { * @return a sound stopper * @since 4.0.0 */ - static @NonNull SoundStop named(final @NonNull Supplier sound) { + static SoundStop named(final Supplier sound) { requireNonNull(sound, "sound"); return new SoundStopImpl(null) { @Override - public @NonNull Key sound() { + public Key sound() { return sound.get().key(); } }; @@ -114,7 +115,7 @@ public interface SoundStop extends Examinable { * @return a sound stopper * @since 4.0.0 */ - static @NonNull SoundStop source(final Sound.@NonNull Source source) { + static SoundStop source(final Sound.Source source) { requireNonNull(source, "source"); return new SoundStopImpl(source) { @Override @@ -132,12 +133,12 @@ public interface SoundStop extends Examinable { * @return a sound stopper * @since 4.0.0 */ - static @NonNull SoundStop namedOnSource(final @NonNull Key sound, final Sound.@NonNull Source source) { + static SoundStop namedOnSource(final Key sound, final Sound.Source source) { requireNonNull(sound, "sound"); requireNonNull(source, "source"); return new SoundStopImpl(source) { @Override - public @NonNull Key sound() { + public Key sound() { return sound; } }; @@ -151,7 +152,7 @@ public interface SoundStop extends Examinable { * @return a sound stopper * @since 4.0.0 */ - static @NonNull SoundStop namedOnSource(final Sound.@NonNull Type sound, final Sound.@NonNull Source source) { + static SoundStop namedOnSource(final Sound.Type sound, final Sound.Source source) { requireNonNull(sound, "sound"); return namedOnSource(sound.key(), source); } @@ -164,12 +165,12 @@ public interface SoundStop extends Examinable { * @return a sound stopper * @since 4.0.0 */ - static @NonNull SoundStop namedOnSource(final @NonNull Supplier sound, final Sound.@NonNull Source source) { + static SoundStop namedOnSource(final Supplier sound, final Sound.Source source) { requireNonNull(sound, "sound"); requireNonNull(source, "source"); return new SoundStopImpl(source) { @Override - public @NonNull Key sound() { + public Key sound() { return sound.get().key(); } }; diff --git a/api/src/main/java/net/kyori/adventure/sound/SoundStopImpl.java b/api/src/main/java/net/kyori/adventure/sound/SoundStopImpl.java index 4c764d97e..561a1fdee 100644 --- a/api/src/main/java/net/kyori/adventure/sound/SoundStopImpl.java +++ b/api/src/main/java/net/kyori/adventure/sound/SoundStopImpl.java @@ -28,9 +28,10 @@ import net.kyori.adventure.internal.Internals; import net.kyori.adventure.key.Key; import net.kyori.examination.ExaminableProperty; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; +@NullMarked abstract class SoundStopImpl implements SoundStop { static final SoundStop ALL = new SoundStopImpl(null) { @Override @@ -66,7 +67,7 @@ public int hashCode() { } @Override - public @NonNull Stream examinableProperties() { + public Stream examinableProperties() { return Stream.of( ExaminableProperty.of("name", this.sound()), ExaminableProperty.of("source", this.source) diff --git a/api/src/main/java/net/kyori/adventure/util/Buildable.java b/api/src/main/java/net/kyori/adventure/util/Buildable.java index 6a85b49bb..6c37db9d9 100644 --- a/api/src/main/java/net/kyori/adventure/util/Buildable.java +++ b/api/src/main/java/net/kyori/adventure/util/Buildable.java @@ -26,7 +26,7 @@ import java.util.function.Consumer; import net.kyori.adventure.builder.AbstractBuilder; import org.jetbrains.annotations.Contract; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; /** @@ -36,6 +36,7 @@ * @param the builder type * @since 4.0.0 */ +@NullMarked public interface Buildable> { /** * Configures {@code builder} using {@code consumer} and then builds. @@ -50,7 +51,7 @@ public interface Buildable> { */ @Contract(mutates = "param1") @Deprecated - static , B extends Builder> @NonNull R configureAndBuild(final @NonNull B builder, final @Nullable Consumer consumer) { + static , B extends Builder> R configureAndBuild(final B builder, final @Nullable Consumer consumer) { return AbstractBuilder.configureAndBuild(builder, consumer); } @@ -61,7 +62,7 @@ public interface Buildable> { * @since 4.0.0 */ @Contract(value = "-> new", pure = true) - @NonNull B toBuilder(); + B toBuilder(); /** * A builder. @@ -80,6 +81,6 @@ interface Builder extends AbstractBuilder { */ @Contract(value = "-> new", pure = true) @Override - @NonNull R build(); + R build(); } } diff --git a/api/src/main/java/net/kyori/adventure/util/Codec.java b/api/src/main/java/net/kyori/adventure/util/Codec.java index b1a646d0f..f853aa843 100644 --- a/api/src/main/java/net/kyori/adventure/util/Codec.java +++ b/api/src/main/java/net/kyori/adventure/util/Codec.java @@ -24,7 +24,7 @@ package net.kyori.adventure.util; import org.jetbrains.annotations.ApiStatus; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; /** * A combination encoder and decoder. @@ -35,6 +35,7 @@ * @param the encode exception type * @since 4.0.0 */ +@NullMarked public interface Codec { /** * Creates a codec. @@ -48,15 +49,15 @@ public interface Codec { * @return a codec * @since 4.10.0 */ - static @NonNull Codec codec(final @NonNull Decoder decoder, final @NonNull Encoder encoder) { + static Codec codec(final Decoder decoder, final Encoder encoder) { return new Codec() { @Override - public @NonNull D decode(final @NonNull E encoded) throws DX { + public D decode(final E encoded) throws DX { return decoder.decode(encoded); } @Override - public @NonNull E encode(final @NonNull D decoded) throws EX { + public E encode(final D decoded) throws EX { return encoder.encode(decoded); } }; @@ -77,15 +78,15 @@ public interface Codec { */ @Deprecated @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") - static @NonNull Codec of(final @NonNull Decoder decoder, final @NonNull Encoder encoder) { + static Codec of(final Decoder decoder, final Encoder encoder) { return new Codec() { @Override - public @NonNull D decode(final @NonNull E encoded) throws DX { + public D decode(final E encoded) throws DX { return decoder.decode(encoded); } @Override - public @NonNull E encode(final @NonNull D decoded) throws EX { + public E encode(final D decoded) throws EX { return encoder.encode(decoded); } }; @@ -99,7 +100,7 @@ public interface Codec { * @throws DX if an exception is encountered while decoding * @since 4.0.0 */ - @NonNull D decode(final @NonNull E encoded) throws DX; + D decode(final E encoded) throws DX; /** * A decoder. @@ -118,7 +119,7 @@ interface Decoder { * @throws X if an exception is encountered while decoding * @since 4.0.0 */ - @NonNull D decode(final @NonNull E encoded) throws X; + D decode(final E encoded) throws X; } /** @@ -129,7 +130,7 @@ interface Decoder { * @throws EX if an exception is encountered while encoding * @since 4.0.0 */ - @NonNull E encode(final @NonNull D decoded) throws EX; + E encode(final D decoded) throws EX; /** * An encoder. @@ -148,6 +149,6 @@ interface Encoder { * @throws X if an exception is encountered while encoding * @since 4.0.0 */ - @NonNull E encode(final @NonNull D decoded) throws X; + E encode(final D decoded) throws X; } } diff --git a/api/src/main/java/net/kyori/adventure/util/ForwardingIterator.java b/api/src/main/java/net/kyori/adventure/util/ForwardingIterator.java index 335affd74..a94705c0c 100644 --- a/api/src/main/java/net/kyori/adventure/util/ForwardingIterator.java +++ b/api/src/main/java/net/kyori/adventure/util/ForwardingIterator.java @@ -27,7 +27,7 @@ import java.util.Objects; import java.util.Spliterator; import java.util.function.Supplier; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; /** * An iterable that forwards the {@link #iterator()} and {@link #spliterator()} calls to some {@link Supplier suppliers}. @@ -35,6 +35,7 @@ * @param the type of the iterable * @since 4.9.0 */ +@NullMarked public final class ForwardingIterator implements Iterable { private final Supplier> iterator; private final Supplier> spliterator; @@ -46,18 +47,18 @@ public final class ForwardingIterator implements Iterable { * @param spliterator the spliterator supplier * @since 4.9.0 */ - public ForwardingIterator(final @NonNull Supplier> iterator, final @NonNull Supplier> spliterator) { + public ForwardingIterator(final Supplier> iterator, final Supplier> spliterator) { this.iterator = Objects.requireNonNull(iterator, "iterator"); this.spliterator = Objects.requireNonNull(spliterator, "spliterator"); } @Override - public @NonNull Iterator iterator() { + public Iterator iterator() { return this.iterator.get(); } @Override - public @NonNull Spliterator spliterator() { + public Spliterator spliterator() { return this.spliterator.get(); } } diff --git a/api/src/main/java/net/kyori/adventure/util/HSVLike.java b/api/src/main/java/net/kyori/adventure/util/HSVLike.java index 10a592156..9d00ecc7b 100644 --- a/api/src/main/java/net/kyori/adventure/util/HSVLike.java +++ b/api/src/main/java/net/kyori/adventure/util/HSVLike.java @@ -28,7 +28,7 @@ import net.kyori.examination.ExaminableProperty; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Range; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; /** * Something that can provide hue, saturation, and value color components. @@ -37,6 +37,7 @@ * * @since 4.6.0 */ +@NullMarked public interface HSVLike extends Examinable { /** * Creates a new HSVLike. @@ -47,7 +48,7 @@ public interface HSVLike extends Examinable { * @return a new HSVLike * @since 4.10.0 */ - static @NonNull HSVLike hsvLike(final float h, final float s, final float v) { + static HSVLike hsvLike(final float h, final float s, final float v) { return new HSVLikeImpl(h, s, v); } @@ -63,7 +64,7 @@ public interface HSVLike extends Examinable { */ @Deprecated @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") - static @NonNull HSVLike of(final float h, final float s, final float v) { + static HSVLike of(final float h, final float s, final float v) { return new HSVLikeImpl(h, s, v); } @@ -76,7 +77,7 @@ public interface HSVLike extends Examinable { * @return a new HSVLike * @since 4.6.0 */ - static @NonNull HSVLike fromRGB(@Range(from = 0x0, to = 0xff) final int red, @Range(from = 0x0, to = 0xff) final int green, @Range(from = 0x0, to = 0xff) final int blue) { + static HSVLike fromRGB(@Range(from = 0x0, to = 0xff) final int red, @Range(from = 0x0, to = 0xff) final int green, @Range(from = 0x0, to = 0xff) final int blue) { final float r = red / 255.0f; final float g = green / 255.0f; final float b = blue / 255.0f; @@ -137,7 +138,7 @@ public interface HSVLike extends Examinable { float v(); @Override - default @NonNull Stream examinableProperties() { + default Stream examinableProperties() { return Stream.of( ExaminableProperty.of("h", this.h()), ExaminableProperty.of("s", this.s()), diff --git a/api/src/main/java/net/kyori/adventure/util/Index.java b/api/src/main/java/net/kyori/adventure/util/Index.java index 1e9896f0c..984f7194e 100644 --- a/api/src/main/java/net/kyori/adventure/util/Index.java +++ b/api/src/main/java/net/kyori/adventure/util/Index.java @@ -34,7 +34,7 @@ import java.util.function.Function; import java.util.function.IntFunction; import org.jetbrains.annotations.Contract; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; /** @@ -44,6 +44,7 @@ * @param the value type * @since 4.0.0 */ +@NullMarked public final class Index { private final Map keyToValue; private final Map valueToKey; @@ -63,7 +64,7 @@ private Index(final Map keyToValue, final Map valueToKey) { * @return the key map * @since 4.0.0 */ - public static > @NonNull Index create(final Class type, final @NonNull Function keyFunction) { + public static > Index create(final Class type, final Function keyFunction) { return create(type, keyFunction, type.getEnumConstants()); } @@ -80,7 +81,7 @@ private Index(final Map keyToValue, final Map valueToKey) { */ @SafeVarargs @SuppressWarnings("varargs") - public static > @NonNull Index create(final Class type, final @NonNull Function keyFunction, final @NonNull V@NonNull... values) { + public static > Index create(final Class type, final Function keyFunction, final V... values) { return create(values, length -> new EnumMap<>(type), keyFunction); } @@ -96,7 +97,7 @@ private Index(final Map keyToValue, final Map valueToKey) { */ @SafeVarargs @SuppressWarnings("varargs") - public static @NonNull Index create(final @NonNull Function keyFunction, final @NonNull V@NonNull... values) { + public static Index create(final Function keyFunction, final V... values) { return create(values, HashMap::new, keyFunction); } @@ -110,15 +111,15 @@ private Index(final Map keyToValue, final Map valueToKey) { * @return the key map * @since 4.0.0 */ - public static @NonNull Index create(final @NonNull Function keyFunction, final @NonNull List constants) { + public static Index create(final Function keyFunction, final List constants) { return create(constants, HashMap::new, keyFunction); } - private static @NonNull Index create(final V[] values, final IntFunction> valueToKeyFactory, final @NonNull Function keyFunction) { + private static Index create(final V[] values, final IntFunction> valueToKeyFactory, final Function keyFunction) { return create(Arrays.asList(values), valueToKeyFactory, keyFunction); } - private static @NonNull Index create(final List values, final IntFunction> valueToKeyFactory, final @NonNull Function keyFunction) { + private static Index create(final List values, final IntFunction> valueToKeyFactory, final Function keyFunction) { final int length = values.size(); final Map keyToValue = new HashMap<>(length); final Map valueToKey = valueToKeyFactory.apply(length); // to support using EnumMap instead of HashMap when possible @@ -141,7 +142,7 @@ private Index(final Map keyToValue, final Map valueToKey) { * @return the keys * @since 4.0.0 */ - public @NonNull Set keys() { + public Set keys() { return Collections.unmodifiableSet(this.keyToValue.keySet()); } @@ -152,7 +153,7 @@ private Index(final Map keyToValue, final Map valueToKey) { * @return the key * @since 4.0.0 */ - public @Nullable K key(final @NonNull V value) { + public @Nullable K key(final V value) { return this.valueToKey.get(value); } @@ -164,7 +165,7 @@ private Index(final Map keyToValue, final Map valueToKey) { * @throws NoSuchElementException if there is no key for the value * @since 4.11.0 */ - public @NonNull K keyOrThrow(final @NonNull V value) { + public K keyOrThrow(final V value) { final K key = this.key(value); if (key == null) { throw new NoSuchElementException("There is no key for value " + value); @@ -181,7 +182,7 @@ private Index(final Map keyToValue, final Map valueToKey) { * @since 4.11.0 */ @Contract("_, null -> null; _, !null -> !null") - public K keyOr(final @NonNull V value, final @Nullable K defaultKey) { + public K keyOr(final V value, final @Nullable K defaultKey) { final K key = this.key(value); return key == null ? defaultKey : key; } @@ -192,7 +193,7 @@ public K keyOr(final @NonNull V value, final @Nullable K defaultKey) { * @return the keys * @since 4.0.0 */ - public @NonNull Set values() { + public Set values() { return Collections.unmodifiableSet(this.valueToKey.keySet()); } @@ -203,7 +204,7 @@ public K keyOr(final @NonNull V value, final @Nullable K defaultKey) { * @return the value * @since 4.0.0 */ - public @Nullable V value(final @NonNull K key) { + public @Nullable V value(final K key) { return this.keyToValue.get(key); } @@ -215,7 +216,7 @@ public K keyOr(final @NonNull V value, final @Nullable K defaultKey) { * @throws NoSuchElementException if there is no value for the key * @since 4.11.0 */ - public @NonNull V valueOrThrow(final @NonNull K key) { + public V valueOrThrow(final K key) { final V value = this.value(key); if (value == null) { throw new NoSuchElementException("There is no value for key " + key); @@ -232,7 +233,7 @@ public K keyOr(final @NonNull V value, final @Nullable K defaultKey) { * @since 4.11.0 */ @Contract("_, null -> null; _, !null -> !null") - public V valueOr(final @NonNull K key, final @Nullable V defaultValue) { + public V valueOr(final K key, final @Nullable V defaultValue) { final V value = this.value(key); return value == null ? defaultValue : value; } @@ -243,7 +244,7 @@ public V valueOr(final @NonNull K key, final @Nullable V defaultValue) { * @return a mapping from key to value in the index * @since 4.10.0 */ - public @NonNull Map keyToValue() { + public Map keyToValue() { return Collections.unmodifiableMap(this.keyToValue); } @@ -253,7 +254,7 @@ public V valueOr(final @NonNull K key, final @Nullable V defaultValue) { * @return a mapping from value to key in the index * @since 4.10.0 */ - public @NonNull Map valueToKey() { + public Map valueToKey() { return Collections.unmodifiableMap(this.valueToKey); } } diff --git a/api/src/main/java/net/kyori/adventure/util/Listenable.java b/api/src/main/java/net/kyori/adventure/util/Listenable.java index a79c4d947..d4a06e85c 100644 --- a/api/src/main/java/net/kyori/adventure/util/Listenable.java +++ b/api/src/main/java/net/kyori/adventure/util/Listenable.java @@ -26,7 +26,7 @@ import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Consumer; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; /** * Something that has listeners. @@ -34,6 +34,7 @@ * @param the listener type * @since 4.0.0 */ +@NullMarked public abstract class Listenable { private final List listeners = new CopyOnWriteArrayList<>(); @@ -43,7 +44,7 @@ public abstract class Listenable { * @param consumer the consumer * @since 4.0.0 */ - protected final void forEachListener(final @NonNull Consumer consumer) { + protected final void forEachListener(final Consumer consumer) { for (final L listener : this.listeners) { consumer.accept(listener); } @@ -55,7 +56,7 @@ protected final void forEachListener(final @NonNull Consumer consumer) { * @param listener the listener * @since 4.0.0 */ - protected final void addListener0(final @NonNull L listener) { + protected final void addListener0(final L listener) { this.listeners.add(listener); } @@ -65,7 +66,7 @@ protected final void addListener0(final @NonNull L listener) { * @param listener the listener * @since 4.0.0 */ - protected final void removeListener0(final @NonNull L listener) { + protected final void removeListener0(final L listener) { this.listeners.remove(listener); } } diff --git a/api/src/main/java/net/kyori/adventure/util/MonkeyBars.java b/api/src/main/java/net/kyori/adventure/util/MonkeyBars.java index 5a42137a1..1c319c172 100644 --- a/api/src/main/java/net/kyori/adventure/util/MonkeyBars.java +++ b/api/src/main/java/net/kyori/adventure/util/MonkeyBars.java @@ -29,13 +29,14 @@ import java.util.EnumSet; import java.util.List; import java.util.Set; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; /** * {@link Collection} related utilities. * * @since 4.8.0 */ +@NullMarked public final class MonkeyBars { private MonkeyBars() { } @@ -51,7 +52,7 @@ private MonkeyBars() { */ @SafeVarargs @SuppressWarnings("varargs") - public static > @NonNull Set enumSet(final Class type, final E@NonNull... constants) { + public static > Set enumSet(final Class type, final E... constants) { final Set set = EnumSet.noneOf(type); Collections.addAll(set, constants); return Collections.unmodifiableSet(set); @@ -68,7 +69,7 @@ private MonkeyBars() { * @return a list * @since 4.8.0 */ - public static @NonNull List addOne(final @NonNull List oldList, final T newElement) { + public static List addOne(final List oldList, final T newElement) { if (oldList.isEmpty()) return Collections.singletonList(newElement); final List newList = new ArrayList<>(oldList.size() + 1); newList.addAll(oldList); diff --git a/api/src/main/java/net/kyori/adventure/util/Nag.java b/api/src/main/java/net/kyori/adventure/util/Nag.java index 2f6361551..2f4bbdac4 100644 --- a/api/src/main/java/net/kyori/adventure/util/Nag.java +++ b/api/src/main/java/net/kyori/adventure/util/Nag.java @@ -23,13 +23,14 @@ */ package net.kyori.adventure.util; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; /** * A nag. * * @since 4.7.0 */ +@NullMarked public abstract class Nag extends RuntimeException { private static final long serialVersionUID = -695562541413409498L; @@ -39,7 +40,7 @@ public abstract class Nag extends RuntimeException { * @param nag the nag * @since 4.7.0 */ - public static void print(final @NonNull Nag nag) { + public static void print(final Nag nag) { nag.printStackTrace(); } diff --git a/api/src/main/java/net/kyori/adventure/util/RGBLike.java b/api/src/main/java/net/kyori/adventure/util/RGBLike.java index 245130311..102984685 100644 --- a/api/src/main/java/net/kyori/adventure/util/RGBLike.java +++ b/api/src/main/java/net/kyori/adventure/util/RGBLike.java @@ -24,13 +24,14 @@ package net.kyori.adventure.util; import org.jetbrains.annotations.Range; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; /** * Something that can provide red, green, and blue colour components. * * @since 4.0.0 */ +@NullMarked public interface RGBLike { /** * Gets the red component. @@ -62,7 +63,7 @@ public interface RGBLike { * @return an HSVLike representing this RGBLike in the HSV color space * @since 4.6.0 */ - default @NonNull HSVLike asHSV() { + default HSVLike asHSV() { return HSVLike.fromRGB(this.red(), this.green(), this.blue()); } } diff --git a/api/src/main/java/net/kyori/adventure/util/Services.java b/api/src/main/java/net/kyori/adventure/util/Services.java index 6d2176cfc..9f5f4b46e 100644 --- a/api/src/main/java/net/kyori/adventure/util/Services.java +++ b/api/src/main/java/net/kyori/adventure/util/Services.java @@ -27,13 +27,14 @@ import java.util.Optional; import java.util.ServiceLoader; import net.kyori.adventure.internal.properties.AdventureProperties; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; /** * Tools for working with {@link ServiceLoader}s. * * @since 4.8.0 */ +@NullMarked public final class Services { private static final boolean SERVICE_LOAD_FAILURES_ARE_FATAL = Boolean.TRUE.equals(AdventureProperties.SERVICE_LOAD_FAILURES_ARE_FATAL.value()); @@ -48,7 +49,7 @@ private Services() { * @return a service, or {@link Optional#empty()} * @since 4.8.0 */ - public static

@NonNull Optional

service(final @NonNull Class

type) { + public static

Optional

service(final Class

type) { final ServiceLoader

loader = Services0.loader(type); final Iterator

it = loader.iterator(); while (it.hasNext()) { @@ -92,7 +93,7 @@ public interface Fallback { * @see Fallback * @since 4.14.0 */ - public static

@NonNull Optional

serviceWithFallback(final @NonNull Class

type) { + public static

Optional

serviceWithFallback(final Class

type) { final ServiceLoader

loader = Services0.loader(type); final Iterator

it = loader.iterator(); P firstFallback = null; diff --git a/api/src/main/java/net/kyori/adventure/util/ShadyPines.java b/api/src/main/java/net/kyori/adventure/util/ShadyPines.java index f869b2252..aaa31a8b5 100644 --- a/api/src/main/java/net/kyori/adventure/util/ShadyPines.java +++ b/api/src/main/java/net/kyori/adventure/util/ShadyPines.java @@ -25,13 +25,14 @@ import java.util.Set; import org.jetbrains.annotations.ApiStatus; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; /** * Various utilities. * * @since 4.0.0 */ +@NullMarked public final class ShadyPines { private ShadyPines() { } @@ -50,7 +51,7 @@ private ShadyPines() { @Deprecated @SafeVarargs @SuppressWarnings("varargs") - public static > @NonNull Set enumSet(final Class type, final E@NonNull... constants) { + public static > Set enumSet(final Class type, final E... constants) { return MonkeyBars.enumSet(type, constants); } diff --git a/api/src/main/java/net/kyori/adventure/util/Ticks.java b/api/src/main/java/net/kyori/adventure/util/Ticks.java index c166dec91..93c6b017e 100644 --- a/api/src/main/java/net/kyori/adventure/util/Ticks.java +++ b/api/src/main/java/net/kyori/adventure/util/Ticks.java @@ -24,13 +24,14 @@ package net.kyori.adventure.util; import java.time.Duration; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; /** * Standard game tick utilities. * * @since 4.0.0 */ +@NullMarked public interface Ticks { /** * The number of ticks that occur in one second. @@ -53,7 +54,7 @@ public interface Ticks { * @return a duration * @since 4.0.0 */ - static @NonNull Duration duration(final long ticks) { + static Duration duration(final long ticks) { return Duration.ofMillis(ticks * SINGLE_TICK_DURATION_MS); } } diff --git a/api/src/main/java/net/kyori/adventure/util/TriState.java b/api/src/main/java/net/kyori/adventure/util/TriState.java index 0964ffca8..6ec080a9d 100644 --- a/api/src/main/java/net/kyori/adventure/util/TriState.java +++ b/api/src/main/java/net/kyori/adventure/util/TriState.java @@ -24,7 +24,7 @@ package net.kyori.adventure.util; import java.util.function.BooleanSupplier; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; /** @@ -32,6 +32,7 @@ * * @since 4.8.0 */ +@NullMarked public enum TriState { /** * State describing the absence of a value. @@ -98,7 +99,7 @@ public boolean toBooleanOrElse(final boolean other) { * @return the boolean representing the tri-state or the result of the passed supplier if this state is {@link #NOT_SET}. * @since 4.10.0 */ - public boolean toBooleanOrElseGet(final @NonNull BooleanSupplier supplier) { + public boolean toBooleanOrElseGet(final BooleanSupplier supplier) { switch (this) { case TRUE: return true; case FALSE: return false; @@ -113,7 +114,7 @@ public boolean toBooleanOrElseGet(final @NonNull BooleanSupplier supplier) { * @return a tri-state * @since 4.8.0 */ - public static @NonNull TriState byBoolean(final boolean value) { + public static TriState byBoolean(final boolean value) { return value ? TRUE : FALSE; } @@ -124,7 +125,7 @@ public boolean toBooleanOrElseGet(final @NonNull BooleanSupplier supplier) { * @return a tri-state * @since 4.8.0 */ - public static @NonNull TriState byBoolean(final @Nullable Boolean value) { + public static TriState byBoolean(final @Nullable Boolean value) { return value == null ? NOT_SET : byBoolean(value.booleanValue()); } } diff --git a/api/src/main/java/net/kyori/adventure/util/UTF8ResourceBundleControl.java b/api/src/main/java/net/kyori/adventure/util/UTF8ResourceBundleControl.java index 2b7226003..271cf9099 100644 --- a/api/src/main/java/net/kyori/adventure/util/UTF8ResourceBundleControl.java +++ b/api/src/main/java/net/kyori/adventure/util/UTF8ResourceBundleControl.java @@ -32,7 +32,7 @@ import java.util.Locale; import java.util.PropertyResourceBundle; import java.util.ResourceBundle; -import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; /** * A {@link ResourceBundle.Control} that enforces UTF-8 string encoding. @@ -41,6 +41,7 @@ * * @since 4.0.0 */ +@NullMarked public final class UTF8ResourceBundleControl extends ResourceBundle.Control { private static final UTF8ResourceBundleControl INSTANCE = new UTF8ResourceBundleControl(); @@ -50,7 +51,7 @@ public final class UTF8ResourceBundleControl extends ResourceBundle.Control { * @return a resource bundle control * @since 4.0.0 */ - public static ResourceBundle.@NonNull Control get() { + public static ResourceBundle.Control get() { return INSTANCE; }