Exemplo n.º 1
0
    def registerSourceDependency(cls, sourceDependency):
        # type: (SourceFileDependency) -> None
        """
        Register a source file dependency. Register
        before the source and target if not done before.
        Also register the model dependency if needed.
        """
        source = sourceDependency.source
        target = sourceDependency.target

        # Element registration
        cls.registerSource(source)
        cls.registerSource(target)
        from modelscripts.megamodels import Megamodel
        Megamodel.registerModel(source.model)
        Megamodel.registerModel(target.model)

        cls._allSourceFileDependencies.append(sourceDependency)

        # BySource
        if source not in cls._sourceFileDependenciesBySource:
            cls._sourceFileDependenciesBySource[source] = []
        cls._sourceFileDependenciesBySource[source].append(sourceDependency)

        # ByTarget
        if target not in cls._sourceFileDependenciesByTarget:
            cls._sourceFileDependenciesByTarget[target] = []
        cls._sourceFileDependenciesByTarget[target].append(sourceDependency)
Exemplo n.º 2
0
    def registerSource(cls, source):
        # type: (ModelSourceFile) -> None
        """
        Register a source. Register the model as well.
        """

        if source.path not in cls._sourceFileByPath:
            cls._allSourceFiles.append(source)

            # ByPath
            metamodel = source.metamodel
            cls._sourceFileByPath[source.path] = source

            # ByMetamodel
            if metamodel not in cls._sourceFilesByMetamodel:
                cls._sourceFilesByMetamodel[metamodel] = []
            if source not in cls._sourceFilesByMetamodel[metamodel]:
                cls._sourceFilesByMetamodel[metamodel].append(source)

            # Register model
            if source.model is not None:
                from modelscripts.megamodels import Megamodel
                Megamodel.registerModel(source.model)
Exemplo n.º 3
0
    def __init__(
            self,
            fileName,
            realFileName=None,
            prequelFileName=None,
            preErrorMessages=(),  #TODO: check the type
            readFileLater=False,
            fillImportBoxLater=False,
            parseFileLater=False,
            noSymbolChecking=False,
            allowedFeatures=(),
            recognizeUSEOCLNativeModelDefinition=False):
        #type: (Text, Optional[Text], Optional[Text], List[Any], bool, bool, bool, bool, List[Text], bool) -> None
        """
        An empty model is created automatically and it
        is associated with this source file.
        This empty model is created according to
        the metamodel specified by the property 'metamodel'.

        An importBox is also created.
        In order to do this the content of the source file is
        parsed looking the declaration of the model name as
        well as import statements. All this information is
        stored in the importBox.

        If `fillImportBoxLater` is True then this importBox
        is left empty for the moment. The client have
        to call explicitly parseToFillImportBox() later.

        The parameter recognizeUSEOCLNativeModelDefinition
        is a patch to allow parsing regular .use file.

        Args:
            fileName:
                The logical name of the file.
                This is not necessarily the file parsed.
            realFileName:
                The real file to be read. If file reading
                has to be postponed, then the parameter
                should be set to None. The doRealFileRead()
                will set the filed realFileName.
            preErrorMessages:
                The errors in this list will be added.
            readFileLater:
                If False the file is read directly.
                Otherwise the method doReadFile() must be called!
            fillImportBoxLater:
                If False, the file read is parsed to find
                megamodel statements (e.g. import) and to
                fill the import box.
                If not parseToFillImportBox() must be called
                after reading the file, and this in order to
                get the imported model.
            allowedFeatures
                The list of features allowed. This depends on
                each parser. This allows to remove the use of
                some features during parsing. For instance to
                forbid the use of association classes.

        """

        # if readFileLater or fillImportBoxLater or parseFileLater:
        #     assert finalizeLater

        # Create an empty model
        # Not to be moved after super
        # This should be done in all case so that
        # the model attribute always exist even if there
        # are some error in reading the file
        self.model = self.emptyModel()  # type: Model

        # Call the super class, read the file or not
        try:
            # This can raise an exception for instance if
            # there is a problem reading the file
            super(ModelSourceFile,
                  self).__init__(fileName=fileName,
                                 realFileName=realFileName,
                                 prequelFileName=prequelFileName,
                                 preErrorMessages=preErrorMessages,
                                 doNotReadFiles=readFileLater,
                                 allowedFeatures=allowedFeatures)
        except FatalError:
            pass  # an error as already been registered

        from modelscripts.megamodels import Megamodel
        Megamodel.registerSource(self)
        Megamodel.registerModel(self.model)

        # Backward link
        self.model.source = self

        # Link issue box
        self.model._issueBox.addParent(self._issueBox)

        # Source to ModelElement Mapping
        self._modelMapping = _ModelSourceMapping()

        # Create first an empty ImportBox.
        self.importBox = ImportBox(self)

        # Then fill it by reading megamodel statements,
        # unless specified.
        try:
            if not fillImportBoxLater:
                parseToFillImportBox(self, noSymbolChecking,
                                     recognizeUSEOCLNativeModelDefinition)

            if not parseFileLater:
                self.parseToFillModel()
                self.finalize()

        except FatalError:
            pass  # nothing to do, the issue has been registered