Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added clone function and addChildren in XoStructureComplexField. #130

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions api/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,6 @@ export class ApiService {
// =================================================================================================================


/**
* @see ZETA-361 for problems with DescriberCache
*/
private getXoDescriberCachedData<T>(
rtc: RuntimeContext,
describers: XoDescriber[],
Expand Down
43 changes: 43 additions & 0 deletions api/xo/xo-structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class XoStructureType {
return from;
}

clone(shallow = false): XoStructureType {
return new XoStructureType(this.typeRtc, this.typeFqn, this.typeLabel, this.typeAbstract, this.typeDocu);
}

decode(from: any): this {
const typeObject = this.getTypeObject(from);
this.typeRtc = RuntimeContext.decode(typeObject.rtc);
Expand Down Expand Up @@ -81,6 +85,10 @@ export abstract class XoStructureField extends XoStructureType {
return super.decode(from);
}

clone(shallow = false): XoStructureField {
return super.clone(shallow) as XoStructureField;
}

get path(): string {
const parentPath = this.parent ? this.parent.path : '';
const parentPathDot = parentPath ? parentPath + '.' : parentPath;
Expand Down Expand Up @@ -125,6 +133,10 @@ export class XoStructurePrimitive extends XoStructureField {
return super.decode(from);
}

clone(shallow = false): XoStructurePrimitive {
return new XoStructurePrimitive(this.parent, this.name, this.label, this.docu, this.typeRtc, this.typeFqn, this.typeLabel, this.typeAbstract, this.typeDocu);
}

static empty(): XoStructurePrimitive {
return new XoStructurePrimitive(null, emptyStructureName);
}
Expand Down Expand Up @@ -181,6 +193,14 @@ export class XoStructureMethod extends XoStructureField {
return super.decode(from);
}


clone(shallow = false): XoStructureMethod {
const result = new XoStructureMethod(this.parent, this.name, this.label, this.docu, this.typeRtc, this.typeFqn, this.typeLabel, this.typeAbstract, this.typeDocu);
result.params.push(...this.params.map(field => field.clone()));
result.returns.push(...this.params.map(field => field.clone()));
return result;
}

static empty(): XoStructureMethod {
return new XoStructureMethod(null, emptyStructureName);
}
Expand All @@ -199,6 +219,12 @@ export class XoStructureMethod extends XoStructureField {
export abstract class XoStructureComplexField extends XoStructureField {
protected _children = new Array<XoStructureField>();

clone(shallow = false): XoStructureComplexField {
const result = super.clone() as XoStructureComplexField;
result._children = shallow ? this.children : this.children.map(child => child.clone());
return result;
}

get length(): number {
return this.children.length;
}
Expand All @@ -213,6 +239,11 @@ export abstract class XoStructureComplexField extends XoStructureField {
this.children.forEach(child => child.parent = this);
}

addChildren(...value: XoStructureField[]) {
this.children.push(...value);
value.forEach(child => child.parent = this);
}

isExpandable(): boolean {
return true;
}
Expand Down Expand Up @@ -244,6 +275,12 @@ export class XoStructureObject extends XoStructureComplexField {
return super.decode(from);
}

clone(shallow = false): XoStructureObject {
const result = new XoStructureObject(this.parent, this.name, this.label, this.docu, this.typeRtc, this.typeFqn, this.typeLabel, this.typeAbstract, this.typeDocu);
result._children = shallow ? this.children : this._children.map(child => child.clone());
return result;
}

valueInstance(rtc: RuntimeContext, fqn: FullQualifiedName): XoObject {
const xo = new XoObject();
xo.rtc = rtc;
Expand All @@ -270,6 +307,12 @@ export class XoStructureArray extends XoStructureComplexField {
return super.decode(from);
}

clone(shallow = false): XoStructureArray {
const result = new XoStructureArray(this.parent, this.name, this.label, this.docu, this.typeRtc, this.typeFqn, this.typeLabel, this.typeAbstract, this.typeDocu);
result._children = shallow ? this._children : this._children.map(child => child.clone());
return result;
}

isPrimitive(): boolean {
return this.typeFqn.isPrimitive();
}
Expand Down
Loading