add geantyref to fix and simplify generic Type parsing.
Also switch to java 23 to avoid conflicts and issues.
This commit is contained in:
parent
659218682e
commit
6eb7fb723f
lib
wrapper/javacord
@ -21,13 +21,13 @@ dependencies {
|
||||
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
implementation(libs.log4j)
|
||||
|
||||
implementation(libs.geantyref)
|
||||
}
|
||||
|
||||
// Apply a specific Java toolchain to ease working on different environments.
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(21)
|
||||
languageVersion = JavaLanguageVersion.of(23)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
package net.tomatentum.marinara.registry;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import io.leangen.geantyref.GenericTypeReflector;
|
||||
import net.tomatentum.marinara.checks.InteractionCheck;
|
||||
|
||||
public class InteractionCheckRegistry {
|
||||
@ -20,10 +21,11 @@ public class InteractionCheckRegistry {
|
||||
checks.add(check);
|
||||
}
|
||||
|
||||
public Optional<InteractionCheck<?>> getCheckFromAnnotation(Class<? extends Annotation> annotation) {
|
||||
public Optional<InteractionCheck<?>> getCheckFromAnnotation(Type annotation) {
|
||||
for (InteractionCheck<?> interactionCheck : checks) {
|
||||
TypeVariable<?> type = interactionCheck.getClass().getTypeParameters()[0];
|
||||
if (type.getClass().equals(annotation.getClass()))
|
||||
ParameterizedType type = (ParameterizedType) GenericTypeReflector.getExactSuperType(interactionCheck.getClass(), InteractionCheck.class);
|
||||
Type typeParam = type.getActualTypeArguments()[0];
|
||||
if (typeParam.equals(annotation))
|
||||
return Optional.of(interactionCheck);
|
||||
}
|
||||
return Optional.empty();
|
||||
|
@ -29,7 +29,7 @@ dependencies {
|
||||
// Apply a specific Java toolchain to ease working on different environments.
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(21)
|
||||
languageVersion = JavaLanguageVersion.of(23)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user