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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/pharo-setup.smalltalk.ston
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SmalltalkCISpec {
#loading : [
SCIMetacelloLoadSpec {
#baseline : 'FamixTypeScriptImporterTests',
#repository : 'github://MTahaCode/FamixTypeScriptImporterTests/master',
#directory : 'sunit',
#platforms : [ #pharo ]
}
],
Expand Down
3 changes: 3 additions & 0 deletions .github/sunit/.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
#format : #tonel
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Class {
#name : 'BaselineOfFamixTypeScriptImporterTests',
#superclass : 'BaselineOf',
#category : 'BaselineOfFamixTypeScriptImporterTests',
#package : 'BaselineOfFamixTypeScriptImporterTests'
}

{ #category : 'baselines' }
BaselineOfFamixTypeScriptImporterTests >> baseline: spec [
<baseline>
spec
for: #common
do: [
self defineDependencies: spec.
self definePackages: spec.
self defineGroups: spec ]
]

{ #category : 'dependencies' }
BaselineOfFamixTypeScriptImporterTests >> defineDependencies: spec [
spec
baseline: 'FamixTypeScript'
with: [ spec
repository: 'github://fuhrmanator/FamixTypeScript:master/src' ].
]

{ #category : 'groups' }
BaselineOfFamixTypeScriptImporterTests >> defineGroups: spec [

]

{ #category : 'packages' }
BaselineOfFamixTypeScriptImporterTests >> definePackages: spec [
spec
package: 'Famix-TypeScript-Importer-Tests'.
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : 'BaselineOfFamixTypeScriptImporterTests' }
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Class {
#name : 'AbstractClassWithCommentsTests',
#superclass : 'TestCase',
#instVars : [
'model',
'theClass'
],
#category : 'Famix-TypeScript-Importer-Tests',
#package : 'Famix-TypeScript-Importer-Tests'
}

{ #category : 'running' }
AbstractClassWithCommentsTests >> setUp [
| file modelPath candidateClasses |
super setUp.

modelPath := OSEnvironment current
at: 'MODEL_JSON_PATH'
ifAbsent: [ nil ].

file := modelPath asFileReference.

self assert: file exists description: 'The Json file is missing'.

file readStreamDo: [ :stream |
model := FamixTypeScriptModel new importFromJSONStream: stream
].


"Finding the Abstract Class"
candidateClasses := (model allWithSubTypesOf: FamixTypeScriptClass) select: [ :each |
each name = 'MyAbstractClass' ].

theClass := candidateClasses
detect: [ :each |
| fileName |
fileName := each sourceAnchor ifNotNil: [ :anchor |
anchor fileName ].
fileName notNil and: [
fileName endsWith:
'src/abstractClassWithComments/abstractClassWithComments.ts' ] ].
]

{ #category : 'tests' }
AbstractClassWithCommentsTests >> testClassHasTwoComments [

| comments |
self assert: theClass isNotNil.

comments := theClass comments.
self assert: comments size equals: 2.
]

{ #category : 'tests' }
AbstractClassWithCommentsTests >> testContainsAbstractClass [ [

self assert: theClass isNotNil.
self assert: theClass isAbstract
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
Class {
#name : 'AbstractTests',
#superclass : 'TestCase',
#instVars : [
'model',
'theClass'
],
#category : 'Famix-TypeScript-Importer-Tests',
#package : 'Famix-TypeScript-Importer-Tests'
}

{ #category : 'running' }
AbstractTests >> setUp [
| file modelPath candidateClasses |
super setUp.

modelPath := OSEnvironment current
at: 'MODEL_JSON_PATH'
ifAbsent: [ nil ].

file := modelPath asFileReference.

self assert: file exists description: 'The Json file is missing'.

file readStreamDo: [ :stream |
model := FamixTypeScriptModel new importFromJSONStream: stream
].


"Finding the Abstract Class"
candidateClasses := (model allWithSubTypesOf: FamixTypeScriptClass) select: [ :each |
each name = 'MyAbstractClass' ].

theClass := candidateClasses
detect: [ :each |
| fileName |
fileName := each sourceAnchor ifNotNil: [ :anchor |
anchor fileName ].
fileName notNil and: [
fileName endsWith:
'src/abstracts/abstracts.ts' ] ].
]

{ #category : 'tests' }
AbstractTests >> testContainsAbstractClass [ [

self assert: theClass isNotNil.
self assert: theClass isAbstract
]
]

{ #category : 'tests' }
AbstractTests >> testContainsAbstractMethods [
| abstractMethod1 abstractmethod2 concreteMethod |

self assert: theClass methods size equals: 3.

abstractMethod1 := theClass methods detect: [ :each | each name = 'abstractMethod1' ] ifNone: [ nil ].
abstractmethod2 := theClass methods detect: [ :each | each name = 'abstractMethod2' ] ifNone: [ nil ].
concreteMethod := theClass methods detect: [ :each | each name = 'concreteMethod' ] ifNone: [ nil ].

self assert: abstractMethod1 isNotNil.
self assert: abstractMethod1 isAbstract.

self assert: abstractmethod2 isNotNil.
self assert: abstractmethod2 isAbstract.

self assert: concreteMethod isNotNil.
self deny: concreteMethod isAbstract.
]
1 change: 1 addition & 0 deletions .github/sunit/Famix-TypeScript-Importer-Tests/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : 'Famix-TypeScript-Importer-Tests' }
4 changes: 2 additions & 2 deletions .github/workflows/run-sunit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Pharo/Moose Tests

on:
push:
branches: [ master, update-for-moose13, MTahaCode/issue99 ]
branches: [ master, merge-importer-tests ]
pull_request:
branches: [ master, update-for-moose13 ]
branches: [ master, merge-importer-tests ]

jobs:
test:
Expand Down
3 changes: 3 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
'srcDirectory': '.github/sunit'
}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ To run the locally built version (not the globally installed one with npm).:
npx ts2famix [options]
```

To import sunit test inside moose:
```smalltalk
Metacello new
baseline: 'FamixTypeScriptImporterTests';
repository: 'github://fuhrmanator/FamixTypeScriptImporter:master';
load.
```

## TypeScript Metamodel API documentation (visualization)

The following was generated by CI using [tplant](https://github.com/bafolts/tplant), in a similar fashion described [here](https://modularmoose.org/posts/2021-07-19-automatic-metamodel-documentation-generation).
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts2famix",
"version": "3.2.0",
"version": "3.3.0",
"description": "A TypeScript to JSON importer for Moose.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/analyze_functions/process_functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,8 @@ function processTypeParameters(
* @param tp A type parameter
* @returns A Famix.TypeParameter representing the type parameter
*/
function processTypeParameter(tp: TypeParameterDeclaration): Famix.ParameterType {
const fmxTypeParameter = entityDictionary.createFamixParameterType(tp);
function processTypeParameter(tp: TypeParameterDeclaration): Famix.TypeParameter {
const fmxTypeParameter = entityDictionary.createFamixTypeParameter(tp);
logger.debug(`type parameter: ${tp.getName()}, (${tp.getType().getText()}), fqn = ${fmxTypeParameter.fullyQualifiedName}`);
processComments(tp, fmxTypeParameter);
return fmxTypeParameter;
Expand Down
22 changes: 11 additions & 11 deletions src/famix_functions/EntityDictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class EntityDictionary {
private fmxInterfaceMap = new Map<string, Famix.Interface | Famix.ParametricInterface>(); // Maps the interface names to their Famix model
private fmxModuleMap = new Map<ModuleDeclaration, Famix.Module>(); // Maps the namespace names to their Famix model
private fmxFileMap = new Map<string, Famix.ScriptEntity | Famix.Module>(); // Maps the source file names to their Famix model
private fmxTypeMap = new Map<TSMorphTypeDeclaration, Famix.Type | Famix.ParameterType>(); // Maps the types declarations to their Famix model
private fmxTypeMap = new Map<TSMorphTypeDeclaration, Famix.Type | Famix.TypeParameter>(); // Maps the types declarations to their Famix model
private fmxPrimitiveTypeMap = new Map<string, Famix.PrimitiveType>(); // Maps the primitive type names to their Famix model
private fmxFunctionAndMethodMap = new Map<string, Famix.Function | Famix.ParametricFunction | Famix.Method | Famix.ParametricMethod>; // Maps the function names to their Famix model
private fmxArrowFunctionMap = new Map<string, Famix.ArrowFunction>; // Maps the function names to their Famix model
Expand Down Expand Up @@ -744,19 +744,19 @@ export class EntityDictionary {
* @param tp A type parameter
* @returns The Famix model of the type parameter
*/
public createFamixParameterType(tp: TypeParameterDeclaration): Famix.ParameterType {
public createFamixTypeParameter(tp: TypeParameterDeclaration): Famix.TypeParameter {

const fmxParameterType = new Famix.ParameterType();
const fmxTypeParameter = new Famix.TypeParameter();

fmxParameterType.name = tp.getName();
initFQN(tp, fmxParameterType);
this.makeFamixIndexFileAnchor(tp, fmxParameterType);
fmxTypeParameter.name = tp.getName();
initFQN(tp, fmxTypeParameter);
this.makeFamixIndexFileAnchor(tp, fmxTypeParameter);

this.famixRep.addElement(fmxParameterType);
this.famixRep.addElement(fmxTypeParameter);

this.fmxElementObjectMap.set(fmxParameterType,tp);
this.fmxElementObjectMap.set(fmxTypeParameter,tp);

return fmxParameterType;
return fmxTypeParameter;
}


Expand Down Expand Up @@ -1668,8 +1668,8 @@ export class EntityDictionary {
let fmxParameterConcretization : Famix.ParameterConcretization | undefined = undefined;

for (let i = 0; i < genericParameters.size; i++) {
const conClassTypeParameter = conClassTypeParametersIterator.next().value as Famix.ParameterType;
const genClassTypeParameter = genClassTypeParametersIterator.next().value as Famix.ParameterType;
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) => {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/famix/model/famix/behavioral_entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FamixJSONExporter } from "../../famix_JSON_exporter";
import { ContainerEntity } from "./container_entity";
import { Parameter } from "./parameter";
import { Invocation } from "./invocation";
import { ParameterType } from "./parameter_type";
import { TypeParameter } from "./type_parameter";
import { EntityTyping } from "./entity_typing";

export class BehavioralEntity extends ContainerEntity {
Expand All @@ -28,9 +28,9 @@ export class BehavioralEntity extends ContainerEntity {
}

private _typing!: EntityTyping;
private _genericParameters: Set<ParameterType> = new Set();
private _genericParameters: Set<TypeParameter> = new Set();

public addGenericParameter(genericParameter: ParameterType): void {
public addGenericParameter(genericParameter: TypeParameter): void {
if (!this._genericParameters.has(genericParameter)) {
this._genericParameters.add(genericParameter);
genericParameter.parentGeneric = this;
Expand Down Expand Up @@ -87,7 +87,7 @@ export class BehavioralEntity extends ContainerEntity {
this._typing = typing;
}

get genericParameters(): Set<ParameterType> {
get genericParameters(): Set<TypeParameter> {
return this._genericParameters;
}
}
2 changes: 1 addition & 1 deletion src/lib/famix/model/famix/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export { Invocation } from "./invocation";
export { Method } from "./method";
export { Module } from "./module";
export { NamedEntity } from "./named_entity";
export { ParameterType } from "./parameter_type";
export { TypeParameter } from "./type_parameter";
export { Parameter } from "./parameter";
export { ParametricClass } from "./parametric_class";
export { ParametricInterface } from "./parametric_interface";
Expand Down
6 changes: 3 additions & 3 deletions src/lib/famix/model/famix/parameter_concretization.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { FamixJSONExporter } from "../../famix_JSON_exporter";
import { Concretization } from "./concretization";
import { Entity } from "./entity";
import { ParameterType } from "./parameter_type";
import { TypeParameter } from "./type_parameter";
import { PrimitiveType } from "./primitive_type";

export class ParameterConcretization extends Entity {

private _genericParameter!: ParameterType;
private _genericParameter!: TypeParameter;
private _concreteParameter!: PrimitiveType;
private _concretizations: Set<Concretization> = new Set();

Expand All @@ -33,7 +33,7 @@ export class ParameterConcretization extends Entity {
return this._genericParameter;
}

set genericParameter(genericEntity: ParameterType) {
set genericParameter(genericEntity: TypeParameter) {
this._genericParameter = genericEntity;
}

Expand Down
8 changes: 4 additions & 4 deletions src/lib/famix/model/famix/parametric_class.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Interface } from "./interface";
import { FamixJSONExporter } from "../../famix_JSON_exporter";
import { Class } from "./class";
import { ParameterType } from "./parameter_type";
import { TypeParameter } from "./type_parameter";
import { PrimitiveType } from "./primitive_type";

export class ParametricClass extends Class {

private _genericParameters: Set<ParameterType> = new Set();
private _genericParameters: Set<TypeParameter> = new Set();

public addGenericParameter(genericParameter: ParameterType): void {
public addGenericParameter(genericParameter: TypeParameter): void {
if (!this._genericParameters.has(genericParameter)) {
this._genericParameters.add(genericParameter);
genericParameter.parentGeneric = this;
Expand Down Expand Up @@ -39,7 +39,7 @@ export class ParametricClass extends Class {
exporter.addProperty("concreteParameters", this.concreteParameters);
}

get genericParameters(): Set<ParameterType> {
get genericParameters(): Set<TypeParameter> {
return this._genericParameters;
}

Expand Down
Loading