From 6f173c164ddb736ca53c7ad8ac54cf3985606651 Mon Sep 17 00:00:00 2001 From: MTahaCode Date: Tue, 15 Sep 2026 18:32:07 -0400 Subject: [PATCH 01/10] updated entities apis to latest metamodel --- .github/ImporterSampleProject/tsconfig.json | 2 +- src/lib/famix/model/famix/concretization.ts | 41 +++++++++++++------ src/lib/famix/model/famix/index.ts | 1 + .../model/famix/parametric_arrow_function.ts | 24 ++++++----- src/lib/famix/model/famix/parametric_class.ts | 35 +++++----------- .../model/famix/parametric_entity_typing.ts | 16 +++++++- .../famix/model/famix/parametric_function.ts | 24 ++++++----- .../famix/model/famix/parametric_interface.ts | 35 +++++----------- .../model/famix/parametric_invocation.ts | 30 ++++++++++++++ .../famix/model/famix/parametric_method.ts | 24 ++++++----- src/lib/famix/model/famix/type.ts | 10 +++++ src/lib/famix/model/famix/type_parameter.ts | 18 ++++---- 12 files changed, 152 insertions(+), 108 deletions(-) create mode 100644 src/lib/famix/model/famix/parametric_invocation.ts diff --git a/.github/ImporterSampleProject/tsconfig.json b/.github/ImporterSampleProject/tsconfig.json index bc080792..9680925d 100644 --- a/.github/ImporterSampleProject/tsconfig.json +++ b/.github/ImporterSampleProject/tsconfig.json @@ -15,6 +15,6 @@ "emitDecoratorMetadata": true, "resolveJsonModule": true }, - "include": ["src/**/*.ts"], + "include": ["src/**/*.ts", "src/**/*.tsx"], "exclude": ["node_modules", "dist"] } diff --git a/src/lib/famix/model/famix/concretization.ts b/src/lib/famix/model/famix/concretization.ts index 2035ba34..3cc78ac9 100644 --- a/src/lib/famix/model/famix/concretization.ts +++ b/src/lib/famix/model/famix/concretization.ts @@ -1,14 +1,22 @@ import { FamixJSONExporter } from "../../famix_JSON_exporter"; import { Entity } from "./entity"; +import { ParametricEntityTyping } from "./parametric_entity_typing"; +import { ParametricInvocation } from "./parametric_invocation"; +import { Type } from "./type"; +import { TypeParameter } from "./type_parameter"; import { ParametricClass } from "./parametric_class"; import { ParametricFunction } from "./parametric_function"; import { ParametricInterface } from "./parametric_interface"; import { ParametricMethod } from "./parametric_method"; +// More will be added here +type ParametricAssociation = ParametricEntityTyping | ParametricInvocation; + export class Concretization extends Entity { - private _genericEntity!: ParametricClass | ParametricInterface | ParametricFunction | ParametricMethod; - private _concreteEntity!: ParametricClass | ParametricInterface | ParametricFunction | ParametricMethod; // is this correct? + private _typeParameter!: TypeParameter; + private _typeArgument!: Type; + private _triggeringAssociation!: ParametricAssociation; public getJSON(): string { const json: FamixJSONExporter = new FamixJSONExporter("Concretization", this); @@ -18,23 +26,32 @@ export class Concretization extends Entity { public addPropertiesToExporter(exporter: FamixJSONExporter): void { super.addPropertiesToExporter(exporter); - exporter.addProperty("genericEntity", this.genericEntity); - exporter.addProperty("concreteEntity", this.concreteEntity); + exporter.addProperty("typeParameter", this._typeParameter); + exporter.addProperty("typeArgument", this._typeArgument); + exporter.addProperty("triggeringAssociation", this._triggeringAssociation); + } + + get typeParameter(): TypeParameter { + return this._typeParameter; + } + + set typeParameter(typeParameter: TypeParameter) { + this._typeParameter = typeParameter; } - get genericEntity() { - return this._genericEntity; + get typeArgument(): Type { + return this._typeArgument; } - set genericEntity(genericEntity: ParametricClass | ParametricInterface | ParametricFunction | ParametricMethod) { - this._genericEntity = genericEntity; + set typeArgument(typeArgument: Type) { + this._typeArgument = typeArgument; } - get concreteEntity() { - return this._concreteEntity; + get triggeringAssociation(): ParametricAssociation { + return this._triggeringAssociation; } - set concreteEntity(concreteEntity: ParametricClass | ParametricInterface | ParametricFunction | ParametricMethod) { - this._concreteEntity = concreteEntity; + set triggeringAssociation(triggeringAssociation: ParametricAssociation) { + this._triggeringAssociation = triggeringAssociation; } } diff --git a/src/lib/famix/model/famix/index.ts b/src/lib/famix/model/famix/index.ts index a2b3aee2..879d2f2c 100644 --- a/src/lib/famix/model/famix/index.ts +++ b/src/lib/famix/model/famix/index.ts @@ -41,3 +41,4 @@ export { ParametricArrowFunction } from "./parametric_arrow_function"; export { ParameterConcretization } from "./parameter_concretization"; export { EntityTyping } from "./entity_typing"; export { ParametricEntityTyping } from "./parametric_entity_typing"; +export { ParametricInvocation } from "./parametric_invocation"; diff --git a/src/lib/famix/model/famix/parametric_arrow_function.ts b/src/lib/famix/model/famix/parametric_arrow_function.ts index f2a38f7e..c5174082 100644 --- a/src/lib/famix/model/famix/parametric_arrow_function.ts +++ b/src/lib/famix/model/famix/parametric_arrow_function.ts @@ -1,19 +1,22 @@ import { FamixJSONExporter } from "../../famix_JSON_exporter"; import { ArrowFunction } from "./arrow_function"; -import { Class } from "./class"; -import { Interface } from "./interface"; -import { PrimitiveType } from "./primitive_type"; +import { TypeParameter } from "./type_parameter"; export class ParametricArrowFunction extends ArrowFunction { - private _concreteParameters: Set = new Set(); + private _typeParameters: Set = new Set(); - public addConcreteParameter(concreteParameter: PrimitiveType | Class | Interface): void { - if (!this._concreteParameters.has(concreteParameter)) { - this._concreteParameters.add(concreteParameter); + public addTypeParameter(typeParameter: TypeParameter): void { + if (!this._typeParameters.has(typeParameter)) { + this._typeParameters.add(typeParameter); + typeParameter.genericEntity = this; } } + public clearTypeParameters(): void { + this._typeParameters.clear(); + } + public getJSON(): string { const json: FamixJSONExporter = new FamixJSONExporter("ParametricArrowFunction", this); this.addPropertiesToExporter(json); @@ -22,11 +25,10 @@ export class ParametricArrowFunction extends ArrowFunction { public addPropertiesToExporter(exporter: FamixJSONExporter): void { super.addPropertiesToExporter(exporter); - exporter.addProperty("genericParameters", this.genericParameters); - exporter.addProperty("concreteParameters", this.concreteParameters); + exporter.addProperty("typeParameters", this._typeParameters); } - get concreteParameters() { - return this._concreteParameters; + get typeParameters(): Set { + return this._typeParameters; } } diff --git a/src/lib/famix/model/famix/parametric_class.ts b/src/lib/famix/model/famix/parametric_class.ts index 0c49e574..c1f2b0f4 100644 --- a/src/lib/famix/model/famix/parametric_class.ts +++ b/src/lib/famix/model/famix/parametric_class.ts @@ -1,30 +1,20 @@ -import { Interface } from "./interface"; import { FamixJSONExporter } from "../../famix_JSON_exporter"; import { Class } from "./class"; import { TypeParameter } from "./type_parameter"; -import { PrimitiveType } from "./primitive_type"; export class ParametricClass extends Class { - private _genericParameters: Set = new Set(); + private _typeParameters: Set = new Set(); - public addGenericParameter(genericParameter: TypeParameter): void { - if (!this._genericParameters.has(genericParameter)) { - this._genericParameters.add(genericParameter); - genericParameter.parentGeneric = this; + public addTypeParameter(typeParameter: TypeParameter): void { + if (!this._typeParameters.has(typeParameter)) { + this._typeParameters.add(typeParameter); + typeParameter.genericEntity = this; } } - clearGenericParameters(): void { - this._genericParameters.clear(); - } - - private _concreteParameters: Set = new Set(); - - public addConcreteParameter(concreteParameter: PrimitiveType | Class | Interface): void { - if (!this._concreteParameters.has(concreteParameter)) { - this._concreteParameters.add(concreteParameter); - } + public clearTypeParameters(): void { + this._typeParameters.clear(); } public getJSON(): string { @@ -35,15 +25,10 @@ export class ParametricClass extends Class { public addPropertiesToExporter(exporter: FamixJSONExporter): void { super.addPropertiesToExporter(exporter); - exporter.addProperty("genericParameters", this.genericParameters); - exporter.addProperty("concreteParameters", this.concreteParameters); - } - - get genericParameters(): Set { - return this._genericParameters; + exporter.addProperty("typeParameters", this._typeParameters); } - get concreteParameters(): Set { - return this._concreteParameters; + get typeParameters(): Set { + return this._typeParameters; } } diff --git a/src/lib/famix/model/famix/parametric_entity_typing.ts b/src/lib/famix/model/famix/parametric_entity_typing.ts index aa0cdc02..932aecb2 100644 --- a/src/lib/famix/model/famix/parametric_entity_typing.ts +++ b/src/lib/famix/model/famix/parametric_entity_typing.ts @@ -1,10 +1,24 @@ import { FamixJSONExporter } from "../../famix_JSON_exporter"; -import { Entity } from "./entity"; +import { Concretization } from "./concretization"; import { EntityTyping } from "./entity_typing"; +import { Entity } from "./entity"; import { Type } from "./type"; export class ParametricEntityTyping extends EntityTyping { + private _concretizations: Set = new Set(); + + public addConcretization(concretization: Concretization): void { + if (!this._concretizations.has(concretization)) { + this._concretizations.add(concretization); + concretization.triggeringAssociation = this; + } + } + + public get concretizations(): Set { + return this._concretizations; + } + public getJSON(): string { const json: FamixJSONExporter = new FamixJSONExporter("ParametricEntityTyping", this); this.addPropertiesToExporter(json); diff --git a/src/lib/famix/model/famix/parametric_function.ts b/src/lib/famix/model/famix/parametric_function.ts index 195fa159..2c17baeb 100644 --- a/src/lib/famix/model/famix/parametric_function.ts +++ b/src/lib/famix/model/famix/parametric_function.ts @@ -1,19 +1,22 @@ import { FamixJSONExporter } from "../../famix_JSON_exporter"; -import { Class } from "./class"; import { Function } from "./function"; -import { Interface } from "./interface"; -import { PrimitiveType } from "./primitive_type"; +import { TypeParameter } from "./type_parameter"; export class ParametricFunction extends Function { - private _concreteParameters: Set = new Set(); + private _typeParameters: Set = new Set(); - public addConcreteParameter(concreteParameter: PrimitiveType | Class | Interface): void { - if (!this._concreteParameters.has(concreteParameter)) { - this._concreteParameters.add(concreteParameter); + public addTypeParameter(typeParameter: TypeParameter): void { + if (!this._typeParameters.has(typeParameter)) { + this._typeParameters.add(typeParameter); + typeParameter.genericEntity = this; } } + public clearTypeParameters(): void { + this._typeParameters.clear(); + } + public getJSON(): string { const json: FamixJSONExporter = new FamixJSONExporter("ParametricFunction", this); this.addPropertiesToExporter(json); @@ -22,11 +25,10 @@ export class ParametricFunction extends Function { public addPropertiesToExporter(exporter: FamixJSONExporter): void { super.addPropertiesToExporter(exporter); - exporter.addProperty("genericParameters", this.genericParameters); - exporter.addProperty("concreteParameters", this.concreteParameters); + exporter.addProperty("typeParameters", this._typeParameters); } - get concreteParameters(): Set { - return this._concreteParameters; + get typeParameters(): Set { + return this._typeParameters; } } diff --git a/src/lib/famix/model/famix/parametric_interface.ts b/src/lib/famix/model/famix/parametric_interface.ts index 9c562cf2..9d452109 100644 --- a/src/lib/famix/model/famix/parametric_interface.ts +++ b/src/lib/famix/model/famix/parametric_interface.ts @@ -1,30 +1,20 @@ import { FamixJSONExporter } from "../../famix_JSON_exporter"; -import { Class } from "./class"; import { Interface } from "./interface"; import { TypeParameter } from "./type_parameter"; -import { PrimitiveType } from "./primitive_type"; export class ParametricInterface extends Interface { - private _genericParameters: Set = new Set(); + private _typeParameters: Set = new Set(); - public addGenericParameter(genericParameter: TypeParameter): void { - if (!this._genericParameters.has(genericParameter)) { - this._genericParameters.add(genericParameter); - genericParameter.parentGeneric = this; + public addTypeParameter(typeParameter: TypeParameter): void { + if (!this._typeParameters.has(typeParameter)) { + this._typeParameters.add(typeParameter); + typeParameter.genericEntity = this; } } - clearGenericParameters(): void { - this._genericParameters.clear(); - } - - private _concreteParameters: Set = new Set(); - - public addConcreteParameter(concreteParameter: PrimitiveType | Class | Interface): void { - if (!this._concreteParameters.has(concreteParameter)) { - this._concreteParameters.add(concreteParameter); - } + public clearTypeParameters(): void { + this._typeParameters.clear(); } public getJSON(): string { @@ -35,15 +25,10 @@ export class ParametricInterface extends Interface { public addPropertiesToExporter(exporter: FamixJSONExporter): void { super.addPropertiesToExporter(exporter); - exporter.addProperty("genericParameters", this.genericParameters); - exporter.addProperty("concreteParameters", this.concreteParameters); - } - - get genericParameters(): Set { - return this._genericParameters; + exporter.addProperty("typeParameters", this._typeParameters); } - get concreteParameters(): Set { - return this._concreteParameters; + get typeParameters(): Set { + return this._typeParameters; } } diff --git a/src/lib/famix/model/famix/parametric_invocation.ts b/src/lib/famix/model/famix/parametric_invocation.ts new file mode 100644 index 00000000..bf505986 --- /dev/null +++ b/src/lib/famix/model/famix/parametric_invocation.ts @@ -0,0 +1,30 @@ +import { FamixJSONExporter } from "../../famix_JSON_exporter"; +import { Concretization } from "./concretization"; +import { Invocation } from "./invocation"; + +export class ParametricInvocation extends Invocation { + private _concretizations: Set = new Set(); + + public addConcretization(concretization: Concretization): void { + if (!this._concretizations.has(concretization)) { + this._concretizations.add(concretization); + } + } + + public get concretizations() { + return this._concretizations; + } + + public getJSON(): string { + const json: FamixJSONExporter = new FamixJSONExporter("ParametricInvocation", this); + + this.addPropertiesToExporter(json); + return json.getJSON(); + } + + public addPropertiesToExporter(exporter: FamixJSONExporter): void { + super.addPropertiesToExporter(exporter); + + exporter.addProperty("concretizations", this.concretizations); + } +} \ No newline at end of file diff --git a/src/lib/famix/model/famix/parametric_method.ts b/src/lib/famix/model/famix/parametric_method.ts index 33a8ac2d..cf6b2a80 100644 --- a/src/lib/famix/model/famix/parametric_method.ts +++ b/src/lib/famix/model/famix/parametric_method.ts @@ -1,19 +1,22 @@ import { FamixJSONExporter } from "../../famix_JSON_exporter"; -import { Class } from "./class"; -import { Interface } from "./interface"; import { Method } from "./method"; -import { PrimitiveType } from "./primitive_type"; +import { TypeParameter } from "./type_parameter"; export class ParametricMethod extends Method { - private _concreteParameters: Set = new Set(); + private _typeParameters: Set = new Set(); - public addConcreteParameter(concreteParameter: PrimitiveType | Class | Interface): void { - if (!this._concreteParameters.has(concreteParameter)) { - this._concreteParameters.add(concreteParameter); + public addTypeParameter(typeParameter: TypeParameter): void { + if (!this._typeParameters.has(typeParameter)) { + this._typeParameters.add(typeParameter); + typeParameter.genericEntity = this; } } + public clearTypeParameters(): void { + this._typeParameters.clear(); + } + public getJSON(): string { const json: FamixJSONExporter = new FamixJSONExporter("ParametricMethod", this); this.addPropertiesToExporter(json); @@ -22,11 +25,10 @@ export class ParametricMethod extends Method { public addPropertiesToExporter(exporter: FamixJSONExporter): void { super.addPropertiesToExporter(exporter); - exporter.addProperty("genericParameters", this.genericParameters); - exporter.addProperty("concreteParameters", this.concreteParameters); + exporter.addProperty("typeParameters", this._typeParameters); } - get concreteParameters(): Set { - return this._concreteParameters; + get typeParameters(): Set { + return this._typeParameters; } } diff --git a/src/lib/famix/model/famix/type.ts b/src/lib/famix/model/famix/type.ts index 5e655be6..994271b1 100644 --- a/src/lib/famix/model/famix/type.ts +++ b/src/lib/famix/model/famix/type.ts @@ -4,6 +4,7 @@ import { ContainerEntity } from "./container_entity"; import { Reference } from "./reference"; import { BehavioralEntity } from "./behavioral_entity"; import { Alias } from "./alias"; +import { EntityTyping } from "./entity_typing"; export class Type extends ContainerEntity { @@ -30,6 +31,15 @@ export class Type extends ContainerEntity { } } + private _incomingTypings: Set = new Set(); + + public addIncomingTyping(incomingTyping: EntityTyping): void { + if (!this._incomingTypings.has(incomingTyping)) { + this._incomingTypings.add(incomingTyping); + incomingTyping.declaredType = this; + } + } + public getJSON(): string { const json: FamixJSONExporter = new FamixJSONExporter("Type", this); this.addPropertiesToExporter(json); diff --git a/src/lib/famix/model/famix/type_parameter.ts b/src/lib/famix/model/famix/type_parameter.ts index a51a0bc9..f5c2ce1a 100644 --- a/src/lib/famix/model/famix/type_parameter.ts +++ b/src/lib/famix/model/famix/type_parameter.ts @@ -2,17 +2,13 @@ import { FamixJSONExporter } from "../../famix_JSON_exporter"; import { Type } from "./type"; import { ParametricClass } from "./parametric_class"; import { ParametricInterface } from "./parametric_interface"; -import { Method } from "./method"; -import { Function as FamixFunction } from "./function"; -import { Accessor } from "./accessor"; import { ParametricMethod } from "./parametric_method"; import { ParametricFunction } from "./parametric_function"; -import { ArrowFunction } from "./arrow_function"; import { ParametricArrowFunction } from "./parametric_arrow_function"; export class TypeParameter extends Type { - private _parentGeneric!: ParametricClass | ParametricInterface | Method | ParametricMethod | Accessor | FamixFunction | ParametricFunction | ArrowFunction | ParametricArrowFunction; + private _genericEntity!: ParametricClass | ParametricInterface | ParametricMethod | ParametricFunction | ParametricArrowFunction; private _baseType!: Type; private _arguments: Set = new Set(); @@ -30,18 +26,18 @@ export class TypeParameter extends Type { public addPropertiesToExporter(exporter: FamixJSONExporter): void { super.addPropertiesToExporter(exporter); - exporter.addProperty("parentGeneric", this.parentGeneric); + exporter.addProperty("genericEntity", this.genericEntity); exporter.addProperty("baseType", this.baseType); exporter.addProperty("arguments", this.arguments); } - get parentGeneric() { - return this._parentGeneric; + get genericEntity() { + return this._genericEntity; } - set parentGeneric(parentGeneric: ParametricClass | ParametricInterface | Method | ParametricMethod | Accessor | FamixFunction | ParametricFunction | ArrowFunction | ParametricArrowFunction) { - this._parentGeneric = parentGeneric; - parentGeneric.addGenericParameter(this); + set genericEntity(genericEntity: ParametricClass | ParametricInterface | ParametricMethod | ParametricFunction | ParametricArrowFunction) { + this._genericEntity = genericEntity; + genericEntity.addTypeParameter(this); } get baseType() { From 37a768bf1c74491951baf2ceb60344208ca3d48e Mon Sep 17 00:00:00 2001 From: MTahaCode Date: Tue, 15 Sep 2026 18:49:59 -0400 Subject: [PATCH 02/10] Concretization and related apis updated to match new metamodel --- src/lib/famix/model/famix/concretization.ts | 8 +++-- src/lib/famix/model/famix/index.ts | 2 ++ .../model/famix/parametric_inheritance.ts | 30 +++++++++++++++++++ .../famix/model/famix/parametric_reference.ts | 30 +++++++++++++++++++ src/lib/famix/model/famix/type.ts | 14 +++++++++ src/lib/famix/model/famix/type_parameter.ts | 13 ++++++++ 6 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 src/lib/famix/model/famix/parametric_inheritance.ts create mode 100644 src/lib/famix/model/famix/parametric_reference.ts diff --git a/src/lib/famix/model/famix/concretization.ts b/src/lib/famix/model/famix/concretization.ts index 3cc78ac9..d9fe58ab 100644 --- a/src/lib/famix/model/famix/concretization.ts +++ b/src/lib/famix/model/famix/concretization.ts @@ -2,6 +2,8 @@ import { FamixJSONExporter } from "../../famix_JSON_exporter"; import { Entity } from "./entity"; import { ParametricEntityTyping } from "./parametric_entity_typing"; import { ParametricInvocation } from "./parametric_invocation"; +import { ParametricInheritance } from "./parametric_inheritance"; +import { ParametricReference } from "./parametric_reference"; import { Type } from "./type"; import { TypeParameter } from "./type_parameter"; import { ParametricClass } from "./parametric_class"; @@ -9,8 +11,8 @@ import { ParametricFunction } from "./parametric_function"; import { ParametricInterface } from "./parametric_interface"; import { ParametricMethod } from "./parametric_method"; -// More will be added here -type ParametricAssociation = ParametricEntityTyping | ParametricInvocation; +// More will be added here (e.g. ParametricImplementation, once Implementation exists) +type ParametricAssociation = ParametricEntityTyping | ParametricInvocation | ParametricInheritance | ParametricReference; export class Concretization extends Entity { @@ -37,6 +39,7 @@ export class Concretization extends Entity { set typeParameter(typeParameter: TypeParameter) { this._typeParameter = typeParameter; + typeParameter.addConcretization(this); } get typeArgument(): Type { @@ -45,6 +48,7 @@ export class Concretization extends Entity { set typeArgument(typeArgument: Type) { this._typeArgument = typeArgument; + typeArgument.addOutgoingConcretization(this); } get triggeringAssociation(): ParametricAssociation { diff --git a/src/lib/famix/model/famix/index.ts b/src/lib/famix/model/famix/index.ts index 879d2f2c..60f839de 100644 --- a/src/lib/famix/model/famix/index.ts +++ b/src/lib/famix/model/famix/index.ts @@ -42,3 +42,5 @@ export { ParameterConcretization } from "./parameter_concretization"; export { EntityTyping } from "./entity_typing"; export { ParametricEntityTyping } from "./parametric_entity_typing"; export { ParametricInvocation } from "./parametric_invocation"; +export { ParametricInheritance } from "./parametric_inheritance"; +export { ParametricReference } from "./parametric_reference"; diff --git a/src/lib/famix/model/famix/parametric_inheritance.ts b/src/lib/famix/model/famix/parametric_inheritance.ts new file mode 100644 index 00000000..a2a8c37f --- /dev/null +++ b/src/lib/famix/model/famix/parametric_inheritance.ts @@ -0,0 +1,30 @@ +import { FamixJSONExporter } from "../../famix_JSON_exporter"; +import { Concretization } from "./concretization"; +import { Inheritance } from "./inheritance"; + +export class ParametricInheritance extends Inheritance { + + private _concretizations: Set = new Set(); + + public addConcretization(concretization: Concretization): void { + if (!this._concretizations.has(concretization)) { + this._concretizations.add(concretization); + concretization.triggeringAssociation = this; + } + } + + public get concretizations(): Set { + return this._concretizations; + } + + public getJSON(): string { + const json: FamixJSONExporter = new FamixJSONExporter("ParametricInheritance", this); + this.addPropertiesToExporter(json); + return json.getJSON(); + } + + public addPropertiesToExporter(exporter: FamixJSONExporter): void { + super.addPropertiesToExporter(exporter); + exporter.addProperty("concretizations", this.concretizations); + } +} diff --git a/src/lib/famix/model/famix/parametric_reference.ts b/src/lib/famix/model/famix/parametric_reference.ts new file mode 100644 index 00000000..6d6bb916 --- /dev/null +++ b/src/lib/famix/model/famix/parametric_reference.ts @@ -0,0 +1,30 @@ +import { FamixJSONExporter } from "../../famix_JSON_exporter"; +import { Concretization } from "./concretization"; +import { Reference } from "./reference"; + +export class ParametricReference extends Reference { + + private _concretizations: Set = new Set(); + + public addConcretization(concretization: Concretization): void { + if (!this._concretizations.has(concretization)) { + this._concretizations.add(concretization); + concretization.triggeringAssociation = this; + } + } + + public get concretizations(): Set { + return this._concretizations; + } + + public getJSON(): string { + const json: FamixJSONExporter = new FamixJSONExporter("ParametricReference", this); + this.addPropertiesToExporter(json); + return json.getJSON(); + } + + public addPropertiesToExporter(exporter: FamixJSONExporter): void { + super.addPropertiesToExporter(exporter); + exporter.addProperty("concretizations", this.concretizations); + } +} diff --git a/src/lib/famix/model/famix/type.ts b/src/lib/famix/model/famix/type.ts index 994271b1..695567a6 100644 --- a/src/lib/famix/model/famix/type.ts +++ b/src/lib/famix/model/famix/type.ts @@ -5,6 +5,7 @@ import { Reference } from "./reference"; import { BehavioralEntity } from "./behavioral_entity"; import { Alias } from "./alias"; import { EntityTyping } from "./entity_typing"; +import { Concretization } from "./concretization"; export class Type extends ContainerEntity { @@ -40,6 +41,14 @@ export class Type extends ContainerEntity { } } + private _outgoingConcretizations: Set = new Set(); + + public addOutgoingConcretization(outgoingConcretization: Concretization): void { + if (!this._outgoingConcretizations.has(outgoingConcretization)) { + this._outgoingConcretizations.add(outgoingConcretization); + } + } + public getJSON(): string { const json: FamixJSONExporter = new FamixJSONExporter("Type", this); this.addPropertiesToExporter(json); @@ -52,6 +61,7 @@ export class Type extends ContainerEntity { /* unsupported properties in MM so far */ // exporter.addProperty("typeAliases", this.getTypeAliases()); exporter.addProperty("incomingReferences", this.incomingReferences); + exporter.addProperty("outgoingConcretizations", this.outgoingConcretizations); } get container() { @@ -78,4 +88,8 @@ export class Type extends ContainerEntity { get incomingReferences() { return this._incomingReferences; } + + get outgoingConcretizations() { + return this._outgoingConcretizations; + } } diff --git a/src/lib/famix/model/famix/type_parameter.ts b/src/lib/famix/model/famix/type_parameter.ts index f5c2ce1a..2636bd5e 100644 --- a/src/lib/famix/model/famix/type_parameter.ts +++ b/src/lib/famix/model/famix/type_parameter.ts @@ -5,12 +5,14 @@ import { ParametricInterface } from "./parametric_interface"; import { ParametricMethod } from "./parametric_method"; import { ParametricFunction } from "./parametric_function"; import { ParametricArrowFunction } from "./parametric_arrow_function"; +import { Concretization } from "./concretization"; export class TypeParameter extends Type { private _genericEntity!: ParametricClass | ParametricInterface | ParametricMethod | ParametricFunction | ParametricArrowFunction; private _baseType!: Type; private _arguments: Set = new Set(); + private _concretizations: Set = new Set(); public addArgument(argument: Type): void { if (!this._arguments.has(argument)) { @@ -18,6 +20,12 @@ export class TypeParameter extends Type { } } + public addConcretization(concretization: Concretization): void { + if (!this._concretizations.has(concretization)) { + this._concretizations.add(concretization); + } + } + public getJSON(): string { const json: FamixJSONExporter = new FamixJSONExporter("TypeParameter", this); this.addPropertiesToExporter(json); @@ -29,6 +37,7 @@ export class TypeParameter extends Type { exporter.addProperty("genericEntity", this.genericEntity); exporter.addProperty("baseType", this.baseType); exporter.addProperty("arguments", this.arguments); + exporter.addProperty("concretizations", this.concretizations); } get genericEntity() { @@ -51,4 +60,8 @@ export class TypeParameter extends Type { get arguments() { return this._arguments; } + + get concretizations() { + return this._concretizations; + } } From fff4d36fbfe720407b5a94dedd359926c7eedd75 Mon Sep 17 00:00:00 2001 From: MTahaCode Date: Tue, 15 Sep 2026 19:10:25 -0400 Subject: [PATCH 03/10] congregated entity typing attributes to superclass, added missing entities relations --- .../famix/model/famix/behavioral_entity.ts | 24 ++++--------------- .../model/famix/parametric_entity_typing.ts | 1 + .../model/famix/parametric_invocation.ts | 1 + 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/lib/famix/model/famix/behavioral_entity.ts b/src/lib/famix/model/famix/behavioral_entity.ts index 560152e3..951df8c1 100644 --- a/src/lib/famix/model/famix/behavioral_entity.ts +++ b/src/lib/famix/model/famix/behavioral_entity.ts @@ -2,8 +2,8 @@ import { FamixJSONExporter } from "../../famix_JSON_exporter"; import { ContainerEntity } from "./container_entity"; import { Parameter } from "./parameter"; import { Invocation } from "./invocation"; -import { TypeParameter } from "./type_parameter"; import { EntityTyping } from "./entity_typing"; +import { ParametricEntityTyping } from "./parametric_entity_typing"; export class BehavioralEntity extends ContainerEntity { @@ -27,19 +27,7 @@ export class BehavioralEntity extends ContainerEntity { } } - private _typing!: EntityTyping; - private _genericParameters: Set = new Set(); - - public addGenericParameter(genericParameter: TypeParameter): void { - if (!this._genericParameters.has(genericParameter)) { - this._genericParameters.add(genericParameter); - genericParameter.parentGeneric = this; - } - } - - clearGenericParameters(): void { - this._genericParameters.clear(); - } + private _typing!: EntityTyping | ParametricEntityTyping; public getJSON(): string { const json: FamixJSONExporter = new FamixJSONExporter("BehavioralEntity", this); @@ -79,15 +67,11 @@ export class BehavioralEntity extends ContainerEntity { return this._incomingInvocations; } - get typing(): EntityTyping { + get typing(): EntityTyping | ParametricEntityTyping { return this._typing; } - set typing(typing: EntityTyping) { + set typing(typing: EntityTyping | ParametricEntityTyping) { this._typing = typing; } - - get genericParameters(): Set { - return this._genericParameters; - } } diff --git a/src/lib/famix/model/famix/parametric_entity_typing.ts b/src/lib/famix/model/famix/parametric_entity_typing.ts index 932aecb2..fd73bb52 100644 --- a/src/lib/famix/model/famix/parametric_entity_typing.ts +++ b/src/lib/famix/model/famix/parametric_entity_typing.ts @@ -27,5 +27,6 @@ export class ParametricEntityTyping extends EntityTyping { public addPropertiesToExporter(exporter: FamixJSONExporter): void { super.addPropertiesToExporter(exporter); + exporter.addProperty("concretizations", this.concretizations); } } diff --git a/src/lib/famix/model/famix/parametric_invocation.ts b/src/lib/famix/model/famix/parametric_invocation.ts index bf505986..03db9db1 100644 --- a/src/lib/famix/model/famix/parametric_invocation.ts +++ b/src/lib/famix/model/famix/parametric_invocation.ts @@ -8,6 +8,7 @@ export class ParametricInvocation extends Invocation { public addConcretization(concretization: Concretization): void { if (!this._concretizations.has(concretization)) { this._concretizations.add(concretization); + concretization.triggeringAssociation = this; } } From c2a18f0f2f928e0ca6b7cac49f6c6b5c2ab8f2c7 Mon Sep 17 00:00:00 2001 From: MTahaCode Date: Wed, 16 Sep 2026 01:30:36 -0400 Subject: [PATCH 04/10] updated recursive loop to incorporate the new famix models --- src/analyze_functions/process_functions.ts | 12 +- src/famix_functions/EntityDictionary.ts | 380 ++++++++++----------- 2 files changed, 182 insertions(+), 210 deletions(-) diff --git a/src/analyze_functions/process_functions.ts b/src/analyze_functions/process_functions.ts index 3f43390e..a878b33b 100644 --- a/src/analyze_functions/process_functions.ts +++ b/src/analyze_functions/process_functions.ts @@ -459,7 +459,9 @@ function processMethod(m: MethodDeclaration | ConstructorDeclaration | MethodSig processComments(m, fmxMethod); - processTypeParameters(m, fmxMethod); + if (fmxMethod instanceof Famix.ParametricMethod) { + processTypeParameters(m, fmxMethod); + } processParameters(m, fmxMethod); @@ -504,7 +506,9 @@ function processFunction(f: FunctionDeclaration | FunctionExpression | ArrowFunc processAliases(f, fmxFunction); - processTypeParameters(f, fmxFunction); + if (fmxFunction instanceof Famix.ParametricFunction || fmxFunction instanceof Famix.ParametricArrowFunction) { + processTypeParameters(f, fmxFunction); + } processParameters(f, fmxFunction); @@ -651,7 +655,7 @@ function processParameter(paramDecl: ParameterDeclaration): Famix.Parameter { function processTypeParameters( e: ClassDeclaration | InterfaceDeclaration | MethodDeclaration | ConstructorDeclaration | MethodSignature | GetAccessorDeclaration | SetAccessorDeclaration | FunctionDeclaration | FunctionExpression | ArrowFunction, - fmxScope: Famix.ParametricClass | Famix.ParametricInterface | Famix.Method | Famix.Accessor | Famix.Function | Famix.ArrowFunction + fmxScope: Famix.ParametricClass | Famix.ParametricInterface | Famix.ParametricMethod | Famix.ParametricFunction | Famix.ParametricArrowFunction ): void { logger.debug(`Finding Type Parameters:`); const nodeStart = e.getStart(); @@ -667,7 +671,7 @@ function processTypeParameters( // Process each type parameter typeParams.forEach((tp) => { const fmxParam = processTypeParameter(tp); - fmxScope.addGenericParameter(fmxParam); + fmxScope.addTypeParameter(fmxParam); }); // Log if no type parameters were found diff --git a/src/famix_functions/EntityDictionary.ts b/src/famix_functions/EntityDictionary.ts index c2af2acb..f2f53e08 100644 --- a/src/famix_functions/EntityDictionary.ts +++ b/src/famix_functions/EntityDictionary.ts @@ -22,10 +22,6 @@ export type TSMorphTypeDeclaration = TypeAliasDeclaration | PropertyDeclaration export type TSMorphParametricType = ClassDeclaration | InterfaceDeclaration | FunctionDeclaration | MethodDeclaration | ArrowFunction; -type ParametricVariantType = Famix.ParametricClass | Famix.ParametricInterface | Famix.ParametricFunction | Famix.ParametricMethod; - -type ConcreteElementTSMorphType = ClassDeclaration | InterfaceDeclaration | FunctionDeclaration | MethodDeclaration; - export type InvocableType = MethodDeclaration | ConstructorDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | FunctionDeclaration | FunctionExpression | ArrowFunction; export class EntityDictionary { @@ -418,70 +414,6 @@ export class EntityDictionary { } - /** - * Creates or gets a Famix concrete element - * @param concreteElement A parametric Element - * @param concreteElementDeclaration the element declaration - * @param concreteArguments concrete arguments - * @returns A parametric Element - */ - public createOrGetFamixConcreteElement(concreteElement : ParametricVariantType, - concreteElementDeclaration : ConcreteElementTSMorphType, - concreteArguments: TypeNode[]): ParametricVariantType { - - let fullyQualifiedFilename = concreteElement.fullyQualifiedName; - let params = ""; - - concreteArguments.map((param) => { - params = params+param.getText()+','; - }); - - params = params.substring(0, params.length - 1); - - fullyQualifiedFilename = Helpers.replaceLastBetweenTags(fullyQualifiedFilename,params); - - let concElement: ParametricVariantType; - - if (!this.fmxInterfaceMap.has(fullyQualifiedFilename) && - !this.fmxClassMap.has(fullyQualifiedFilename) && - !this.fmxFunctionAndMethodMap.has(fullyQualifiedFilename)){ - concElement = _.cloneDeep(concreteElement); - concElement.fullyQualifiedName = fullyQualifiedFilename; - concElement.clearGenericParameters(); - concreteArguments.map((param) => { - if (param instanceof TypeParameterDeclaration) { - const parameter = this.createOrGetFamixType(param.getText(),param.getType(), param); - concElement.addConcreteParameter(parameter); - } else { - logger.warn(`> WARNING: concrete argument ${param.getText()} is not a TypeParameterDeclaration. It is a ${param.getKindName()}.`); - } - }); - - if (concreteElement instanceof Famix.ParametricClass) { - this.fmxClassMap.set(fullyQualifiedFilename, concElement as Famix.ParametricClass); - } else if (concreteElement instanceof Famix.ParametricInterface) { - this.fmxInterfaceMap.set(fullyQualifiedFilename, concElement as Famix.ParametricInterface); - } else if (concreteElement instanceof Famix.ParametricFunction) { - this.fmxFunctionAndMethodMap.set(fullyQualifiedFilename, concElement as Famix.ParametricFunction); - } else { // if (concreteElement instanceof Famix.ParametricMethod) { - this.fmxFunctionAndMethodMap.set(fullyQualifiedFilename, concElement as Famix.ParametricMethod); - } - this.famixRep.addElement(concElement); - this.fmxElementObjectMap.set(concElement,concreteElementDeclaration); - } else { - if (concreteElement instanceof Famix.ParametricClass) { - concElement = this.fmxClassMap.get(fullyQualifiedFilename) as Famix.ParametricClass; - } else if (concreteElement instanceof Famix.ParametricInterface) { - concElement = this.fmxInterfaceMap.get(fullyQualifiedFilename) as Famix.ParametricInterface; - } else if (concreteElement instanceof Famix.ParametricFunction) { - concElement = this.fmxFunctionAndMethodMap.get(fullyQualifiedFilename) as Famix.ParametricFunction; - } else { // if (concreteElement instanceof Famix.ParametricMethod) { - concElement = this.fmxFunctionAndMethodMap.get(fullyQualifiedFilename) as Famix.ParametricMethod; - } - } - return concElement; - } - /** * Creates a Famix property * @param property A property @@ -1633,76 +1565,54 @@ export class EntityDictionary { } /** - * Creates a Famix concretization - * @param cls A class - * @returns The Famix model of the concretization - */ - public createFamixConcretization(conEntity : Famix.ParametricClass | Famix.ParametricInterface | Famix.ParametricFunction | Famix.ParametricMethod ,genEntity : Famix.ParametricClass | Famix.ParametricInterface | Famix.ParametricFunction | Famix.ParametricMethod): Famix.Concretization { - - const fmxConcretization : Famix.Concretization = new Famix.Concretization(); - - fmxConcretization.concreteEntity = conEntity; - fmxConcretization.genericEntity = genEntity; - // this.fmxElementObjectMap.set(fmxConcretization,null); - this.famixRep.addElement(fmxConcretization); - // const parameterConcretization = this.createFamixParameterConcretization(fmxConcretization); - - return fmxConcretization; - } - - /** - * Creates a Famix concretization - * @param concretization A FamixConcretization - * @returns The Famix model of the ParameterConcrestisation + * Creates a Famix concretization for each type parameter of a generic entity that is substituted by a concrete type argument + * @param genEntity The generic entity whose type parameters are being concretized + * @param typeArguments The concrete type arguments, in the same order as genEntity's type parameters + * @param triggeringAssociation The parametric association (typing, invocation, inheritance or reference) that caused this concretization + * @returns The Famix models of the concretizations created, one per type parameter / type argument pair */ - public createFamixParameterConcretization(concretization: Famix.Concretization): Famix.ParameterConcretization | undefined{ - const conClass = concretization.concreteEntity; - const genClass = concretization.genericEntity; - logger.debug(`Creating parameter concretization between ${conClass.fullyQualifiedName} and ${genClass.fullyQualifiedName}`); - const parameterConcretizations = this.famixRep._getAllEntitiesWithType("ParameterConcretization") as Set; - const concreteParameters = conClass.concreteParameters; - const genericParameters = genClass.genericParameters; - - const conClassTypeParametersIterator = concreteParameters.values(); - const genClassTypeParametersIterator = genericParameters.values(); - let fmxParameterConcretization : Famix.ParameterConcretization | undefined = undefined; - - for (let i = 0; i < genericParameters.size; i++) { - const conClassTypeParameter = conClassTypeParametersIterator.next().value as Famix.TypeParameter; - const genClassTypeParameter = genClassTypeParametersIterator.next().value as Famix.TypeParameter; - let createParameterConcretization : boolean = true; - if(conClassTypeParameter && genClassTypeParameter && conClassTypeParameter.name != genClassTypeParameter.name){ - parameterConcretizations.forEach((param : Famix.ParameterConcretization) => { - if (conClassTypeParameter.name == param.concreteParameter.name && genClassTypeParameter.name == param.genericParameter.name) { - createParameterConcretization = false; - fmxParameterConcretization = param; - } - }); - if (createParameterConcretization) { - fmxParameterConcretization = new Famix.ParameterConcretization(); - fmxParameterConcretization.genericParameter = genClassTypeParameter; - fmxParameterConcretization.concreteParameter = conClassTypeParameter; - fmxParameterConcretization.addConcretization(concretization); - // this.fmxElementObjectMap.set(fmxParameterConcretization,null); - } else { - if (!fmxParameterConcretization) { - throw new Error(`fmxParameterConcretization was undefined for concretization with generic parameter ${genClassTypeParameter.name} and concrete parameter ${conClassTypeParameter.name}`); - } - fmxParameterConcretization.addConcretization(concretization); - } - this.famixRep.addElement(fmxParameterConcretization); + public createFamixConcretization( + genEntity: Famix.ParametricClass | Famix.ParametricInterface | Famix.ParametricFunction | Famix.ParametricMethod | Famix.ParametricArrowFunction, + typeArguments: TypeNode[], + triggeringAssociation: Famix.ParametricEntityTyping | Famix.ParametricInvocation | Famix.ParametricInheritance | Famix.ParametricReference + ): Famix.Concretization[] { + + const typeParameters = Array.from(genEntity.typeParameters); + const fmxConcretizations: Famix.Concretization[] = []; + + typeParameters.forEach((typeParameter, i) => { + const typeArgumentNode = typeArguments[i]; + if (!typeArgumentNode) { + return; } - } - if (!fmxParameterConcretization) { - logger.error(`fmxParameterConcretization was undefined for concretization with concrete entity ${conClass.fullyQualifiedName} and generic entity ${genClass.fullyQualifiedName}`); - } - return fmxParameterConcretization; + const fmxTypeArgument = this.createOrGetFamixType( + typeArgumentNode.getText(), + typeArgumentNode.getType(), + typeArgumentNode as unknown as TSMorphTypeDeclaration + ); + + const fmxConcretization: Famix.Concretization = new Famix.Concretization(); + fmxConcretization.typeParameter = typeParameter; + fmxConcretization.typeArgument = fmxTypeArgument; + triggeringAssociation.addConcretization(fmxConcretization); + + this.famixRep.addElement(fmxConcretization); + fmxConcretizations.push(fmxConcretization); + }); + + return fmxConcretizations; } /** - * Creates a Famix concretization between two classes or two interfaces - * @param element A class or an Interface + * @param element The subclass or subinterface declaration whose `extends` clause is inspected + * @example + * ```ts + * class Box {} + * class StringBox extends Box {} + * // -> ParametricInheritance(subclass: StringBox, superclass: Box) + * // Concretization(typeParameter: T, typeArgument: string) + * ``` */ public createFamixConcretizationClassOrInterfaceSpecialisation(element: ClassDeclaration | InterfaceDeclaration){ @@ -1734,34 +1644,43 @@ export class EntityDictionary { EntityDeclaration = entity.getExpression().getSymbol()?.getDeclarations()[0] as InterfaceDeclaration; genEntity = this.createOrGetFamixInterface(EntityDeclaration) as Famix.ParametricInterface; } + // might need rework for e.g: class A extends B implements C {} or for interface having multiple inheritances const genParams = EntityDeclaration.getTypeParameters().map((param) => param.getText()); const args = element.getHeritageClauses()[0].getTypeNodes()[0].getTypeArguments(); const conParams = element.getHeritageClauses()[0].getTypeNodes()[0].getTypeArguments().map((param) => param.getText()); - if (!Helpers.arraysAreEqual(conParams,genParams)) { - const conEntity = this.createOrGetFamixConcreteElement(genEntity,EntityDeclaration,args); - const concretizations = this.famixRep._getAllEntitiesWithType("Concretization") as Set; - let createConcretization : boolean = true; - concretizations.forEach((conc : Famix.Concretization) => { - if (genEntity.fullyQualifiedName == conc.genericEntity.fullyQualifiedName && conc.concreteEntity.fullyQualifiedName == conEntity.fullyQualifiedName){ - createConcretization = false; - } - }); - - if (createConcretization) { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const fmxConcretization : Famix.Concretization = this.createFamixConcretization(conEntity,genEntity); - } + if (!Helpers.arraysAreEqual(conParams,genParams)) { //checks if any of the type parameters (e.g ) are substituted by a concrete type (e.g ) + const subEntity = element instanceof ClassDeclaration + ? this.createOrGetFamixClass(element) + : this.createOrGetFamixInterface(element); + + const fmxParametricInheritance = new Famix.ParametricInheritance(); + fmxParametricInheritance.subclass = subEntity; + fmxParametricInheritance.superclass = genEntity; + this.famixRep.addElement(fmxParametricInheritance); + + this.createFamixConcretization(genEntity, args, fmxParametricInheritance); } } }); } - // TODO: This function seems unfinished - } + // TODO: This function seems unfinished for multiple inheritances + } /** - * Creates a Famix concretization between a class and its instanciations - * @param cls A class + * @param cls The generic class declaration whose constructor call sites are inspected + * @example + * ```ts + * class Box { + * constructor(public value: T) {} + * } + * + * function makeBox() { + * return new Box("hi"); + * } + * // -> ParametricInvocation(sender: makeBox, receiver: Box, candidates: [Box.constructor]) + * // Concretization(typeParameter: T, typeArgument: string) + * ``` */ public createFamixConcretizationGenericInstantiation(cls: ClassDeclaration){ @@ -1780,19 +1699,32 @@ export class EntityDictionary { const genEntity = this.createOrGetFamixClass(cls) as Famix.ParametricClass; const genParams = cls.getTypeParameters().map((param) => param.getText()); if (!Helpers.arraysAreEqual(conParams,genParams)) { - const conEntity = this.createOrGetFamixConcreteElement(genEntity,cls,instance.getTypeArguments()); - const concretizations = this.famixRep._getAllEntitiesWithType("Concretization") as Set; - let createConcretization : boolean = true; - concretizations.forEach((conc : Famix.Concretization) => { - if (genEntity.fullyQualifiedName == conc.genericEntity.fullyQualifiedName && conc.concreteEntity.fullyQualifiedName == conEntity.fullyQualifiedName){ - createConcretization = false; + const args = instance.getTypeArguments(); + + const containerOfNode = Helpers.findAncestor(instance.getExpression() as Identifier); + const containerFQN = FQNFunctions.getFQN(containerOfNode); + let sender = this.famixRep.getFamixEntityByFullyQualifiedName(containerFQN) as Famix.ContainerEntity; + if (sender instanceof Famix.Type) {//if accidently resolving to a type instead of a container + const senderContainer = sender.container; + if (senderContainer) { + sender = senderContainer; } - }); - - if (createConcretization) { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const fmxConcretization : Famix.Concretization = this.createFamixConcretization(conEntity,genEntity); } + + const fmxParametricInvocation = new Famix.ParametricInvocation(); + fmxParametricInvocation.sender = sender; + fmxParametricInvocation.receiver = genEntity; + + const constructorDeclaration = cls.getConstructors()[0]; + if (constructorDeclaration) { + const fmxConstructor = this.createOrGetFamixMethod(constructorDeclaration, {}); + fmxParametricInvocation.addCandidate(fmxConstructor); + fmxParametricInvocation.signature = fmxConstructor.signature; + } + + this.famixRep.addElement(fmxParametricInvocation); + + this.createFamixConcretization(genEntity, args, fmxParametricInvocation); } } }); @@ -1801,14 +1733,25 @@ export class EntityDictionary { } /** - * Creates a Famix concretization between a class and its instanciations - * @param func A function + * @param element The generic function or method declaration whose call sites are inspected + * @example + * ```ts + * function identity(value: T): T { + * return value; + * } + * + * function caller() { + * return identity(42); + * } + * // -> ParametricInvocation(sender: caller, receiver: , candidates: [identity]) + * // Concretization(typeParameter: T, typeArgument: number) + * ``` */ public createFamixConcretizationFunctionInstantiation(element: FunctionDeclaration | MethodDeclaration){ const isGeneric = element.getTypeParameters().length > 0; if (isGeneric) { const genParams = element.getTypeParameters().map(param => param.getText()); - const uses = element.findReferencesAsNodes(); + const uses = element.findReferencesAsNodes() as Array; uses.forEach(usage => { let currentNode: TsMorphNode | undefined = usage; @@ -1829,19 +1772,28 @@ export class EntityDictionary { } else { genElement = this.createOrGetFamixMethod(element, {}) as Famix.ParametricMethod; } - const concElement = this.createOrGetFamixConcreteElement(genElement,element,args); - const concretizations = this.famixRep._getAllEntitiesWithType("Concretization") as Set; - let createConcretization : boolean = true; - concretizations.forEach((conc : Famix.Concretization) => { - if (genElement.fullyQualifiedName == conc.genericEntity.fullyQualifiedName && conc.concreteEntity.fullyQualifiedName == concElement.fullyQualifiedName){ - createConcretization = false; + + const containerOfNode = Helpers.findAncestor(usage); + const containerFQN = FQNFunctions.getFQN(containerOfNode); + let sender = this.famixRep.getFamixEntityByFullyQualifiedName(containerFQN) as Famix.ContainerEntity; + if (sender instanceof Famix.Type) { + const senderContainer = sender.container; + if (senderContainer) { + sender = senderContainer; } - }); - - if (createConcretization) { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const fmxConcretization : Famix.Concretization = this.createFamixConcretization(concElement,genElement); } + + const receiverFullyQualifiedName = FQNFunctions.getFQN(element.getParent()); + const receiver = this.famixRep.getFamixEntityByFullyQualifiedName(receiverFullyQualifiedName) as Famix.NamedEntity; + + const fmxParametricInvocation = new Famix.ParametricInvocation(); + fmxParametricInvocation.sender = sender; + fmxParametricInvocation.receiver = receiver; + fmxParametricInvocation.addCandidate(genElement); + fmxParametricInvocation.signature = genElement.signature; + this.famixRep.addElement(fmxParametricInvocation); + + this.createFamixConcretization(genElement, args, fmxParametricInvocation); } } break; @@ -1854,8 +1806,19 @@ export class EntityDictionary { } /** - * Creates a Famix concretization between a class and an interface - * @param cls A class + * @param cls The implementing class declaration whose `implements` clause is inspected + * @example + * ```ts + * interface Comparable { + * compareTo(other: T): number; + * } + * + * class Money implements Comparable { + * compareTo(other: Money): number { return 0; } + * } + * // -> ParametricInheritance(subclass: Money, superclass: Comparable) + * // Concretization(typeParameter: T, typeArgument: Money) + * ``` */ public createFamixConcretizationInterfaceClass(cls: ClassDeclaration){ @@ -1869,28 +1832,33 @@ export class EntityDictionary { const args = cls.getHeritageClauses()[0].getTypeNodes()[0].getTypeArguments(); if (!Helpers.arraysAreEqual(conParams,genParams)) { const genInterface = this.createOrGetFamixInterface(interfaceDeclaration) as Famix.ParametricInterface; - const conInterface = this.createOrGetFamixConcreteElement(genInterface,interfaceDeclaration,args); - const concretizations = this.famixRep._getAllEntitiesWithType("Concretization") as Set; - let createConcretization : boolean = true; - concretizations.forEach((conc : Famix.Concretization) => { - if (genInterface.fullyQualifiedName == conc.genericEntity.fullyQualifiedName && conc.concreteEntity.fullyQualifiedName == conInterface.fullyQualifiedName){ - createConcretization = false; - } - }); - - if (createConcretization) { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const fmxConcretization : Famix.Concretization = this.createFamixConcretization(conInterface,genInterface); - } + const conClass = this.createOrGetFamixClass(cls); + + const fmxParametricInheritance = new Famix.ParametricInheritance(); + fmxParametricInheritance.subclass = conClass; + fmxParametricInheritance.superclass = genInterface; + this.famixRep.addElement(fmxParametricInheritance); + + this.createFamixConcretization(genInterface, args, fmxParametricInheritance); } } }); } /** - * Creates a Famix concretization between an interface and a Type - * @param element A variable or a function - * @param inter An interface + * @param element The generic class or interface declaration whose usages as a declared type are inspected + * @example + * ```ts + * interface Repository { + * findById(id: string): T; + * } + * + * class UserService { + * private repo: Repository; + * } + * // -> ParametricEntityTyping(typedEntity: repo, declaredType: Repository) + * // Concretization(typeParameter: T, typeArgument: User) + * ``` */ public createFamixConcretizationTypeInstanciation(element: InterfaceDeclaration | ClassDeclaration) { @@ -1919,18 +1887,19 @@ export class EntityDictionary { } else { genElement = this.createOrGetFamixInterface(element) as Famix.ParametricInterface; } - const concElement = this.createOrGetFamixConcreteElement(genElement, element, args); - const concretizations = this.famixRep._getAllEntitiesWithType("Concretization") as Set; - let createConcretization: boolean = true; - concretizations.forEach((conc: Famix.Concretization) => { - if (genElement.fullyQualifiedName == conc.genericEntity.fullyQualifiedName && conc.concreteEntity.fullyQualifiedName == concElement.fullyQualifiedName) { - createConcretization = false; - } - }); - - if (createConcretization) { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const fmxConcretization: Famix.Concretization = this.createFamixConcretization(concElement, genElement); + const typedEntityNode = typeReferenceNode.getParent(); + const typedEntityFQN = typedEntityNode ? FQNFunctions.getFQN(typedEntityNode) : undefined; + const fmxTypedEntity = typedEntityFQN + ? this.famixRep.getFamixEntityByFullyQualifiedName(typedEntityFQN) as Famix.Entity + : undefined; + + if (fmxTypedEntity) { + const fmxParametricEntityTyping = new Famix.ParametricEntityTyping(); + fmxParametricEntityTyping.typedEntity = fmxTypedEntity; + fmxParametricEntityTyping.declaredType = genElement; + this.famixRep.addElement(fmxParametricEntityTyping); + + this.createFamixConcretization(genElement, args, fmxParametricEntityTyping); } } break; @@ -2045,7 +2014,6 @@ function getInterfaceOrClassDeclarationFromExpression(expression: ExpressionWith } import { Symbol as TSMorphSymbol, Node as TsMorphNode } from "ts-morph"; -import _ from "lodash"; function resolveSymbolToInterfaceOrClassDeclaration(symbol: TSMorphSymbol): InterfaceDeclaration | ClassDeclaration | undefined { // Get the declarations associated with the symbol From c99b52e12c4e65ca375fbb191f7ec18defdb9c4e Mon Sep 17 00:00:00 2001 From: MTahaCode Date: Wed, 16 Sep 2026 02:51:05 -0400 Subject: [PATCH 05/10] updated tests rename from genericParameters to typeParameters as changed in famix api --- test/concreteAndGenericParameter.test.ts | 10 +++++----- test/genericClass.test.ts | 6 +++--- test/genericInterface.test.ts | 4 ++-- test/generics.test.ts | 8 ++++---- test/parametricArrowFunction.test.ts | 2 +- test/parametricMethod.test.ts | 9 +++++---- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/test/concreteAndGenericParameter.test.ts b/test/concreteAndGenericParameter.test.ts index f159df1e..d7228502 100644 --- a/test/concreteAndGenericParameter.test.ts +++ b/test/concreteAndGenericParameter.test.ts @@ -1,5 +1,5 @@ import { Importer, logger } from '../src/analyze'; -import { ParametricClass } from '../src/lib/famix/model/famix'; +import { ParametricClass, TypeParameter } from '../src/lib/famix/model/famix'; import { project, exportProjectSourceFilesForEndtoEndPharoTests } from './testUtils'; const importer = new Importer(); @@ -46,16 +46,16 @@ describe('Tests for concrete and generic parameter', () => { it("should contain a concrete and generic parameter ''", () => { const classA = Array.from(fmxRep._getAllEntitiesWithType("ParametricClass") as Set).find(v => v.name === "ClassA"); expect(classA).toBeTruthy(); - const param = classA?.genericParameters; - const firstParameter = param?.values().next().value as ParametricClass; + const param = classA?.typeParameters; + const firstParameter = param?.values().next().value as TypeParameter; expect(firstParameter?.name).toBe('V'); }); it("should contain a generic parameter 'U'", () => { const classC = Array.from(fmxRep._getAllEntitiesWithType("ParametricClass") as Set).find(v => v.name === "ClassC"); expect(classC).toBeTruthy(); - const param = classC?.genericParameters; - const firstParameter = param?.values().next().value as ParametricClass; + const param = classC?.typeParameters; + const firstParameter = param?.values().next().value as TypeParameter; expect(firstParameter?.name).toBe('U'); }); diff --git a/test/genericClass.test.ts b/test/genericClass.test.ts index c0f57227..27844404 100644 --- a/test/genericClass.test.ts +++ b/test/genericClass.test.ts @@ -32,10 +32,10 @@ describe('Tests for generic class', () => { expect(pList).toBeTruthy(); const MyClass = pList.find(p => p.name === "MyClass"); expect(MyClass).toBeTruthy(); - expect(MyClass?.genericParameters.size).toBe(1); + expect(MyClass?.typeParameters.size).toBe(1); if (MyClass) { - expect((Array.from(MyClass.genericParameters)[0] as TypeParameter).name).toBe("T"); - expect((Array.from(MyClass.genericParameters)[0] as TypeParameter).parentGeneric).toBe(MyClass); + expect((Array.from(MyClass.typeParameters)[0] as TypeParameter).name).toBe("T"); + expect((Array.from(MyClass.typeParameters)[0] as TypeParameter).genericEntity).toBe(MyClass); } }); diff --git a/test/genericInterface.test.ts b/test/genericInterface.test.ts index f6669d39..e34afb79 100644 --- a/test/genericInterface.test.ts +++ b/test/genericInterface.test.ts @@ -35,9 +35,9 @@ describe('Tests for generic interface', () => { expect(pList).toBeTruthy(); const MyInterface = pList.find(p => p.name === "MyInterface"); expect(MyInterface).toBeTruthy(); - expect(MyInterface?.genericParameters.size).toBe(1); + expect(MyInterface?.typeParameters.size).toBe(1); if (MyInterface) { - expect((Array.from(MyInterface.genericParameters)[0] as TypeParameter).name).toBe("T"); + expect((Array.from(MyInterface.typeParameters)[0] as TypeParameter).name).toBe("T"); } }); }); diff --git a/test/generics.test.ts b/test/generics.test.ts index ea5d0f08..b2dd08df 100644 --- a/test/generics.test.ts +++ b/test/generics.test.ts @@ -37,9 +37,9 @@ describe('Generics', () => { expect(pList).toBeTruthy(); const myDao = pList.find(p => p.name === "MyDao"); expect(myDao).toBeTruthy(); - expect(myDao?.genericParameters.size).toBe(1); + expect(myDao?.typeParameters.size).toBe(1); if (myDao) { - expect((Array.from(myDao.genericParameters)[0] as TypeParameter).name).toBe("T"); + expect((Array.from(myDao.typeParameters)[0] as TypeParameter).name).toBe("T"); } }); @@ -48,9 +48,9 @@ describe('Generics', () => { expect(pList).toBeTruthy(); const myDaoInterface = pList.find(p => p.name === "MyDaoInterface"); expect(myDaoInterface).toBeTruthy(); - expect(myDaoInterface?.genericParameters.size).toBe(1); + expect(myDaoInterface?.typeParameters.size).toBe(1); if (myDaoInterface) { - expect((Array.from(myDaoInterface.genericParameters)[0] as TypeParameter).name).toBe("T"); + expect((Array.from(myDaoInterface.typeParameters)[0] as TypeParameter).name).toBe("T"); } }); diff --git a/test/parametricArrowFunction.test.ts b/test/parametricArrowFunction.test.ts index 24b35731..6770f285 100644 --- a/test/parametricArrowFunction.test.ts +++ b/test/parametricArrowFunction.test.ts @@ -42,7 +42,7 @@ describe('ArrowFunctions', () => { }); it("should contain a type parameter T", () => { - const typeParameter = theFunction?.genericParameters.values().next().value as TypeParameter; + const typeParameter = theFunction?.typeParameters.values().next().value as TypeParameter; expect(typeParameter.name).toBe('T'); }); diff --git a/test/parametricMethod.test.ts b/test/parametricMethod.test.ts index 64475bb0..914da9e3 100644 --- a/test/parametricMethod.test.ts +++ b/test/parametricMethod.test.ts @@ -1,6 +1,7 @@ import { Importer } from '../src/analyze'; import { ParametricClass } from "../src/lib/famix/model/famix/parametric_class"; import { ParametricMethod } from "../src/lib/famix/model/famix/parametric_method"; +import { TypeParameter } from "../src/lib/famix/model/famix/type_parameter"; import { project, exportProjectSourceFilesForEndtoEndPharoTests } from './testUtils'; const importer = new Importer(); @@ -40,8 +41,8 @@ describe('Tests for generics', () => { const pcList = Array.from(fmxRep._getAllEntitiesWithType("ParametricClass") as Set); expect(pcList).toBeTruthy(); const parametricClass = pcList.find(c => c.name === "ClassParametric"); - const typeParameters = parametricClass?.genericParameters; - expect(typeParameters?.values().next().value.name).toBe('T'); + const typeParameters = parametricClass?.typeParameters; + expect(typeParameters?.values().next()?.value?.name).toBe('T'); }); const theClass = fmxRep._getFamixClass("{parametricMethod.ts}.ClassParametric[ClassDeclaration]"); @@ -73,8 +74,8 @@ describe('Tests for generics', () => { const pmList = Array.from(fmxRep._getAllEntitiesWithType("ParametricMethod") as Set); expect(pmList).toBeTruthy(); const parametricMethod = pmList.find(m => m.name === "methodParametric"); - const typeParameters = parametricMethod?.genericParameters; - expect(typeParameters?.values().next().value.name).toBe('V'); + const typeParameters = parametricMethod?.typeParameters; + expect(typeParameters?.values().next()?.value?.name).toBe('V'); }); }); From 65711d26bce6af4d5a4446d048a42ee59f3e871a Mon Sep 17 00:00:00 2001 From: MTahaCode Date: Fri, 25 Sep 2026 15:46:06 -0400 Subject: [PATCH 06/10] parametric entity typing updated to use new concretization structure --- src/famix_functions/EntityDictionary.ts | 84 ++++++++++++++++++---- src/lib/famix/model/famix/entity_typing.ts | 8 ++- 2 files changed, 75 insertions(+), 17 deletions(-) diff --git a/src/famix_functions/EntityDictionary.ts b/src/famix_functions/EntityDictionary.ts index f2f53e08..93876d69 100644 --- a/src/famix_functions/EntityDictionary.ts +++ b/src/famix_functions/EntityDictionary.ts @@ -5,7 +5,7 @@ */ -import { ClassDeclaration, ConstructorDeclaration, FunctionDeclaration, Identifier, InterfaceDeclaration, MethodDeclaration, MethodSignature, ModuleDeclaration, PropertyDeclaration, PropertySignature, SourceFile, TypeParameterDeclaration, VariableDeclaration, ParameterDeclaration, Decorator, GetAccessorDeclaration, SetAccessorDeclaration, ImportSpecifier, CommentRange, EnumDeclaration, EnumMember, TypeAliasDeclaration, FunctionExpression, ImportDeclaration, ImportEqualsDeclaration, SyntaxKind, Expression, TypeNode, Scope, ArrowFunction, ExpressionWithTypeArguments, HeritageClause, ts, Type } from "ts-morph"; +import { Node, ClassDeclaration, ConstructorDeclaration, FunctionDeclaration, Identifier, InterfaceDeclaration, MethodDeclaration, MethodSignature, ModuleDeclaration, PropertyDeclaration, PropertySignature, SourceFile, TypeParameterDeclaration, VariableDeclaration, ParameterDeclaration, Decorator, GetAccessorDeclaration, SetAccessorDeclaration, ImportSpecifier, CommentRange, EnumDeclaration, EnumMember, TypeAliasDeclaration, FunctionExpression, ImportDeclaration, ImportEqualsDeclaration, SyntaxKind, Expression, TypeNode, Scope, ArrowFunction, ExpressionWithTypeArguments, HeritageClause, ts, Type } from "ts-morph"; import { isAmbient, isNamespace } from "../analyze_functions/process_functions"; import * as Famix from "../lib/famix/model/famix"; import { FamixRepository } from "../lib/famix/famix_repository"; @@ -24,6 +24,7 @@ export type TSMorphParametricType = ClassDeclaration | InterfaceDeclaration | Fu export type InvocableType = MethodDeclaration | ConstructorDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | FunctionDeclaration | FunctionExpression | ArrowFunction; +export type TypeParameteredNode = PropertyDeclaration | PropertySignature; export class EntityDictionary { public famixRep = new FamixRepository(); @@ -40,10 +41,11 @@ export class EntityDictionary { private fmxVariableMap = new Map(); // Maps the variables to their Famix model private fmxImportClauseMap = new Map(); // Maps the import clauses to their Famix model private fmxEnumMap = new Map(); // Maps the enum names to their Famix model + private fmxTypeParameterMap = new Map(); // Maps the type parameter declarations to their Famix model private fmxInheritanceMap = new Map(); // Maps the inheritance names to their Famix model private UNKNOWN_VALUE = '(unknown due to parsing error)'; // The value to use when a name is not usable public fmxElementObjectMap = new Map(); - public tsMorphElementObjectMap = new Map(); + public tsMorphElementObjectMap = new Map(); public fmxEntityTypingMap = new Map(); constructor() { @@ -66,6 +68,7 @@ export class EntityDictionary { this.fmxVariableMap = new Map(); this.fmxImportClauseMap = new Map(); this.fmxEnumMap = new Map(); + this.fmxTypeParameterMap = new Map(); this.fmxInheritanceMap = new Map(); this.famixRep.setFmxElementObjectMap(this.fmxElementObjectMap); } @@ -547,7 +550,7 @@ export class EntityDictionary { logger.error(`Failed to get return type for ${fqn}: ${error}`); } - const fmxType = this.createOrGetFamixType(methodTypeName, method.getType(), method); + const fmxType = this.createOrGetFamixType(methodTypeName, method.getReturnType(), method); // console.log(`Created/retrieved return type with FQN: ${fmxType.fullyQualifiedName}`); fmxMethod.numberOfLinesOfCode = method.getEndLineNumber() - method.getStartLineNumber(); fmxMethod.numberOfParameters = method.getParameters().length; @@ -558,7 +561,7 @@ export class EntityDictionary { this.famixRep.addElement(fmxMethod); this.makeFamixIndexFileAnchor(method, fmxMethod); - this.createOrGetFamixEntityTyping(fmxMethod, fmxType); + this.createOrGetFamixEntityTyping(fmxMethod, fmxType, method); this.fmxFunctionAndMethodMap.set(fqn, fmxMethod); logger.debug(`Added method ${fqn} to famixRep`); @@ -608,14 +611,14 @@ export class EntityDictionary { logger.error(`> WARNING: got exception ${error}. Failed to get usable name for return type of function: ${func.getName()}. Continuing...`); } - const fmxType = this.createOrGetFamixType(functionTypeName, func.getType(), func); + const fmxType = this.createOrGetFamixType(functionTypeName, func.getReturnType(), func); fmxFunction.numberOfLinesOfCode = func.getEndLineNumber() - func.getStartLineNumber(); const parameters = func.getParameters(); fmxFunction.numberOfParameters = parameters.length; fmxFunction.numberOfStatements = func.getStatements().length; this.makeFamixIndexFileAnchor(func, fmxFunction); - this.createOrGetFamixEntityTyping(fmxFunction, fmxType); + this.createOrGetFamixEntityTyping(fmxFunction, fmxType, func); this.famixRep.addElement(fmxFunction); @@ -677,8 +680,13 @@ export class EntityDictionary { * @returns The Famix model of the type parameter */ public createFamixTypeParameter(tp: TypeParameterDeclaration): Famix.TypeParameter { - + const foundTypeParameter = this.fmxTypeParameterMap.get(tp); + if (foundTypeParameter) { + return foundTypeParameter; + } + const fmxTypeParameter = new Famix.TypeParameter(); + this.fmxTypeParameterMap.set(tp, fmxTypeParameter); fmxTypeParameter.name = tp.getName(); initFQN(tp, fmxTypeParameter); @@ -819,7 +827,7 @@ export class EntityDictionary { return fmxVariable; } - public createOrGetFamixEntityTyping(entity: Famix.BehavioralEntity | Famix.StructuralEntity, type: Famix.Type): Famix.EntityTyping { + public createOrGetFamixEntityTyping(entity: Famix.BehavioralEntity | Famix.StructuralEntity, type: Famix.Type, tsMorphElement: Node | undefined = undefined): Famix.EntityTyping { if (this.fmxEntityTypingMap.has(entity)) { const rEntityTyping = this.fmxEntityTypingMap.get(entity); if (rEntityTyping) { @@ -831,11 +839,36 @@ export class EntityDictionary { let fmxEntityTyping: Famix.EntityTyping | Famix.ParametricEntityTyping = new Famix.EntityTyping(); - if (entity instanceof Famix.ParametricArrowFunction - || entity instanceof Famix.ParametricFunction - || entity instanceof Famix.ParametricMethod - ) { - fmxEntityTyping = new Famix.ParametricEntityTyping(); + if (tsMorphElement && (TypeNode.isFunctionDeclaration(tsMorphElement) || TypeNode.isMethodDeclaration(tsMorphElement) || TypeNode.isArrowFunction(tsMorphElement))) { + const isParameterized = tsMorphElement.getTypeParameters().length > 0; + if (isParameterized) { + + + fmxEntityTyping = new Famix.ParametricEntityTyping(); + + const calls = tsMorphElement + .getSourceFile() + .getDescendantsOfKind(ts.SyntaxKind.CallExpression) + .filter(call => { + const expression = call.getExpression(); + if (!TypeNode.isArrowFunction(tsMorphElement)) { + return expression.getText() === tsMorphElement.getName(); + } + return expression.getText() === this.createOrGetFamixArrowFunction(tsMorphElement, {}).name; //arrow function names are generated + }); + + calls.forEach(call => { + const args = call.getTypeArguments(); + + if (args.length > 0) { + this.createFamixConcretization( + entity as Famix.ParametricFunction, + args, + fmxEntityTyping as Famix.ParametricEntityTyping + ); + } + }); + } } fmxEntityTyping.typedEntity = entity; @@ -970,6 +1003,27 @@ export class EntityDictionary { return this.createOrGetFamixPrimitiveType(typeName); } + // if the type refers to a declared class, interface or enum, use that entity instead of creating a new type + if (tsMorphType && !tsMorphType.isAnonymous()) { // skip `typeof Foo`, object literals + const decl = (tsMorphType.getTargetType() ?? tsMorphType) // List -> List + .getSymbol()?.getDeclarations()[0]; + + if (decl && !decl.getSourceFile().isInNodeModules() && !decl.getSourceFile().isFromExternalLibrary()) { + if (TypeNode.isInterfaceDeclaration(decl)) { + return this.createOrGetFamixInterface(decl); + } + if (TypeNode.isClassDeclaration(decl)) { + return this.createOrGetFamixClass(decl); + } + if (TypeNode.isEnumDeclaration(decl)) { + return this.createOrGetFamixEnum(decl); + } + if (TypeNode.isTypeParameterDeclaration(decl)) { + return this.createFamixTypeParameter(decl); + } + } + } + if (element.isKind(SyntaxKind.MethodSignature) || element.isKind(SyntaxKind.MethodDeclaration)) { const methodFQN = FQNFunctions.getFQN(element); const returnTypeFQN = `${methodFQN.replace(/\[Method(Signature|Declaration)\]$/, '')}[ReturnType]`; @@ -1552,7 +1606,7 @@ export class EntityDictionary { initFQN(arrowExpression as unknown as TSMorphObjectType, fmxArrowFunction); this.makeFamixIndexFileAnchor(arrowExpression as unknown as TSMorphObjectType, fmxArrowFunction); - this.createOrGetFamixEntityTyping(fmxArrowFunction, fmxType); + this.createOrGetFamixEntityTyping(fmxArrowFunction, fmxType, arrowExpression); this.famixRep.addElement(fmxArrowFunction); this.fmxElementObjectMap.set(fmxArrowFunction,arrowFunction as unknown as TSMorphObjectType); @@ -1890,7 +1944,7 @@ export class EntityDictionary { const typedEntityNode = typeReferenceNode.getParent(); const typedEntityFQN = typedEntityNode ? FQNFunctions.getFQN(typedEntityNode) : undefined; const fmxTypedEntity = typedEntityFQN - ? this.famixRep.getFamixEntityByFullyQualifiedName(typedEntityFQN) as Famix.Entity + ? this.famixRep.getFamixEntityByFullyQualifiedName(typedEntityFQN) as Famix.BehavioralEntity | Famix.StructuralEntity : undefined; if (fmxTypedEntity) { diff --git a/src/lib/famix/model/famix/entity_typing.ts b/src/lib/famix/model/famix/entity_typing.ts index 94dcce28..4c4ecfa3 100644 --- a/src/lib/famix/model/famix/entity_typing.ts +++ b/src/lib/famix/model/famix/entity_typing.ts @@ -1,10 +1,14 @@ import { FamixJSONExporter } from "../../famix_JSON_exporter"; +import { BehavioralEntity } from "./behavioral_entity"; import { Entity } from "./entity"; +import { StructuralEntity } from "./structural_entity"; import { Type } from "./type"; +type TypedEntity = StructuralEntity | BehavioralEntity; + export class EntityTyping extends Entity { - private _typedEntity!: Entity; + private _typedEntity!: TypedEntity; private _declaredType!: Type; public getJSON(): string { @@ -23,7 +27,7 @@ export class EntityTyping extends Entity { return this._typedEntity; } - set typedEntity(typedEntity: Entity) { + set typedEntity(typedEntity: TypedEntity) { this._typedEntity = typedEntity; } From 7dcc0b2b5b0ff1df7efac03b08beb56fd0fe8b05 Mon Sep 17 00:00:00 2001 From: MTahaCode Date: Fri, 25 Sep 2026 16:29:08 -0400 Subject: [PATCH 07/10] debugging lines --- src/famix_functions/EntityDictionary.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/famix_functions/EntityDictionary.ts b/src/famix_functions/EntityDictionary.ts index 93876d69..1639464b 100644 --- a/src/famix_functions/EntityDictionary.ts +++ b/src/famix_functions/EntityDictionary.ts @@ -852,9 +852,11 @@ export class EntityDictionary { .filter(call => { const expression = call.getExpression(); if (!TypeNode.isArrowFunction(tsMorphElement)) { - return expression.getText() === tsMorphElement.getName(); + console.log(`Comparing expression.getText(): ${expression.getText().replace("instance.", '')} with tsMorphElement.getName(): ${tsMorphElement.getName()}`); + return expression.getText().replace("instance.", '') === tsMorphElement.getName(); } - return expression.getText() === this.createOrGetFamixArrowFunction(tsMorphElement, {}).name; //arrow function names are generated + console.log(`Comparing expression.getText(): ${expression.getText().replace("instance.", '')} with tsMorphElement.getName(): ${this.createOrGetFamixArrowFunction(tsMorphElement, {}).name}`); + return expression.getText().replace("instance.", '') === this.createOrGetFamixArrowFunction(tsMorphElement, {}).name; //arrow function names are generated }); calls.forEach(call => { From d713bcbc1ef8f1880d204e1706502dcb4f92f06e Mon Sep 17 00:00:00 2001 From: MTahaCode Date: Fri, 25 Sep 2026 16:32:06 -0400 Subject: [PATCH 08/10] tests reflecting new concretization structure for parametric invocations, inheritance and entity typing --- .../concretizationClassSpecialization.test.ts | 57 ++- ...oncretizationFunctionInstantiation.test.ts | 81 ++-- ...concretizationGenericInstantiation.test.ts | 248 +++++++++++-- test/concretizationInterfaceClass.test.ts | 36 +- ...cretizationInterfaceSpecialization.test.ts | 78 ++-- test/concretizationTypeInstantiation.test.ts | 350 +++++++++++++++--- test/fullyQualifiedName.test.ts | 26 +- 7 files changed, 658 insertions(+), 218 deletions(-) diff --git a/test/concretizationClassSpecialization.test.ts b/test/concretizationClassSpecialization.test.ts index 8abfb583..78b07650 100644 --- a/test/concretizationClassSpecialization.test.ts +++ b/test/concretizationClassSpecialization.test.ts @@ -1,5 +1,5 @@ import { Importer } from '../src/analyze'; -import { Concretization, ParameterConcretization, ParametricClass } from '../src/lib/famix/model/famix'; +import { Concretization, ParametricClass, ParametricInheritance } from '../src/lib/famix/model/famix'; import { project, exportProjectSourceFilesForEndtoEndPharoTests } from './testUtils'; const importer = new Importer(); @@ -34,16 +34,18 @@ describe('Tests for concretization', () => { expect(fmxRep).toBeTruthy(); }); - it("should contain 6 generic classes", () => { - expect(fmxRep._getAllEntitiesWithType("ParametricClass").size).toBe(6); + it("should contain 3 generic classes", () => { + // ClassA, ClassD and ClassE declare their own type parameters. + // ClassB, ClassC and ClassF are plain (non-generic) subclasses, not ParametricClass. + expect(fmxRep._getAllEntitiesWithType("ParametricClass").size).toBe(3); }); - it("should contain generic classes named ClassA", () => { + it("should contain a single generic class named ClassA", () => { const listOfNames = Array.from(fmxRep._getAllEntitiesWithType("ParametricClass")).map(e => (e as ParametricClass).name); expect(listOfNames).toContain("ClassA"); const numberOfClassA = listOfNames.filter(name => name === "ClassA").length; - expect(numberOfClassA).toBe(3); + expect(numberOfClassA).toBe(1); }); const theClass = fmxRep._getFamixClass("{concretizationClassSpecialization.ts}.ClassA[ClassDeclaration]"); @@ -53,36 +55,33 @@ describe('Tests for concretization', () => { if (theClass) expect(theClass.isAbstract).toBe(false); }); - it("should contain 3 concretizations", () => { - expect(fmxRep._getAllEntitiesWithType("Concretization").size).toBe(3); + it("should contain 4 concretizations", () => { + expect(fmxRep._getAllEntitiesWithType("Concretization").size).toBe(4); }); - it("The generic Class should be ClassA with genericParameter T", () => { - const theConcretizations = fmxRep._getAllEntitiesWithType("Concretization") as Set; - const iterator = theConcretizations.values(); - const firstElement = iterator.next().value as Concretization; - expect(firstElement.genericEntity).toBe(theClass); - const T = firstElement.genericEntity.genericParameters.values().next().value as ParametricClass; - expect(T.name).toBe("T"); + it("should contain a concretization of ClassA's type parameter T with string", () => { + const theConcretizations = Array.from(fmxRep._getAllEntitiesWithType("Concretization")); + const concretizationOfClassA = theConcretizations.find(c => c.typeParameter.genericEntity === theClass && c.typeArgument.name === "string"); + expect(concretizationOfClassA).toBeTruthy(); + expect(concretizationOfClassA?.typeParameter.name).toBe("T"); }); - it.skip("should contain two parameter concretization", () => { - expect(fmxRep._getAllEntitiesWithType("ParameterConcretization").size).toBe(2); + it("should contain 4 ParametricInheritance associations, one per subclass extending a generic superclass", () => { + // ClassB -> ClassA, ClassC -> ClassA, ClassD -> ClassA, ClassF -> ClassE. + expect(fmxRep._getAllEntitiesWithType("ParametricInheritance").size).toBe(4); }); - it.skip("The first parameter concretization should contain two concretizations", () => { - const theConcretizations = fmxRep._getAllEntitiesWithType("ParameterConcretization") as Set; - const iterator = theConcretizations.values(); - const firstElement = iterator.next().value as ParameterConcretization; - expect(firstElement).toBeTruthy(); - const genericParameter = firstElement.genericParameter; - expect(genericParameter).toBeTruthy(); - const concParameter = firstElement.concreteParameter; - expect(concParameter).toBeTruthy(); - - expect(genericParameter.name).toBe("T"); - expect(concParameter.name).toBe("string"); - expect(firstElement.concretizations.size).toBe(2); + it("should link ClassB's ParametricInheritance from ClassA to its own concretization", () => { + const inheritances = Array.from(fmxRep._getAllEntitiesWithType("ParametricInheritance")); + const classBInheritance = inheritances.find(i => i.subclass.name === "ClassB"); + expect(classBInheritance).toBeTruthy(); + expect(classBInheritance?.superclass).toBe(theClass); + + const ownConcretizations = Array.from(classBInheritance?.concretizations ?? []); + expect(ownConcretizations.length).toBe(1); + expect(ownConcretizations[0].typeParameter.name).toBe("T"); + expect(ownConcretizations[0].typeArgument.name).toBe("string"); + expect(ownConcretizations[0].triggeringAssociation).toBe(classBInheritance); }); }); diff --git a/test/concretizationFunctionInstantiation.test.ts b/test/concretizationFunctionInstantiation.test.ts index a0131353..a9034b5a 100644 --- a/test/concretizationFunctionInstantiation.test.ts +++ b/test/concretizationFunctionInstantiation.test.ts @@ -1,5 +1,5 @@ import { Importer } from '../src/analyze'; -import { Concretization, ParametricFunction, ParametricMethod } from '../src/lib/famix/model/famix'; +import { Concretization, ParametricFunction, ParametricInvocation, ParametricMethod } from '../src/lib/famix/model/famix'; import { project, exportProjectSourceFilesForEndtoEndPharoTests } from './testUtils'; const importer = new Importer(); @@ -37,60 +37,75 @@ describe('Tests for concretization', () => { expect(fmxRep).toBeTruthy(); }); - it("should contain two generic functions", () => { - expect(fmxRep._getAllEntitiesWithType("ParametricFunction").size).toBe(2); + it("should contain one generic function", () => { + expect(fmxRep._getAllEntitiesWithType("ParametricFunction").size).toBe(1); }); - it("should contain generic functions named createInstance", () => { + it("should contain a single generic function named createInstance", () => { const listOfNames = Array.from(fmxRep._getAllEntitiesWithType("ParametricFunction")).map(e => (e as ParametricFunction).name); expect(listOfNames).toContain("createInstance"); const numberOfCreateInstance = listOfNames.filter(name => name === "createInstance").length; - expect(numberOfCreateInstance).toBe(2); + expect(numberOfCreateInstance).toBe(1); }); - it("should contain two generic methods", () => { - expect(fmxRep._getAllEntitiesWithType("ParametricMethod").size).toBe(2); + it("should contain one generic method", () => { + expect(fmxRep._getAllEntitiesWithType("ParametricMethod").size).toBe(1); }); - it("should contain generic methods named process", () => { + it("should contain a single generic method named process", () => { const listOfNames = Array.from(fmxRep._getAllEntitiesWithType("ParametricMethod")).map(e => (e as ParametricMethod).name); expect(listOfNames).toContain("process"); - const numberOfCreateInstance = listOfNames.filter(name => name === "process").length; - expect(numberOfCreateInstance).toBe(2); + const numberOfProcess = listOfNames.filter(name => name === "process").length; + expect(numberOfProcess).toBe(1); }); it("should contain two concretizations", () => { expect(fmxRep._getAllEntitiesWithType("Concretization").size).toBe(2); }); - const theInterface = fmxRep._getFamixInterface("{src/concretizationFunctionInstantiation.ts}.CustomType[InterfaceDeclaration]"); - - it.skip("The concrete Function should be createInstance with concreteParameter CustomType", () => { - const theConcretizations = fmxRep._getAllEntitiesWithType("Concretization") as Set; - const iterator = theConcretizations.values(); - const firstElement = iterator.next().value as Concretization; - expect(firstElement).toBeTruthy(); - const secondElement = iterator.next().value as Concretization; - expect(secondElement.concreteEntity.name).toBe("createInstance"); - const concParameter = secondElement.concreteEntity.concreteParameters.values().next().value as ParametricFunction; - expect(concParameter).toBeTruthy(); - expect(concParameter.name).toBe(theInterface?.name); + it("should contain a concretization of createInstance's type parameter T with CustomType", () => { + const theConcretizations = Array.from(fmxRep._getAllEntitiesWithType("Concretization") as Set); + const concretizationOfCreateInstance = theConcretizations.find(c => c.typeArgument.name === "CustomType"); + expect(concretizationOfCreateInstance).toBeTruthy(); + expect(concretizationOfCreateInstance?.typeParameter.name).toBe("T"); }); - it.skip("The concrete Method should be process with concreteParameter string", () => { - const theConcretizations = fmxRep._getAllEntitiesWithType("Concretization") as Set; - const iterator = theConcretizations.values(); - const firstElement = iterator.next().value as Concretization; - expect(firstElement).toBeTruthy(); - expect(firstElement.concreteEntity.name).toBe("process"); - const concParameter = firstElement.concreteEntity.concreteParameters.values().next().value as ParametricMethod; - expect(concParameter).toBeTruthy(); - expect(concParameter.name).toBe("string"); + it("should contain a concretization of process's type parameter V with string", () => { + const theConcretizations = Array.from(fmxRep._getAllEntitiesWithType("Concretization") as Set); + const concretizationOfProcess = theConcretizations.find(c => c.typeParameter.name === "V"); + expect(concretizationOfProcess).toBeTruthy(); + expect(concretizationOfProcess?.typeArgument.name).toBe("string"); }); - it.skip("should contain two parameter concretizations", () => { - expect(fmxRep._getAllEntitiesWithType("ParameterConcretization").size).toBe(2); + it("should contain two ParametricInvocation associations", () => { + expect(fmxRep._getAllEntitiesWithType("ParametricInvocation").size).toBe(2); }); + + it("should record the ParametricInvocation for the createInstance call", () => { + const invocations = Array.from(fmxRep._getAllEntitiesWithType("ParametricInvocation") as Set); + const createInstanceInvocation = invocations.find(inv => Array.from(inv.candidates).some(c => c.name === "createInstance")); + expect(createInstanceInvocation).toBeTruthy(); + expect(createInstanceInvocation?.sender).toBeTruthy(); + expect(createInstanceInvocation?.signature).toBeTruthy(); + + const ownConcretizations = Array.from(createInstanceInvocation?.concretizations ?? []); + expect(ownConcretizations.length).toBe(1); + expect(ownConcretizations[0].typeParameter.name).toBe("T"); + expect(ownConcretizations[0].typeArgument.name).toBe("CustomType"); + }); + + it("should record the ParametricInvocation for the processor.process call", () => { + const invocations = Array.from(fmxRep._getAllEntitiesWithType("ParametricInvocation") as Set); + const processInvocation = invocations.find(inv => Array.from(inv.candidates).some(c => c.name === "process")); + expect(processInvocation).toBeTruthy(); + expect(processInvocation?.receiver.name).toBe("Processor"); + + const ownConcretizations = Array.from(processInvocation?.concretizations ?? []); + expect(ownConcretizations.length).toBe(1); + expect(ownConcretizations[0].typeParameter.name).toBe("V"); + expect(ownConcretizations[0].typeArgument.name).toBe("string"); + }); + }); diff --git a/test/concretizationGenericInstantiation.test.ts b/test/concretizationGenericInstantiation.test.ts index 45d7a7c9..f9c9d765 100644 --- a/test/concretizationGenericInstantiation.test.ts +++ b/test/concretizationGenericInstantiation.test.ts @@ -1,21 +1,42 @@ import { Importer } from '../src/analyze'; -import { Concretization, ParametricClass } from '../src/lib/famix/model/famix'; -import { project, exportProjectSourceFilesForEndtoEndPharoTests } from './testUtils'; +import { + Concretization, + ParametricClass, + ParametricInvocation +} from '../src/lib/famix/model/famix'; +import { + project, + exportProjectSourceFilesForEndtoEndPharoTests +} from './testUtils'; const importer = new Importer(); -project.createSourceFile("concretizationGenericInstantiation.ts", -` +project.createSourceFile( + "concretizationGenericInstantiation.ts", + ` class ClassA { property: T; - + constructor(value: T) { this.property = value; } } -const instance = new ClassA(42); -`); +const instanceA = new ClassA(42); + +class ClassB { + property1: T; + property2: U; + + constructor(value1: T, value2: U) { + this.property1 = value1; + this.property2 = value2; + } +} + +const instanceB = new ClassB(42, "Hello"); +` +); exportProjectSourceFilesForEndtoEndPharoTests(project, __filename); @@ -27,50 +48,201 @@ describe('Tests for concretization', () => { expect(fmxRep).toBeTruthy(); }); - it("should contain 1 generic class", () => { - expect(fmxRep._getAllEntitiesWithType("ParametricClass").size).toBe(2); + it("should contain 2 generic classes", () => { + expect( + fmxRep._getAllEntitiesWithType("ParametricClass").size + ).toBe(2); }); - it("should contain generic classes named ClassA", () => { - const listOfNames = Array.from(fmxRep._getAllEntitiesWithType("ParametricClass")).map(e => (e as ParametricClass).name); + it("should contain a single generic class named ClassA", () => { + const listOfNames = Array.from( + fmxRep._getAllEntitiesWithType("ParametricClass") + ).map(e => (e as ParametricClass).name); + expect(listOfNames).toContain("ClassA"); - const numberOfClassA = listOfNames.filter(name => name === "ClassA").length; - expect(numberOfClassA).toBe(2); + const numberOfClassA = + listOfNames.filter(name => name === "ClassA").length; + + expect(numberOfClassA).toBe(1); }); - const theClass = fmxRep._getFamixClass("{concretizationGenericInstantiation.ts}.ClassA[ClassDeclaration]"); + it("should contain a single generic class named ClassB", () => { + const listOfNames = Array.from( + fmxRep._getAllEntitiesWithType("ParametricClass") + ).map(e => (e as ParametricClass).name); + + expect(listOfNames).toContain("ClassB"); + + const numberOfClassB = + listOfNames.filter(name => name === "ClassB").length; + + expect(numberOfClassB).toBe(1); + }); + + const classA = fmxRep._getFamixClass( + "{concretizationGenericInstantiation.ts}.ClassA[ClassDeclaration]" + ); + + const classB = fmxRep._getFamixClass( + "{concretizationGenericInstantiation.ts}.ClassB[ClassDeclaration]" // + ); + + it("should not contain abstract classes", () => { + expect(classA).toBeTruthy(); + expect(classB).toBeTruthy(); + + if (classA) expect(classA.isAbstract).toBe(false); + if (classB) expect(classB.isAbstract).toBe(false); + }); + + /* + * ClassA + */ + + it("should contain a concretization of ClassA's type parameter T with number", () => { + const concretizations = Array.from( + fmxRep._getAllEntitiesWithType("Concretization") as Set + ); + + const classAConcretizations = concretizations.filter( + concretization => + concretization.typeParameter.genericEntity === classA + ); + + expect(classAConcretizations.length).toBe(1); + + expect(classAConcretizations[0].typeParameter.name).toBe("T"); + expect(classAConcretizations[0].typeArgument.name).toBe("number"); + }); + + /* + * ClassB + */ + + it("should contain two concretizations for ClassB", () => { + const concretizations = Array.from( + fmxRep._getAllEntitiesWithType("Concretization") as Set + ); - it ("should not be an abstract class", () => { - expect(theClass).toBeTruthy(); - if (theClass) expect(theClass.isAbstract).toBe(false); + const classBConcretizations = concretizations.filter( + concretization => + concretization.typeParameter.genericEntity === classB + ); + + expect(classBConcretizations.length).toBe(2); }); - it("should contain one concretization", () => { - expect(fmxRep._getAllEntitiesWithType("Concretization").size).toBe(1); + it("should concretize ClassB's T with number and U with string", () => { + const concretizations = Array.from( + fmxRep._getAllEntitiesWithType("Concretization") as Set + ); + + const classBConcretizations = concretizations.filter( + concretization => + concretization.typeParameter.genericEntity === classB + ); + + const concretizationT = classBConcretizations.find( + concretization => + concretization.typeParameter.name === "T" + ); + + const concretizationU = classBConcretizations.find( + concretization => + concretization.typeParameter.name === "U" + ); + + expect(concretizationT).toBeTruthy(); + expect(concretizationU).toBeTruthy(); + + expect(concretizationT?.typeArgument.name).toBe("number"); + expect(concretizationU?.typeArgument.name).toBe("string"); }); - it("The generic Class should be ClassA with genericParameter T", () => { - const theConcretizations = fmxRep._getAllEntitiesWithType("Concretization") as Set; - const iterator = theConcretizations.values(); - const firstElement = iterator.next().value as Concretization; - expect(firstElement.genericEntity).toBe(theClass); - const T = firstElement.genericEntity.genericParameters.values().next().value as ParametricClass; - expect(T.name).toBe("T"); + /* + * ParametricInvocations + */ + + it("should contain two ParametricInvocations", () => { + expect( + fmxRep._getAllEntitiesWithType("ParametricInvocation").size + ).toBe(2); }); - it.skip("The concrete Class should be ClassA with concreteParameter string", () => { - const theConcretization = fmxRep._getAllEntitiesWithType("Concretization") as Set; - const iterator = theConcretization.values(); - const firstElement = iterator.next().value as Concretization; - expect(firstElement.concreteEntity.name).toBe("ClassA"); - const concParameter = firstElement.concreteEntity.concreteParameters.values().next().value as ParametricClass; - expect(concParameter).toBeTruthy(); - expect(concParameter.name).toBe("number"); + it("should contain the correct ParametricInvocation for ClassA", () => { + const invocations = Array.from( + fmxRep._getAllEntitiesWithType( + "ParametricInvocation" + ) as Set + ); + + const classAInvocation = invocations.find( + invocation => invocation.receiver === classA + ); + + expect(classAInvocation).toBeTruthy(); + + if (!classAInvocation) return; + + expect(classAInvocation.sender).toBeTruthy(); + expect(classAInvocation.signature).toBeTruthy(); + + const candidates = Array.from(classAInvocation.candidates); + + expect(candidates.length).toBe(1); + expect(candidates[0].name).toBe("constructor"); + + const ownConcretizations = + Array.from(classAInvocation.concretizations); + + expect(ownConcretizations.length).toBe(1); + expect(ownConcretizations[0].typeParameter.name).toBe("T"); + expect(ownConcretizations[0].typeArgument.name).toBe("number"); }); - it.skip("should contain one parameter concretization", () => { - expect(fmxRep._getAllEntitiesWithType("ParameterConcretization").size).toBe(1); + it("should contain the correct ParametricInvocation for ClassB", () => { + const invocations = Array.from( + fmxRep._getAllEntitiesWithType( + "ParametricInvocation" + ) as Set + ); + + const classBInvocation = invocations.find( + invocation => invocation.receiver === classB + ); + + expect(classBInvocation).toBeTruthy(); + + if (!classBInvocation) return; + + expect(classBInvocation.sender).toBeTruthy(); + expect(classBInvocation.signature).toBeTruthy(); + + const candidates = Array.from(classBInvocation.candidates); + + expect(candidates.length).toBe(1); + expect(candidates[0].name).toBe("constructor"); + + const ownConcretizations = + Array.from(classBInvocation.concretizations); + + expect(ownConcretizations.length).toBe(2); + + const concretizationT = ownConcretizations.find( + concretization => + concretization.typeParameter.name === "T" + ); + + const concretizationU = ownConcretizations.find( + concretization => + concretization.typeParameter.name === "U" + ); + + expect(concretizationT).toBeTruthy(); + expect(concretizationU).toBeTruthy(); + + expect(concretizationT?.typeArgument.name).toBe("number"); + expect(concretizationU?.typeArgument.name).toBe("string"); }); - -}); +}); \ No newline at end of file diff --git a/test/concretizationInterfaceClass.test.ts b/test/concretizationInterfaceClass.test.ts index 072fa6bc..946f69ee 100644 --- a/test/concretizationInterfaceClass.test.ts +++ b/test/concretizationInterfaceClass.test.ts @@ -1,5 +1,5 @@ import { Importer } from '../src/analyze'; -import { ParametricInterface } from '../src/lib/famix/model/famix'; +import { Concretization, ParametricInheritance, ParametricInterface } from '../src/lib/famix/model/famix'; import { project, exportProjectSourceFilesForEndtoEndPharoTests } from './testUtils'; const importer = new Importer(); @@ -23,24 +23,44 @@ describe('Tests for concretization', () => { expect(fmxRep).toBeTruthy(); }); - it("should contain 2 generic interfaces", () => { - expect(fmxRep._getAllEntitiesWithType("ParametricInterface").size).toBe(2); + it("should contain 1 generic interface", () => { + expect(fmxRep._getAllEntitiesWithType("ParametricInterface").size).toBe(1); }); - it("should contain generic interfaces named InterfaceD", () => { + it("should contain a single generic interface named InterfaceD", () => { const listOfNames = Array.from(fmxRep._getAllEntitiesWithType("ParametricInterface")).map(e => (e as ParametricInterface).name); expect(listOfNames).toContain("InterfaceD"); const numberOfInterfaceD = listOfNames.filter(name => name === "InterfaceD").length; - expect(numberOfInterfaceD).toBe(2); + expect(numberOfInterfaceD).toBe(1); }); it("should contain one concretization", () => { expect(fmxRep._getAllEntitiesWithType("Concretization").size).toBe(1); }); - - it.skip("should contain one parameter concretization", () => { - expect(fmxRep._getAllEntitiesWithType("ParameterConcretization").size).toBe(1); + + it("should contain a concretization of InterfaceD's type parameter T with number", () => { + const theConcretizations = fmxRep._getAllEntitiesWithType("Concretization") as Set; + const theConcretization = theConcretizations.values().next().value as Concretization; + expect(theConcretization.typeParameter.name).toBe("T"); + expect(theConcretization.typeArgument.name).toBe("number"); + }); + + it("should contain one ParametricInheritance for `class ClassG implements InterfaceD`", () => { + expect(fmxRep._getAllEntitiesWithType("ParametricInheritance").size).toBe(1); + }); + + it("should link ClassG's ParametricInheritance from InterfaceD to its own concretization", () => { + const inheritances = Array.from(fmxRep._getAllEntitiesWithType("ParametricInheritance") as Set); + const classGInheritance = inheritances[0]; + expect(classGInheritance).toBeTruthy(); + expect(classGInheritance.subclass.name).toBe("ClassG"); + expect(classGInheritance.superclass.name).toBe("InterfaceD"); + + const ownConcretizations = Array.from(classGInheritance.concretizations); + expect(ownConcretizations.length).toBe(1); + expect(ownConcretizations[0].typeParameter.name).toBe("T"); + expect(ownConcretizations[0].typeArgument.name).toBe("number"); }); }); diff --git a/test/concretizationInterfaceSpecialization.test.ts b/test/concretizationInterfaceSpecialization.test.ts index 2fe80591..154b348b 100644 --- a/test/concretizationInterfaceSpecialization.test.ts +++ b/test/concretizationInterfaceSpecialization.test.ts @@ -1,5 +1,5 @@ import { Importer } from '../src/analyze'; -import { Concretization, ParameterConcretization, ParametricInterface } from '../src/lib/famix/model/famix'; +import { Concretization, ParametricInheritance, ParametricInterface } from '../src/lib/famix/model/famix'; import { project, exportProjectSourceFilesForEndtoEndPharoTests } from './testUtils'; const importer = new Importer(); @@ -38,67 +38,65 @@ describe('Tests for concretization', () => { expect(fmxRep).toBeTruthy(); }); - it("should contain 8 generic interfaces", () => { - expect(fmxRep._getAllEntitiesWithType("ParametricInterface").size).toBe(8); + it("should contain 3 generic interfaces", () => { + // InterfaceA, InterfaceD and InterfaceE declare their own type parameters. + // InterfaceB, InterfaceF and the merged InterfaceH are plain (non-generic) interfaces. + expect(fmxRep._getAllEntitiesWithType("ParametricInterface").size).toBe(3); }); - it("should contain generic interfaces named InterfaceA", () => { + it("should contain a single generic interface named InterfaceA", () => { const listOfNames = Array.from(fmxRep._getAllEntitiesWithType("ParametricInterface")).map(e => (e as ParametricInterface).name); expect(listOfNames).toContain("InterfaceA"); const numberOfInterfaceA = listOfNames.filter(name => name === "InterfaceA").length; - expect(numberOfInterfaceA).toBe(4); + expect(numberOfInterfaceA).toBe(1); }); - it("should contain generic interfaces named InterfaceE", () => { + it("should contain a single generic interface named InterfaceE", () => { const listOfNames = Array.from(fmxRep._getAllEntitiesWithType("ParametricInterface")).map(e => (e as ParametricInterface).name); expect(listOfNames).toContain("InterfaceE"); const numberOfInterfaceE = listOfNames.filter(name => name === "InterfaceE").length; - expect(numberOfInterfaceE).toBe(3); + expect(numberOfInterfaceE).toBe(1); }); const theInterface = fmxRep._getFamixInterface("{concretizationInterfaceSpecialization.ts}.InterfaceA[InterfaceDeclaration]"); - it("should contain 3 concretizations", () => { - expect(fmxRep._getAllEntitiesWithType("Concretization").size).toBe(5); + it("should contain 6 concretizations", () => { + expect(fmxRep._getAllEntitiesWithType("Concretization").size).toBe(6); }); - it("The generic Class should be InterfaceA with genericParameter T", () => { - const theConcretizations = fmxRep._getAllEntitiesWithType("Concretization") as Set; - const iterator = theConcretizations.values(); - const firstElement = iterator.next().value as Concretization; - expect(firstElement.genericEntity).toBe(theInterface); - const T = firstElement.genericEntity.genericParameters.values().next().value as ParametricInterface; - expect(T).toBeTruthy(); - expect(T.name).toBe("T"); + it("should contain a concretization of InterfaceA's type parameter T with string", () => { + const theConcretizations = Array.from(fmxRep._getAllEntitiesWithType("Concretization") as Set); + const concretizationOfInterfaceA = theConcretizations.find(c => c.typeParameter.genericEntity === theInterface && c.typeArgument.name === "string"); + expect(concretizationOfInterfaceA).toBeTruthy(); + expect(concretizationOfInterfaceA?.typeParameter.name).toBe("T"); }); - it.skip("The concrete Class should be InterfaceA with concreteParameter string", () => { - const theConcretizations = fmxRep._getAllEntitiesWithType("Concretization") as Set; - const iterator = theConcretizations.values(); - const firstElement = iterator.next().value as Concretization; - expect(firstElement.concreteEntity.name).toBe("InterfaceA"); - const concParameter = firstElement.concreteEntity.concreteParameters.values().next().value as ParametricInterface; - expect(concParameter).toBeTruthy(); - expect(concParameter.name).toBe("string"); + it("should contain 6 ParametricInheritance associations", () => { + expect(fmxRep._getAllEntitiesWithType("ParametricInheritance").size).toBe(6); }); - it.skip("should contain two parameter concretization", () => { - expect(fmxRep._getAllEntitiesWithType("ParameterConcretization").size).toBe(3); + it("should link InterfaceB's ParametricInheritance from InterfaceA to its own concretization", () => { + const inheritances = Array.from(fmxRep._getAllEntitiesWithType("ParametricInheritance")); + const interfaceBInheritance = inheritances.find(i => i.subclass.name === "InterfaceB"); + expect(interfaceBInheritance).toBeTruthy(); + expect(interfaceBInheritance?.superclass).toBe(theInterface); + + const ownConcretizations = Array.from(interfaceBInheritance?.concretizations); + expect(ownConcretizations.length).toBe(1); + expect(ownConcretizations[0].typeParameter.name).toBe("T"); + expect(ownConcretizations[0].typeArgument.name).toBe("string"); }); - it.skip("The first parameter concretization should contain two concretizations", () => { - const theConcretization = fmxRep._getAllEntitiesWithType("ParameterConcretization") as Set; - const iterator = theConcretization.values(); - const firstElement = iterator.next().value as ParameterConcretization; - expect(firstElement).toBeTruthy(); - const genericParameter = firstElement.genericParameter; - expect(genericParameter).toBeTruthy(); - const concParameter = firstElement.concreteParameter; - expect(concParameter).toBeTruthy(); - - expect(genericParameter.name).toBe("T"); - expect(concParameter.name).toBe("string"); - expect(firstElement.concretizations.size).toBe(2); + it("should record two separate ParametricInheritance for the merged InterfaceH declaration", () => { + // InterfaceH extends InterfaceE in its first declaration, then is merged with + // `extends InterfaceE, InterfaceA`: each extended generic interface gets + // its own ParametricInheritance, so InterfaceH ends up with 3 in total. + const inheritances = Array.from(fmxRep._getAllEntitiesWithType("ParametricInheritance")); + const interfaceHInheritances = inheritances.filter(i => i.subclass.name === "InterfaceH"); + expect(interfaceHInheritances.length).toBe(3); + + const superclassNames = interfaceHInheritances.map(i => i.superclass.name).sort(); + expect(superclassNames).toEqual(["InterfaceA", "InterfaceE", "InterfaceE"]); }); }); diff --git a/test/concretizationTypeInstantiation.test.ts b/test/concretizationTypeInstantiation.test.ts index ce3e46c4..8d28f0db 100644 --- a/test/concretizationTypeInstantiation.test.ts +++ b/test/concretizationTypeInstantiation.test.ts @@ -1,78 +1,314 @@ -import { Importer } from '../src/analyze'; -import { Concretization, ParametricInterface } from '../src/lib/famix/model/famix'; -import { project, exportProjectSourceFilesForEndtoEndPharoTests } from './testUtils'; +import { Importer } from "../src/analyze"; +import { + Concretization, + ParametricEntityTyping, + ParametricInterface, +} from "../src/lib/famix/model/famix"; +import { + project, + exportProjectSourceFilesForEndtoEndPharoTests, +} from "./testUtils"; const importer = new Importer(); -project.createSourceFile("concretizationTypeInstantiation.ts", -` +project.createSourceFile( + "concretizationTypeInstantiation.ts", + ` interface InterfaceE { (param: T): void; } const interfaceInstance: InterfaceE = { value: "example" }; -class MyClass { +class MyClass { } function processInstance(instance: MyClass): MyClass { return instance; } -`); + +function genericFunction(first: T, second: U): void { +} + +genericFunction(42, "Hello"); + +genericFunction(42, "Hello"); + +class MyClass2 { + + genericMethod(first: T, second: U): void { + } +} + +const instance = new MyClass2(); + +instance.genericMethod(true, 42); + +instance.genericMethod(true, 42); +`, +); exportProjectSourceFilesForEndtoEndPharoTests(project, __filename); const fmxRep = importer.famixRepFromProject(project); -describe('Tests for concretization', () => { - - it("should parse generics", () => { - expect(fmxRep).toBeTruthy(); - }); - - it("should contain 3 generic interfaces", () => { - expect(fmxRep._getAllEntitiesWithType("ParametricInterface").size).toBe(2); - }); - - it("should contain 2 generic classes", () => { - expect(fmxRep._getAllEntitiesWithType("ParametricClass").size).toBe(2); - }); - - it("should contain generic interfaces named InterfaceE", () => { - const listOfNames = Array.from(fmxRep._getAllEntitiesWithType("ParametricInterface")).map(e => (e as ParametricInterface).name); - expect(listOfNames).toContain("InterfaceE"); - const numberOfInterfaceE = listOfNames.filter(name => name === "InterfaceE").length; - expect(numberOfInterfaceE).toBe(2); - }); - - it("should contain 3 concretizations", () => { - expect(fmxRep._getAllEntitiesWithType("Concretization").size).toBe(2); - }); - - it.skip("should contain two parameter concretization", () => { - expect(fmxRep._getAllEntitiesWithType("ParameterConcretization").size).toBe(2); - }); - - - it.skip("The concrete Class should be MyClass with concreteParameter boolean", () => { - const theConcretizations = fmxRep._getAllEntitiesWithType("Concretization") as Set; - const iterator = theConcretizations.values(); - const firstElement = iterator.next().value as Concretization; - expect(firstElement.concreteEntity.name).toBe("MyClass"); - const concParameter = firstElement.concreteEntity.concreteParameters.values().next().value as ParametricInterface; - expect(concParameter).toBeTruthy(); - expect(concParameter.name).toBe("boolean"); - }); - - it.skip("The concrete Interface should be InterfaceE with concreteParameter number", () => { - const theConcretizations = fmxRep._getAllEntitiesWithType("Concretization") as Set; - const iterator = theConcretizations.values(); - const secondElement = iterator.next().value as Concretization; - expect(secondElement).toBeTruthy(); - expect(secondElement.concreteEntity.name).toBe("InterfaceE"); - const concParameter = secondElement.concreteEntity.concreteParameters.values().next().value as ParametricInterface; - expect(concParameter).toBeTruthy(); - expect(concParameter.name).toBe("number"); - }); +describe("Tests for concretization", () => { + it("should parse generics", () => { + expect(fmxRep).toBeTruthy(); + }); + + it("should contain 1 generic interface", () => { + expect(fmxRep._getAllEntitiesWithType("ParametricInterface").size).toBe(1); + }); + + it("should contain 1 generic class", () => { + expect(fmxRep._getAllEntitiesWithType("ParametricClass").size).toBe(1); + }); + + it("should contain a single generic interface named InterfaceE", () => { + const listOfNames = Array.from( + fmxRep._getAllEntitiesWithType("ParametricInterface"), + ).map((e) => (e as ParametricInterface).name); + expect(listOfNames).toContain("InterfaceE"); + const numberOfInterfaceE = listOfNames.filter( + (name) => name === "InterfaceE", + ).length; + expect(numberOfInterfaceE).toBe(1); + }); + + it("should contain 9 concretizations", () => { + // InterfaceE from the variable annotation, plus MyClass counted once + // for the parameter type and once for the return type of processInstance: each declared + // type usage gets its own ParametricEntityTyping and its own Concretization. + expect(fmxRep._getAllEntitiesWithType("Concretization").size).toBe(9); + }); + + it("should contain a concretization of InterfaceE's type parameter T with number", () => { + const theConcretizations = Array.from( + fmxRep._getAllEntitiesWithType("Concretization") as Set, + ); + const concretizationOfInterfaceE = theConcretizations.find( + (c) => c.typeParameter.name === "T" && c.typeArgument.name === "number", + ); + expect(concretizationOfInterfaceE).toBeTruthy(); + }); + + it("should contain two concretizations of MyClass's type parameter V with boolean", () => { + const theConcretizations = Array.from( + fmxRep._getAllEntitiesWithType("Concretization") as Set, + ); + const concretizationsOfMyClass = theConcretizations.filter( + (c) => c.typeArgument.name === "boolean" && c.typeParameter.name === "V", + ); + expect(concretizationsOfMyClass.length).toBe(2); + concretizationsOfMyClass.forEach((c) => + expect(c.typeParameter.name).toBe("V"), + ); + }); + + it("should contain 3 ParametricEntityTyping associations", () => { + expect(fmxRep._getAllEntitiesWithType("ParametricEntityTyping").size).toBe( + 5, + ); + }); + + it("should type the interfaceInstance variable as InterfaceE via its own ParametricEntityTyping", () => { + const typings = Array.from( + fmxRep._getAllEntitiesWithType( + "ParametricEntityTyping", + ) as Set, + ); + const variableTyping = typings.find( + (t) => t.typedEntity.name === "interfaceInstance", + ); + expect(variableTyping).toBeTruthy(); + expect(variableTyping?.declaredType.name).toBe("InterfaceE"); + + const ownConcretizations = Array.from( + variableTyping?.concretizations ?? [], + ); + expect(ownConcretizations.length).toBe(1); + expect(ownConcretizations[0].typeArgument.name).toBe("number"); + }); + + it("should type both processInstance's parameter and its return type as MyClass via separate ParametricEntityTyping", () => { + // The parameter (`instance`) and the function itself (carrying the return type) are two + // distinct typedEntity targets, each getting its own ParametricEntityTyping. + const typings = Array.from( + fmxRep._getAllEntitiesWithType( + "ParametricEntityTyping", + ) as Set, + ); + const myClassTypings = typings.filter( + (t) => t.declaredType.name === "MyClass", + ); + expect(myClassTypings.length).toBe(2); + + const typedEntityNames = myClassTypings + .map((t) => t.typedEntity.name) + .sort(); + expect(typedEntityNames).toEqual(["instance", "processInstance"]); + }); + + it("should contain ParametricEntityTyping for genericFunction invocations", () => { + const typings = Array.from( + fmxRep._getAllEntitiesWithType( + "ParametricEntityTyping", + ) as Set, + ); + + expect(typings.length).toBeGreaterThanOrEqual(2); + + const functionTypings = typings.filter( + (typing) => typing.declaredType.name === "void", + ); + + expect(functionTypings.length).toBe(2); + }); + + it("should contain one concretization in ParametricEntityTyping for genericFunction", () => { + const typings = Array.from( + fmxRep._getAllEntitiesWithType( + "ParametricEntityTyping", + ) as Set, + ); + + const typing = typings.find( + (typing) => + typing.declaredType.name === "void" && + typing.concretizations.size === 1, + ); + + expect(typing).toBeTruthy(); + + if (!typing) return; + + expect(typing.concretizations.size).toBe(1); + + const concretization = Array.from(typing.concretizations)[0]; + + expect(concretization.typeParameter.name).toBe("T"); + expect(concretization.typeArgument.name).toBe("number"); + + expect(concretization.triggeringAssociation).toBe(typing); + }); + + it("should contain two concretizations in ParametricEntityTyping for genericFunction", () => { + const typings = Array.from( + fmxRep._getAllEntitiesWithType( + "ParametricEntityTyping", + ) as Set, + ); + + const typing = typings.find( + (typing) => + typing.declaredType.name === "void" && + typing.concretizations.size === 2, + ); + + expect(typing).toBeTruthy(); + + if (!typing) return; + + const concretizations = Array.from(typing.concretizations); + + expect(concretizations.length).toBe(2); + + const concretizationT = concretizations.find( + (c) => c.typeParameter.name === "T", + ); + + const concretizationU = concretizations.find( + (c) => c.typeParameter.name === "U", + ); + + expect(concretizationT).toBeTruthy(); + expect(concretizationU).toBeTruthy(); + + expect(concretizationT?.typeArgument.name).toBe("number"); + expect(concretizationU?.typeArgument.name).toBe("string"); + + expect(concretizationT?.triggeringAssociation).toBe(typing); + + expect(concretizationU?.triggeringAssociation).toBe(typing); + }); + + it("should contain ParametricEntityTyping for genericMethod invocations", () => { + const typings = Array.from( + fmxRep._getAllEntitiesWithType( + "ParametricEntityTyping", + ) as Set, + ); + + const methodTypings = typings.filter( + (typing) => typing.declaredType.name === "void", + ); + + expect(methodTypings.length).toBe(2); + }); + + it("should contain one concretization in ParametricEntityTyping for genericMethod", () => { + const typings = Array.from( + fmxRep._getAllEntitiesWithType( + "ParametricEntityTyping", + ) as Set, + ); + + const typing = typings.find( + (typing) => + typing.declaredType.name === "void" && + typing.concretizations.size === 1, + ); + + expect(typing).toBeTruthy(); + + if (!typing) return; + + const concretization = Array.from(typing.concretizations)[0]; + + expect(concretization.typeParameter.name).toBe("T"); + expect(concretization.typeArgument.name).toBe("boolean"); + + expect(concretization.triggeringAssociation).toBe(typing); + }); + + it("should contain two concretizations in ParametricEntityTyping for genericMethod", () => { + const typings = Array.from( + fmxRep._getAllEntitiesWithType( + "ParametricEntityTyping", + ) as Set, + ); + + const typing = typings.find( + (typing) => + typing.declaredType.name === "void" && + typing.concretizations.size === 2, + ); + + expect(typing).toBeTruthy(); + + if (!typing) return; + + const concretizations = Array.from(typing.concretizations); + + expect(concretizations.length).toBe(2); + + const concretizationT = concretizations.find( + (c) => c.typeParameter.name === "T", + ); + + const concretizationU = concretizations.find( + (c) => c.typeParameter.name === "U", + ); + + expect(concretizationT).toBeTruthy(); + expect(concretizationU).toBeTruthy(); + + expect(concretizationT?.typeArgument.name).toBe("boolean"); + expect(concretizationU?.typeArgument.name).toBe("number"); + + expect(concretizationT?.triggeringAssociation).toBe(typing); + expect(concretizationU?.triggeringAssociation).toBe(typing); + }); }); diff --git a/test/fullyQualifiedName.test.ts b/test/fullyQualifiedName.test.ts index bec2b1ff..be002cab 100644 --- a/test/fullyQualifiedName.test.ts +++ b/test/fullyQualifiedName.test.ts @@ -3,19 +3,19 @@ import { getFQN } from '../src/fqn'; import { project, exportProjectSourceFilesForEndtoEndPharoTests } from './testUtils'; const sourceFile = project.createSourceFile('/sampleFile.ts', ` - const createClassA1 = () => { - return class A { - method1() {} - } - }; - const createClassA2 = () => { - return class A { - method2() {} - } - }; - const instance1 = createClassA1(); - const instance2 = createClassA2(); - `); + const createClassA1 = () => { + return class A { + method1() {} + } + }; + const createClassA2 = () => { + return class A { + method2() {} + } + }; + const instance1 = createClassA1(); + const instance2 = createClassA2(); +`); exportProjectSourceFilesForEndtoEndPharoTests(project, __filename); From e26bb7ed28a364a0ec7a3ab79f077872185ae845 Mon Sep 17 00:00:00 2001 From: "C. Fuhrman" Date: Sat, 26 Sep 2026 10:09:23 -0400 Subject: [PATCH 09/10] update uml --- doc-uml/famix-typescript-model.puml | 209 ++++++++++++++++------------ 1 file changed, 118 insertions(+), 91 deletions(-) diff --git a/doc-uml/famix-typescript-model.puml b/doc-uml/famix-typescript-model.puml index 07ee8bc1..6b447c97 100644 --- a/doc-uml/famix-typescript-model.puml +++ b/doc-uml/famix-typescript-model.puml @@ -158,6 +158,23 @@ class Parameter extends StructuralEntity { +parentEntity: BehavioralEntity +parentEntity: BehavioralEntity } +class EntityTyping extends Entity { + -_typedEntity: TypedEntity + -_declaredType: Type + +getJSON(): string + +addPropertiesToExporter(exporter: FamixJSONExporter): void + +typedEntity: TypedEntity + +typedEntity: TypedEntity + +declaredType: Type + +declaredType: Type +} +class ParametricInvocation extends Invocation { + -_concretizations: Set + +addConcretization(concretization: Concretization): void + +concretizations: Set + +getJSON(): string + +addPropertiesToExporter(exporter: FamixJSONExporter): void +} class Property extends StructuralEntity { -_isClassSide: boolean +readOnly: boolean @@ -183,18 +200,7 @@ class Property extends StructuralEntity { +parentEntity: Class | Interface +parentEntity: Class | Interface } -class Inheritance extends EntityWithSourceAnchor { - -_superclass: Class | Interface - -_subclass: Class | Interface - +getJSON(): string - +addPropertiesToExporter(exporter: FamixJSONExporter): void - +superclass: Class | Interface - +superclass: Class | Interface - +subclass: Class | Interface - +subclass: Class | Interface -} -class Class extends Type { - -_isAbstract: boolean +class Interface extends Type { -_properties: Set +addProperty(property: Property): void -_methods: Set @@ -207,8 +213,6 @@ class Class extends Type { +removeSubInheritance(subInheritance: Inheritance): void +getJSON(): string +addPropertiesToExporter(exporter: FamixJSONExporter): void - +isAbstract: boolean - +isAbstract: boolean +properties: Set +methods: Set +superInheritances: Set @@ -239,7 +243,8 @@ class Method extends BehavioralEntity { +isProtected: boolean +isProtected: boolean } -class Interface extends Type { +class Class extends Type { + -_isAbstract: boolean -_properties: Set +addProperty(property: Property): void -_methods: Set @@ -252,92 +257,130 @@ class Interface extends Type { +removeSubInheritance(subInheritance: Inheritance): void +getJSON(): string +addPropertiesToExporter(exporter: FamixJSONExporter): void + +isAbstract: boolean + +isAbstract: boolean +properties: Set +methods: Set +superInheritances: Set +subInheritances: Set } -class PrimitiveType extends Type { +class Inheritance extends EntityWithSourceAnchor { + -_superclass: Class | Interface + -_subclass: Class | Interface +getJSON(): string +addPropertiesToExporter(exporter: FamixJSONExporter): void + +superclass: Class | Interface + +superclass: Class | Interface + +subclass: Class | Interface + +subclass: Class | Interface } -class ParametricClass extends Class { - -_genericParameters: Set - +addGenericParameter(genericParameter: TypeParameter): void - +clearGenericParameters(): void - -_concreteParameters: Set - +addConcreteParameter(concreteParameter: Class | Interface | PrimitiveType): void +class ParametricInheritance extends Inheritance { + -_concretizations: Set + +addConcretization(concretization: Concretization): void + +concretizations: Set +getJSON(): string +addPropertiesToExporter(exporter: FamixJSONExporter): void - +genericParameters: Set - +concreteParameters: Set } -class ParametricInterface extends Interface { - -_genericParameters: Set - +addGenericParameter(genericParameter: TypeParameter): void - +clearGenericParameters(): void - -_concreteParameters: Set - +addConcreteParameter(concreteParameter: Class | Interface | PrimitiveType): void +class Reference extends Entity { + -_source: ContainerEntity + -_target: Type + +getJSON(): string + +addPropertiesToExporter(exporter: FamixJSONExporter): void + +source: ContainerEntity + +source: ContainerEntity + +target: Type + +target: Type +} +class ParametricReference extends Reference { + -_concretizations: Set + +addConcretization(concretization: Concretization): void + +concretizations: Set +getJSON(): string +addPropertiesToExporter(exporter: FamixJSONExporter): void - +genericParameters: Set - +concreteParameters: Set } -class Function extends BehavioralEntity { +class ParametricClass extends Class { + -_typeParameters: Set + +addTypeParameter(typeParameter: TypeParameter): void + +clearTypeParameters(): void +getJSON(): string +addPropertiesToExporter(exporter: FamixJSONExporter): void + +typeParameters: Set } -class Accessor extends Method { +class ParametricInterface extends Interface { + -_typeParameters: Set + +addTypeParameter(typeParameter: TypeParameter): void + +clearTypeParameters(): void +getJSON(): string +addPropertiesToExporter(exporter: FamixJSONExporter): void + +typeParameters: Set } class ParametricMethod extends Method { - -_concreteParameters: Set - +addConcreteParameter(concreteParameter: Class | Interface | PrimitiveType): void + -_typeParameters: Set + +addTypeParameter(typeParameter: TypeParameter): void + +clearTypeParameters(): void + +getJSON(): string + +addPropertiesToExporter(exporter: FamixJSONExporter): void + +typeParameters: Set +} +class Function extends BehavioralEntity { +getJSON(): string +addPropertiesToExporter(exporter: FamixJSONExporter): void - +concreteParameters: Set } class ParametricFunction extends Function { - -_concreteParameters: Set - +addConcreteParameter(concreteParameter: Class | Interface | PrimitiveType): void + -_typeParameters: Set + +addTypeParameter(typeParameter: TypeParameter): void + +clearTypeParameters(): void +getJSON(): string +addPropertiesToExporter(exporter: FamixJSONExporter): void - +concreteParameters: Set + +typeParameters: Set } class ArrowFunction extends BehavioralEntity { +getJSON(): string +addPropertiesToExporter(exporter: FamixJSONExporter): void } class ParametricArrowFunction extends ArrowFunction { - -_concreteParameters: Set - +addConcreteParameter(concreteParameter: Class | Interface | PrimitiveType): void + -_typeParameters: Set + +addTypeParameter(typeParameter: TypeParameter): void + +clearTypeParameters(): void +getJSON(): string +addPropertiesToExporter(exporter: FamixJSONExporter): void - +concreteParameters: Set + +typeParameters: Set } class TypeParameter extends Type { - -_parentGeneric: Method | ParametricArrowFunction | ArrowFunction | ParametricClass | ParametricInterface | ParametricMethod | Accessor | FamixFunction | ParametricFunction + -_genericEntity: ParametricClass | ParametricInterface | ParametricMethod | ParametricFunction | ParametricArrowFunction -_baseType: Type -_arguments: Set + -_concretizations: Set +addArgument(argument: Type): void + +addConcretization(concretization: Concretization): void +getJSON(): string +addPropertiesToExporter(exporter: FamixJSONExporter): void - +parentGeneric: Method | ParametricArrowFunction | ArrowFunction | ParametricClass | ParametricInterface | ParametricMethod | Accessor | FamixFunction | ParametricFunction - +parentGeneric: Method | ParametricArrowFunction | ArrowFunction | ParametricClass | ParametricInterface | ParametricMethod | Accessor | FamixFunction | ParametricFunction + +genericEntity: ParametricClass | ParametricInterface | ParametricMethod | ParametricFunction | ParametricArrowFunction + +genericEntity: ParametricClass | ParametricInterface | ParametricMethod | ParametricFunction | ParametricArrowFunction +baseType: Type +baseType: Type +arguments: Set + +concretizations: Set } -class EntityTyping extends Entity { - -_typedEntity: Entity - -_declaredType: Type +class Concretization extends Entity { + -_typeParameter: TypeParameter + -_typeArgument: Type + -_triggeringAssociation: ParametricAssociation + +getJSON(): string + +addPropertiesToExporter(exporter: FamixJSONExporter): void + +typeParameter: TypeParameter + +typeParameter: TypeParameter + +typeArgument: Type + +typeArgument: Type + +triggeringAssociation: ParametricAssociation + +triggeringAssociation: ParametricAssociation +} +class ParametricEntityTyping extends EntityTyping { + -_concretizations: Set + +addConcretization(concretization: Concretization): void + +concretizations: Set +getJSON(): string +addPropertiesToExporter(exporter: FamixJSONExporter): void - +typedEntity: Entity - +typedEntity: Entity - +declaredType: Type - +declaredType: Type } class BehavioralEntity extends ContainerEntity { -_signature: string @@ -346,10 +389,7 @@ class BehavioralEntity extends ContainerEntity { -_numberOfParameters: number -_incomingInvocations: Set +addIncomingInvocation(incomingInvocation: Invocation): void - -_typing: EntityTyping - -_genericParameters: Set - +addGenericParameter(genericParameter: TypeParameter): void - +clearGenericParameters(): void + -_typing: ParametricEntityTyping | EntityTyping +getJSON(): string +addPropertiesToExporter(exporter: FamixJSONExporter): void +signature: string @@ -358,9 +398,8 @@ class BehavioralEntity extends ContainerEntity { +numberOfParameters: number +numberOfParameters: number +incomingInvocations: Set - +typing: EntityTyping - +typing: EntityTyping - +genericParameters: Set + +typing: ParametricEntityTyping | EntityTyping + +typing: ParametricEntityTyping | EntityTyping } class Invocation extends Entity { -_candidates: Set @@ -378,16 +417,6 @@ class Invocation extends Entity { +signature: string +signature: string } -class Reference extends Entity { - -_source: ContainerEntity - -_target: Type - +getJSON(): string - +addPropertiesToExporter(exporter: FamixJSONExporter): void - +source: ContainerEntity - +source: ContainerEntity - +target: Type - +target: Type -} class Variable extends StructuralEntity { -_parentContainerEntity: ContainerEntity +getJSON(): string @@ -440,6 +469,10 @@ class Type extends ContainerEntity { -_behavioralEntitiesWithDeclaredType: Set -_incomingReferences: Set +addIncomingReference(incomingReference: Reference): void + -_incomingTypings: Set + +addIncomingTyping(incomingTyping: EntityTyping): void + -_outgoingConcretizations: Set + +addOutgoingConcretization(outgoingConcretization: Concretization): void +getJSON(): string +addPropertiesToExporter(exporter: FamixJSONExporter): void +container: ContainerEntity @@ -448,20 +481,17 @@ class Type extends ContainerEntity { +structuresWithDeclaredType: Set +behavioralEntitiesWithDeclaredType: Set +incomingReferences: Set -} -class ParametricEntityTyping extends EntityTyping { - +getJSON(): string - +addPropertiesToExporter(exporter: FamixJSONExporter): void + +outgoingConcretizations: Set } class StructuralEntity extends NamedEntity { -_incomingAccesses: Set +addIncomingAccess(incomingAccess: Access): void - -_typing: EntityTyping | ParametricEntityTyping + -_typing: ParametricEntityTyping | EntityTyping +getJSON(): string +addPropertiesToExporter(exporter: FamixJSONExporter): void +incomingAccesses: Set - +typing: EntityTyping | ParametricEntityTyping - +typing: EntityTyping | ParametricEntityTyping + +typing: ParametricEntityTyping | EntityTyping + +typing: ParametricEntityTyping | EntityTyping } class Access extends Entity { -_accessor: ContainerEntity @@ -476,15 +506,9 @@ class Access extends Entity { +isWrite: boolean +isWrite: boolean } -class Concretization extends Entity { - -_genericEntity: ParametricClass | ParametricInterface | ParametricMethod | ParametricFunction - -_concreteEntity: ParametricClass | ParametricInterface | ParametricMethod | ParametricFunction +class Accessor extends Method { +getJSON(): string +addPropertiesToExporter(exporter: FamixJSONExporter): void - +genericEntity: ParametricClass | ParametricInterface | ParametricMethod | ParametricFunction - +genericEntity: ParametricClass | ParametricInterface | ParametricMethod | ParametricFunction - +concreteEntity: ParametricClass | ParametricInterface | ParametricMethod | ParametricFunction - +concreteEntity: ParametricClass | ParametricInterface | ParametricMethod | ParametricFunction } class Enum extends Type { -_values: Set @@ -513,6 +537,10 @@ class IndexedFileAnchor extends SourceAnchor { +fileName: string +fileName: string } +class PrimitiveType extends Type { + +getJSON(): string + +addPropertiesToExporter(exporter: FamixJSONExporter): void +} class ParameterConcretization extends Entity { -_genericParameter: TypeParameter -_concreteParameter: PrimitiveType @@ -540,16 +568,17 @@ class EntityDictionary { -fmxFileMap: Map -fmxTypeMap: Map -fmxPrimitiveTypeMap: Map - -fmxFunctionAndMethodMap: Map + -fmxFunctionAndMethodMap: Map -fmxArrowFunctionMap: Map -fmxParameterMap: Map -fmxVariableMap: Map -fmxImportClauseMap: Map -fmxEnumMap: Map + -fmxTypeParameterMap: Map -fmxInheritanceMap: Map -UNKNOWN_VALUE: string +fmxElementObjectMap: Map - +tsMorphElementObjectMap: Map + +tsMorphElementObjectMap: Map +fmxEntityTypingMap: Map +reset(): void +getAbsolutePath(): string @@ -560,14 +589,13 @@ class EntityDictionary { +createFamixAlias(typeAliasDeclaration: TypeAliasDeclaration): Famix.Alias +createOrGetFamixClass(cls: ClassDeclaration): Famix.Class | Famix.ParametricClass +createOrGetFamixInterface(inter: InterfaceDeclaration): Famix.Interface | Famix.ParametricInterface - +createOrGetFamixConcreteElement(concreteElement: ParametricVariantType, concreteElementDeclaration: ConcreteElementTSMorphType, concreteArguments: TypeNode[]): ParametricVariantType +createFamixProperty(property: PropertyDeclaration | PropertySignature): Famix.Property +createOrGetFamixMethod(method: ConstructorDeclaration | MethodSignature | GetAccessorDeclaration | SetAccessorDeclaration | MethodDeclaration, currentCC: { [key: string]: number; }): Famix.Method | Famix.ParametricMethod | Famix.Accessor - +createOrGetFamixFunction(func: FunctionExpression | FunctionDeclaration, currentCC: { [key: string]: number; }): Famix.Function | Famix.ParametricFunction + +createOrGetFamixFunction(func: FunctionExpression | FunctionDeclaration, currentCC: { [key: string]: number; }): Famix.ParametricFunction | Famix.Function +createOrGetFamixParameter(param: ParameterDeclaration): Famix.Parameter +createFamixTypeParameter(tp: TypeParameterDeclaration): Famix.TypeParameter +createOrGetFamixVariable(variable: VariableDeclaration): Famix.Variable - +createOrGetFamixEntityTyping(entity: Famix.BehavioralEntity | Famix.StructuralEntity, type: Famix.Type): Famix.EntityTyping + +createOrGetFamixEntityTyping(entity: Famix.BehavioralEntity | Famix.StructuralEntity, type: Famix.Type, tsMorphElement?: Node | undefined): Famix.EntityTyping +createOrGetFamixEnum(enumEntity: EnumDeclaration): Famix.Enum +createFamixEnumValue(enumMember: EnumMember): Famix.EnumValue +createOrGetFamixDecorator(decorator: Decorator, decoratedEntity: PropertyDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | ParameterDeclaration | ClassDeclaration | MethodDeclaration): Famix.Decorator @@ -583,8 +611,7 @@ class EntityDictionary { +createFamixImportClause(importedEntity: Famix.NamedEntity, importingEntity: Famix.Module): void +oldCreateOrGetFamixImportClause(importClauseInfo: { importDeclaration?: ImportEqualsDeclaration | ImportDeclaration | undefined; importerSourceFile: SourceFile; moduleSpecifierFilePath: string; importElement: ImportSpecifier | Identifier; isInExports: boolean; isDefaultExport: boolean; }): void +createOrGetFamixArrowFunction(arrowExpression: Expression, currentCC: { [key: string]: number; }): Famix.ParametricArrowFunction | Famix.ArrowFunction - +createFamixConcretization(conEntity: Famix.ParametricClass | Famix.ParametricInterface | Famix.ParametricMethod | Famix.ParametricFunction, genEntity: Famix.ParametricClass | Famix.ParametricInterface | Famix.ParametricMethod | Famix.ParametricFunction): Famix.Concretization - +createFamixParameterConcretization(concretization: Famix.Concretization): Famix.ParameterConcretization | undefined + +createFamixConcretization(genEntity: Famix.ParametricClass | Famix.ParametricInterface | Famix.ParametricMethod | Famix.ParametricFunction | Famix.ParametricArrowFunction, typeArguments: TypeNode[], triggeringAssociation: Famix.ParametricInvocation | Famix.ParametricEntityTyping | Famix.ParametricInheritance | Famix.ParametricReference): Famix.Concretization[] +createFamixConcretizationClassOrInterfaceSpecialisation(element: ClassDeclaration | InterfaceDeclaration): void +createFamixConcretizationGenericInstantiation(cls: ClassDeclaration): void +createFamixConcretizationFunctionInstantiation(element: FunctionDeclaration | MethodDeclaration): void From 1c9e644822c4209c67a87bbda06a4074700bf031 Mon Sep 17 00:00:00 2001 From: Christopher Fuhrman Date: Mon, 28 Sep 2026 16:57:32 -0400 Subject: [PATCH 10/10] Reference to UML diagram for parametric modeling --- src/analyze_functions/process_functions.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/analyze_functions/process_functions.ts b/src/analyze_functions/process_functions.ts index a878b33b..98068b83 100644 --- a/src/analyze_functions/process_functions.ts +++ b/src/analyze_functions/process_functions.ts @@ -1056,6 +1056,9 @@ function processNodeForInvocations(nodeReferencingInvocable: Identifier, invocab /** * Builds a Famix model for the inheritances of the classes and interfaces of the source files + * + * See https://modularmoose.org/_astro/uml-new-parametrics-mm.BTiU1iMv_1BpMeh.webp + * * @param classes An array of classes * @param interfaces An array of interfaces */