Search in sources :

Example 1 with ArgumentContribution

use of net.robinfriedli.aiode.entities.xml.ArgumentContribution in project aiode by robinfriedli.

the class InitialiseCommandContributionsTask method perform.

@Override
public void perform(@Nullable JDA shard) throws Exception {
    Context commandContributionContext = commandManager.getCommandContributionContext();
    @SuppressWarnings("rawtypes") List<CommandHierarchyNode> commandHierarchyNodes = commandContributionContext.getInstancesOf(CommandHierarchyNode.class);
    for (@SuppressWarnings("unchecked") CommandHierarchyNode<ArgumentContributionDelegate> commandHierarchyNode : commandHierarchyNodes) {
        Map<String, ArgumentContributionDelegate> argumentContributions = commandHierarchyNode.getArguments();
        for (ArgumentContributionDelegate argumentContributionDelegate : argumentContributions.values()) {
            ArgumentContribution argumentContribution = argumentContributionDelegate.unwrapArgumentContribution();
            List<XmlElement> excludedArguments = argumentContribution.getExcludedArguments();
            List<XmlElement> requiredArguments = argumentContribution.getRequiredArguments();
            validateReferencedArguments(commandHierarchyNode, argumentContribution, excludedArguments);
            validateReferencedArguments(commandHierarchyNode, argumentContribution, requiredArguments);
        }
    }
}
Also used : Context(net.robinfriedli.jxp.persist.Context) CommandHierarchyNode(net.robinfriedli.aiode.entities.xml.CommandHierarchyNode) XmlElement(net.robinfriedli.jxp.api.XmlElement) ArgumentContributionDelegate(net.robinfriedli.aiode.command.argument.ArgumentContributionDelegate) ArgumentContribution(net.robinfriedli.aiode.entities.xml.ArgumentContribution)

Example 2 with ArgumentContribution

use of net.robinfriedli.aiode.entities.xml.ArgumentContribution in project aiode by robinfriedli.

the class InitialiseCommandContributionsTask method validateReferencedArguments.

private void validateReferencedArguments(CommandHierarchyNode<?> commandHierarchyNode, ArgumentContribution argumentContribution, Collection<XmlElement> arguments) {
    for (XmlElement argument : arguments) {
        String argumentIdentifier = argument.getAttribute("argument").getValue();
        ArgumentContribution referencedArgument = commandHierarchyNode.getArgument(argumentIdentifier).unwrapArgumentContribution();
        if (referencedArgument == null) {
            throw new IllegalStateException(String.format("Invalid command configuration for node '%s'. Cannot find referenced argument identifier '%s' required for element %s on argument %s.", commandHierarchyNode.getId(), argumentIdentifier, argument, argumentContribution));
        }
    }
}
Also used : XmlElement(net.robinfriedli.jxp.api.XmlElement) ArgumentContribution(net.robinfriedli.aiode.entities.xml.ArgumentContribution)

Aggregations

ArgumentContribution (net.robinfriedli.aiode.entities.xml.ArgumentContribution)2 XmlElement (net.robinfriedli.jxp.api.XmlElement)2 ArgumentContributionDelegate (net.robinfriedli.aiode.command.argument.ArgumentContributionDelegate)1 CommandHierarchyNode (net.robinfriedli.aiode.entities.xml.CommandHierarchyNode)1 Context (net.robinfriedli.jxp.persist.Context)1