From 67a34ded80da054b60ae8e0f1905e060547684fe Mon Sep 17 00:00:00 2001 From: Revxrsal Date: Wed, 18 Sep 2024 01:06:20 +0300 Subject: [PATCH] ensure Switch is only used on booleans --- .../java/revxrsal/commands/node/parser/ParameterNodeImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/src/main/java/revxrsal/commands/node/parser/ParameterNodeImpl.java b/common/src/main/java/revxrsal/commands/node/parser/ParameterNodeImpl.java index 8bc6ca58..37552f83 100644 --- a/common/src/main/java/revxrsal/commands/node/parser/ParameterNodeImpl.java +++ b/common/src/main/java/revxrsal/commands/node/parser/ParameterNodeImpl.java @@ -42,6 +42,7 @@ import revxrsal.commands.stream.MutableStringStream; import revxrsal.commands.stream.MutableStringStreamImpl; import revxrsal.commands.stream.StringStream; +import revxrsal.commands.util.Classes; import java.util.Collection; @@ -75,6 +76,9 @@ public ParameterNodeImpl( this.isOptional = isOptional; this.switchAnn = parameter.getAnnotation(Switch.class); this.flagAnn = parameter.getAnnotation(Flag.class); + if (isSwitch() && Classes.wrap(type()) != Boolean.class) { + throw new IllegalArgumentException("@Switch can only be used on boolean types!"); + } if (isSwitch() && isFlag()) { throw new IllegalArgumentException("A parameter cannot have @Switch and @Flag at the same time!"); }