mirror of
https://github.com/lucko/LuckPerms.git
synced 2025-08-26 15:54:22 +02:00
Add some missing null annotations
This commit is contained in:
@@ -170,7 +170,7 @@ public interface Action extends Comparable<Action> {
|
||||
* @param type the type
|
||||
* @return the builder
|
||||
*/
|
||||
@NonNull Builder targetType(Action.Target.Type type);
|
||||
@NonNull Builder targetType(Target.@NonNull Type type);
|
||||
|
||||
/**
|
||||
* Sets the acted object for the entry.
|
||||
|
@@ -103,7 +103,7 @@ public interface ContextCalculator<T> {
|
||||
*
|
||||
* @return a set of potential contexts
|
||||
*/
|
||||
default ContextSet estimatePotentialContexts() {
|
||||
default @NonNull ContextSet estimatePotentialContexts() {
|
||||
return ImmutableContextSet.empty();
|
||||
}
|
||||
|
||||
|
@@ -40,7 +40,7 @@ public interface MessagingService {
|
||||
*
|
||||
* @return the name of this messaging service
|
||||
*/
|
||||
String getName();
|
||||
@NonNull String getName();
|
||||
|
||||
/**
|
||||
* Uses the messaging service to inform other servers about a general
|
||||
|
@@ -201,11 +201,11 @@ public interface Node {
|
||||
/**
|
||||
* Gets the metadata corresponding to the given <code>key</code>, if present.
|
||||
*
|
||||
* @param key the key
|
||||
* @param <T> the metadata type
|
||||
* @param key the key
|
||||
* @return the data, if present
|
||||
*/
|
||||
<T> Optional<T> getMetadata(NodeMetadataKey<T> key);
|
||||
<T> Optional<T> getMetadata(@NonNull NodeMetadataKey<T> key);
|
||||
|
||||
/**
|
||||
* Gets the metadata corresponding to the given <code>key</code>, throwing an exception
|
||||
@@ -216,7 +216,7 @@ public interface Node {
|
||||
* @return the data
|
||||
* @throws IllegalStateException if data isn't present
|
||||
*/
|
||||
default <T> T metadata(NodeMetadataKey<T> key) throws IllegalStateException {
|
||||
default <T> T metadata(@NonNull NodeMetadataKey<T> key) throws IllegalStateException {
|
||||
return getMetadata(key).orElseThrow(() -> new IllegalStateException("Node '" + getKey() + "' does not have '" + key.name() + "' attached."));
|
||||
}
|
||||
|
||||
|
@@ -109,7 +109,7 @@ public interface NodeBuilder<N extends ScopedNode<N, B>, B extends NodeBuilder<N
|
||||
* @param unit the unit <code>duration</code> is measured in
|
||||
* @return the builder
|
||||
*/
|
||||
default @NonNull B expiry(long duration, TimeUnit unit) {
|
||||
default @NonNull B expiry(long duration, @NonNull TimeUnit unit) {
|
||||
if (duration <= 0) {
|
||||
throw new IllegalArgumentException("duration must be positive");
|
||||
}
|
||||
|
@@ -35,6 +35,8 @@ import net.luckperms.api.node.types.RegexPermissionNode;
|
||||
import net.luckperms.api.node.types.SuffixNode;
|
||||
import net.luckperms.api.node.types.WeightNode;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
@@ -48,59 +50,105 @@ public interface NodeType<T extends Node> {
|
||||
/**
|
||||
* Node type for {@link PermissionNode}.
|
||||
*/
|
||||
NodeType<PermissionNode> PERMISSION = new SimpleNodeType<>("PERMISSION", n -> n instanceof PermissionNode, n -> (PermissionNode) n);
|
||||
NodeType<PermissionNode> PERMISSION = new SimpleNodeType<>(
|
||||
"PERMISSION",
|
||||
n -> n instanceof PermissionNode,
|
||||
n -> (PermissionNode) n
|
||||
);
|
||||
|
||||
/**
|
||||
* Node type for {@link RegexPermissionNode}.
|
||||
*/
|
||||
NodeType<RegexPermissionNode> REGEX_PERMISSION = new SimpleNodeType<>("REGEX_PERMISSION", n -> n instanceof RegexPermissionNode, n -> (RegexPermissionNode) n);
|
||||
NodeType<RegexPermissionNode> REGEX_PERMISSION = new SimpleNodeType<>(
|
||||
"REGEX_PERMISSION",
|
||||
n -> n instanceof RegexPermissionNode,
|
||||
n -> (RegexPermissionNode) n
|
||||
);
|
||||
|
||||
/**
|
||||
* Node type for {@link InheritanceNode}.
|
||||
*/
|
||||
NodeType<InheritanceNode> INHERITANCE = new SimpleNodeType<>("INHERITANCE", n -> n instanceof InheritanceNode, n -> (InheritanceNode) n);
|
||||
NodeType<InheritanceNode> INHERITANCE = new SimpleNodeType<>(
|
||||
"INHERITANCE",
|
||||
n -> n instanceof InheritanceNode,
|
||||
n -> (InheritanceNode) n
|
||||
);
|
||||
|
||||
/**
|
||||
* Node type for {@link PrefixNode}.
|
||||
*/
|
||||
NodeType<PrefixNode> PREFIX = new SimpleNodeType<>("PREFIX", n -> n instanceof PrefixNode, n -> (PrefixNode) n);
|
||||
NodeType<PrefixNode> PREFIX = new SimpleNodeType<>(
|
||||
"PREFIX",
|
||||
n -> n instanceof PrefixNode,
|
||||
n -> (PrefixNode) n
|
||||
);
|
||||
|
||||
/**
|
||||
* Node type for {@link SuffixNode}.
|
||||
*/
|
||||
NodeType<SuffixNode> SUFFIX = new SimpleNodeType<>("SUFFIX", n -> n instanceof SuffixNode, n -> (SuffixNode) n);
|
||||
NodeType<SuffixNode> SUFFIX = new SimpleNodeType<>(
|
||||
"SUFFIX",
|
||||
n -> n instanceof SuffixNode,
|
||||
n -> (SuffixNode) n
|
||||
);
|
||||
|
||||
/**
|
||||
* Node type for {@link MetaNode}.
|
||||
*/
|
||||
NodeType<MetaNode> META = new SimpleNodeType<>("META", n -> n instanceof MetaNode, n -> (MetaNode) n);
|
||||
NodeType<MetaNode> META = new SimpleNodeType<>(
|
||||
"META",
|
||||
n -> n instanceof MetaNode,
|
||||
n -> (MetaNode) n
|
||||
);
|
||||
|
||||
/**
|
||||
* Node type for {@link WeightNode}.
|
||||
*/
|
||||
NodeType<WeightNode> WEIGHT = new SimpleNodeType<>("WEIGHT", n -> n instanceof WeightNode, n -> (WeightNode) n);
|
||||
NodeType<WeightNode> WEIGHT = new SimpleNodeType<>(
|
||||
"WEIGHT",
|
||||
n -> n instanceof WeightNode,
|
||||
n -> (WeightNode) n
|
||||
);
|
||||
|
||||
/**
|
||||
* Node type for {@link DisplayNameNode}.
|
||||
*/
|
||||
NodeType<DisplayNameNode> DISPLAY_NAME = new SimpleNodeType<>("DISPLAY_NAME", n -> n instanceof DisplayNameNode, n -> (DisplayNameNode) n);
|
||||
NodeType<DisplayNameNode> DISPLAY_NAME = new SimpleNodeType<>(
|
||||
"DISPLAY_NAME",
|
||||
n -> n instanceof DisplayNameNode,
|
||||
n -> (DisplayNameNode) n
|
||||
);
|
||||
|
||||
/**
|
||||
* Node type for {@link ChatMetaNode}.
|
||||
*
|
||||
* <p>This is an abstract type, and therefore will never
|
||||
* be returned from {@link Node#getType()}.</p>
|
||||
*/
|
||||
NodeType<ChatMetaNode<?, ?>> CHAT_META = new SimpleNodeType<>("CHAT_META", n -> n instanceof ChatMetaNode<?, ?>, n -> (ChatMetaNode<?, ?>) n);
|
||||
NodeType<ChatMetaNode<?, ?>> CHAT_META = new SimpleNodeType<>(
|
||||
"CHAT_META",
|
||||
n -> n instanceof ChatMetaNode<?, ?>,
|
||||
n -> (ChatMetaNode<?, ?>) n
|
||||
);
|
||||
|
||||
/**
|
||||
* Node type for {@link ChatMetaNode} or {@link MetaNode}.
|
||||
*
|
||||
* <p>This is an abstract type, and therefore will never
|
||||
* be returned from {@link Node#getType()}.</p>
|
||||
*/
|
||||
NodeType<Node> META_OR_CHAT_META = new SimpleNodeType<>("META_OR_CHAT_META", n -> META.matches(n) || CHAT_META.matches(n), Function.identity());
|
||||
NodeType<Node> META_OR_CHAT_META = new SimpleNodeType<>(
|
||||
"META_OR_CHAT_META",
|
||||
n -> META.matches(n) || CHAT_META.matches(n),
|
||||
Function.identity()
|
||||
);
|
||||
|
||||
/**
|
||||
* Gets a name for the node type.
|
||||
*
|
||||
* @return a name
|
||||
*/
|
||||
String name();
|
||||
@NonNull String name();
|
||||
|
||||
/**
|
||||
* Returns if the passed node matches the type
|
||||
@@ -108,7 +156,7 @@ public interface NodeType<T extends Node> {
|
||||
* @param node the node to test
|
||||
* @return true if the node has the same type
|
||||
*/
|
||||
boolean matches(Node node);
|
||||
boolean matches(@NonNull Node node);
|
||||
|
||||
/**
|
||||
* Casts the given {@link Node} to the type defined by the {@link NodeType}.
|
||||
@@ -120,7 +168,7 @@ public interface NodeType<T extends Node> {
|
||||
* @return the casted node
|
||||
* @throws IllegalArgumentException if the node to cast does not match the type
|
||||
*/
|
||||
T cast(Node node);
|
||||
@NonNull T cast(@NonNull Node node);
|
||||
|
||||
/**
|
||||
* Attempts to cast the given {@link Node} to the type defined by the
|
||||
@@ -132,7 +180,7 @@ public interface NodeType<T extends Node> {
|
||||
* @param node the node to cast
|
||||
* @return an optional, possibly containing a casted node
|
||||
*/
|
||||
default Optional<T> tryCast(Node node) {
|
||||
default @NonNull Optional<T> tryCast(@NonNull Node node) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
if (!matches(node)) {
|
||||
return Optional.empty();
|
||||
@@ -147,7 +195,7 @@ public interface NodeType<T extends Node> {
|
||||
*
|
||||
* @return a predicate for the {@link #matches(Node)} method.
|
||||
*/
|
||||
default Predicate<Node> predicate() {
|
||||
default @NonNull Predicate<Node> predicate() {
|
||||
return this::matches;
|
||||
}
|
||||
|
||||
@@ -159,7 +207,7 @@ public interface NodeType<T extends Node> {
|
||||
* @param and a predicate to AND with the result of the type match check
|
||||
* @return a matching predicate, ANDed with the given predicate parameter
|
||||
*/
|
||||
default Predicate<Node> predicate(Predicate<? super T> and) {
|
||||
default @NonNull Predicate<Node> predicate(@NonNull Predicate<? super T> and) {
|
||||
return node -> matches(node) && and.test(cast(node));
|
||||
}
|
||||
|
||||
|
@@ -25,6 +25,9 @@
|
||||
|
||||
package net.luckperms.api.node;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
@@ -41,18 +44,18 @@ final class SimpleNodeType<T extends Node> implements NodeType<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
public @NotNull String name() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Node node) {
|
||||
public boolean matches(@NonNull Node node) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
return this.matches.test(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T cast(Node node) {
|
||||
public @NotNull T cast(@NonNull Node node) {
|
||||
if (!matches(node)) {
|
||||
throw new IllegalArgumentException("Node " + node.getClass() + " does not match " + this.name);
|
||||
}
|
||||
|
@@ -134,7 +134,7 @@ public interface NodeMatcher<T extends Node> extends Predicate<Node> {
|
||||
* @param <T> the node type
|
||||
* @return the matcher
|
||||
*/
|
||||
static <T extends Node> @NonNull NodeMatcher<T> type(NodeType<? extends T> type) {
|
||||
static <T extends Node> @NonNull NodeMatcher<T> type(@NonNull NodeType<? extends T> type) {
|
||||
return LuckPermsProvider.get().getNodeMatcherFactory().type(type);
|
||||
}
|
||||
|
||||
|
@@ -117,6 +117,6 @@ public interface NodeMatcherFactory {
|
||||
* @param <T> the node type
|
||||
* @return the matcher
|
||||
*/
|
||||
<T extends Node> @NonNull NodeMatcher<T> type(NodeType<? extends T> type);
|
||||
<T extends Node> @NonNull NodeMatcher<T> type(@NonNull NodeType<? extends T> type);
|
||||
|
||||
}
|
||||
|
@@ -93,7 +93,7 @@ public enum DataQueryOrder implements Comparator<DataType> {
|
||||
* @param comparator the comparator
|
||||
* @return the ordered data types
|
||||
*/
|
||||
public static List<DataType> order(@NonNull Comparator<? super DataType> comparator) {
|
||||
public static @NonNull List<DataType> order(@NonNull Comparator<? super DataType> comparator) {
|
||||
int compare = comparator.compare(DataType.TRANSIENT, DataType.NORMAL);
|
||||
if (compare > 0) {
|
||||
// transient first
|
||||
|
@@ -32,6 +32,7 @@ import net.luckperms.api.query.OptionKey;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A function that generates a {@link DataQueryOrder} comparator for
|
||||
@@ -52,7 +53,8 @@ public interface DataQueryOrderFunction {
|
||||
* @return the data query order function
|
||||
* @since 5.2
|
||||
*/
|
||||
static DataQueryOrderFunction always(Comparator<DataType> comparator) {
|
||||
static @NonNull DataQueryOrderFunction always(@NonNull Comparator<DataType> comparator) {
|
||||
Objects.requireNonNull(comparator, "comparator");
|
||||
return id -> comparator;
|
||||
}
|
||||
|
||||
|
@@ -31,6 +31,7 @@ import net.luckperms.api.query.OptionKey;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
@@ -53,7 +54,8 @@ public interface DataTypeFilterFunction {
|
||||
* @param predicate the predicate
|
||||
* @return the data type filter function
|
||||
*/
|
||||
static DataTypeFilterFunction always(Predicate<DataType> predicate) {
|
||||
static @NonNull DataTypeFilterFunction always(@NonNull Predicate<DataType> predicate) {
|
||||
Objects.requireNonNull(predicate, "predicate");
|
||||
return id -> predicate;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user