Skip to content

Commit

Permalink
implement skipIndexing flag for Produces annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaktushose committed Dec 13, 2023
1 parent 557fe0f commit 4f94815
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,14 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface Produces {

/**
* Whether jda-commands should ignore this method at indexing during startup. Useful if you wish to register your
* dependency providers manually by calling
* {@link com.github.kaktushose.jda.commands.dependency.DependencyInjector#registerProvider(Object)
* DependencyInjector#registerProvider(Object)}
*
* @return Whether jda-commands should ignore this method, default {@code true}
*/
boolean skipIndexing() default false;

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public void index(@NotNull Class<?> clazz, @NotNull String... packages) {
Set<Method> methods = reflections.getMethodsAnnotatedWith(Produces.class);
for (Method method : methods) {
log.debug("Found producer {}", method.getName());

Produces produces = method.getAnnotation(Produces.class);
if (produces.skipIndexing()) {
log.debug("Method is marked as indexIgnore. Skipping Producer {}", method);
return;
}

if (method.getParameterTypes().length != 0) {
log.error("An error has occurred! Skipping Producer {}", method,
new IllegalArgumentException("Producer method must not have parameters!"));
Expand Down

0 comments on commit 4f94815

Please sign in to comment.