ts2famix 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +5 -5
  2. package/dist/analyze.js +8 -5
  3. package/dist/analyze_functions/processAccesses.js +7 -6
  4. package/dist/analyze_functions/processFiles.js +43 -43
  5. package/dist/analyze_functions/processImportClauses.js +25 -7
  6. package/dist/analyze_functions/processInheritances.js +8 -7
  7. package/dist/analyze_functions/processInvocations.js +6 -5
  8. package/dist/famix_functions/famix_functions.js +19 -21
  9. package/dist/famix_functions/famix_functions_associations.js +29 -14
  10. package/dist/famix_functions/famix_functions_index.js +32 -15
  11. package/dist/famix_functions/famix_functions_types.js +2 -1
  12. package/dist/lib/famix/src/famix_repository.js +6 -0
  13. package/dist/lib/famix/src/model/famix/access.js +3 -3
  14. package/dist/lib/famix/src/model/famix/accessor.js +3 -3
  15. package/dist/lib/famix/src/model/famix/alias.js +3 -3
  16. package/dist/lib/famix/src/model/famix/association.js +3 -3
  17. package/dist/lib/famix/src/model/famix/behavioral_entity.js +6 -6
  18. package/dist/lib/famix/src/model/famix/class.js +3 -3
  19. package/dist/lib/famix/src/model/famix/comment.js +3 -3
  20. package/dist/lib/famix/src/model/famix/container_entity.js +3 -3
  21. package/dist/lib/famix/src/model/famix/decorator.js +3 -3
  22. package/dist/lib/famix/src/model/famix/entity.js +3 -3
  23. package/dist/lib/famix/src/model/famix/enum.js +3 -3
  24. package/dist/lib/famix/src/model/famix/enum_value.js +3 -3
  25. package/dist/lib/famix/src/model/famix/function.js +3 -3
  26. package/dist/lib/famix/src/model/famix/implicit_variable.js +3 -3
  27. package/dist/lib/famix/src/model/famix/import_clause.js +3 -3
  28. package/dist/lib/famix/src/model/famix/index.js +3 -7
  29. package/dist/lib/famix/src/model/famix/indexed_file_anchor.js +17 -3
  30. package/dist/lib/famix/src/model/famix/inheritance.js +3 -3
  31. package/dist/lib/famix/src/model/famix/interface.js +3 -3
  32. package/dist/lib/famix/src/model/famix/invocation.js +3 -3
  33. package/dist/lib/famix/src/model/famix/method.js +3 -3
  34. package/dist/lib/famix/src/model/famix/module.js +3 -3
  35. package/dist/lib/famix/src/model/famix/named_entity.js +4 -4
  36. package/dist/lib/famix/src/model/famix/namespace.js +3 -3
  37. package/dist/lib/famix/src/model/famix/parameter.js +3 -3
  38. package/dist/lib/famix/src/model/famix/{type_parameter.js → parameter_type.js} +7 -7
  39. package/dist/lib/famix/src/model/famix/parameterizable_class.js +11 -11
  40. package/dist/lib/famix/src/model/famix/parameterizable_interface.js +11 -11
  41. package/dist/lib/famix/src/model/famix/parameterized_type.js +3 -3
  42. package/dist/lib/famix/src/model/famix/primitive_type.js +3 -3
  43. package/dist/lib/famix/src/model/famix/property.js +3 -3
  44. package/dist/lib/famix/src/model/famix/reference.js +3 -3
  45. package/dist/lib/famix/src/model/famix/scoping_entity.js +6 -5
  46. package/dist/lib/famix/src/model/famix/script_entity.js +3 -3
  47. package/dist/lib/famix/src/model/famix/source_anchor.js +3 -3
  48. package/dist/lib/famix/src/model/famix/source_language.js +8 -3
  49. package/dist/lib/famix/src/model/famix/sourced_entity.js +7 -3
  50. package/dist/lib/famix/src/model/famix/structural_entity.js +3 -3
  51. package/dist/lib/famix/src/model/famix/text_anchor.js +3 -3
  52. package/dist/lib/famix/src/model/famix/type.js +3 -3
  53. package/dist/lib/famix/src/model/famix/variable.js +3 -3
  54. package/dist/ts2famix-cli.js +16 -3
  55. package/package.json +14 -13
  56. package/src/analyze.ts +10 -4
  57. package/src/analyze_functions/processAccesses.ts +7 -6
  58. package/src/analyze_functions/processFiles.ts +44 -46
  59. package/src/analyze_functions/processImportClauses.ts +25 -7
  60. package/src/analyze_functions/processInheritances.ts +8 -7
  61. package/src/analyze_functions/processInvocations.ts +6 -5
  62. package/src/famix_functions/famix_functions.ts +20 -23
  63. package/src/famix_functions/famix_functions_associations.ts +32 -15
  64. package/src/famix_functions/famix_functions_index.ts +34 -18
  65. package/src/famix_functions/famix_functions_types.ts +2 -1
  66. package/src/generate_uml.sh +1 -0
  67. package/src/lib/famix/src/famix_repository.ts +12 -3
  68. package/src/lib/famix/src/model/famix/access.ts +3 -3
  69. package/src/lib/famix/src/model/famix/accessor.ts +3 -3
  70. package/src/lib/famix/src/model/famix/alias.ts +3 -3
  71. package/src/lib/famix/src/model/famix/association.ts +3 -3
  72. package/src/lib/famix/src/model/famix/behavioral_entity.ts +8 -8
  73. package/src/lib/famix/src/model/famix/class.ts +3 -3
  74. package/src/lib/famix/src/model/famix/comment.ts +3 -3
  75. package/src/lib/famix/src/model/famix/container_entity.ts +3 -3
  76. package/src/lib/famix/src/model/famix/decorator.ts +3 -3
  77. package/src/lib/famix/src/model/famix/entity.ts +3 -3
  78. package/src/lib/famix/src/model/famix/enum.ts +3 -3
  79. package/src/lib/famix/src/model/famix/enum_value.ts +3 -3
  80. package/src/lib/famix/src/model/famix/function.ts +3 -3
  81. package/src/lib/famix/src/model/famix/implicit_variable.ts +3 -3
  82. package/src/lib/famix/src/model/famix/import_clause.ts +3 -3
  83. package/src/lib/famix/src/model/famix/index.ts +40 -42
  84. package/src/lib/famix/src/model/famix/indexed_file_anchor.ts +25 -3
  85. package/src/lib/famix/src/model/famix/inheritance.ts +3 -3
  86. package/src/lib/famix/src/model/famix/interface.ts +3 -3
  87. package/src/lib/famix/src/model/famix/invocation.ts +3 -3
  88. package/src/lib/famix/src/model/famix/method.ts +3 -3
  89. package/src/lib/famix/src/model/famix/module.ts +3 -3
  90. package/src/lib/famix/src/model/famix/named_entity.ts +4 -4
  91. package/src/lib/famix/src/model/famix/namespace.ts +3 -3
  92. package/src/lib/famix/src/model/famix/parameter.ts +3 -3
  93. package/src/lib/famix/src/model/famix/{type_parameter.ts → parameter_type.ts} +9 -9
  94. package/src/lib/famix/src/model/famix/parameterizable_class.ts +12 -12
  95. package/src/lib/famix/src/model/famix/parameterizable_interface.ts +12 -12
  96. package/src/lib/famix/src/model/famix/parameterized_type.ts +3 -3
  97. package/src/lib/famix/src/model/famix/primitive_type.ts +3 -3
  98. package/src/lib/famix/src/model/famix/property.ts +3 -3
  99. package/src/lib/famix/src/model/famix/reference.ts +3 -3
  100. package/src/lib/famix/src/model/famix/scoping_entity.ts +6 -5
  101. package/src/lib/famix/src/model/famix/script_entity.ts +3 -3
  102. package/src/lib/famix/src/model/famix/source_anchor.ts +3 -3
  103. package/src/lib/famix/src/model/famix/source_language.ts +9 -3
  104. package/src/lib/famix/src/model/famix/sourced_entity.ts +6 -3
  105. package/src/lib/famix/src/model/famix/structural_entity.ts +3 -3
  106. package/src/lib/famix/src/model/famix/text_anchor.ts +3 -3
  107. package/src/lib/famix/src/model/famix/type.ts +3 -3
  108. package/src/lib/famix/src/model/famix/variable.ts +3 -3
  109. package/src/ts2famix-cli.ts +17 -3
  110. package/dist/lib/famix/src/model/famix/c_source_language.js +0 -16
  111. package/dist/lib/famix/src/model/famix/custom_source_language.js +0 -23
  112. package/src/lib/famix/src/model/famix/c_source_language.ts +0 -15
  113. package/src/lib/famix/src/model/famix/custom_source_language.ts +0 -27
