{"action":"created","issue":{"url":"https://api.github.com/repos/igordejanovic/textX/issues/83","repository_url":"https://api.github.com/repos/igordejanovic/textX","labels_url":"https://api.github.com/repos/igordejanovic/textX/issues/83/labels{/name}","comments_url":"https://api.github.com/repos/igordejanovic/textX/issues/83/comments","events_url":"https://api.github.com/repos/igordejanovic/textX/issues/83/events","html_url":"https://github.com/igordejanovic/textX/issues/83","id":354734235,"node_id":"MDU6SXNzdWUzNTQ3MzQyMzU=","number":83,"title":"How to ensure imported objects are resolved?","user":{"login":"fgro93","id":17844615,"node_id":"MDQ6VXNlcjE3ODQ0NjE1","avatar_url":"https://avatars1.githubusercontent.com/u/17844615?v=4","gravatar_id":"","url":"https://api.github.com/users/fgro93","html_url":"https://github.com/fgro93","followers_url":"https://api.github.com/users/fgro93/followers","following_url":"https://api.github.com/users/fgro93/following{/other_user}","gists_url":"https://api.github.com/users/fgro93/gists{/gist_id}","starred_url":"https://api.github.com/users/fgro93/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fgro93/subscriptions","organizations_url":"https://api.github.com/users/fgro93/orgs","repos_url":"https://api.github.com/users/fgro93/repos","events_url":"https://api.github.com/users/fgro93/events{/privacy}","received_events_url":"https://api.github.com/users/fgro93/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-08-28T13:34:58Z","updated_at":"2018-08-28T20:15:39Z","closed_at":null,"author_association":"NONE","body":"Files/Code can be found here: https://github.com/fgro93/textX-Problem\r\n\r\nI have the following multi meta-model:\r\n`FModel.tx`\r\n```\r\nimport IModel\r\n\r\nFModel:\r\n(imports+=Import)*\r\n(components+=Component)*;\r\n\r\nImport:\r\n\t'import' importURI=STRING;\r\n\r\nConnector: 'connect' prototype=[Prototype]'.'port=[Port];\r\n\r\nPrototype:\r\n\t'contains' component=[Component] ('as' name=ID)?;\r\n\r\nComponent: \r\n\t'component' name=ID\r\n\t('{'(\r\n             prototypes+=Prototype |\r\n             ports+=Port |\r\n             connectors+=Connector\r\n         )*'}')?;\r\n\r\nPort:\r\n\t'requires' interface=[Interface];\r\n```\r\n`IModel.tx`\r\n```\r\nIModel: (interfaces+=Interface)*;\r\nInterface: name = ID;\r\n```\r\n\r\nAnd three model files:\r\n`main.fmodel`\r\n```\r\nimport \"hasPort.fmodel\"\r\n\r\ncomponent ConnectPort {\r\n\tcontains HasPort\r\n\t\r\n\tconnect HasPort.Port1\r\n}\r\n```\r\n`hasPort.fmodel`\r\n```\r\nimport \"ports.imodel\"\r\n\r\ncomponent HasPort {\r\n\trequires Port0\r\n\trequires Port1\r\n}\r\n```\r\n`ports.imodel`\r\n```\r\nPort0\r\nPort1\r\n```\r\nMy python code:\r\n```\r\nfrom textx.metamodel import metamodel_from_file\r\nfrom textx.scoping import MetaModelProvider\r\nfrom textx.scoping.providers import FQNImportURI\r\n\r\n\r\nclass PortFQN():\r\n    def __call__(self, obj, attr, obj_ref):\r\n        ports = obj.prototype.ports\r\n        for port in ports:\r\n        #Does not work because interface is not yet resolved\r\n            if port.interface.name == obj_ref.obj_name:\r\n                return port\r\n        return None\r\n\r\nclass ComponentHACK():\r\n    def __call__(self, obj, attr, obj_ref):\r\n        return obj.parent.parent.components[0]\r\n\r\nclass PrototypeHACK():\r\n    def __call__(self, obj, attr, obj_ref):\r\n        parent = obj\r\n        while hasattr(parent, 'parent'):\r\n            parent = parent.parent\r\n        for model in parent._tx_model_repository.local_models.filename_to_model.values():\r\n            return model.components[0]\r\n\r\nif __name__ == '__main__':\r\n    f_mm = metamodel_from_file('FModel.tx')\r\n    i_mm = metamodel_from_file('IModel.tx')\r\n    MetaModelProvider.add_metamodel('*.fmodel', f_mm)\r\n    MetaModelProvider.add_metamodel('*.imodel', i_mm)\r\n\r\n    f_mm.register_scope_providers({\r\n        \"*.interface\": FQNImportURI(),\r\n        \"*.component\": ComponentHACK(),\r\n        \"*.prototype\": PrototypeHACK(),\r\n        \"*.port\": PortFQN(),\r\n    })\r\n    f = f_mm.model_from_file(\"main.fmodel\")\r\n    print(f)\r\n```\r\n\r\nProblem arises in the PortFQN. I thought I can simply resolve the `Port1` by using the object references I already have in my `Component ConnectPort`, but I cannot. I cannot decide which `Port` instance I have to return from `HasPort` because they are not yet resolved, therefore I cannot access their `name` attribute. Any idea on how to solve this?"},"comment":{"url":"https://api.github.com/repos/igordejanovic/textX/issues/comments/416725295","html_url":"https://github.com/igordejanovic/textX/issues/83#issuecomment-416725295","issue_url":"https://api.github.com/repos/igordejanovic/textX/issues/83","id":416725295,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNjcyNTI5NQ==","user":{"login":"goto40","id":16887130,"node_id":"MDQ6VXNlcjE2ODg3MTMw","avatar_url":"https://avatars3.githubusercontent.com/u/16887130?v=4","gravatar_id":"","url":"https://api.github.com/users/goto40","html_url":"https://github.com/goto40","followers_url":"https://api.github.com/users/goto40/followers","following_url":"https://api.github.com/users/goto40/following{/other_user}","gists_url":"https://api.github.com/users/goto40/gists{/gist_id}","starred_url":"https://api.github.com/users/goto40/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/goto40/subscriptions","organizations_url":"https://api.github.com/users/goto40/orgs","repos_url":"https://api.github.com/users/goto40/repos","events_url":"https://api.github.com/users/goto40/events{/privacy}","received_events_url":"https://api.github.com/users/goto40/received_events","type":"User","site_admin":false},"created_at":"2018-08-28T20:15:39Z","updated_at":"2018-08-28T20:15:39Z","author_association":"COLLABORATOR","body":"Hi - I am not sure if I got all the details...\r\n\r\nI just tried to check the rest of the code:\r\n * Having a Prototype with optional name may cause problems, when referencing this object.\r\n * Objects without name cannot be referenced without extra-effort. \r\n\r\nIt may be clearer to find another solution.\r\nIf there is an unnamed prototype, then the name must be identical to the component --> in this case a custom scope provider can be a solution.\r\n\r\nIf you omit the optional name, you may get a much simpler model.\r\n"}}
{"actor":{"display_login":"goto40"}}