-
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.
- Loading branch information
Showing
55 changed files
with
614 additions
and
449 deletions.
There are no files selected for viewing
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
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,47 @@ | ||
import type { GraphNode } from '@cm2ml/ir' | ||
|
||
import { Uml } from '../uml' | ||
import type { UmlTag, UmlType } from '../uml' | ||
|
||
import { handlers } from './handlers' | ||
import type { Handler } from './metamodel' | ||
|
||
export const typeHandlers: Partial<Record<UmlType, Handler>> = { | ||
Abstraction: handlers.AbstractionHandler, | ||
Class: handlers.ClassHandler, | ||
DataType: handlers.DataTypeHandler, | ||
Dependency: handlers.DependencyHandler, | ||
Enumeration: handlers.EnumerationHandler, | ||
EnumerationLiteral: handlers.EnumerationLiteralHandler, | ||
Generalization: handlers.GeneralizationHandler, | ||
Interface: handlers.InterfaceHandler, | ||
InterfaceRealization: handlers.InterfaceRealizationHandler, | ||
LiteralInteger: handlers.LiteralIntegerHandler, | ||
LiteralUnlimitedNatural: handlers.LiteralUnlimitedNaturalHandler, | ||
Model: handlers.ModelHandler, | ||
Operation: handlers.OperationHandler, | ||
Package: handlers.PackageHandler, | ||
Parameter: handlers.ParameterHandler, | ||
PrimitiveType: handlers.PrimitiveTypeHandler, | ||
Property: handlers.PropertyHandler, | ||
} | ||
|
||
export const tagHandlers: Partial<Record<UmlTag, Handler>> = { | ||
interfaceRealization: handlers.InterfaceRealizationHandler, | ||
ownedAttribute: handlers.PropertyHandler, | ||
ownedLiteral: handlers.EnumerationLiteralHandler, | ||
ownedParameter: handlers.ParameterHandler, | ||
ownedOperation: handlers.OperationHandler, | ||
} | ||
|
||
export function getHandler(node: GraphNode) { | ||
const type = Uml.getType(node) | ||
if (type) { | ||
return typeHandlers[type] | ||
} | ||
const tag = node.tag | ||
if (Uml.isValidTag(tag)) { | ||
return tagHandlers[tag] | ||
} | ||
return undefined | ||
} |
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,3 @@ | ||
import { Abstraction } from '../metamodel' | ||
|
||
export const AbstractionHandler = Abstraction.createHandler() |
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,3 @@ | ||
import { Class } from '../metamodel' | ||
|
||
export const ClassHandler = Class.createHandler() |
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,3 @@ | ||
import { DataType } from '../metamodel' | ||
|
||
export const DataTypeHandler = DataType.createHandler() |
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,27 @@ | ||
import type { GraphNode } from '@cm2ml/ir' | ||
|
||
import { Uml } from '../../uml' | ||
import { Dependency } from '../metamodel' | ||
|
||
export const DependencyHandler = Dependency.createHandler((node: GraphNode) => { | ||
const clientId = node.getAttribute(Uml.Attributes.client)?.value.literal | ||
if (!clientId) { | ||
throw new Error('Missing client attribute on dependency') | ||
} | ||
const client = node.model.getNodeById(clientId) | ||
if (!client) { | ||
throw new Error(`Could not find client with id ${clientId} for dependency`) | ||
} | ||
const supplierId = node.getAttribute(Uml.Attributes.supplier)?.value.literal | ||
if (!supplierId) { | ||
throw new Error('Missing supplier attribute on dependency') | ||
} | ||
const supplier = node.model.getNodeById(supplierId) | ||
if (!supplier) { | ||
throw new Error( | ||
`Could not find supplier with id ${supplierId} for dependency`, | ||
) | ||
} | ||
// TODO: Update tag | ||
node.model.addEdge('dependency', client, supplier) | ||
}) |
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,3 @@ | ||
import { Enumeration } from '../metamodel' | ||
|
||
export const EnumerationHandler = Enumeration.createHandler() |
4 changes: 4 additions & 0 deletions
4
packages/uml-parser/src/metamodel/handlers/EnumerationLiteral.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,4 @@ | ||
import { EnumerationLiteral } from '../metamodel' | ||
|
||
// TODO | ||
export const EnumerationLiteralHandler = EnumerationLiteral.createHandler() |
8 changes: 3 additions & 5 deletions
8
...uml-parser/src/refiners/generalization.ts → .../src/metamodel/handlers/Generalization.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
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,3 @@ | ||
import { Interface } from '../metamodel' | ||
|
||
export const InterfaceHandler = Interface.createHandler() |
9 changes: 3 additions & 6 deletions
9
...rser/src/refiners/interfaceRealization.ts → ...etamodel/handlers/InterfaceRealization.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
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,3 @@ | ||
import { LiteralInteger } from '../metamodel' | ||
|
||
export const LiteralIntegerHandler = LiteralInteger.createHandler() |
4 changes: 4 additions & 0 deletions
4
packages/uml-parser/src/metamodel/handlers/LiteralUnlimitedNatural.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,4 @@ | ||
import { LiteralUnlimitedNatural } from '../metamodel' | ||
|
||
export const LiteralUnlimitedNaturalHandler = | ||
LiteralUnlimitedNatural.createHandler() |
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,3 @@ | ||
import { Model } from '../metamodel' | ||
|
||
export const ModelHandler = Model.createHandler() |
24 changes: 24 additions & 0 deletions
24
packages/uml-parser/src/metamodel/handlers/MultiplicityElement.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,24 @@ | ||
import { Uml } from '../../uml' | ||
import { MultiplicityElement } from '../metamodel' | ||
|
||
export const MultiplicityElementHandler = MultiplicityElement.createHandler( | ||
(node) => { | ||
node.children.forEach((child) => { | ||
if (child.tag === Uml.Tags.lowerValue) { | ||
node.model.addEdge('lowerValue', node, child) | ||
const lowerValue = child.getAttribute('value')?.value.literal | ||
if (lowerValue === undefined) { | ||
throw new Error('LowerValue must have a value') | ||
} | ||
node.addAttribute({ name: 'lower', value: { literal: lowerValue } }) | ||
} else if (child.tag === Uml.Tags.upperValue) { | ||
node.model.addEdge('upperValue', node, child) | ||
const upperValue = child.getAttribute('value')?.value.literal | ||
if (upperValue === undefined) { | ||
throw new Error('UpperValue must have a value') | ||
} | ||
node.addAttribute({ name: 'upper', value: { literal: upperValue } }) | ||
} | ||
}) | ||
}, | ||
) |
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,17 @@ | ||
import { Uml } from '../../uml' | ||
import { Operation, Parameter } from '../metamodel' | ||
|
||
// TODO | ||
export const OperationHandler = Operation.createHandler((node) => { | ||
const parent = node.parent | ||
if (!parent) { | ||
throw new Error('OwnedOperation must have a parent') | ||
} | ||
node.model.addEdge('ownedOperation', parent, node) | ||
node.children.forEach((child) => { | ||
if (Parameter.isAssignable(child)) { | ||
node.model.addEdge('ownedParameter', node, child) | ||
} | ||
}) | ||
node.tag = Uml.Types.Operation | ||
}) |
63 changes: 31 additions & 32 deletions
63
packages/uml-parser/src/refiners/package.ts → ...-parser/src/metamodel/handlers/Package.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
14 changes: 14 additions & 0 deletions
14
packages/uml-parser/src/metamodel/handlers/PackageableElement.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,14 @@ | ||
import { Package, PackageableElement } from '../metamodel' | ||
|
||
export const PackageableElementHandler = PackageableElement.createHandler( | ||
(node) => { | ||
const parent = node.parent | ||
if (!parent) { | ||
return | ||
} | ||
if (!Package.isAssignable(parent)) { | ||
return | ||
} | ||
node.model.addEdge('owningPackage', node, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Uml } from '../../uml' | ||
import { Parameter } from '../metamodel' | ||
|
||
// TODO | ||
export const ParameterHandler = Parameter.createHandler((node) => { | ||
const parent = node.parent | ||
if (parent) { | ||
node.model.addEdge('operation', node, parent) | ||
} | ||
node.tag = Uml.Types.Parameter | ||
}) |
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,3 @@ | ||
import { PrimitiveType } from '../metamodel' | ||
|
||
export const PrimitiveTypeHandler = PrimitiveType.createHandler() |
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,7 @@ | ||
import { Uml } from '../../uml' | ||
import { Property } from '../metamodel' | ||
|
||
export const PropertyHandler = Property.createHandler((node) => { | ||
// TODO | ||
node.tag = Uml.Types.Property | ||
}) |
18 changes: 18 additions & 0 deletions
18
packages/uml-parser/src/metamodel/handlers/TypedElement.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,18 @@ | ||
import { Uml } from '../../uml' | ||
import { TypedElement } from '../metamodel' | ||
|
||
// TODO | ||
export const TypedElementHandler = TypedElement.createHandler((node) => { | ||
const type = node.getAttribute('type')?.value.literal | ||
if (type === undefined) { | ||
return | ||
} | ||
if (Uml.isValidType(type)) { | ||
return | ||
} | ||
const resolvedType = node.model.getNodeById(type) | ||
if (!resolvedType) { | ||
return | ||
} | ||
node.model.addEdge('type', node, resolvedType) | ||
}) |
Oops, something went wrong.