wouterdoeland
08/07/2017, 6:09 PMfun getParameters(command: KClass<out SimpleCommand>): List<Pair<KParameter, Argument>> {
val constructor = command.primaryConstructor ?: throw IllegalArgumentException("Command has no primary constructor")
return constructor.parameters.map { it to (it.findAnnotation<Argument>() ?: throw MissingAnnotationException("Found parameter without Argument annotation", Argument::class.qualifiedName)) }.apply {
// check if there are any non-string parameters
forEach {
if(it.second.optional && !it.first.isOptional)
throw IllegalArgumentException("Found parameter that is not optional, but their annotation says it is (add a default value to the parameter '${it.second.name}').")
if(it.first.type != String::class)
throw IllegalArgumentException("Found parameter without String type.")
}
}
}