From bf17da20f37ea78fce6c29dc3dffb416d672f493 Mon Sep 17 00:00:00 2001 From: MTahaCode Date: Wed, 22 Jul 2026 16:00:29 -0400 Subject: [PATCH 1/5] Added property to the TFunctionMetrics for cyclomaticComplexity inside generator --- .../FamixTypeScriptArrowFunction.class.st | 5 +- .../FamixTypeScriptFunction.class.st | 5 +- .../FamixTypeScriptTFunctionMetrics.trait.st | 42 ++++++++++++++++ .../FamixTWithSourceLanguages.extension.st | 4 +- .../FamixTypeScriptGenerator.class.st | 49 ++++++++++++------- src/Famix-TypeScript-Generator/package.st | 2 +- 6 files changed, 81 insertions(+), 26 deletions(-) create mode 100644 src/Famix-TypeScript-Entities/FamixTypeScriptTFunctionMetrics.trait.st diff --git a/src/Famix-TypeScript-Entities/FamixTypeScriptArrowFunction.class.st b/src/Famix-TypeScript-Entities/FamixTypeScriptArrowFunction.class.st index 08bb822..5ea002b 100644 --- a/src/Famix-TypeScript-Entities/FamixTypeScriptArrowFunction.class.st +++ b/src/Famix-TypeScript-Entities/FamixTypeScriptArrowFunction.class.st @@ -41,6 +41,7 @@ I represent a TypeScript arrow function. | Name | Type | Default value | Comment | |---| +| `cyclomaticComplexity` | `Number` | false | Cyclomatic Complexity Property for Functions.| | `isStub` | `Boolean` | false | Flag true if the entity attributes are incomplete, either because the entity is missing or not imported.| | `name` | `String` | nil | Basic name of the entity, not full reference.| | `signature` | `String` | nil | Signature of the message being sent| @@ -49,8 +50,8 @@ I represent a TypeScript arrow function. Class { #name : 'FamixTypeScriptArrowFunction', #superclass : 'FamixTypeScriptBehaviouralEntity', - #traits : 'FamixTDefinedInModule + FamixTFunction + FamixTImportable + FamixTInvocable', - #classTraits : 'FamixTDefinedInModule classTrait + FamixTFunction classTrait + FamixTImportable classTrait + FamixTInvocable classTrait', + #traits : 'FamixTDefinedInModule + FamixTFunction + FamixTImportable + FamixTInvocable + FamixTypeScriptTFunctionMetrics', + #classTraits : 'FamixTDefinedInModule classTrait + FamixTFunction classTrait + FamixTImportable classTrait + FamixTInvocable classTrait + FamixTypeScriptTFunctionMetrics classTrait', #category : 'Famix-TypeScript-Entities-Entities', #package : 'Famix-TypeScript-Entities', #tag : 'Entities' diff --git a/src/Famix-TypeScript-Entities/FamixTypeScriptFunction.class.st b/src/Famix-TypeScript-Entities/FamixTypeScriptFunction.class.st index a0927c2..29ee80b 100644 --- a/src/Famix-TypeScript-Entities/FamixTypeScriptFunction.class.st +++ b/src/Famix-TypeScript-Entities/FamixTypeScriptFunction.class.st @@ -41,6 +41,7 @@ I represent a TypeScript function. | Name | Type | Default value | Comment | |---| +| `cyclomaticComplexity` | `Number` | false | Cyclomatic Complexity Property for Functions.| | `isStub` | `Boolean` | false | Flag true if the entity attributes are incomplete, either because the entity is missing or not imported.| | `name` | `String` | nil | Basic name of the entity, not full reference.| | `signature` | `String` | nil | Signature of the message being sent| @@ -49,8 +50,8 @@ I represent a TypeScript function. Class { #name : 'FamixTypeScriptFunction', #superclass : 'FamixTypeScriptBehaviouralEntity', - #traits : 'FamixTDefinedInModule + FamixTFunction + FamixTImportable + FamixTInvocable', - #classTraits : 'FamixTDefinedInModule classTrait + FamixTFunction classTrait + FamixTImportable classTrait + FamixTInvocable classTrait', + #traits : 'FamixTDefinedInModule + FamixTFunction + FamixTImportable + FamixTInvocable + FamixTypeScriptTFunctionMetrics', + #classTraits : 'FamixTDefinedInModule classTrait + FamixTFunction classTrait + FamixTImportable classTrait + FamixTInvocable classTrait + FamixTypeScriptTFunctionMetrics classTrait', #category : 'Famix-TypeScript-Entities-Entities', #package : 'Famix-TypeScript-Entities', #tag : 'Entities' diff --git a/src/Famix-TypeScript-Entities/FamixTypeScriptTFunctionMetrics.trait.st b/src/Famix-TypeScript-Entities/FamixTypeScriptTFunctionMetrics.trait.st new file mode 100644 index 0000000..7b91a34 --- /dev/null +++ b/src/Famix-TypeScript-Entities/FamixTypeScriptTFunctionMetrics.trait.st @@ -0,0 +1,42 @@ +" +## Properties +====================== + +| Name | Type | Default value | Comment | +|---| +| `cyclomaticComplexity` | `Number` | false | Cyclomatic Complexity Property for Functions.| + +" +Trait { + #name : 'FamixTypeScriptTFunctionMetrics', + #instVars : [ + '#cyclomaticComplexity => FMProperty defaultValue: false' + ], + #category : 'Famix-TypeScript-Entities-Traits', + #package : 'Famix-TypeScript-Entities', + #tag : 'Traits' +} + +{ #category : 'meta' } +FamixTypeScriptTFunctionMetrics classSide >> annotation [ + + + + + ^ self +] + +{ #category : 'accessing' } +FamixTypeScriptTFunctionMetrics >> cyclomaticComplexity [ + + + + + ^ cyclomaticComplexity ifNil: [ cyclomaticComplexity := false ] +] + +{ #category : 'accessing' } +FamixTypeScriptTFunctionMetrics >> cyclomaticComplexity: anObject [ + + cyclomaticComplexity := anObject +] diff --git a/src/Famix-TypeScript-Generator/FamixTWithSourceLanguages.extension.st b/src/Famix-TypeScript-Generator/FamixTWithSourceLanguages.extension.st index 8a7b66a..130b75b 100644 --- a/src/Famix-TypeScript-Generator/FamixTWithSourceLanguages.extension.st +++ b/src/Famix-TypeScript-Generator/FamixTWithSourceLanguages.extension.st @@ -1,6 +1,6 @@ -Extension { #name : #FamixTWithSourceLanguages } +Extension { #name : 'FamixTWithSourceLanguages' } -{ #category : #'*Famix-TypeScript-Generator' } +{ #category : '*Famix-TypeScript-Generator' } FamixTWithSourceLanguages >> formattedSourceText [ ^ self sourceLanguage ifNotNil: [ :language | language format: self sourceText from: self ] diff --git a/src/Famix-TypeScript-Generator/FamixTypeScriptGenerator.class.st b/src/Famix-TypeScript-Generator/FamixTypeScriptGenerator.class.st index ed86b8e..fa562ee 100644 --- a/src/Famix-TypeScript-Generator/FamixTypeScriptGenerator.class.st +++ b/src/Famix-TypeScript-Generator/FamixTypeScriptGenerator.class.st @@ -1,6 +1,6 @@ Class { - #name : #FamixTypeScriptGenerator, - #superclass : #FamixBasicInfrastructureGenerator, + #name : 'FamixTypeScriptGenerator', + #superclass : 'FamixBasicInfrastructureGenerator', #instVars : [ 'access', 'class', @@ -44,30 +44,32 @@ Class { 'parametricClass', 'parametricInterface', 'concretization', - 'parameterConcretization' + 'parameterConcretization', + 'tTypeScriptFunctionMetrics' ], - #category : #'Famix-TypeScript-Generator' + #category : 'Famix-TypeScript-Generator', + #package : 'Famix-TypeScript-Generator' } -{ #category : #accessing } +{ #category : 'accessing' } FamixTypeScriptGenerator class >> packageName [ ^ #'Famix-TypeScript-Entities' ] -{ #category : #accessing } +{ #category : 'accessing' } FamixTypeScriptGenerator class >> packageNameForAnnotations [ ^ #'FamixTypeScript' ] -{ #category : #accessing } +{ #category : 'accessing' } FamixTypeScriptGenerator class >> prefix [ ^ #'FamixTypeScript' ] -{ #category : #accessing } +{ #category : 'accessing' } FamixTypeScriptGenerator class >> translationDictionary [ | classNames associations | @@ -79,7 +81,7 @@ FamixTypeScriptGenerator class >> translationDictionary [ ^ Dictionary newFrom: associations. ] -{ #category : #comments } +{ #category : 'comments' } FamixTypeScriptGenerator >> commentForConcretization [ "To verify" ^ '## Relations @@ -113,7 +115,7 @@ FamixTypeScriptGenerator >> commentForConcretization [ ' ] -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } FamixTypeScriptGenerator >> commentForParameterConcretization [ ^ '## Relations ====================== @@ -146,7 +148,7 @@ FamixTypeScriptGenerator >> commentForParameterConcretization [ ' ] -{ #category : #comments } +{ #category : 'comments' } FamixTypeScriptGenerator >> commentForTCanBeInterface [ ^ 'I allow an entity to be an interface abstraction ex: @@ -158,13 +160,13 @@ public interface Flyable { ```' ] -{ #category : #definition } +{ #category : 'definition' } FamixTypeScriptGenerator >> commentForTWithInterfaces [ ^ 'I can contain interfaces (Packages, Methods, Classes...)' ] -{ #category : #definition } +{ #category : 'definition' } FamixTypeScriptGenerator >> defineClasses [ super defineClasses. @@ -221,7 +223,7 @@ FamixTypeScriptGenerator >> defineClasses [ "self defineComments." ] -{ #category : #definition } +{ #category : 'definition' } FamixTypeScriptGenerator >> defineHierarchy [ super defineHierarchy. @@ -283,6 +285,7 @@ FamixTypeScriptGenerator >> defineHierarchy [ function --|> #TDefinedInModule. function --|> #TInvocable. function --|> #TImportable. + function --|> #TFunctionMetrics. parametricFunction --|> function. parametricFunction --|> #TParametricEntity. @@ -292,6 +295,7 @@ FamixTypeScriptGenerator >> defineHierarchy [ arrowFunction --|> #TDefinedInModule. arrowFunction --|> #TInvocable. arrowFunction --|> #TImportable. + arrowFunction --|> #TFunctionMetrics. "Dublicate code for adding cyclomatic complexity" parametricArrowFunction --|> arrowFunction. parametricArrowFunction --|> #TParametricEntity. @@ -416,7 +420,7 @@ FamixTypeScriptGenerator >> defineHierarchy [ parameterType --|> #TWithInheritances. ] -{ #category : #definition } +{ #category : 'definition' } FamixTypeScriptGenerator >> defineProperties [ super defineProperties. @@ -433,7 +437,11 @@ FamixTypeScriptGenerator >> defineProperties [ comment: 'Properties may be postfixed with a private modifier that makes the property private even in JavaScript.'. (comment property: #isJSDoc type: #Boolean defaultValue: false) comment: 'Comments can have the form of JSDoc.'. - + + "Adding the following for cyclomatic complexity property for TFunctionMetrics" + (tTypeScriptFunctionMetrics property: #cyclomaticComplexity type: #Number defaultValue: false) + comment: 'Cyclomatic Complexity Property for Functions.'. + "The following are not need because of THasKind (?)" "(method property: #isConstructor type: #Boolean defaultValue: false) @@ -442,15 +450,17 @@ FamixTypeScriptGenerator >> defineProperties [ comment: 'Method is a getter'. (method property: #isSetter type: #Boolean defaultValue: false) comment: 'Method is a setter'" + + ] -{ #category : #definition } +{ #category : 'definition' } FamixTypeScriptGenerator >> defineRelations [ super defineRelations. (decorator property: #decoratedEntity) *- (namedEntity property: #decorators). ] -{ #category : #definition } +{ #category : 'definition' } FamixTypeScriptGenerator >> defineTraits [ super defineTraits. @@ -458,9 +468,10 @@ FamixTypeScriptGenerator >> defineTraits [ tWithInterfaces comment: self commentForTWithInterfaces. tTypeScriptClassMetrics := builder newTraitNamed: #TClassMetrics. + tTypeScriptFunctionMetrics := builder newTraitNamed: #TFunctionMetrics. ] -{ #category : #definition } +{ #category : 'definition' } FamixTypeScriptGenerator >> newBuilder [ ^ super newBuilder diff --git a/src/Famix-TypeScript-Generator/package.st b/src/Famix-TypeScript-Generator/package.st index 41f22d4..44ed289 100644 --- a/src/Famix-TypeScript-Generator/package.st +++ b/src/Famix-TypeScript-Generator/package.st @@ -1 +1 @@ -Package { #name : #'Famix-TypeScript-Generator' } +Package { #name : 'Famix-TypeScript-Generator' } From f5157389c6309c8ec893b8393cd89573f4e30785 Mon Sep 17 00:00:00 2001 From: MTahaCode Date: Wed, 22 Jul 2026 21:58:58 -0400 Subject: [PATCH 2/5] Added test for cyclomatic complexity presence in function and arrow function --- ...mixTypeScriptTFunctionMetricsTest.class.st | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/Famix-TypeScript-Tests/FamixTypeScriptTFunctionMetricsTest.class.st diff --git a/src/Famix-TypeScript-Tests/FamixTypeScriptTFunctionMetricsTest.class.st b/src/Famix-TypeScript-Tests/FamixTypeScriptTFunctionMetricsTest.class.st new file mode 100644 index 0000000..e1f7dc3 --- /dev/null +++ b/src/Famix-TypeScript-Tests/FamixTypeScriptTFunctionMetricsTest.class.st @@ -0,0 +1,23 @@ +Class { + #name : 'FamixTypeScriptTFunctionMetricsTest', + #superclass : 'TestCase', + #category : 'Famix-TypeScript-Tests-Entities', + #package : 'Famix-TypeScript-Tests', + #tag : 'Entities' +} + +{ #category : 'tests' } +FamixTypeScriptTFunctionMetricsTest >> testCyclomaticComplexityPresence [ + | af1 f1 model | + model := FamixTypeScriptModel new. + f1 := FamixTypeScriptFunction named: 'func1' model: model. + af1 := FamixTypeScriptArrowFunction named: 'arrowFunc1' model: model. + + f1 cyclomaticComplexity: 100. + self assert: f1 cyclomaticComplexity equals: 100. + + af1 cyclomaticComplexity: 100. + self assert: af1 cyclomaticComplexity equals: 100. + + +] From 11d67cae5b025c40e1aa03ea340cea082b0f5477 Mon Sep 17 00:00:00 2001 From: MTahaCode Date: Thu, 23 Jul 2026 15:21:49 -0400 Subject: [PATCH 3/5] Added isAmbient, isModule and isNamespace as properties to FamixTypeScriptModule Entity. --- .../FamixTypeScriptArrowFunction.class.st | 2 +- .../FamixTypeScriptFunction.class.st | 2 +- .../FamixTypeScriptModule.class.st | 13 +++++++++++++ .../FamixTypeScriptTFunctionMetrics.trait.st | 8 ++++---- .../FamixTypeScriptGenerator.class.st | 7 ++++++- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/Famix-TypeScript-Entities/FamixTypeScriptArrowFunction.class.st b/src/Famix-TypeScript-Entities/FamixTypeScriptArrowFunction.class.st index 5ea002b..d784c6f 100644 --- a/src/Famix-TypeScript-Entities/FamixTypeScriptArrowFunction.class.st +++ b/src/Famix-TypeScript-Entities/FamixTypeScriptArrowFunction.class.st @@ -41,7 +41,7 @@ I represent a TypeScript arrow function. | Name | Type | Default value | Comment | |---| -| `cyclomaticComplexity` | `Number` | false | Cyclomatic Complexity Property for Functions.| +| `cyclomaticComplexity` | `Number` | 0 | Cyclomatic Complexity Property for Functions.| | `isStub` | `Boolean` | false | Flag true if the entity attributes are incomplete, either because the entity is missing or not imported.| | `name` | `String` | nil | Basic name of the entity, not full reference.| | `signature` | `String` | nil | Signature of the message being sent| diff --git a/src/Famix-TypeScript-Entities/FamixTypeScriptFunction.class.st b/src/Famix-TypeScript-Entities/FamixTypeScriptFunction.class.st index 29ee80b..35f9208 100644 --- a/src/Famix-TypeScript-Entities/FamixTypeScriptFunction.class.st +++ b/src/Famix-TypeScript-Entities/FamixTypeScriptFunction.class.st @@ -41,7 +41,7 @@ I represent a TypeScript function. | Name | Type | Default value | Comment | |---| -| `cyclomaticComplexity` | `Number` | false | Cyclomatic Complexity Property for Functions.| +| `cyclomaticComplexity` | `Number` | 0 | Cyclomatic Complexity Property for Functions.| | `isStub` | `Boolean` | false | Flag true if the entity attributes are incomplete, either because the entity is missing or not imported.| | `name` | `String` | nil | Basic name of the entity, not full reference.| | `signature` | `String` | nil | Signature of the message being sent| diff --git a/src/Famix-TypeScript-Entities/FamixTypeScriptModule.class.st b/src/Famix-TypeScript-Entities/FamixTypeScriptModule.class.st index 256bbdf..bc31b2d 100644 --- a/src/Famix-TypeScript-Entities/FamixTypeScriptModule.class.st +++ b/src/Famix-TypeScript-Entities/FamixTypeScriptModule.class.st @@ -18,6 +18,14 @@ | `incomingImports` | `FamixTImportable` | `importedEntity` | `FamixTImport` | List of imports of this entity| +## Properties +====================== + +| Name | Type | Default value | Comment | +|---| +| `isAmbient` | `Boolean` | false | | +| `isModule` | `Boolean` | false | | +| `isNamespace` | `Boolean` | false | | " Class { @@ -25,6 +33,11 @@ Class { #superclass : 'FamixTypeScriptScriptEntity', #traits : 'FamixTImportable + FamixTWithImports + FamixTWithLocalVariables', #classTraits : 'FamixTImportable classTrait + FamixTWithImports classTrait + FamixTWithLocalVariables classTrait', + #instVars : [ + '#isAmbient => FMProperty defaultValue: false', + '#isModule => FMProperty defaultValue: false', + '#isNamespace => FMProperty defaultValue: false' + ], #category : 'Famix-TypeScript-Entities-Entities', #package : 'Famix-TypeScript-Entities', #tag : 'Entities' diff --git a/src/Famix-TypeScript-Entities/FamixTypeScriptTFunctionMetrics.trait.st b/src/Famix-TypeScript-Entities/FamixTypeScriptTFunctionMetrics.trait.st index 7b91a34..99b1621 100644 --- a/src/Famix-TypeScript-Entities/FamixTypeScriptTFunctionMetrics.trait.st +++ b/src/Famix-TypeScript-Entities/FamixTypeScriptTFunctionMetrics.trait.st @@ -4,13 +4,13 @@ | Name | Type | Default value | Comment | |---| -| `cyclomaticComplexity` | `Number` | false | Cyclomatic Complexity Property for Functions.| +| `cyclomaticComplexity` | `Number` | 0 | Cyclomatic Complexity Property for Functions.| " Trait { #name : 'FamixTypeScriptTFunctionMetrics', #instVars : [ - '#cyclomaticComplexity => FMProperty defaultValue: false' + '#cyclomaticComplexity => FMProperty defaultValue: 0' ], #category : 'Famix-TypeScript-Entities-Traits', #package : 'Famix-TypeScript-Entities', @@ -29,10 +29,10 @@ FamixTypeScriptTFunctionMetrics classSide >> annotation [ { #category : 'accessing' } FamixTypeScriptTFunctionMetrics >> cyclomaticComplexity [ - + - ^ cyclomaticComplexity ifNil: [ cyclomaticComplexity := false ] + ^ cyclomaticComplexity ifNil: [ cyclomaticComplexity := 0 ] ] { #category : 'accessing' } diff --git a/src/Famix-TypeScript-Generator/FamixTypeScriptGenerator.class.st b/src/Famix-TypeScript-Generator/FamixTypeScriptGenerator.class.st index fa562ee..921d8c2 100644 --- a/src/Famix-TypeScript-Generator/FamixTypeScriptGenerator.class.st +++ b/src/Famix-TypeScript-Generator/FamixTypeScriptGenerator.class.st @@ -438,9 +438,14 @@ FamixTypeScriptGenerator >> defineProperties [ (comment property: #isJSDoc type: #Boolean defaultValue: false) comment: 'Comments can have the form of JSDoc.'. + "Trait Properties can be exported into another function" "Adding the following for cyclomatic complexity property for TFunctionMetrics" - (tTypeScriptFunctionMetrics property: #cyclomaticComplexity type: #Number defaultValue: false) + (tTypeScriptFunctionMetrics property: #cyclomaticComplexity type: #Number defaultValue: 0) comment: 'Cyclomatic Complexity Property for Functions.'. + + (module property: #isAmbient type: #Boolean defaultValue: false). + (module property: #isModule type: #Boolean defaultValue: false). + (module property: #isNamespace type: #Boolean defaultValue: false). "The following are not need because of THasKind (?)" From 1baf2ad868ba376c2b92d75c7aae03d4637c5e85 Mon Sep 17 00:00:00 2001 From: MTahaCode Date: Mon, 27 Jul 2026 12:46:43 -0400 Subject: [PATCH 4/5] added tests for isAmbient, isModule and isNamespace --- .../FamixTypeScriptModuleTest.class.st | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/Famix-TypeScript-Tests/FamixTypeScriptModuleTest.class.st diff --git a/src/Famix-TypeScript-Tests/FamixTypeScriptModuleTest.class.st b/src/Famix-TypeScript-Tests/FamixTypeScriptModuleTest.class.st new file mode 100644 index 0000000..5a7a516 --- /dev/null +++ b/src/Famix-TypeScript-Tests/FamixTypeScriptModuleTest.class.st @@ -0,0 +1,48 @@ +Class { + #name : 'FamixTypeScriptModuleTest', + #superclass : 'TestCase', + #category : 'Famix-TypeScript-Tests', + #package : 'Famix-TypeScript-Tests' +} + +{ #category : 'tests' } +FamixTypeScriptModuleTest >> testIsAmbient [ + | m1 m2 model | + model := FamixTypeScriptModel new. + m1 := FamixTypeScriptModule named: 'module1' model: model. + m2 := FamixTypeScriptModule named: 'module2' model: model. + + m1 isAmbient: true. + self assert: m1 isAmbient equals: true. + + m1 isAmbient: false. + self assert: m1 isAmbient equals: false. +] + +{ #category : 'tests' } +FamixTypeScriptModuleTest >> testIsModule [ + | m1 m2 model | + model := FamixTypeScriptModel new. + m1 := FamixTypeScriptModule named: 'module1' model: model. + m2 := FamixTypeScriptModule named: 'module2' model: model. + + m1 isModule: true. + self assert: m1 isModule equals: true. + + m1 isModule: false. + self assert: m1 isModule equals: false. +] + +{ #category : 'tests' } +FamixTypeScriptModuleTest >> testIsNamespace [ + | m1 m2 model | + model := FamixTypeScriptModel new. + m1 := FamixTypeScriptModule named: 'module1' model: model. + m2 := FamixTypeScriptModule named: 'module2' model: model. + + m1 isNamespace: true. + self assert: m1 isNamespace equals: true. + + m1 isNamespace: false. + self assert: m1 isNamespace equals: false. +] From 8f9399ecebff36c9b071df442dee9eddd8ad228d Mon Sep 17 00:00:00 2001 From: MTahaCode Date: Mon, 3 Aug 2026 16:27:37 -0400 Subject: [PATCH 5/5] updated ci to use Moose 12 --- .github/workflows/common.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/common.yml b/.github/workflows/common.yml index d9a460a..9de40d9 100644 --- a/.github/workflows/common.yml +++ b/.github/workflows/common.yml @@ -15,8 +15,8 @@ jobs: strategy: matrix: # List of images at https://github.com/hpi-swa/smalltalkCI#images - # Use Moose64-11 that includes our visualization tool - smalltalk: [Moose64-11] + # Use Moose64-12 that includes our visualization tool + smalltalk: [Moose64-12] name: ${{ matrix.smalltalk }} steps: - name: Checkout code