-
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: inverse inheritance for assignability
- Loading branch information
Showing
15 changed files
with
156 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Uml } from '../uml' | ||
|
||
import { UmlElement } from './umlElement' | ||
|
||
export const Class = new UmlElement( | ||
(node) => Uml.getType(node) === Uml.Types.Class, | ||
) |
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,7 @@ | ||
import { Uml } from '../uml' | ||
|
||
import { UmlElement } from './umlElement' | ||
|
||
export const ElementImport = new UmlElement( | ||
(node) => node.tag === Uml.Tags.elementImport, | ||
) |
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,31 @@ | ||
import { Stream } from '@yeger/streams' | ||
|
||
import { Uml } from '../uml' | ||
|
||
import { DirectedRelationship } from './relationship' | ||
|
||
export const Generalization = DirectedRelationship.extend( | ||
(node) => node.tag === Uml.Tags.generalization, | ||
(node) => { | ||
const specfic = node.parent | ||
if (!specfic) { | ||
throw new Error('Missing parent for generalization') | ||
} | ||
const generalChild = Stream.from(node.children).find( | ||
(child) => child.tag === Uml.Tags.general, | ||
) | ||
if (!generalChild) { | ||
throw new Error('Missing general child for generalization') | ||
} | ||
const generalId = generalChild.getAttribute('idref')?.value.literal | ||
if (!generalId) { | ||
throw new Error('Missing idref attribute on general') | ||
} | ||
const general = node.model.getNodeById(generalId) | ||
if (!general) { | ||
throw new Error(`Could not find general with id ${generalId}`) | ||
} | ||
node.model.addEdge('generalization', specfic, general) | ||
node.model.removeNode(node) | ||
}, | ||
) |
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,7 @@ | ||
import { Uml } from '../uml' | ||
|
||
import { UmlElement } from './umlElement' | ||
|
||
export const Model = new UmlElement( | ||
(node) => Uml.getType(node) === Uml.Types.Model, | ||
) |
15 changes: 0 additions & 15 deletions
15
packages/uml-parser/src/refiners/nodes/packageableElement.ts
This file was deleted.
Oops, something went wrong.
36 changes: 18 additions & 18 deletions
36
.../uml-parser/src/refiners/nodes/package.ts → packages/uml-parser/src/refiners/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
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 { UmlElement } from './umlElement' | ||
|
||
export const PackageImport = new UmlElement( | ||
(node) => node.tag === Uml.Tags.packageImport, | ||
) |
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 { UmlElement } from './umlElement' | ||
|
||
export const PackageMerge = new UmlElement( | ||
(node) => node.tag === Uml.Tags.packageMerge, | ||
) |
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 { UmlElement } from './umlElement' | ||
|
||
export const PackageableElement = new UmlElement( | ||
(node) => node.tag === Uml.Tags.packagedElement, | ||
) |
This file was deleted.
Oops, something went wrong.
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 { UmlElement } from './umlElement' | ||
|
||
// TODO | ||
export const Relationship = new UmlElement(() => false) | ||
|
||
// TODO | ||
export const DirectedRelationship = Relationship.extend(() => false) |
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,36 @@ | ||
import type { GraphNode } from '@cm2ml/ir' | ||
|
||
export class UmlElement { | ||
readonly #isAssignable: (node: GraphNode) => boolean | ||
readonly #refine?: (node: GraphNode) => void | ||
private readonly subRefiners: UmlElement[] = [] | ||
public constructor( | ||
isAssignable: (node: GraphNode) => boolean, | ||
refine?: (node: GraphNode) => void, | ||
private readonly parent?: UmlElement, | ||
) { | ||
this.#isAssignable = isAssignable | ||
this.#refine = refine | ||
} | ||
|
||
public isAssignable(node: GraphNode): boolean { | ||
return ( | ||
this.#isAssignable(node) || | ||
this.subRefiners.some((r) => r.isAssignable(node)) | ||
) | ||
} | ||
|
||
public refine(node: GraphNode): void { | ||
this.parent?.refine(node) | ||
this.#refine?.(node) | ||
} | ||
|
||
public extend( | ||
isAssignable: (node: GraphNode) => boolean, | ||
refine?: (node: GraphNode) => void, | ||
): UmlElement { | ||
const subRefiner = new UmlElement(isAssignable, refine, this) | ||
this.subRefiners.push(subRefiner) | ||
return subRefiner | ||
} | ||
} |
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