private function recursivelyFindUseStatementsFor(
        EntityPackage $entity_package,
        PackageClass $package_class,
        array &$checked = []
    ) {
        $result              = [];
        $entity_package_name = $entity_package->getPackage()->getName();

        if (isset($checked[$entity_package_name])) {
            return $result;
        } else {
            $checked[$entity_package_name] = true;
        }

        foreach ($entity_package->getDependentPackages() as $name => $dependent_package) {
            /* @var $dependent_package EntityPackage */
            $use_statements = $this->recursivelyFindUseStatementsFor($dependent_package, $package_class, $checked);
            $result         = array_merge($result, $use_statements);
        }

        $this->writeIfDebug(
            '          - Scanning for traits in <info>' . $entity_package->getPackage()->getName() . '</info>.'
        );

        $contents = $this->content_provider->getPackageContent($entity_package);
        $traits   = $contents->getOptionalTraits($package_class->getShortName());

        foreach ($traits as $trait) {
            /* @var $trait \Hostnet\Component\EntityPlugin\OptionalPackageTrait */
            $requirement = $trait->getRequirement();
            if ($this->doesEntityExistInTree($entity_package, $requirement)) {
                $result[] = $trait;
                $this->writeIfDebug(
                    '            Injected <info>' . $trait->getName() .   '</info> from <info>' .
                    $entity_package->getPackage()->getName() .
                    '</info>.'
                );
            } else {
                $this->writeIfDebug(
                    '            Not injected <warn>' . $trait->getName() .   '</warn> from <info>' .
                    $entity_package->getPackage()->getName() . ' because ' . $requirement . ' is not found</info>.'
                );
            }
        }

        $package_class = $contents->getClassOrTrait($package_class->getShortName());
        if ($package_class) {
            $result[] = $package_class;
            $this->writeIfDebug(
                '            Found <info>' . $package_class->getName() . '</info> in <info>'
                . $entity_package->getPackage()->getName() . '</info>.'
            );
        }
        return $result;
    }