Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ImporterSampleProject/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"emitDecoratorMetadata": true,
"resolveJsonModule": true
},
"include": ["src/**/*.ts"],
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["node_modules", "dist"]
}
209 changes: 118 additions & 91 deletions doc-uml/famix-typescript-model.puml

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions src/analyze_functions/process_functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -1052,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
*/
Expand Down
464 changes: 244 additions & 220 deletions src/famix_functions/EntityDictionary.ts

Large diffs are not rendered by default.

24 changes: 4 additions & 20 deletions src/lib/famix/model/famix/behavioral_entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -27,19 +27,7 @@ export class BehavioralEntity extends ContainerEntity {
}
}

private _typing!: EntityTyping;
private _genericParameters: Set<TypeParameter> = 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);
Expand Down Expand Up @@ -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<TypeParameter> {
return this._genericParameters;
}
}
45 changes: 33 additions & 12 deletions src/lib/famix/model/famix/concretization.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
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";
import { ParametricFunction } from "./parametric_function";
import { ParametricInterface } from "./parametric_interface";
import { ParametricMethod } from "./parametric_method";

// More will be added here (e.g. ParametricImplementation, once Implementation exists)
type ParametricAssociation = ParametricEntityTyping | ParametricInvocation | ParametricInheritance | ParametricReference;

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);
Expand All @@ -18,23 +28,34 @@ 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;
typeParameter.addConcretization(this);
}

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;
typeArgument.addOutgoingConcretization(this);
}

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;
}
}
8 changes: 6 additions & 2 deletions src/lib/famix/model/famix/entity_typing.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -23,7 +27,7 @@ export class EntityTyping extends Entity {
return this._typedEntity;
}

set typedEntity(typedEntity: Entity) {
set typedEntity(typedEntity: TypedEntity) {
this._typedEntity = typedEntity;
}

Expand Down
3 changes: 3 additions & 0 deletions src/lib/famix/model/famix/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ 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";
export { ParametricInheritance } from "./parametric_inheritance";
export { ParametricReference } from "./parametric_reference";
24 changes: 13 additions & 11 deletions src/lib/famix/model/famix/parametric_arrow_function.ts
Original file line number Diff line number Diff line change
@@ -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<PrimitiveType | Class | Interface> = new Set();
private _typeParameters: Set<TypeParameter> = 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);
Expand All @@ -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<TypeParameter> {
return this._typeParameters;
}
}
35 changes: 10 additions & 25 deletions src/lib/famix/model/famix/parametric_class.ts
Original file line number Diff line number Diff line change
@@ -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<TypeParameter> = new Set();
private _typeParameters: Set<TypeParameter> = 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<PrimitiveType | Class | Interface> = 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 {
Expand All @@ -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<TypeParameter> {
return this._genericParameters;
exporter.addProperty("typeParameters", this._typeParameters);
}

get concreteParameters(): Set<PrimitiveType | Class | Interface> {
return this._concreteParameters;
get typeParameters(): Set<TypeParameter> {
return this._typeParameters;
}
}
17 changes: 16 additions & 1 deletion src/lib/famix/model/famix/parametric_entity_typing.ts
Original file line number Diff line number Diff line change
@@ -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<Concretization> = new Set();

public addConcretization(concretization: Concretization): void {
if (!this._concretizations.has(concretization)) {
this._concretizations.add(concretization);
concretization.triggeringAssociation = this;
}
}

public get concretizations(): Set<Concretization> {
return this._concretizations;
}

public getJSON(): string {
const json: FamixJSONExporter = new FamixJSONExporter("ParametricEntityTyping", this);
this.addPropertiesToExporter(json);
Expand All @@ -13,5 +27,6 @@ export class ParametricEntityTyping extends EntityTyping {

public addPropertiesToExporter(exporter: FamixJSONExporter): void {
super.addPropertiesToExporter(exporter);
exporter.addProperty("concretizations", this.concretizations);
}
}
24 changes: 13 additions & 11 deletions src/lib/famix/model/famix/parametric_function.ts
Original file line number Diff line number Diff line change
@@ -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<PrimitiveType | Class | Interface> = new Set();
private _typeParameters: Set<TypeParameter> = 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);
Expand All @@ -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<PrimitiveType | Class | Interface> {
return this._concreteParameters;
get typeParameters(): Set<TypeParameter> {
return this._typeParameters;
}
}
Loading
Loading