@@ -31,6 +31,7 @@ const fqn_1 = require("../fqn");
31
31
  const famix_functions_index_1 = require("./famix_functions_index");
32
32
  const famix_functions_associations_1 = require("./famix_functions_associations");
33
33
  const famix_functions_types_1 = require("./famix_functions_types");
34
+ const analyze_1 = require("../analyze");
34
35
  /**
35
36
  * This class contains all the functions needed to create Famix entities
36
37
  */
@@ -115,7 +116,7 @@ class FamixFunctions {
115
116
  fmxAlias = new Famix.Alias(this.famixRep);
116
117
  fmxAlias.setName(a.getName());
117
118
  const aliasNameWithGenerics = aliasName + (a.getTypeParameters().length ? ("<" + a.getTypeParameters().map(tp => tp.getName()).join(", ") + ">") : "");
118
- console.info(`> NOTE: alias ${aliasName} has fully qualified name ${aliasFullyQualifiedName} and name with generics ${aliasNameWithGenerics}.`);
119
+ analyze_1.logger.debug(`> NOTE: alias ${aliasName} has fully qualified name ${aliasFullyQualifiedName} and name with generics ${aliasNameWithGenerics}.`);
119
120
  const fmxType = this.createOrGetFamixType(aliasNameWithGenerics, a);
120
121
  fmxAlias.setAliasedEntity(fmxType);
121
122
  this.famixFunctionsIndex.makeFamixIndexFileAnchor(a, fmxAlias);
@@ -195,7 +196,7 @@ class FamixFunctions {
195
196
  propTypeName = property.getType().getText().trim();
196
197
  }
197
198
  catch (error) {
198
- console.error(`> WARNING: got exception ${error}. Failed to get usable name for property: ${property.getName()}. Continuing...`);
199
+ analyze_1.logger.error(`> WARNING: got exception ${error}. Failed to get usable name for property: ${property.getName()}. Continuing...`);
199
200
  }
200
201
  const fmxType = this.createOrGetFamixType(propTypeName, property);
201
202
  fmxProperty.setDeclaredType(fmxType);
@@ -288,7 +289,7 @@ class FamixFunctions {
288
289
  methodTypeName = method.getReturnType().getText().trim();
289
290
  }
290
291
  catch (error) {
291
- console.error(`> WARNING: got exception ${error}. Failed to get usable name for return type of method: ${fmxMethod.getName()}. Continuing...`);
292
+ analyze_1.logger.error(`> WARNING: got exception ${error}. Failed to get usable name for return type of method: ${fmxMethod.getName()}. Continuing...`);
292
293
  }
293
294
  const fmxType = this.createOrGetFamixType(methodTypeName, method);
294
295
  fmxMethod.setDeclaredType(fmxType);
@@ -327,7 +328,7 @@ class FamixFunctions {
327
328
  functionTypeName = func.getReturnType().getText().trim();
328
329
  }
329
330
  catch (error) {
330
- console.error(`> WARNING: got exception ${error}. Failed to get usable name for return type of function: ${func.getName()}. Continuing...`);
331
+ analyze_1.logger.error(`> WARNING: got exception ${error}. Failed to get usable name for return type of function: ${func.getName()}. Continuing...`);
331
332
  }
332
333
  const fmxType = this.createOrGetFamixType(functionTypeName, func);
333
334
  fmxFunction.setDeclaredType(fmxType);
@@ -350,7 +351,7 @@ class FamixFunctions {
350
351
  paramTypeName = param.getType().getText().trim();
351
352
  }
352
353
  catch (error) {
353
- console.error(`> WARNING: got exception ${error}. Failed to get usable name for parameter: ${param.getName()}. Continuing...`);
354
+ analyze_1.logger.error(`> WARNING: got exception ${error}. Failed to get usable name for parameter: ${param.getName()}. Continuing...`);
354
355
  }
355
356
  const fmxType = this.createOrGetFamixType(paramTypeName, param);
356
357
  fmxParam.setDeclaredType(fmxType);
@@ -363,11 +364,11 @@ class FamixFunctions {
363
364
  * @param tp A type parameter
364
365
  * @returns The Famix model of the type parameter
365
366
  */
366
- createFamixTypeParameter(tp) {
367
- const fmxTypeParameter = new Famix.TypeParameter(this.famixRep);
368
- fmxTypeParameter.setName(tp.getName());
369
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(tp, fmxTypeParameter);
370
- return fmxTypeParameter;
367
+ createFamixParameterType(tp) {
368
+ const fmxParameterType = new Famix.ParameterType(this.famixRep);
369
+ fmxParameterType.setName(tp.getName());
370
+ this.famixFunctionsIndex.makeFamixIndexFileAnchor(tp, fmxParameterType);
371
+ return fmxParameterType;
371
372
  }
372
373
  /**
373
374
  * Creates a Famix variable
@@ -381,7 +382,7 @@ class FamixFunctions {
381
382
  variableTypeName = variable.getType().getText().trim();
382
383
  }
383
384
  catch (error) {
384
- console.error(`> WARNING: got exception ${error}. Failed to get usable name for variable: ${variable.getName()}. Continuing...`);
385
+ analyze_1.logger.error(`> WARNING: got exception ${error}. Failed to get usable name for variable: ${variable.getName()}. Continuing...`);
385
386
  }
386
387
  const fmxType = this.createOrGetFamixType(variableTypeName, variable);
387
388
  fmxVariable.setDeclaredType(fmxType);
@@ -412,7 +413,7 @@ class FamixFunctions {
412
413
  enumValueTypeName = enumMember.getType().getText().trim();
413
414
  }
414
415
  catch (error) {
415
- console.error(`> WARNING: got exception ${error}. Failed to get usable name for enum value: ${enumMember.getName()}. Continuing...`);
416
+ analyze_1.logger.error(`> WARNING: got exception ${error}. Failed to get usable name for enum value: ${enumMember.getName()}. Continuing...`);
416
417
  }
417
418
  const fmxType = this.createOrGetFamixType(enumValueTypeName, enumMember);
418
419
  fmxEnumValue.setDeclaredType(fmxType);
@@ -446,9 +447,9 @@ class FamixFunctions {
446
447
  * @returns The Famix model of the comment
447
448
  */
448
449
  createFamixComment(comment, fmxScope, isJSDoc) {
450
+ analyze_1.logger.debug(`> NOTE: creating comment ${comment.getText()} in scope ${fmxScope.getName()}.`);
449
451
  const fmxComment = new Famix.Comment(this.famixRep);
450
- fmxComment.setContent(comment.getText());
451
- fmxComment.setContainer(fmxScope);
452
+ fmxComment.setContainer(fmxScope); // adds comment to the container's comments collection
452
453
  fmxComment.setIsJSDoc(isJSDoc);
453
454
  this.famixFunctionsIndex.makeFamixIndexFileAnchor(comment, fmxComment);
454
455
  return fmxComment;
@@ -489,6 +490,8 @@ class FamixFunctions {
489
490
  }
490
491
  /**
491
492
  * Creates a Famix import clause
493
+ * @param importClauseInfo An import clause
494
+ * @param importDeclaration An import declaration (optional)
492
495
  * @param importer A source file which is a module
493
496
  * @param moduleSpecifier The name of the module where the export declaration is
494
497
  * @param moduleSpecifierFilePath The path of the module where the export declaration is
@@ -496,13 +499,8 @@ class FamixFunctions {
496
499
  * @param isInExports A boolean indicating if the imported entity is in the exports
497
500
  * @param isDefaultExport A boolean indicating if the imported entity is a default export
498
501
  */
499
- createFamixImportClause(importer, moduleSpecifier, moduleSpecifierFilePath, importElement, isInExports, isDefaultExport) {
500
- this.famixFunctionsAssociations.createFamixImportClause(importer, moduleSpecifier, moduleSpecifierFilePath, importElement, isInExports, isDefaultExport);
501
- }
502
- // create the same function as createFamixImportClause but with a signature that has a single object parameter that has all the parameters
503
- // this way we can call this function from the processImportClauses.ts file
504
- createFamixImportClause2(importClause) {
505
- this.famixFunctionsAssociations.createFamixImportClause(importClause.importer, importClause.moduleSpecifier, importClause.moduleSpecifierFilePath, importClause.importElement, importClause.isInExports, importClause.isDefaultExport);
502
+ createFamixImportClause(importClauseInfo) {
503
+ this.famixFunctionsAssociations.createFamixImportClause(importClauseInfo);
506
504
  }
507
505
  /**
508
506
  * Gets a Famix entity by fully qualified name
@@ -28,7 +28,7 @@ const ts_morph_1 = require("ts-morph");
28
28
  const Famix = __importStar(require("../lib/famix/src/model/famix"));
29
29
  const fqn_1 = require("../fqn");
30
30
  const famix_functions_index_1 = require("./famix_functions_index");
31
- const famix_1 = require("../lib/famix/src/model/famix");
31
+ const analyze_1 = require("../analyze");
32
32
  /**
33
33
  * This class is used to build a Famix model for the associations
34
34
  */
@@ -90,7 +90,7 @@ class FamixFunctionsAssociations {
90
90
  const fmxInheritance = new Famix.Inheritance(this.famixRep);
91
91
  // const clsName = cls.getName();
92
92
  const classFullyQualifiedName = this.FQNFunctions.getFQN(cls);
93
- console.info(`createFamixInheritance: classFullyQualifiedName: class fqn = ${classFullyQualifiedName}`);
93
+ analyze_1.logger.debug(`createFamixInheritance: classFullyQualifiedName: class fqn = ${classFullyQualifiedName}`);
94
94
  let subClass;
95
95
  if (cls instanceof ts_morph_1.ClassDeclaration) {
96
96
  subClass = this.famixClassMap.get(classFullyQualifiedName);
@@ -137,16 +137,18 @@ class FamixFunctionsAssociations {
137
137
  }
138
138
  /**
139
139
  * Creates a Famix import clause
140
+ * @param importClauseInfo The information needed to create a Famix import clause
141
+ * @param importDeclaration The import declaration
140
142
  * @param importer A source file which is a module
141
- * @param moduleSpecifier The name of the module where the export declaration is
142
143
  * @param moduleSpecifierFilePath The path of the module where the export declaration is
143
144
  * @param importElement The imported entity
144
145
  * @param isInExports A boolean indicating if the imported entity is in the exports
145
146
  * @param isDefaultExport A boolean indicating if the imported entity is a default export
146
147
  */
147
- createFamixImportClause(importer, moduleSpecifier, moduleSpecifierFilePath, importElement, isInExports, isDefaultExport) {
148
+ createFamixImportClause(importClauseInfo) {
148
149
  var _a, _b;
149
- console.info(`createFamixImportClause: Creating import clause:`);
150
+ const { importDeclaration, importer, moduleSpecifierFilePath, importElement, isInExports, isDefaultExport } = importClauseInfo;
151
+ analyze_1.logger.debug(`createFamixImportClause: Creating import clause:`);
150
152
  const fmxImportClause = new Famix.ImportClause(this.famixRep);
151
153
  let importedEntity;
152
154
  let importedEntityName;
@@ -184,15 +186,10 @@ class FamixFunctionsAssociations {
184
186
  const fmxImporter = this.getFamixEntityByFullyQualifiedName(importerFullyQualifiedName);
185
187
  fmxImportClause.setImportingEntity(fmxImporter);
186
188
  fmxImportClause.setImportedEntity(importedEntity);
187
- fmxImportClause.setModuleSpecifier(moduleSpecifier);
188
- console.info(`createFamixImportClause: ${(_a = fmxImportClause.getImportedEntity()) === null || _a === void 0 ? void 0 : _a.getName()} (of type ${fmxImportClause.getImportedEntity() instanceof famix_1.Class ? 'Class' :
189
- fmxImportClause.getImportedEntity() instanceof famix_1.Interface ? 'Interface' :
190
- fmxImportClause.getImportedEntity() instanceof Function ? 'Function' :
191
- fmxImportClause.getImportedEntity() instanceof famix_1.Enum ? 'Enum' :
192
- fmxImportClause.getImportedEntity() instanceof famix_1.Alias ? 'Alias' :
193
- fmxImportClause.getImportedEntity() instanceof famix_1.Variable ? 'Variable' :
194
- 'NamedEntity'}) is imported by ${(_b = fmxImportClause.getImportingEntity()) === null || _b === void 0 ? void 0 : _b.getName()}`);
195
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(null, fmxImportClause);
189
+ fmxImportClause.setModuleSpecifier(importDeclaration === null || importDeclaration === void 0 ? void 0 : importDeclaration.getModuleSpecifierValue());
190
+ analyze_1.logger.debug(`createFamixImportClause: ${(_a = fmxImportClause.getImportedEntity()) === null || _a === void 0 ? void 0 : _a.getName()} (of type ${getSubTypeName(fmxImportClause.getImportedEntity())}) is imported by ${(_b = fmxImportClause.getImportingEntity()) === null || _b === void 0 ? void 0 : _b.getName()}`);
191
+ // make an index file anchor for the import clause
192
+ this.famixFunctionsIndex.makeFamixIndexFileAnchor(importDeclaration, fmxImportClause);
196
193
  fmxImporter.addOutgoingImport(fmxImportClause);
197
194
  }
198
195
  /**
@@ -221,3 +218,21 @@ class FamixFunctionsAssociations {
221
218
  }
222
219
  }
223
220
  exports.FamixFunctionsAssociations = FamixFunctionsAssociations;
221
+ function getSubTypeName(fmxNamedEntity) {
222
+ const name = fmxNamedEntity instanceof Famix.Class ? 'Class' :
223
+ fmxNamedEntity instanceof Famix.Interface ? 'Interface' :
224
+ fmxNamedEntity instanceof Famix.Function ? 'Function' :
225
+ fmxNamedEntity instanceof Famix.Enum ? 'Enum' :
226
+ fmxNamedEntity instanceof Famix.EnumValue ? 'EnumValue' :
227
+ fmxNamedEntity instanceof Famix.Alias ? 'Alias' :
228
+ fmxNamedEntity instanceof Famix.Variable ? 'Variable' :
229
+ fmxNamedEntity instanceof Famix.Type ? 'Type' :
230
+ fmxNamedEntity instanceof Famix.Method ? 'Method' :
231
+ fmxNamedEntity instanceof Famix.Decorator ? 'Decorator' :
232
+ fmxNamedEntity instanceof Famix.Accessor ? 'Accessor' :
233
+ fmxNamedEntity instanceof Famix.Parameter ? 'Parameter' :
234
+ fmxNamedEntity instanceof Famix.Property ? 'Property' :
235
+ 'NamedEntity';
236
+ analyze_1.logger.debug(`${fmxNamedEntity.getName()} is of type ${name}`);
237
+ return name;
238
+ }
@@ -31,6 +31,7 @@ const ts_morph_1 = require("ts-morph");
31
31
  const Famix = __importStar(require("../lib/famix/src/model/famix"));
32
32
  const fqn_1 = require("../fqn");
33
33
  const grapheme_splitter_1 = __importDefault(require("grapheme-splitter"));
34
+ const analyze_1 = require("../analyze");
34
35
  /**
35
36
  * This class is used to build a Famix model for the index file anchors
36
37
  */
@@ -49,12 +50,23 @@ class FamixFunctionsIndex {
49
50
  * @param famixElement The Famix model of the source element
50
51
  */
51
52
  makeFamixIndexFileAnchor(sourceElement, famixElement) {
53
+ analyze_1.logger.debug("making index file anchor for '" + (sourceElement === null || sourceElement === void 0 ? void 0 : sourceElement.getText()) + "' with famixElement " + famixElement.getJSON());
52
54
  const fmxIndexFileAnchor = new Famix.IndexedFileAnchor(this.famixRep);
53
55
  fmxIndexFileAnchor.setElement(famixElement);
54
56
  if (sourceElement !== null) {
55
57
  fmxIndexFileAnchor.setFileName(sourceElement.getSourceFile().getFilePath());
58
+ let sourceStart, sourceEnd, sourceLineStart, sourceLineEnd;
56
59
  if (!(sourceElement instanceof ts_morph_1.CommentRange)) {
57
- // sourceElement.getStart() and sourceElement.getEnd() are based on text that has not been split into grapheme clusters, so we need to split the text and then adjust the start and end positions by finding the string inside the split text that has been joined together to form the original text
60
+ sourceStart = sourceElement.getStart();
61
+ sourceEnd = sourceElement.getEnd();
62
+ sourceLineStart = sourceElement.getStartLineNumber();
63
+ sourceLineEnd = sourceElement.getEndLineNumber();
64
+ }
65
+ else {
66
+ sourceStart = sourceElement.getPos();
67
+ sourceEnd = sourceElement.getEnd();
68
+ }
69
+ if (analyze_1.config.expectGraphemes) {
58
70
  /**
59
71
  * The following logic handles the case of multi-code point characters (e.g. emoji) in the source text.
60
72
  * This is needed because Pharo/Smalltalk treats multi-code point characters as a single character,
@@ -69,30 +81,35 @@ class FamixFunctionsIndex {
69
81
  const sourceFileText = sourceElement.getSourceFile().getFullText();
70
82
  const hasGraphemeClusters = splitter.countGraphemes(sourceFileText) > 1;
71
83
  if (hasGraphemeClusters) {
72
- const sourceElementText = sourceFileText.substring(sourceElement.getStart(), sourceElement.getEnd());
84
+ const sourceElementText = sourceFileText.substring(sourceStart, sourceEnd);
73
85
  const sourceElementTextGraphemes = splitter.splitGraphemes(sourceElementText);
74
86
  const sourceFileTextGraphemes = splitter.splitGraphemes(sourceFileText);
75
- const start = sourceElement.getStart();
76
- const numberOfGraphemeClustersBeforeStart = splitter.countGraphemes(sourceFileText.substring(0, start));
87
+ const numberOfGraphemeClustersBeforeStart = splitter.countGraphemes(sourceFileText.substring(0, sourceStart));
77
88
  // find the start of the sourceElementTextGraphemes array in the sourceFileTextGraphemes array
78
- const newStart = indexOfSplitArray({ searchArray: sourceFileTextGraphemes,
89
+ sourceStart = indexOfSplitArray({ searchArray: sourceFileTextGraphemes,
79
90
  targetArray: sourceElementTextGraphemes,
80
- start: start - numberOfGraphemeClustersBeforeStart });
81
- const newEnd = newStart + sourceElementTextGraphemes.length;
82
- // note: the +1 is because the source anchor is 1-based, but ts-morph is 0-based
83
- fmxIndexFileAnchor.setStartPos(newStart + 1);
84
- fmxIndexFileAnchor.setEndPos(newEnd + 1);
85
- }
86
- else {
87
- // note: the +1 is because the source anchor is 1-based, but ts-morph is 0-based
88
- fmxIndexFileAnchor.setStartPos(sourceElement.getStart() + 1);
89
- fmxIndexFileAnchor.setEndPos(sourceElement.getEnd() + 1);
91
+ start: sourceStart - numberOfGraphemeClustersBeforeStart });
92
+ sourceEnd = sourceStart + sourceElementTextGraphemes.length;
90
93
  }
91
94
  }
95
+ // note: the +1 is because the source anchor is 1-based, but ts-morph is 0-based
96
+ fmxIndexFileAnchor.setStartPos(sourceStart + 1);
97
+ fmxIndexFileAnchor.setEndPos(sourceEnd + 1);
98
+ if (!(sourceElement instanceof ts_morph_1.CommentRange)) {
99
+ fmxIndexFileAnchor.setStartLine(sourceLineStart);
100
+ fmxIndexFileAnchor.setEndLine(sourceLineEnd);
101
+ }
92
102
  if (!(famixElement instanceof Famix.Association) && !(famixElement instanceof Famix.Comment) && !(sourceElement instanceof ts_morph_1.CommentRange) && !(sourceElement instanceof ts_morph_1.Identifier) && !(sourceElement instanceof ts_morph_1.ImportSpecifier) && !(sourceElement instanceof ts_morph_1.ExpressionWithTypeArguments)) {
93
103
  famixElement.setFullyQualifiedName(this.FQNFunctions.getFQN(sourceElement));
94
104
  }
95
105
  }
106
+ else {
107
+ // sourceElement is null
108
+ analyze_1.logger.warn("sourceElement is null for famixElement " + famixElement.getJSON());
109
+ fmxIndexFileAnchor.setFileName("unknown");
110
+ fmxIndexFileAnchor.setStartPos(0);
111
+ fmxIndexFileAnchor.setEndPos(0);
112
+ }
96
113
  }
97
114
  }
98
115
  exports.FamixFunctionsIndex = FamixFunctionsIndex;
@@ -28,6 +28,7 @@ const ts_morph_1 = require("ts-morph");
28
28
  const Famix = __importStar(require("../lib/famix/src/model/famix"));
29
29
  const fqn_1 = require("../fqn");
30
30
  const famix_functions_index_1 = require("./famix_functions_index");
31
+ const analyze_1 = require("../analyze");
31
32
  /**
32
33
  * This class is used to build a Famix model for the types
33
34
  */
@@ -52,7 +53,7 @@ class FamixFunctionsTypes {
52
53
  let fmxType;
53
54
  let isPrimitiveType = false;
54
55
  let isParameterizedType = false;
55
- console.info("Creating (or getting) type: '" + typeName + "' of element: " + element.getText() + " of kind: " + element.getKindName());
56
+ analyze_1.logger.debug("Creating (or getting) type: '" + typeName + "' of element: " + element.getText() + " of kind: " + element.getKindName());
56
57
  const typeAncestor = this.findTypeAncestor(element);
57
58
  const ancestorFullyQualifiedName = this.FQNFunctions.getFQN(typeAncestor);
58
59
  const ancestor = this.getFamixEntityByFullyQualifiedName(ancestorFullyQualifiedName);
@@ -16,6 +16,7 @@ class FamixRepository {
16
16
  this.famixFunctions = new Set(); // All Famix functions
17
17
  this.famixFiles = new Set(); // All Famix files
18
18
  this.idCounter = 1; // Id counter
19
+ this.addElement(new famix_1.SourceLanguage(this)); // add the source language entity (TypeScript)
19
20
  }
20
21
  /**
21
22
  * Gets a Famix entity by id
@@ -36,6 +37,11 @@ class FamixRepository {
36
37
  const entity = allEntities.find(e => e.getFullyQualifiedName() === fullyQualifiedName);
37
38
  return entity;
38
39
  }
40
+ export(arg0) {
41
+ if (arg0.format === "json") {
42
+ return this.getJSON();
43
+ }
44
+ }
39
45
  // Only for tests
40
46
  /**
41
47
  * Gets all Famix entities
@@ -25,9 +25,9 @@ class Access extends association_1.Association {
25
25
  this.isWrite = isWrite;
26
26
  }
27
27
  getJSON() {
28
- const mse = new famix_JSON_exporter_1.FamixJSONExporter("Access", this);
29
- this.addPropertiesToExporter(mse);
30
- return mse.getJSON();
28
+ const json = new famix_JSON_exporter_1.FamixJSONExporter("Access", this);
29
+ this.addPropertiesToExporter(json);
30
+ return json.getJSON();
31
31
  }
32
32
  addPropertiesToExporter(exporter) {
33
33
  super.addPropertiesToExporter(exporter);
@@ -5,9 +5,9 @@ const famix_JSON_exporter_1 = require("../../famix_JSON_exporter");
5
5
  const method_1 = require("./method");
6
6
  class Accessor extends method_1.Method {
7
7
  getJSON() {
8
- const mse = new famix_JSON_exporter_1.FamixJSONExporter("Accessor", this);
9
- this.addPropertiesToExporter(mse);
10
- return mse.getJSON();
8
+ const json = new famix_JSON_exporter_1.FamixJSONExporter("Accessor", this);
9
+ this.addPropertiesToExporter(json);
10
+ return json.getJSON();
11
11
  }
12
12
  addPropertiesToExporter(exporter) {
13
13
  super.addPropertiesToExporter(exporter);
@@ -19,9 +19,9 @@ class Alias extends named_entity_1.NamedEntity {
19
19
  aliasedEntity.addTypeAlias(this);
20
20
  }
21
21
  getJSON() {
22
- const mse = new famix_JSON_exporter_1.FamixJSONExporter("Alias", this);
23
- this.addPropertiesToExporter(mse);
24
- return mse.getJSON();
22
+ const json = new famix_JSON_exporter_1.FamixJSONExporter("Alias", this);
23
+ this.addPropertiesToExporter(json);
24
+ return json.getJSON();
25
25
  }
26
26
  addPropertiesToExporter(exporter) {
27
27
  super.addPropertiesToExporter(exporter);
@@ -23,9 +23,9 @@ class Association extends sourced_entity_1.SourcedEntity {
23
23
  }
24
24
  }
25
25
  getJSON() {
26
- const mse = new famix_JSON_exporter_1.FamixJSONExporter("Association", this);
27
- this.addPropertiesToExporter(mse);
28
- return mse.getJSON();
26
+ const json = new famix_JSON_exporter_1.FamixJSONExporter("Association", this);
27
+ this.addPropertiesToExporter(json);
28
+ return json.getJSON();
29
29
  }
30
30
  addPropertiesToExporter(exporter) {
31
31
  super.addPropertiesToExporter(exporter);
@@ -53,19 +53,19 @@ class BehavioralEntity extends container_entity_1.ContainerEntity {
53
53
  this.declaredType = declaredType;
54
54
  declaredType.addBehavioralEntityWithDeclaredType(this);
55
55
  }
56
- getTypeParameters() {
56
+ getParameterTypes() {
57
57
  return this.typeParameters;
58
58
  }
59
- addTypeParameter(typeParameter) {
59
+ addParameterType(typeParameter) {
60
60
  if (!this.typeParameters.has(typeParameter)) {
61
61
  this.typeParameters.add(typeParameter);
62
62
  typeParameter.setParentGeneric(this);
63
63
  }
64
64
  }
65
65
  getJSON() {
66
- const mse = new famix_JSON_exporter_1.FamixJSONExporter("BehavioralEntity", this);
67
- this.addPropertiesToExporter(mse);
68
- return mse.getJSON();
66
+ const json = new famix_JSON_exporter_1.FamixJSONExporter("BehavioralEntity", this);
67
+ this.addPropertiesToExporter(json);
68
+ return json.getJSON();
69
69
  }
70
70
  addPropertiesToExporter(exporter) {
71
71
  super.addPropertiesToExporter(exporter);
@@ -75,7 +75,7 @@ class BehavioralEntity extends container_entity_1.ContainerEntity {
75
75
  exporter.addProperty("numberOfParameters", this.getNumberOfParameters());
76
76
  exporter.addProperty("incomingInvocations", this.getIncomingInvocations());
77
77
  exporter.addProperty("declaredType", this.getDeclaredType());
78
- exporter.addProperty("typeParameters", this.getTypeParameters());
78
+ exporter.addProperty("typeParameters", this.getParameterTypes());
79
79
  }
80
80
  }
81
81
  exports.BehavioralEntity = BehavioralEntity;
@@ -54,9 +54,9 @@ class Class extends type_1.Type {
54
54
  }
55
55
  }
56
56
  getJSON() {
57
- const mse = new famix_JSON_exporter_1.FamixJSONExporter("Class", this);
58
- this.addPropertiesToExporter(mse);
59
- return mse.getJSON();
57
+ const json = new famix_JSON_exporter_1.FamixJSONExporter("Class", this);
58
+ this.addPropertiesToExporter(json);
59
+ return json.getJSON();
60
60
  }
61
61
  addPropertiesToExporter(exporter) {
62
62
  super.addPropertiesToExporter(exporter);
@@ -24,9 +24,9 @@ class Comment extends sourced_entity_1.SourcedEntity {
24
24
  this.content = content;
25
25
  }
26
26
  getJSON() {
27
- const mse = new famix_JSON_exporter_1.FamixJSONExporter("Comment", this);
28
- this.addPropertiesToExporter(mse);
29
- return mse.getJSON();
27
+ const json = new famix_JSON_exporter_1.FamixJSONExporter("Comment", this);
28
+ this.addPropertiesToExporter(json);
29
+ return json.getJSON();
30
30
  }
31
31
  addPropertiesToExporter(exporter) {
32
32
  super.addPropertiesToExporter(exporter);
@@ -103,9 +103,9 @@ class ContainerEntity extends named_entity_1.NamedEntity {
103
103
  }
104
104
  }
105
105
  getJSON() {
106
- const mse = new famix_JSON_exporter_1.FamixJSONExporter("ContainerEntity", this);
107
- this.addPropertiesToExporter(mse);
108
- return mse.getJSON();
106
+ const json = new famix_JSON_exporter_1.FamixJSONExporter("ContainerEntity", this);
107
+ this.addPropertiesToExporter(json);
108
+ return json.getJSON();
109
109
  }
110
110
  addPropertiesToExporter(exporter) {
111
111
  super.addPropertiesToExporter(exporter);
@@ -18,9 +18,9 @@ class Decorator extends named_entity_1.NamedEntity {
18
18
  decoratedEntity.addDecorator(this);
19
19
  }
20
20
  getJSON() {
21
- const mse = new famix_JSON_exporter_1.FamixJSONExporter("Decorator", this);
22
- this.addPropertiesToExporter(mse);
23
- return mse.getJSON();
21
+ const json = new famix_JSON_exporter_1.FamixJSONExporter("Decorator", this);
22
+ this.addPropertiesToExporter(json);
23
+ return json.getJSON();
24
24
  }
25
25
  addPropertiesToExporter(exporter) {
26
26
  super.addPropertiesToExporter(exporter);
@@ -5,9 +5,9 @@ const famix_JSON_exporter_1 = require("../../famix_JSON_exporter");
5
5
  const famix_base_element_1 = require("../../famix_base_element");
6
6
  class Entity extends famix_base_element_1.FamixBaseElement {
7
7
  getJSON() {
8
- const mse = new famix_JSON_exporter_1.FamixJSONExporter("Entity", this);
9
- this.addPropertiesToExporter(mse);
10
- return mse.getJSON();
8
+ const json = new famix_JSON_exporter_1.FamixJSONExporter("Entity", this);
9
+ this.addPropertiesToExporter(json);
10
+ return json.getJSON();
11
11
  }
12
12
  addPropertiesToExporter(exporter) {
13
13
  super.addPropertiesToExporter(exporter);
@@ -18,9 +18,9 @@ class Enum extends type_1.Type {
18
18
  }
19
19
  }
20
20
  getJSON() {
21
- const mse = new famix_JSON_exporter_1.FamixJSONExporter("Enum", this);
22
- this.addPropertiesToExporter(mse);
23
- return mse.getJSON();
21
+ const json = new famix_JSON_exporter_1.FamixJSONExporter("Enum", this);
22
+ this.addPropertiesToExporter(json);
23
+ return json.getJSON();
24
24
  }
25
25
  addPropertiesToExporter(exporter) {
26
26
  super.addPropertiesToExporter(exporter);
@@ -12,9 +12,9 @@ class EnumValue extends structural_entity_1.StructuralEntity {
12
12
  parentEntity.addValue(this);
13
13
  }
14
14
  getJSON() {
15
- const mse = new famix_JSON_exporter_1.FamixJSONExporter("EnumValue", this);
16
- this.addPropertiesToExporter(mse);
17
- return mse.getJSON();
15
+ const json = new famix_JSON_exporter_1.FamixJSONExporter("EnumValue", this);
16
+ this.addPropertiesToExporter(json);
17
+ return json.getJSON();
18
18
  }
19
19
  addPropertiesToExporter(exporter) {
20
20
  super.addPropertiesToExporter(exporter);
@@ -5,9 +5,9 @@ const famix_JSON_exporter_1 = require("../../famix_JSON_exporter");
5
5
  const behavioral_entity_1 = require("./behavioral_entity");
6
6
  class Function extends behavioral_entity_1.BehavioralEntity {
7
7
  getJSON() {
8
- const mse = new famix_JSON_exporter_1.FamixJSONExporter("Function", this);
9
- this.addPropertiesToExporter(mse);
10
- return mse.getJSON();
8
+ const json = new famix_JSON_exporter_1.FamixJSONExporter("Function", this);
9
+ this.addPropertiesToExporter(json);
10
+ return json.getJSON();
11
11
  }
12
12
  addPropertiesToExporter(exporter) {
13
13
  super.addPropertiesToExporter(exporter);
@@ -5,9 +5,9 @@ const famix_JSON_exporter_1 = require("../../famix_JSON_exporter");
5
5
  const variable_1 = require("./variable");
6
6
  class ImplicitVariable extends variable_1.Variable {
7
7
  getJSON() {
8
- const mse = new famix_JSON_exporter_1.FamixJSONExporter("ImplicitVariable", this);
9
- this.addPropertiesToExporter(mse);
10
- return mse.getJSON();
8
+ const json = new famix_JSON_exporter_1.FamixJSONExporter("ImplicitVariable", this);
9
+ this.addPropertiesToExporter(json);
10
+ return json.getJSON();
11
11
  }
12
12
  addPropertiesToExporter(exporter) {
13
13
  super.addPropertiesToExporter(exporter);
@@ -25,9 +25,9 @@ class ImportClause extends association_1.Association {
25
25
  this.moduleSpecifier = moduleSpecifier;
26
26
  }
27
27
  getJSON() {
28
- const mse = new famix_JSON_exporter_1.FamixJSONExporter("ImportClause", this);
29
- this.addPropertiesToExporter(mse);
30
- return mse.getJSON();
28
+ const json = new famix_JSON_exporter_1.FamixJSONExporter("ImportClause", this);
29
+ this.addPropertiesToExporter(json);
30
+ return json.getJSON();
31
31
  }
32
32
  addPropertiesToExporter(exporter) {
33
33
  super.addPropertiesToExporter(exporter);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Variable = exports.Type = exports.TextAnchor = exports.StructuralEntity = exports.SourcedEntity = exports.SourceLanguage = exports.SourceAnchor = exports.ScriptEntity = exports.ScopingEntity = exports.Reference = exports.PrimitiveType = exports.ParameterizedType = exports.ParameterizableInterface = exports.ParameterizableClass = exports.Parameter = exports.TypeParameter = exports.Namespace = exports.NamedEntity = exports.Module = exports.Method = exports.Invocation = exports.Interface = exports.Inheritance = exports.IndexedFileAnchor = exports.ImportClause = exports.ImplicitVariable = exports.Function = exports.Property = exports.Enum = exports.EnumValue = exports.Entity = exports.Decorator = exports.CustomSourceLanguage = exports.ContainerEntity = exports.Comment = exports.Class = exports.CSourceLanguage = exports.BehavioralEntity = exports.Association = exports.Alias = exports.Accessor = exports.Access = void 0;
3
+ exports.Variable = exports.Type = exports.TextAnchor = exports.StructuralEntity = exports.SourcedEntity = exports.SourceLanguage = exports.SourceAnchor = exports.ScriptEntity = exports.ScopingEntity = exports.Reference = exports.PrimitiveType = exports.ParameterizedType = exports.ParameterizableInterface = exports.ParameterizableClass = exports.Parameter = exports.ParameterType = exports.Namespace = exports.NamedEntity = exports.Module = exports.Method = exports.Invocation = exports.Interface = exports.Inheritance = exports.IndexedFileAnchor = exports.ImportClause = exports.ImplicitVariable = exports.Function = exports.Property = exports.Enum = exports.EnumValue = exports.Entity = exports.Decorator = exports.ContainerEntity = exports.Comment = exports.Class = exports.BehavioralEntity = exports.Association = exports.Alias = exports.Accessor = exports.Access = void 0;
4
4
  var access_1 = require("./access");
5
5
  Object.defineProperty(exports, "Access", { enumerable: true, get: function () { return access_1.Access; } });
6
6
  var accessor_1 = require("./accessor");
@@ -11,16 +11,12 @@ var association_1 = require("./association");
11
11
  Object.defineProperty(exports, "Association", { enumerable: true, get: function () { return association_1.Association; } });
12
12
  var behavioral_entity_1 = require("./behavioral_entity");
13
13
  Object.defineProperty(exports, "BehavioralEntity", { enumerable: true, get: function () { return behavioral_entity_1.BehavioralEntity; } });
14
- var c_source_language_1 = require("./c_source_language");
15
- Object.defineProperty(exports, "CSourceLanguage", { enumerable: true, get: function () { return c_source_language_1.CSourceLanguage; } });
16
14
  var class_1 = require("./class");
17
15
  Object.defineProperty(exports, "Class", { enumerable: true, get: function () { return class_1.Class; } });
18
16
  var comment_1 = require("./comment");
19
17
  Object.defineProperty(exports, "Comment", { enumerable: true, get: function () { return comment_1.Comment; } });
20
18
  var container_entity_1 = require("./container_entity");
21
19
  Object.defineProperty(exports, "ContainerEntity", { enumerable: true, get: function () { return container_entity_1.ContainerEntity; } });
22
- var custom_source_language_1 = require("./custom_source_language");
23
- Object.defineProperty(exports, "CustomSourceLanguage", { enumerable: true, get: function () { return custom_source_language_1.CustomSourceLanguage; } });
24
20
  var decorator_1 = require("./decorator");
25
21
  Object.defineProperty(exports, "Decorator", { enumerable: true, get: function () { return decorator_1.Decorator; } });
26
22
  var entity_1 = require("./entity");
@@ -53,8 +49,8 @@ var named_entity_1 = require("./named_entity");
53
49
  Object.defineProperty(exports, "NamedEntity", { enumerable: true, get: function () { return named_entity_1.NamedEntity; } });
54
50
  var namespace_1 = require("./namespace");
55
51
  Object.defineProperty(exports, "Namespace", { enumerable: true, get: function () { return namespace_1.Namespace; } });
56
- var type_parameter_1 = require("./type_parameter");
57
- Object.defineProperty(exports, "TypeParameter", { enumerable: true, get: function () { return type_parameter_1.TypeParameter; } });
52
+ var parameter_type_1 = require("./parameter_type");
53
+ Object.defineProperty(exports, "ParameterType", { enumerable: true, get: function () { return parameter_type_1.ParameterType; } });
58
54
  var parameter_1 = require("./parameter");
59
55
  Object.defineProperty(exports, "Parameter", { enumerable: true, get: function () { return parameter_1.Parameter; } });
60
56
  var parameterizable_class_1 = require("./parameterizable_class");