|
7 | 7 | ensurePackage,
|
8 | 8 | getNodeDefinition,
|
9 | 9 | Node,
|
10 |
| - NODE_TYPES, |
| 10 | + NODE_TYPES, NodeDefinition, |
11 | 11 | PackageDescription,
|
12 | 12 | PropertyDefinition,
|
13 | 13 | registerNodeDefinition,
|
@@ -828,20 +828,27 @@ export class ECoreNode extends NodeAdapter {
|
828 | 828 |
|
829 | 829 | parent?: ECoreNode;
|
830 | 830 |
|
831 |
| - constructor(public eo: ECore.EObject) { |
| 831 | + constructor(public eo: ECore.EObject, parent?: ECoreNode) { |
832 | 832 | super();
|
833 |
| - const container = this.eo.eContainer; |
834 |
| - if (container?.isKindOf(THE_NODE_ECLASS_V2) || container?.isKindOf(THE_NODE_ECLASS_V1)) { |
| 833 | + const container = eo.eContainer; |
| 834 | + if (parent) { |
| 835 | + this.parent = parent; |
| 836 | + } else if (container?.isKindOf(THE_NODE_ECLASS_V2) || container?.isKindOf(THE_NODE_ECLASS_V1)) { |
835 | 837 | this.parent = new ECoreNode(container);
|
836 | 838 | }
|
837 | 839 | }
|
838 | 840 |
|
| 841 | + private __nodeDefinition?: NodeDefinition; |
| 842 | + |
839 | 843 | get nodeDefinition() {
|
840 |
| - return { |
841 |
| - package: this.eo.eClass.eContainer.get("name") as string, |
842 |
| - name: this.eo.eClass.get("name") as string, |
843 |
| - properties: this.getProperties() |
844 |
| - }; |
| 844 | + if (!this.__nodeDefinition) { |
| 845 | + this.__nodeDefinition = { |
| 846 | + package: this.eo.eClass.eContainer.get("name") as string, |
| 847 | + name: this.eo.eClass.get("name") as string, |
| 848 | + properties: this.getProperties() |
| 849 | + }; |
| 850 | + } |
| 851 | + return this.__nodeDefinition; |
845 | 852 | }
|
846 | 853 |
|
847 | 854 | get(...path: string[]): NodeAdapter | undefined {
|
@@ -869,8 +876,13 @@ export class ECoreNode extends NodeAdapter {
|
869 | 876 | return result;
|
870 | 877 | }
|
871 | 878 |
|
872 |
| - getChildren(role?: string): NodeAdapter[] { |
873 |
| - return this.getChildrenEObjects(role).map(c => new ECoreNode(c)); |
| 879 | + private __children?: ECoreNode[] = undefined; |
| 880 | + |
| 881 | + getChildren(role?: string): ECoreNode[] { |
| 882 | + if (this.__children === undefined) { |
| 883 | + this.__children = this.getChildrenEObjects().map(c => new ECoreNode(c, this)); |
| 884 | + } |
| 885 | + return this.__children!.filter(c => !role || c.getRole() == role); |
874 | 886 | }
|
875 | 887 |
|
876 | 888 | getId(): string {
|
@@ -921,12 +933,11 @@ export class ECoreNode extends NodeAdapter {
|
921 | 933 | return result;
|
922 | 934 | }
|
923 | 935 |
|
924 |
| - protected getChildrenEObjects(role: string | undefined) { |
| 936 | + protected getChildrenEObjects() { |
925 | 937 | return this.eo.eContents()
|
926 | 938 | .filter((c) => c.isKindOf(THE_NODE_ECLASS_V2) || c.isKindOf(THE_NODE_ECLASS_V1))
|
927 | 939 | .filter((c) => c.eContainingFeature.get("name") != "origin")
|
928 |
| - .filter((c) => c.eContainingFeature.get("name") != "destination") |
929 |
| - .filter((c) => role == null || role == c.eContainingFeature.get("name")); |
| 940 | + .filter((c) => c.eContainingFeature.get("name") != "destination"); |
930 | 941 | }
|
931 | 942 |
|
932 | 943 | isDeclaration(): boolean {
|
|
0 commit comments