<commit_before>"""Support for generation for models based on pyecore."""
import os

from pyecore.ecore import EPackage
from pygen.jinja import JinjaTask, JinjaGenerator


class EcoreTask(JinjaTask):
    """
    Base class for Jinja based generation of Pyecore models.
    
    Attributes:
        element_type: Ecore type to be searched in model and to be iterated over.
    """

    element_type = None

    def filtered_elements(self, model):
        """Return iterator based on `element_type`."""
        return (e for e in model.eAllContents() if isinstance(e, self.element_type))

    @classmethod
    def folder_path_for_package(cls, package: EPackage):
        parent = package.eContainer()
        if parent:
            return os.path.join(cls.folder_path_for_package(parent), package.name)
        return package.name


class EcorePackageInitTask(EcoreTask):
    """Generation of package init file from Ecore model with Jinja2."""

    template_name = 'package.py'
    element_type = EPackage

    def relative_path_for_element(self, element: EPackage):
        folder = self.folder_path_for_package(element)
        path = os.path.join(folder, '__init__.py')
        return path


class EcorePackageModuleTask(EcoreTask):
    """Generation of package model from Ecore model with Jinja2."""

    template_name = 'module.py'
    element_type = EPackage

    def relative_path_for_element(self, element: EPackage):
        folder = self.folder_path_for_package(element)
        path = os.path.join(folder, '{}.py'.format(element.name))
        return path


class EcoreGenerator(JinjaGenerator):
    """Generation of static ecore model classes."""

    tasks = [
        EcorePackageInitTask,
        EcorePackageModuleTask,
    ]

    templates_path = 'templates'
<commit_msg>moved bit more to base class<commit_after>"""Support for generation for models based on pyecore."""
import os

from pyecore.ecore import EPackage
from pygen.jinja import JinjaTask, JinjaGenerator


class EcoreTask(JinjaTask):
    """
    Base class for Jinja based generation of Pyecore models.
    
    Attributes:
        element_type: Ecore type to be searched in model and to be iterated over.
    """

    element_type = None

    def filtered_elements(self, model):
        """Return iterator based on `element_type`."""
        return (e for e in model.eAllContents() if isinstance(e, self.element_type))

    @classmethod
    def folder_path_for_package(cls, package: EPackage):
        """Returns path to folder holding generated artifact for given element."""
        parent = package.eContainer()
        if parent:
            return os.path.join(cls.folder_path_for_package(parent), package.name)
        return package.name

    @staticmethod
    def filename_for_element(package: EPackage):
        """Returns generated file name."""
        raise NotImplementedError

    def relative_path_for_element(self, element: EPackage):
        path = os.path.join(self.folder_path_for_package(element),
                            self.filename_for_element(element))
        return path


class EcorePackageInitTask(EcoreTask):
    """Generation of package init file from Ecore model with Jinja2."""

    template_name = 'package.py'
    element_type = EPackage

    @staticmethod
    def filename_for_element(package: EPackage):
        return '__init__.py'


class EcorePackageModuleTask(EcoreTask):
    """Generation of package model from Ecore model with Jinja2."""

    template_name = 'module.py'
    element_type = EPackage

    @staticmethod
    def filename_for_element(package: EPackage):
        return '{}.py'.format(package.name)


class EcoreGenerator(JinjaGenerator):
    """Generation of static ecore model classes."""

    tasks = [
        EcorePackageInitTask,
        EcorePackageModuleTask,
    ]

    templates_path = 'templates'

{'fraction_non_alphanumeric': 0.08738621586475943, 'fraction_numerical': 0.0010403120936280884, 'mean_word_length': 3.2263736263736265, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7007491', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1059, 'n_words': 310}