add Logging to Parsers
This commit is contained in:
parent
b764972eba
commit
7249c99b69
@ -3,13 +3,19 @@ package net.tomatentum.marinara.parser;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import net.tomatentum.marinara.interaction.annotation.Button;
|
import net.tomatentum.marinara.interaction.annotation.Button;
|
||||||
|
import net.tomatentum.marinara.util.LoggerUtil;
|
||||||
|
import net.tomatentum.marinara.util.ReflectionUtil;
|
||||||
|
|
||||||
public class ButtonParser implements AnnotationParser {
|
public class ButtonParser implements AnnotationParser {
|
||||||
|
|
||||||
private Method method;
|
private Method method;
|
||||||
private Consumer<String> consumer;
|
private Consumer<String> consumer;
|
||||||
|
|
||||||
|
private Logger logger = LoggerUtil.getLogger(getClass());
|
||||||
|
|
||||||
public ButtonParser(Method method, Consumer<String> consumer) {
|
public ButtonParser(Method method, Consumer<String> consumer) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.consumer = consumer;
|
this.consumer = consumer;
|
||||||
@ -18,6 +24,7 @@ public class ButtonParser implements AnnotationParser {
|
|||||||
@Override
|
@Override
|
||||||
public void parse() {
|
public void parse() {
|
||||||
Button button = getMethod().getAnnotation(Button.class);
|
Button button = getMethod().getAnnotation(Button.class);
|
||||||
|
logger.trace("Parsed Button annotation {} for method {}", button.toString(), ReflectionUtil.getFullMethodName(method));
|
||||||
this.consumer.accept(button.value());
|
this.consumer.accept(button.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,9 +6,13 @@ import java.util.Arrays;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import net.tomatentum.marinara.checks.AppliedCheck;
|
import net.tomatentum.marinara.checks.AppliedCheck;
|
||||||
import net.tomatentum.marinara.checks.InteractionCheck;
|
import net.tomatentum.marinara.checks.InteractionCheck;
|
||||||
import net.tomatentum.marinara.registry.InteractionCheckRegistry;
|
import net.tomatentum.marinara.registry.InteractionCheckRegistry;
|
||||||
|
import net.tomatentum.marinara.util.LoggerUtil;
|
||||||
|
import net.tomatentum.marinara.util.ReflectionUtil;
|
||||||
|
|
||||||
public class InteractionCheckParser implements AnnotationParser {
|
public class InteractionCheckParser implements AnnotationParser {
|
||||||
|
|
||||||
@ -16,6 +20,8 @@ public class InteractionCheckParser implements AnnotationParser {
|
|||||||
private Method method;
|
private Method method;
|
||||||
private Consumer<AppliedCheck> consumer;
|
private Consumer<AppliedCheck> consumer;
|
||||||
|
|
||||||
|
private Logger logger = LoggerUtil.getLogger(getClass());
|
||||||
|
|
||||||
public InteractionCheckParser(Method method, Consumer<AppliedCheck> consumer, InteractionCheckRegistry checkRegistry) {
|
public InteractionCheckParser(Method method, Consumer<AppliedCheck> consumer, InteractionCheckRegistry checkRegistry) {
|
||||||
this.checkRegistry = checkRegistry;
|
this.checkRegistry = checkRegistry;
|
||||||
this.method = method;
|
this.method = method;
|
||||||
@ -30,8 +36,11 @@ public class InteractionCheckParser implements AnnotationParser {
|
|||||||
|
|
||||||
private void convertAnnotation(Annotation annotation) {
|
private void convertAnnotation(Annotation annotation) {
|
||||||
Optional<InteractionCheck<?>> check = this.checkRegistry.getCheckFromAnnotation(annotation.annotationType());
|
Optional<InteractionCheck<?>> check = this.checkRegistry.getCheckFromAnnotation(annotation.annotationType());
|
||||||
if (check.isPresent())
|
if (check.isPresent()) {
|
||||||
consumer.accept(new AppliedCheck(check.get(), annotation));
|
AppliedCheck appliedCheck = new AppliedCheck(check.get(), annotation);
|
||||||
|
logger.trace("Parsed InteractionCheck {} for annotation {} for method {}", check.getClass().getName(), annotation.toString(), ReflectionUtil.getFullMethodName(method));
|
||||||
|
consumer.accept(appliedCheck);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,10 +3,13 @@ package net.tomatentum.marinara.parser;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition;
|
import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition;
|
||||||
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
|
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommand;
|
||||||
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
|
import net.tomatentum.marinara.interaction.commands.annotation.SubCommand;
|
||||||
import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup;
|
import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup;
|
||||||
|
import net.tomatentum.marinara.util.LoggerUtil;
|
||||||
import net.tomatentum.marinara.util.ReflectionUtil;
|
import net.tomatentum.marinara.util.ReflectionUtil;
|
||||||
|
|
||||||
public class SlashCommandParser implements AnnotationParser {
|
public class SlashCommandParser implements AnnotationParser {
|
||||||
@ -14,6 +17,8 @@ public class SlashCommandParser implements AnnotationParser {
|
|||||||
private Method method;
|
private Method method;
|
||||||
private Consumer<ExecutableSlashCommandDefinition> consumer;
|
private Consumer<ExecutableSlashCommandDefinition> consumer;
|
||||||
|
|
||||||
|
private Logger logger = LoggerUtil.getLogger(getClass());
|
||||||
|
|
||||||
public SlashCommandParser(Method method, Consumer<ExecutableSlashCommandDefinition> consumer) {
|
public SlashCommandParser(Method method, Consumer<ExecutableSlashCommandDefinition> consumer) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.consumer = consumer;
|
this.consumer = consumer;
|
||||||
@ -37,6 +42,9 @@ public class SlashCommandParser implements AnnotationParser {
|
|||||||
builder.setSubCommand(subCmd);
|
builder.setSubCommand(subCmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExecutableSlashCommandDefinition def = builder.build();
|
||||||
|
|
||||||
|
logger.trace("Parsed using SlashCommandParser for method {} with the result:\n{}", ReflectionUtil.getFullMethodName(method), def.toString());
|
||||||
consumer.accept(builder.build());
|
consumer.accept(builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user