Skip to content

Commit

Permalink
add reflection wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Goldmensch committed Dec 25, 2024
1 parent fe4b191 commit 477597c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.github.kaktushose.jda.commands.definitions.description;

import java.lang.annotation.Annotation;
import java.util.Collection;

public record ClassDescription(
Class<?> clazz,
String name,
Collection<Annotation> annotations,
Collection<MethodDescription> methods
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.github.kaktushose.jda.commands.definitions.description;

import java.util.function.Function;

public interface Descriptor extends Function<Class<?>, ClassDescription> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.kaktushose.jda.commands.definitions.description;

import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.SequencedCollection;
import java.util.function.BiFunction;

public record MethodDescription(
Class<?> returnType,
String name,
Collection<ParameterDescription> parameters,
Collection<Annotation> annotations,
BiFunction<Object, SequencedCollection<Object>, Object> invoker
) {
public Object invoke(Object instance, SequencedCollection<Object> arguments) {
return invoker.apply(instance, arguments);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.github.kaktushose.jda.commands.definitions.description;

import java.lang.annotation.Annotation;
import java.util.Collection;

public record ParameterDescription(
Class<?> type,
Collection<Annotation> annotations
) {
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.github.kaktushose.jda.commands.definitions.features;

import com.github.kaktushose.jda.commands.definitions.description.MethodDescription;
import com.github.kaktushose.jda.commands.definitions.interactions.Interaction;
import com.github.kaktushose.jda.commands.dispatching.context.InvocationContext;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Method;
import java.util.SequencedCollection;

public sealed interface Invokeable permits Replyable, Interaction {
Expand All @@ -16,11 +16,11 @@ public sealed interface Invokeable permits Replyable, Interaction {
default void invoke(@NotNull Object instance, @NotNull InvocationContext<?> invocation) throws Throwable {
SequencedCollection<Object> arguments = invocation.arguments();

method().invoke(instance, arguments.toArray());
method().invoke(instance, arguments);
}

@NotNull
Method method();
MethodDescription method();

@NotNull
SequencedCollection<Class<?>> methodSignature();
Expand Down

0 comments on commit 477597c

Please sign in to comment.