Skip to content

Commit

Permalink
ensure Switch is only used on booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
Revxrsal committed Sep 17, 2024
1 parent 1820e00 commit 67a34de
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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!");
}
Expand Down

0 comments on commit 67a34de

Please sign in to comment.