Skip to content

Commit

Permalink
chore(api/builder-chat-identity-internal): migrate to jspecify
Browse files Browse the repository at this point in the history
  • Loading branch information
powercasgamer committed Oct 12, 2023
1 parent 1ea8039 commit a7b3b4c
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import java.util.function.Consumer;
import org.jetbrains.annotations.Contract;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

/**
Expand All @@ -35,6 +35,7 @@
* @since 4.10.0
*/
@FunctionalInterface
@NullMarked
public interface AbstractBuilder<R> {
/**
* Configures {@code builder} using {@code consumer} and then builds.
Expand All @@ -47,7 +48,7 @@ public interface AbstractBuilder<R> {
* @since 4.10.0
*/
@Contract(mutates = "param1")
static <R, B extends AbstractBuilder<R>> @NonNull R configureAndBuild(final @NonNull B builder, final @Nullable Consumer<? super B> consumer) {
static <R, B extends AbstractBuilder<R>> R configureAndBuild(final B builder, final @Nullable Consumer<? super B> consumer) {
if (consumer != null) {
consumer.accept(builder);
}
Expand All @@ -61,5 +62,5 @@ public interface AbstractBuilder<R> {
* @since 4.10.0
*/
@Contract(value = "-> new", pure = true)
@NonNull R build();
R build();
}
17 changes: 9 additions & 8 deletions api/src/main/java/net/kyori/adventure/chat/ChatType.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import net.kyori.examination.Examinable;
import net.kyori.examination.ExaminableProperty;
import org.jetbrains.annotations.Contract;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

import static java.util.Objects.requireNonNull;
Expand All @@ -42,6 +42,7 @@
* @since 4.12.0
* @sinceMinecraft 1.19
*/
@NullMarked
public interface ChatType extends Examinable, Keyed {
/**
* A chat message from a player.
Expand Down Expand Up @@ -106,7 +107,7 @@ public interface ChatType extends Examinable, Keyed {
* @return the chat type
* @since 4.12.0
*/
static @NonNull ChatType chatType(final @NonNull Keyed key) {
static ChatType chatType(final Keyed key) {
return key instanceof ChatType ? (ChatType) key : new ChatTypeImpl(requireNonNull(key, "key").key());
}

Expand All @@ -119,7 +120,7 @@ public interface ChatType extends Examinable, Keyed {
* @sinceMinecraft 1.19
*/
@Contract(value = "_ -> new", pure = true)
default ChatType.@NonNull Bound bind(final @NonNull ComponentLike name) {
default ChatType.Bound bind(final ComponentLike name) {
return this.bind(name, null);
}

Expand All @@ -133,12 +134,12 @@ public interface ChatType extends Examinable, Keyed {
* @sinceMinecraft 1.19
*/
@Contract(value = "_, _ -> new", pure = true)
default ChatType.@NonNull Bound bind(final @NonNull ComponentLike name, final @Nullable ComponentLike target) {
default ChatType.Bound bind(final ComponentLike name, final @Nullable ComponentLike target) {
return new ChatTypeImpl.BoundImpl(this, requireNonNull(name.asComponent(), "name"), ComponentLike.unbox(target));
}

@Override
default @NonNull Stream<? extends ExaminableProperty> examinableProperties() {
default Stream<? extends ExaminableProperty> examinableProperties() {
return Stream.of(ExaminableProperty.of("key", this.key()));
}

Expand All @@ -158,7 +159,7 @@ interface Bound extends Examinable {
* @sinceMinecraft 1.19
*/
@Contract(pure = true)
@NonNull ChatType type();
ChatType type();

/**
* Get the name component.
Expand All @@ -168,7 +169,7 @@ interface Bound extends Examinable {
* @sinceMinecraft 1.19
*/
@Contract(pure = true)
@NonNull Component name();
Component name();

/**
* Get the target component.
Expand All @@ -181,7 +182,7 @@ interface Bound extends Examinable {
@Nullable Component target();

@Override
default @NonNull Stream<? extends ExaminableProperty> examinableProperties() {
default Stream<? extends ExaminableProperty> examinableProperties() {
return Stream.of(
ExaminableProperty.of("type", this.type()),
ExaminableProperty.of("name", this.name()),
Expand Down
11 changes: 6 additions & 5 deletions api/src/main/java/net/kyori/adventure/chat/ChatTypeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@
import net.kyori.adventure.internal.Internals;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
final class ChatTypeImpl implements ChatType {
private final Key key;

ChatTypeImpl(final @NonNull Key key) {
ChatTypeImpl(final Key key) {
this.key = key;
}

@Override
public @NonNull Key key() {
public Key key() {
return this.key;
}

Expand All @@ -58,12 +59,12 @@ static final class BoundImpl implements ChatType.Bound {
}

@Override
public @NonNull ChatType type() {
public ChatType type() {
return this.chatType;
}

@Override
public @NonNull Component name() {
public Component name() {
return this.name;
}

Expand Down
15 changes: 8 additions & 7 deletions api/src/main/java/net/kyori/adventure/chat/SignedMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import net.kyori.examination.ExaminableProperty;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

/**
Expand All @@ -43,6 +43,7 @@
* @sinceMinecraft 1.19
*/
@ApiStatus.NonExtendable
@NullMarked
public interface SignedMessage extends Identified, Examinable {

/**
Expand All @@ -54,7 +55,7 @@ public interface SignedMessage extends Identified, Examinable {
* @sinceMinecraft 1.19
*/
@Contract(value = "_ -> new", pure = true)
static @NonNull Signature signature(final byte[] signature) {
static Signature signature(final byte[] signature) {
return new SignedMessageImpl.SignatureImpl(signature);
}

Expand All @@ -68,7 +69,7 @@ public interface SignedMessage extends Identified, Examinable {
* @sinceMinecraft 1.19
*/
@Contract(value = "_, _ -> new", pure = true)
static @NonNull SignedMessage system(final @NonNull String message, final @Nullable ComponentLike unsignedContent) {
static SignedMessage system(final String message, final @Nullable ComponentLike unsignedContent) {
return new SignedMessageImpl(message, ComponentLike.unbox(unsignedContent));
}

Expand All @@ -80,7 +81,7 @@ public interface SignedMessage extends Identified, Examinable {
* @sinceMinecraft 1.19
*/
@Contract(pure = true)
@NonNull Instant timestamp();
Instant timestamp();

/**
* The salt.
Expand Down Expand Up @@ -120,7 +121,7 @@ public interface SignedMessage extends Identified, Examinable {
* @sinceMinecraft 1.19
*/
@Contract(pure = true)
@NonNull String message();
String message();

/**
* Checks if this message is a system message.
Expand All @@ -147,7 +148,7 @@ default boolean canDelete() {
}

@Override
default @NonNull Stream<? extends ExaminableProperty> examinableProperties() {
default Stream<? extends ExaminableProperty> examinableProperties() {
return Stream.of(
ExaminableProperty.of("timestamp", this.timestamp()),
ExaminableProperty.of("salt", this.salt()),
Expand Down Expand Up @@ -177,7 +178,7 @@ interface Signature extends Examinable {
byte[] bytes();

@Override
default @NonNull Stream<? extends ExaminableProperty> examinableProperties() {
default Stream<? extends ExaminableProperty> examinableProperties() {
return Stream.of(ExaminableProperty.of("bytes", this.bytes()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
import java.time.Instant;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

// Used for system messages ONLY
@NullMarked
final class SignedMessageImpl implements SignedMessage {
static final SecureRandom RANDOM = new SecureRandom();

Expand All @@ -47,7 +48,7 @@ final class SignedMessageImpl implements SignedMessage {
}

@Override
public @NonNull Instant timestamp() {
public Instant timestamp() {
return this.instant;
}

Expand All @@ -67,12 +68,12 @@ public Signature signature() {
}

@Override
public @NonNull String message() {
public String message() {
return this.message;
}

@Override
public @NonNull Identity identity() {
public Identity identity() {
return Identity.nil();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@
*/
package net.kyori.adventure.identity;

import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;

/**
* Something that can be identified by an {@link Identity}.
*
* @since 4.0.0
*/
@NullMarked
public interface Identified {
/**
* Gets the identity.
*
* @return the identity
* @since 4.0.0
*/
@NonNull Identity identity();
Identity identity();
}
13 changes: 7 additions & 6 deletions api/src/main/java/net/kyori/adventure/identity/Identity.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import net.kyori.adventure.text.Component;
import net.kyori.examination.Examinable;
import net.kyori.examination.ExaminableProperty;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;

/**
* An identity used to track the sender of messages for the social interaction features
Expand All @@ -41,6 +41,7 @@
* @since 4.0.0
* @sinceMinecraft 1.16
*/
@NullMarked
public interface Identity extends Examinable, Identified {
/**
* A pointer to a name.
Expand Down Expand Up @@ -75,7 +76,7 @@ public interface Identity extends Examinable, Identified {
* @return the {@code null} identity
* @since 4.0.0
*/
static @NonNull Identity nil() {
static Identity nil() {
return NilIdentity.INSTANCE;
}

Expand All @@ -86,7 +87,7 @@ public interface Identity extends Examinable, Identified {
* @return an identity
* @since 4.0.0
*/
static @NonNull Identity identity(final @NonNull UUID uuid) {
static Identity identity(final UUID uuid) {
if (uuid.equals(NilIdentity.NIL_UUID)) return NilIdentity.INSTANCE;
return new IdentityImpl(uuid);
}
Expand All @@ -97,15 +98,15 @@ public interface Identity extends Examinable, Identified {
* @return the uuid
* @since 4.0.0
*/
@NonNull UUID uuid();
UUID uuid();

@Override
default @NonNull Identity identity() {
default Identity identity() {
return this;
}

@Override
default @NonNull Stream<? extends ExaminableProperty> examinableProperties() {
default Stream<? extends ExaminableProperty> examinableProperties() {
return Stream.of(ExaminableProperty.of("uuid", this.uuid()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import java.util.UUID;
import net.kyori.adventure.internal.Internals;
import net.kyori.examination.Examinable;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
final class IdentityImpl implements Examinable, Identity {
private final UUID uuid;

Expand All @@ -37,7 +38,7 @@ final class IdentityImpl implements Examinable, Identity {
}

@Override
public @NonNull UUID uuid() {
public UUID uuid() {
return this.uuid;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
package net.kyori.adventure.identity;

import java.util.UUID;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
final class NilIdentity implements Identity {
static final UUID NIL_UUID = new UUID(0, 0);
static final Identity INSTANCE = new NilIdentity();

@Override
public @NonNull UUID uuid() {
public UUID uuid() {
return NIL_UUID;
}

Expand Down
5 changes: 3 additions & 2 deletions api/src/main/java/net/kyori/adventure/internal/Internals.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
import net.kyori.examination.Examinable;
import net.kyori.examination.string.StringExaminer;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;

/**
* Utilities internal to Adventure.
*/
@ApiStatus.Internal
@NullMarked
public final class Internals {
private Internals() {
}
Expand All @@ -43,7 +44,7 @@ private Internals() {
* @return the result from examining
* @since 4.10.0
*/
public static @NonNull String toString(final @NonNull Examinable examinable) {
public static String toString(final Examinable examinable) {
return examinable.examine(StringExaminer.simpleEscaping());
}
}
Loading

0 comments on commit a7b3b4c

Please sign in to comment.