Skip to content

Commit 4fb6ff2

Browse files
committed
check annotation retention in more places
1 parent d272003 commit 4fb6ff2

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

common/src/main/java/revxrsal/commands/Lamp.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import java.util.function.Predicate;
6464
import java.util.function.Supplier;
6565

66+
import static revxrsal.commands.util.Classes.checkRetention;
6667
import static revxrsal.commands.util.Classes.wrap;
6768
import static revxrsal.commands.util.Preconditions.notNull;
6869

@@ -744,6 +745,7 @@ public Builder() {
744745
public <T extends Annotation> Builder<A> annotationReplacer(@NotNull Class<T> annotationType, @NotNull AnnotationReplacer<T> replacer) {
745746
notNull(annotationType, "annotation type");
746747
notNull(replacer, "annotation replacer");
748+
checkRetention(annotationType);
747749
annotationReplacers.computeIfAbsent(annotationType, k -> new HashSet<>()).add(replacer);
748750
return this;
749751
}

common/src/main/java/revxrsal/commands/autocomplete/SuggestionProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import java.util.List;
3838
import java.util.function.Function;
3939

40+
import static revxrsal.commands.util.Classes.checkRetention;
41+
4042
/**
4143
* An interface that supplies completions for the user depending on their input.
4244
*/
@@ -154,6 +156,7 @@ static <A extends CommandActor> Factory<? super A> forTypeAndSubclasses(@NotNull
154156
* @return The newly created {@link Factory}.
155157
*/
156158
static @NotNull <A extends CommandActor, L extends Annotation> SuggestionProvider.@NotNull Factory<? super A> forAnnotation(@NotNull Class<L> annotationType, @NotNull Function<L, SuggestionProvider<A>> provider) {
159+
checkRetention(annotationType);
157160
return (type, annotations, lamp) -> {
158161
L annotation = annotations.get(annotationType);
159162
if (annotation != null)

common/src/main/java/revxrsal/commands/command/CommandPermission.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import java.lang.annotation.Annotation;
3232
import java.util.function.Function;
3333

34+
import static revxrsal.commands.util.Classes.checkRetention;
35+
3436
/**
3537
* Represents a permission that is required in order to execute a
3638
* command.
@@ -82,6 +84,7 @@ static <A extends CommandActor, T extends Annotation> Factory<A> forAnnotation(
8284
@NotNull Class<T> annotationType,
8385
@NotNull Function<T, @Nullable CommandPermission<A>> permissionCreator
8486
) {
87+
checkRetention(annotationType);
8588
return (annotations, lamp) -> {
8689
T annotation = annotations.get(annotationType);
8790
if (annotation != null)

common/src/main/java/revxrsal/commands/util/Classes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ private static void addPrimitive(
262262
*/
263263
public static void checkRetention(@NotNull Class<? extends Annotation> type) {
264264
if (!type.isAnnotationPresent(Retention.class) || type.getAnnotation(Retention.class).value() != RetentionPolicy.RUNTIME)
265-
throw new IllegalArgumentException("Tried to check for annotation @" + type.getName() + ", but it does not have @Retention(RetentionPolicy.RUNTIME)!");
265+
throw new IllegalArgumentException("Tried to check for annotation @" + type.getName() + ", but it does not have @Retention(RetentionPolicy.RUNTIME)! " +
266+
"As such, it may be present but we cannot see it.");
266267
}
267268
}

0 commit comments

Comments
 (0)