def describe()

in util-validator/src/main/scala/com/twitter/util/validation/DescriptorFactory.scala [115:188]


  def describe(method: Method): Option[MethodDescriptor] = buildMethodDescriptor(method)

  /**
   * Describe an [[Executable]] given an optional "mix-in" Class.
   *
   * @note the returned [[ExecutableDescriptor]] is NOT cached. It is up to the caller of this
   *       method to optimize any calls to this method.
   */
  def describeExecutable[T](
    executable: Executable,
    mixinClazz: Option[Class[_]]
  ): ExecutableDescriptor = {
    executable match {
      case constructor: Constructor[_] =>
        val desc = getJson4sConstructorDescriptor(constructor)
        val clazz = constructor.getDeclaringClass.asInstanceOf[Class[T]]
        val parameterAnnotations = mixinClazz match {
          case Some(mixin) =>
            val constructorAnnotationMap = getConstructorParams(clazz, desc)
            // augment with mixin class field annotations
            constructorAnnotationMap.map {
              case (name, params) =>
                try {
                  val method = mixin.getDeclaredMethod(name)
                  (
                    name,
                    params.copy(annotations =
                      params.annotations ++
                        method.getAnnotations.filter(isConstraintAnnotation))
                  )
                } catch {
                  case NonFatal(_) => // do nothing
                    (name, params)
                }
            }
          case _ =>
            getConstructorParams(clazz, desc)
        }
        buildConstructorDescriptor(
          constructor.getDeclaringClass,
          desc,
          Some(parameterAnnotations)
        )
      case method: Method =>
        MethodDescriptor(
          method = method,
          annotations = method.getDeclaredAnnotations.filter(isConstraintAnnotation),
          members = method.getParameters.map { parameter =>
            val name = parameter.getName
            // augment with mixin class field annotations
            val parameterAnnotations =
              mixinClazz match {
                case Some(mixin) =>
                  try {
                    val method = mixin.getDeclaredMethod(name)
                    parameter.getAnnotations ++
                      method.getAnnotations.filter(isConstraintAnnotation)
                  } catch {
                    case NonFatal(_) => // do nothing
                      parameter.getAnnotations
                  }
                case _ => // do nothing
                  parameter.getAnnotations
              }
            parameter.getName -> buildPropertyDescriptor(
              Reflector.scalaTypeOf(parameter.getParameterizedType),
              parameterAnnotations
            )
          }.toMap
        )
      case _ => // should not get here
        throw new IllegalArgumentException
    }
  }