public static function fromReflection(ReflectionClass $reflectionClass)
    {
        if ($reflectionClass->isTrait() !== true) {
            throw new InvalidArgumentException('The reflected class must be a trait.');
        }

        $tg = new static($reflectionClass->getShortName(), $reflectionClass->getNamespaceName());

        // Documentation.
        if ($reflectionClass->getReflectionDocComment()->isEmpty() !== true) {
            $tg->setDocumentation(DocCommentGenerator::fromReflection($reflectionClass->getReflectionDocComment()));
        }

        // Uses.
        foreach ($reflectionClass->getUses() as $use) {
            $use = UseTraitGenerator::fromReflection($use);
            if ($tg->getNamespace() !== null && strpos($use->getTraitClass(), $tg->getNamespace()) === 0) {
                $use->setTraitClass(substr($use->getTraitClass(), strlen($tg->getNamespace()) + 1));
            }

            $tg->addTraitUse($use);
        }

        // Properties.
        foreach ($reflectionClass->getOwnProperties() as $property) {
            $tg->addProperty(PropertyGenerator::fromReflection($property));
        }

        // Methods.
        foreach ($reflectionClass->getOwnMethods() as $method) {
            $tg->addMethod(MethodGenerator::fromReflection($method));
        }

        return $tg;
    }