-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(uml): implement element import handler
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
packages/uml-parser/src/metamodel/handlers/ElementImport.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { GraphNode } from '@cm2ml/ir' | ||
|
||
import { Uml } from '../../uml' | ||
import { ElementImport } from '../metamodel' | ||
|
||
export const ElementImportHandler = ElementImport.createHandler( | ||
(elementImport) => { | ||
addEdge_importedElement(elementImport) | ||
addEdge_importingNamespace(elementImport) | ||
}, | ||
) | ||
|
||
function addEdge_importedElement(elementImport: GraphNode) { | ||
const importedElementId = elementImport.getAttribute( | ||
Uml.Attributes.importedElement, | ||
)?.value.literal | ||
if (!importedElementId) { | ||
throw new Error('Missing importedElement attribute on ElementImport') | ||
} | ||
const importedElement = elementImport.model.getNodeById(importedElementId) | ||
if (!importedElement) { | ||
throw new Error( | ||
`Missing importedElement with id ${importedElementId} for ElementImport`, | ||
) | ||
} | ||
elementImport.model.addEdge('importedElement', elementImport, importedElement) | ||
} | ||
|
||
function addEdge_importingNamespace(elementImport: GraphNode) { | ||
const parent = elementImport.parent | ||
if (!parent) { | ||
throw new Error('Missing parent for ElementImport') | ||
} | ||
elementImport.model.addEdge('importingNamespace', elementImport, parent) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters