<commit_before>/*
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package uk.co.thinkofdeath.command;

import uk.co.thinkofdeath.command.parsers.ArgumentParser;
import uk.co.thinkofdeath.command.parsers.IntegerParser;
import uk.co.thinkofdeath.command.parsers.ParserException;
import uk.co.thinkofdeath.command.parsers.StringParser;
import uk.co.thinkofdeath.command.validators.ArgumentValidator;
import uk.co.thinkofdeath.command.validators.TypeHandler;

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * A CommandManager handles registration and parsing
 * of commands as well as provided methods for completing
 * commands.
 *
 * <p>
 *
 * This works using reflection and a series of annotations
 * to define commands. The {@link uk.co.thinkofdeath.command.Command}
 * annotation is used to define the syntax of command, words
 * are treated as sub-commands while `?` are markers for
 * where user controlled arguments will go. For example:
 *
 * <pre><code>
 * &#064;Command("tp ?")
 * public void teleport(Player sender, Player target) {
 *     // Code to teleport here
 * }</code></pre>
 *
 * For more information on the {@link uk.co.thinkofdeath.command.Command}
 * annotation's handling see: {@link #register(CommandHandler)}
 *
 * <p>
 *
 * The command system supports overloading commands so that
 * different argument/caller types will call different methods
 * for the same command syntax. This also allow for you to
 * require a specific caller for certain commands For example:
 *
 * <pre><code>
 * &#064;Command("tp ?")
 * public void teleport(Player sender, Player target) {
 *     // Only a Player (or sub-class of) can call this
 * }
 *
 * &#064;Command("tp ? ?")
 * public void teleport(ConsoleCommandSender sender, Player a, Player b) {
 *     // If the console calls `/tp a b`
 * }
 *
 * &#064;Command("tp ? ?")
 * public void teleport(Player sender, Player a, Player b) {
 *     // If the player calls `/tp a b`
 * }
 *
 * &#064;Command("tp ? ?")
 * public void teleport(CommandSender sender, Player a, World target) {
 *     // If the CommandSender calls `/tp a world` but with
 *     // a world instead of a player
 * }
 * </code></pre>
 *
 * Argument validator annotations can be used to place limits on
 * certain arguments. {@link uk.co.thinkofdeath.command.validators.MaxLength}
 * for example applies to String arguments and will check if
 * the provided argument is smaller or equal to its argument and
 * if its not the command will fail. This can also be used to
 * allow the same argument to go to different methods based on
 * its value. For example:
 *
 * <pre><code>
 * &#064;Command("player set nick ?")
 * public void setNick(Player player, @MaxLength(16) String newNick) {
 *     // If newNick is more than 16 characters this will not
 *     // be called
 * }
 *
 * &#064;Command("do something ?")
 * public void doSomethingSmall(CommandSender sender, @Range(min = 0, max = 5) int something) {
 *     // If something is between (inclusive) 0 and 5
 * }
 *
 * &#064;Command("do something ?")
 * public void doSomethingMid(CommandSender sender, @Range(min = 6, max = 15) int something) {
 *     // If something is between (inclusive) 6 and 15
 * }
 *
 * &#064;Command("do something ?")
 * public void doSomethingLarge(CommandSender sender, @Range(min = 16) int something) {
 *     // If something is greater or equal to 16
 * }
 * </code></pre>
 */<commit_msg>Document the validator change<commit_after>/*
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package uk.co.thinkofdeath.command;

import uk.co.thinkofdeath.command.parsers.ArgumentParser;
import uk.co.thinkofdeath.command.parsers.IntegerParser;
import uk.co.thinkofdeath.command.parsers.ParserException;
import uk.co.thinkofdeath.command.parsers.StringParser;
import uk.co.thinkofdeath.command.validators.ArgumentValidator;
import uk.co.thinkofdeath.command.validators.TypeHandler;

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * A CommandManager handles registration and parsing
 * of commands as well as provided methods for completing
 * commands.
 *
 * <p>
 *
 * This works using reflection and a series of annotations
 * to define commands. The {@link uk.co.thinkofdeath.command.Command}
 * annotation is used to define the syntax of command, words
 * are treated as sub-commands while `?` are markers for
 * where user controlled arguments will go. For example:
 *
 * <pre><code>
 * &#064;Command("tp ?")
 * public void teleport(Player sender, Player target) {
 *     // Code to teleport here
 * }</code></pre>
 *
 * For more information on the {@link uk.co.thinkofdeath.command.Command}
 * annotation's handling see: {@link #register(CommandHandler)}
 *
 * <p>
 *
 * The command system supports overloading commands so that
 * different argument/caller types will call different methods
 * for the same command syntax. This also allow for you to
 * require a specific caller for certain commands For example:
 *
 * <pre><code>
 * &#064;Command("tp ?")
 * public void teleport(Player sender, Player target) {
 *     // Only a Player (or sub-class of) can call this
 * }
 *
 * &#064;Command("tp ? ?")
 * public void teleport(ConsoleCommandSender sender, Player a, Player b) {
 *     // If the console calls `/tp a b`
 * }
 *
 * &#064;Command("tp ? ?")
 * public void teleport(Player sender, Player a, Player b) {
 *     // If the player calls `/tp a b`
 * }
 *
 * &#064;Command("tp ? ?")
 * public void teleport(CommandSender sender, Player a, World target) {
 *     // If the CommandSender calls `/tp a world` but with
 *     // a world instead of a player
 * }
 * </code></pre>
 *
 * Argument validator annotations can be used to place limits on
 * certain arguments. {@link uk.co.thinkofdeath.command.validators.MaxLength}
 * for example applies to String arguments and will check if
 * the provided argument is smaller or equal to its argument and
 * if its not the command will fail. This can also be used to
 * allow the same argument to go to different methods based on
 * its value. For example:
 *
 * <pre><code>
 * &#064;Command("player set nick ?")
 * public void setNick(Player player, @MaxLength(16) String newNick) {
 *     // If newNick is more than 16 characters this will not
 *     // be called
 * }
 *
 * &#064;Command("do something ?")
 * public void doSomethingSmall(CommandSender sender, @Range(min = 0, max = 5) int something) {
 *     // If something is between (inclusive) 0 and 5
 * }
 *
 * &#064;Command("do something ?")
 * public void doSomethingMid(CommandSender sender, @Range(min = 6, max = 15) int something) {
 *     // If something is between (inclusive) 6 and 15
 * }
 *
 * &#064;Command("do something ?")
 * public void doSomethingLarge(CommandSender sender, @Range(min = 16) int something) {
 *     // If something is greater or equal to 16
 * }
 * </code></pre>
 *
 * Argument validators placed on the method will apply to the first argument
 */
{'fraction_non_alphanumeric': 0.11002386634844868, 'fraction_numerical': 0.012649164677804296, 'mean_word_length': 3.8111366245694605, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4626883', 'n_tokens_mistral': 2470, 'n_tokens_neox': 2329, 'n_words': 911}