ts2famix 1.1.0 → 1.2.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 +3 -3
  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 +26 -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 +3 -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 +28 -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 +3 -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
@@ -1,9 +1,9 @@
1
- import { ClassDeclaration, ConstructorDeclaration, FunctionDeclaration, Identifier, InterfaceDeclaration, MethodDeclaration, SourceFile, GetAccessorDeclaration, SetAccessorDeclaration, Node, ImportSpecifier, SyntaxKind, FunctionExpression, ExpressionWithTypeArguments } from "ts-morph";
1
+ import { ClassDeclaration, ConstructorDeclaration, FunctionDeclaration, Identifier, InterfaceDeclaration, MethodDeclaration, SourceFile, GetAccessorDeclaration, SetAccessorDeclaration, Node, ImportSpecifier, SyntaxKind, FunctionExpression, ExpressionWithTypeArguments, ImportDeclaration } from "ts-morph";
2
2
  import * as Famix from "../lib/famix/src/model/famix";
3
3
  import { FamixRepository } from "../lib/famix/src/famix_repository";
4
4
  import { FQNFunctions } from "../fqn";
5
5
  import { FamixFunctionsIndex } from "./famix_functions_index";
6
- import { Alias, Class, Enum, Interface, Variable } from "../lib/famix/src/model/famix";
6
+ import { logger } from "../analyze";
7
7
 
8
8
  /**
9
9
  * This class is used to build a Famix model for the associations
@@ -79,7 +79,7 @@ export class FamixFunctionsAssociations {
79
79
  const fmxInheritance = new Famix.Inheritance(this.famixRep);
80
80
  // const clsName = cls.getName();
81
81
  const classFullyQualifiedName = this.FQNFunctions.getFQN(cls);
82
- console.info(`createFamixInheritance: classFullyQualifiedName: class fqn = ${classFullyQualifiedName}`);
82
+ logger.debug(`createFamixInheritance: classFullyQualifiedName: class fqn = ${classFullyQualifiedName}`);
83
83
  let subClass: Famix.Class | Famix.Interface;
84
84
  if (cls instanceof ClassDeclaration) {
85
85
  subClass = this.famixClassMap.get(classFullyQualifiedName);
@@ -133,15 +133,17 @@ export class FamixFunctionsAssociations {
133
133
 
134
134
  /**
135
135
  * Creates a Famix import clause
136
+ * @param importClauseInfo The information needed to create a Famix import clause
137
+ * @param importDeclaration The import declaration
136
138
  * @param importer A source file which is a module
137
- * @param moduleSpecifier The name of the module where the export declaration is
138
139
  * @param moduleSpecifierFilePath The path of the module where the export declaration is
139
140
  * @param importElement The imported entity
140
141
  * @param isInExports A boolean indicating if the imported entity is in the exports
141
142
  * @param isDefaultExport A boolean indicating if the imported entity is a default export
142
143
  */
143
- public createFamixImportClause(importer: SourceFile, moduleSpecifier: string, moduleSpecifierFilePath: string, importElement: ImportSpecifier | Identifier, isInExports: boolean, isDefaultExport: boolean): void {
144
- console.info(`createFamixImportClause: Creating import clause:`);
144
+ public createFamixImportClause(importClauseInfo: {importDeclaration?: ImportDeclaration, importer: SourceFile, moduleSpecifierFilePath: string, importElement: ImportSpecifier | Identifier, isInExports: boolean, isDefaultExport: boolean}): void {
145
+ const {importDeclaration, importer, moduleSpecifierFilePath, importElement, isInExports, isDefaultExport} = importClauseInfo;
146
+ logger.debug(`createFamixImportClause: Creating import clause:`);
145
147
  const fmxImportClause = new Famix.ImportClause(this.famixRep);
146
148
 
147
149
  let importedEntity: Famix.NamedEntity;
@@ -181,17 +183,13 @@ export class FamixFunctionsAssociations {
181
183
  const fmxImporter = this.getFamixEntityByFullyQualifiedName(importerFullyQualifiedName) as Famix.Module;
182
184
  fmxImportClause.setImportingEntity(fmxImporter);
183
185
  fmxImportClause.setImportedEntity(importedEntity);
184
- fmxImportClause.setModuleSpecifier(moduleSpecifier);
186
+ fmxImportClause.setModuleSpecifier(importDeclaration?.getModuleSpecifierValue() as string);
185
187
 
186
- console.info(`createFamixImportClause: ${fmxImportClause.getImportedEntity()?.getName()} (of type ${fmxImportClause.getImportedEntity() instanceof Class ? 'Class' :
187
- fmxImportClause.getImportedEntity() instanceof Interface ? 'Interface' :
188
- fmxImportClause.getImportedEntity() instanceof Function ? 'Function' :
189
- fmxImportClause.getImportedEntity() instanceof Enum ? 'Enum' :
190
- fmxImportClause.getImportedEntity() instanceof Alias ? 'Alias' :
191
- fmxImportClause.getImportedEntity() instanceof Variable ? 'Variable' :
192
- 'NamedEntity'}) is imported by ${fmxImportClause.getImportingEntity()?.getName()}`);
188
+ logger.debug(`createFamixImportClause: ${fmxImportClause.getImportedEntity()?.getName()} (of type ${
189
+ getSubTypeName(fmxImportClause.getImportedEntity())}) is imported by ${fmxImportClause.getImportingEntity()?.getName()}`);
193
190
 
194
- this.famixFunctionsIndex.makeFamixIndexFileAnchor(null, fmxImportClause);
191
+ // make an index file anchor for the import clause
192
+ this.famixFunctionsIndex.makeFamixIndexFileAnchor(importDeclaration, fmxImportClause);
195
193
 
196
194
  fmxImporter.addOutgoingImport(fmxImportClause);
197
195
  }
@@ -223,3 +221,22 @@ export class FamixFunctionsAssociations {
223
221
  return node.getAncestors().find(a => a.getKind() === SyntaxKind.MethodDeclaration || a.getKind() === SyntaxKind.Constructor || a.getKind() === SyntaxKind.FunctionDeclaration || a.getKind() === SyntaxKind.FunctionExpression || a.getKind() === SyntaxKind.ModuleDeclaration || a.getKind() === SyntaxKind.SourceFile || a.getKindName() === "GetAccessor" || a.getKindName() === "SetAccessor" || a.getKind() === SyntaxKind.ClassDeclaration);
224
222
  }
225
223
  }
224
+ function getSubTypeName(fmxNamedEntity: Famix.NamedEntity) {
225
+ const name = fmxNamedEntity instanceof Famix.Class ? 'Class' :
226
+ fmxNamedEntity instanceof Famix.Interface ? 'Interface' :
227
+ fmxNamedEntity instanceof Famix.Function ? 'Function' :
228
+ fmxNamedEntity instanceof Famix.Enum ? 'Enum' :
229
+ fmxNamedEntity instanceof Famix.EnumValue ? 'EnumValue' :
230
+ fmxNamedEntity instanceof Famix.Alias ? 'Alias' :
231
+ fmxNamedEntity instanceof Famix.Variable ? 'Variable' :
232
+ fmxNamedEntity instanceof Famix.Type ? 'Type' :
233
+ fmxNamedEntity instanceof Famix.Method ? 'Method' :
234
+ fmxNamedEntity instanceof Famix.Decorator ? 'Decorator' :
235
+ fmxNamedEntity instanceof Famix.Accessor ? 'Accessor' :
236
+ fmxNamedEntity instanceof Famix.Parameter ? 'Parameter' :
237
+ fmxNamedEntity instanceof Famix.Property ? 'Property' :
238
+ 'NamedEntity';
239
+ logger.debug(`${fmxNamedEntity.getName()} is of type ${name}`);
240
+ return name;
241
+ }
242
+
@@ -1,8 +1,9 @@
1
- import { ClassDeclaration, ConstructorDeclaration, FunctionDeclaration, Identifier, InterfaceDeclaration, MethodDeclaration, MethodSignature, ModuleDeclaration, PropertyDeclaration, PropertySignature, SourceFile, TypeParameterDeclaration, VariableDeclaration, ParameterDeclaration, Decorator, GetAccessorDeclaration, SetAccessorDeclaration, ImportSpecifier, CommentRange, EnumDeclaration, EnumMember, TypeAliasDeclaration, FunctionExpression, ExpressionWithTypeArguments } from "ts-morph";
1
+ import { ClassDeclaration, ConstructorDeclaration, FunctionDeclaration, Identifier, InterfaceDeclaration, MethodDeclaration, MethodSignature, ModuleDeclaration, PropertyDeclaration, PropertySignature, SourceFile, TypeParameterDeclaration, VariableDeclaration, ParameterDeclaration, Decorator, GetAccessorDeclaration, SetAccessorDeclaration, ImportSpecifier, CommentRange, EnumDeclaration, EnumMember, TypeAliasDeclaration, FunctionExpression, ExpressionWithTypeArguments, ImportDeclaration } from "ts-morph";
2
2
  import * as Famix from "../lib/famix/src/model/famix";
3
3
  import { FamixRepository } from "../lib/famix/src/famix_repository";
4
4
  import { FQNFunctions } from "../fqn";
5
5
  import GraphemeSplitter from "grapheme-splitter";
6
+ import { logger, config } from "../analyze";
6
7
 
7
8
  /**
8
9
  * This class is used to build a Famix model for the index file anchors
@@ -25,14 +26,22 @@ export class FamixFunctionsIndex {
25
26
  * @param sourceElement A source element
26
27
  * @param famixElement The Famix model of the source element
27
28
  */
28
- public makeFamixIndexFileAnchor(sourceElement: SourceFile | ModuleDeclaration | ClassDeclaration | InterfaceDeclaration | MethodDeclaration | ConstructorDeclaration | MethodSignature | FunctionDeclaration | FunctionExpression | ParameterDeclaration | VariableDeclaration | PropertyDeclaration | PropertySignature | TypeParameterDeclaration | Identifier | Decorator | GetAccessorDeclaration | SetAccessorDeclaration | ImportSpecifier | CommentRange | EnumDeclaration | EnumMember | TypeAliasDeclaration | ExpressionWithTypeArguments, famixElement: Famix.SourcedEntity): void {
29
+ public makeFamixIndexFileAnchor(sourceElement: ImportDeclaration | SourceFile | ModuleDeclaration | ClassDeclaration | InterfaceDeclaration | MethodDeclaration | ConstructorDeclaration | MethodSignature | FunctionDeclaration | FunctionExpression | ParameterDeclaration | VariableDeclaration | PropertyDeclaration | PropertySignature | TypeParameterDeclaration | Identifier | Decorator | GetAccessorDeclaration | SetAccessorDeclaration | ImportSpecifier | CommentRange | EnumDeclaration | EnumMember | TypeAliasDeclaration | ExpressionWithTypeArguments, famixElement: Famix.SourcedEntity): void {
30
+ logger.debug("making index file anchor for '" + sourceElement?.getText() + "' with famixElement " + famixElement.getJSON());
29
31
  const fmxIndexFileAnchor = new Famix.IndexedFileAnchor(this.famixRep);
30
32
  fmxIndexFileAnchor.setElement(famixElement);
31
33
 
32
34
  if (sourceElement !== null) {
33
35
  fmxIndexFileAnchor.setFileName(sourceElement.getSourceFile().getFilePath());
36
+ let sourceStart, sourceEnd: number;
34
37
  if (!(sourceElement instanceof CommentRange)) {
35
- // 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
38
+ sourceStart = sourceElement.getStart();
39
+ sourceEnd = sourceElement.getEnd();
40
+ } else {
41
+ sourceStart = sourceElement.getPos();
42
+ sourceEnd = sourceElement.getEnd();
43
+ }
44
+ if (config.expectGraphemes) {
36
45
  /**
37
46
  * The following logic handles the case of multi-code point characters (e.g. emoji) in the source text.
38
47
  * This is needed because Pharo/Smalltalk treats multi-code point characters as a single character,
@@ -47,31 +56,32 @@ export class FamixFunctionsIndex {
47
56
  const sourceFileText = sourceElement.getSourceFile().getFullText();
48
57
  const hasGraphemeClusters = splitter.countGraphemes(sourceFileText) > 1;
49
58
  if (hasGraphemeClusters) {
50
- const sourceElementText = sourceFileText.substring(sourceElement.getStart(), sourceElement.getEnd());
59
+ const sourceElementText = sourceFileText.substring(sourceStart, sourceEnd);
51
60
  const sourceElementTextGraphemes = splitter.splitGraphemes(sourceElementText);
52
61
  const sourceFileTextGraphemes = splitter.splitGraphemes(sourceFileText);
53
- const start = sourceElement.getStart();
54
- const numberOfGraphemeClustersBeforeStart = splitter.countGraphemes(sourceFileText.substring(0, start));
62
+ const numberOfGraphemeClustersBeforeStart = splitter.countGraphemes(sourceFileText.substring(0, sourceStart));
55
63
 
56
64
  // find the start of the sourceElementTextGraphemes array in the sourceFileTextGraphemes array
57
- const newStart = indexOfSplitArray({searchArray: sourceFileTextGraphemes,
65
+ sourceStart = indexOfSplitArray({searchArray: sourceFileTextGraphemes,
58
66
  targetArray: sourceElementTextGraphemes,
59
- start: start - numberOfGraphemeClustersBeforeStart});
60
- const newEnd = newStart + sourceElementTextGraphemes.length;
61
-
62
- // note: the +1 is because the source anchor is 1-based, but ts-morph is 0-based
63
- fmxIndexFileAnchor.setStartPos(newStart + 1);
64
- fmxIndexFileAnchor.setEndPos(newEnd + 1);
65
- } else {
66
- // note: the +1 is because the source anchor is 1-based, but ts-morph is 0-based
67
- fmxIndexFileAnchor.setStartPos(sourceElement.getStart() + 1);
68
- fmxIndexFileAnchor.setEndPos(sourceElement.getEnd() + 1);
69
- }
67
+ start: sourceStart - numberOfGraphemeClustersBeforeStart});
68
+ sourceEnd = sourceStart + sourceElementTextGraphemes.length;
69
+ }
70
70
  }
71
+ // note: the +1 is because the source anchor is 1-based, but ts-morph is 0-based
72
+ fmxIndexFileAnchor.setStartPos(sourceStart + 1);
73
+ fmxIndexFileAnchor.setEndPos(sourceEnd + 1);
71
74
 
72
75
  if (!(famixElement instanceof Famix.Association) && !(famixElement instanceof Famix.Comment) && !(sourceElement instanceof CommentRange) && !(sourceElement instanceof Identifier) && !(sourceElement instanceof ImportSpecifier) && !(sourceElement instanceof ExpressionWithTypeArguments)) {
73
76
  (famixElement as Famix.NamedEntity).setFullyQualifiedName(this.FQNFunctions.getFQN(sourceElement));
74
77
  }
78
+ } else {
79
+ // sourceElement is null
80
+ logger.warn("sourceElement is null for famixElement " + famixElement.getJSON());
81
+ fmxIndexFileAnchor.setFileName("unknown");
82
+ fmxIndexFileAnchor.setStartPos(0);
83
+ fmxIndexFileAnchor.setEndPos(0);
84
+
75
85
  }
76
86
  }
77
87
  }
@@ -3,6 +3,7 @@ import * as Famix from "../lib/famix/src/model/famix";
3
3
  import { FamixRepository } from "../lib/famix/src/famix_repository";
4
4
  import { FQNFunctions } from "../fqn";
5
5
  import { FamixFunctionsIndex } from "./famix_functions_index";
6
+ import { logger } from "../analyze";
6
7
 
7
8
  /**
8
9
  * This class is used to build a Famix model for the types
@@ -34,7 +35,7 @@ export class FamixFunctionsTypes {
34
35
  let isPrimitiveType = false;
35
36
  let isParameterizedType = false;
36
37
 
37
- console.info("Creating (or getting) type: '" + typeName + "' of element: " + element.getText() + " of kind: " + element.getKindName());
38
+ logger.debug("Creating (or getting) type: '" + typeName + "' of element: " + element.getText() + " of kind: " + element.getKindName());
38
39
 
39
40
  const typeAncestor = this.findTypeAncestor(element);
40
41
  const ancestorFullyQualifiedName = this.FQNFunctions.getFQN(typeAncestor);
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env bash
1
2
  # Gets latest plantuml
2
3
  rm -f plantuml.jar
3
4
  wget --no-verbose https://downloads.sourceforge.net/project/plantuml/plantuml.jar
@@ -1,11 +1,10 @@
1
1
  import { FamixBaseElement } from "./famix_base_element";
2
- import { Class, Interface, Namespace, Variable, Method, Function as FamixFunctionEntity, Type, NamedEntity, ScriptEntity, Module } from "./model/famix";
2
+ import { Class, Interface, Namespace, Variable, Method, Function as FamixFunctionEntity, Type, NamedEntity, ScriptEntity, Module, SourceLanguage } from "./model/famix";
3
3
 
4
4
  /**
5
5
  * This class is used to store all Famix elements
6
6
  */
7
7
  export class FamixRepository {
8
-
9
8
  private elements = new Set<FamixBaseElement>(); // All Famix elements
10
9
  private famixClasses = new Set<Class>(); // All Famix classes
11
10
  private famixInterfaces = new Set<Interface>(); // All Famix interfaces
@@ -16,6 +15,10 @@ export class FamixRepository {
16
15
  private famixFiles = new Set<ScriptEntity | Module>(); // All Famix files
17
16
  private idCounter = 1; // Id counter
18
17
 
18
+ constructor() {
19
+ this.addElement(new SourceLanguage(this)); // add the source language entity (TypeScript)
20
+ }
21
+
19
22
  /**
20
23
  * Gets a Famix entity by id
21
24
  * @param id An id of a Famix entity
@@ -37,7 +40,13 @@ export class FamixRepository {
37
40
  return entity;
38
41
  }
39
42
 
40
-
43
+ export(arg0: { format: string; }) {
44
+ if(arg0.format === "json") {
45
+ return this.getJSON();
46
+ }
47
+ }
48
+
49
+
41
50
  // Only for tests
42
51
 
43
52
  /**
@@ -39,9 +39,9 @@ export class Access extends Association {
39
39
 
40
40
 
41
41
  public getJSON(): string {
42
- const mse: FamixJSONExporter = new FamixJSONExporter("Access", this);
43
- this.addPropertiesToExporter(mse);
44
- return mse.getJSON();
42
+ const json: FamixJSONExporter = new FamixJSONExporter("Access", this);
43
+ this.addPropertiesToExporter(json);
44
+ return json.getJSON();
45
45
  }
46
46
 
47
47
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -4,9 +4,9 @@ import { Method } from "./method";
4
4
  export class Accessor extends Method {
5
5
 
6
6
  public getJSON(): string {
7
- const mse: FamixJSONExporter = new FamixJSONExporter("Accessor", this);
8
- this.addPropertiesToExporter(mse);
9
- return mse.getJSON();
7
+ const json: FamixJSONExporter = new FamixJSONExporter("Accessor", this);
8
+ this.addPropertiesToExporter(json);
9
+ return json.getJSON();
10
10
  }
11
11
 
12
12
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -28,9 +28,9 @@ export class Alias extends NamedEntity {
28
28
 
29
29
 
30
30
  public getJSON(): string {
31
- const mse: FamixJSONExporter = new FamixJSONExporter("Alias", this);
32
- this.addPropertiesToExporter(mse);
33
- return mse.getJSON();
31
+ const json: FamixJSONExporter = new FamixJSONExporter("Alias", this);
32
+ this.addPropertiesToExporter(json);
33
+ return json.getJSON();
34
34
  }
35
35
 
36
36
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -31,9 +31,9 @@ export class Association extends SourcedEntity {
31
31
 
32
32
 
33
33
  public getJSON(): string {
34
- const mse: FamixJSONExporter = new FamixJSONExporter("Association", this);
35
- this.addPropertiesToExporter(mse);
36
- return mse.getJSON();
34
+ const json: FamixJSONExporter = new FamixJSONExporter("Association", this);
35
+ this.addPropertiesToExporter(json);
36
+ return json.getJSON();
37
37
  }
38
38
 
39
39
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -3,7 +3,7 @@ import { Type } from "./type";
3
3
  import { ContainerEntity } from "./container_entity";
4
4
  import { Parameter } from "./parameter";
5
5
  import { Invocation } from "./invocation";
6
- import { TypeParameter } from "./type_parameter";
6
+ import { ParameterType } from "./parameter_type";
7
7
 
8
8
  export class BehavioralEntity extends ContainerEntity {
9
9
 
@@ -74,13 +74,13 @@ export class BehavioralEntity extends ContainerEntity {
74
74
  declaredType.addBehavioralEntityWithDeclaredType(this);
75
75
  }
76
76
 
77
- private typeParameters: Set<TypeParameter> = new Set();
77
+ private typeParameters: Set<ParameterType> = new Set();
78
78
 
79
- public getTypeParameters(): Set<TypeParameter> {
79
+ public getParameterTypes(): Set<ParameterType> {
80
80
  return this.typeParameters;
81
81
  }
82
82
 
83
- public addTypeParameter(typeParameter: TypeParameter): void {
83
+ public addParameterType(typeParameter: ParameterType): void {
84
84
  if (!this.typeParameters.has(typeParameter)) {
85
85
  this.typeParameters.add(typeParameter);
86
86
  typeParameter.setParentGeneric(this);
@@ -89,9 +89,9 @@ export class BehavioralEntity extends ContainerEntity {
89
89
 
90
90
 
91
91
  public getJSON(): string {
92
- const mse: FamixJSONExporter = new FamixJSONExporter("BehavioralEntity", this);
93
- this.addPropertiesToExporter(mse);
94
- return mse.getJSON();
92
+ const json: FamixJSONExporter = new FamixJSONExporter("BehavioralEntity", this);
93
+ this.addPropertiesToExporter(json);
94
+ return json.getJSON();
95
95
  }
96
96
 
97
97
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -102,6 +102,6 @@ export class BehavioralEntity extends ContainerEntity {
102
102
  exporter.addProperty("numberOfParameters", this.getNumberOfParameters());
103
103
  exporter.addProperty("incomingInvocations", this.getIncomingInvocations());
104
104
  exporter.addProperty("declaredType", this.getDeclaredType());
105
- exporter.addProperty("typeParameters", this.getTypeParameters());
105
+ exporter.addProperty("typeParameters", this.getParameterTypes());
106
106
  }
107
107
  }
@@ -70,9 +70,9 @@ export class Class extends Type {
70
70
 
71
71
 
72
72
  public getJSON(): string {
73
- const mse: FamixJSONExporter = new FamixJSONExporter("Class", this);
74
- this.addPropertiesToExporter(mse);
75
- return mse.getJSON();
73
+ const json: FamixJSONExporter = new FamixJSONExporter("Class", this);
74
+ this.addPropertiesToExporter(json);
75
+ return json.getJSON();
76
76
  }
77
77
 
78
78
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -36,9 +36,9 @@ export class Comment extends SourcedEntity {
36
36
 
37
37
 
38
38
  public getJSON(): string {
39
- const mse: FamixJSONExporter = new FamixJSONExporter("Comment", this);
40
- this.addPropertiesToExporter(mse);
41
- return mse.getJSON();
39
+ const json: FamixJSONExporter = new FamixJSONExporter("Comment", this);
40
+ this.addPropertiesToExporter(json);
41
+ return json.getJSON();
42
42
  }
43
43
 
44
44
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -143,9 +143,9 @@ export class ContainerEntity extends NamedEntity {
143
143
 
144
144
 
145
145
  public getJSON(): string {
146
- const mse: FamixJSONExporter = new FamixJSONExporter("ContainerEntity", this);
147
- this.addPropertiesToExporter(mse);
148
- return mse.getJSON();
146
+ const json: FamixJSONExporter = new FamixJSONExporter("ContainerEntity", this);
147
+ this.addPropertiesToExporter(json);
148
+ return json.getJSON();
149
149
  }
150
150
 
151
151
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -26,9 +26,9 @@ export class Decorator extends NamedEntity {
26
26
 
27
27
 
28
28
  public getJSON(): string {
29
- const mse: FamixJSONExporter = new FamixJSONExporter("Decorator", this);
30
- this.addPropertiesToExporter(mse);
31
- return mse.getJSON();
29
+ const json: FamixJSONExporter = new FamixJSONExporter("Decorator", this);
30
+ this.addPropertiesToExporter(json);
31
+ return json.getJSON();
32
32
  }
33
33
 
34
34
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -4,9 +4,9 @@ import { FamixBaseElement } from "../../famix_base_element";
4
4
  export class Entity extends FamixBaseElement {
5
5
 
6
6
  public getJSON(): string {
7
- const mse: FamixJSONExporter = new FamixJSONExporter("Entity", this);
8
- this.addPropertiesToExporter(mse);
9
- return mse.getJSON();
7
+ const json: FamixJSONExporter = new FamixJSONExporter("Entity", this);
8
+ this.addPropertiesToExporter(json);
9
+ return json.getJSON();
10
10
  }
11
11
 
12
12
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -19,9 +19,9 @@ export class Enum extends Type {
19
19
 
20
20
 
21
21
  public getJSON(): string {
22
- const mse: FamixJSONExporter = new FamixJSONExporter("Enum", this);
23
- this.addPropertiesToExporter(mse);
24
- return mse.getJSON();
22
+ const json: FamixJSONExporter = new FamixJSONExporter("Enum", this);
23
+ this.addPropertiesToExporter(json);
24
+ return json.getJSON();
25
25
  }
26
26
 
27
27
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -17,9 +17,9 @@ export class EnumValue extends StructuralEntity {
17
17
 
18
18
 
19
19
  public getJSON(): string {
20
- const mse: FamixJSONExporter = new FamixJSONExporter("EnumValue", this);
21
- this.addPropertiesToExporter(mse);
22
- return mse.getJSON();
20
+ const json: FamixJSONExporter = new FamixJSONExporter("EnumValue", this);
21
+ this.addPropertiesToExporter(json);
22
+ return json.getJSON();
23
23
  }
24
24
 
25
25
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -4,9 +4,9 @@ import { BehavioralEntity } from "./behavioral_entity";
4
4
  export class Function extends BehavioralEntity {
5
5
 
6
6
  public getJSON(): string {
7
- const mse: FamixJSONExporter = new FamixJSONExporter("Function", this);
8
- this.addPropertiesToExporter(mse);
9
- return mse.getJSON();
7
+ const json: FamixJSONExporter = new FamixJSONExporter("Function", this);
8
+ this.addPropertiesToExporter(json);
9
+ return json.getJSON();
10
10
  }
11
11
 
12
12
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -4,9 +4,9 @@ import { Variable } from "./variable";
4
4
  export class ImplicitVariable extends Variable {
5
5
 
6
6
  public getJSON(): string {
7
- const mse: FamixJSONExporter = new FamixJSONExporter("ImplicitVariable", this);
8
- this.addPropertiesToExporter(mse);
9
- return mse.getJSON();
7
+ const json: FamixJSONExporter = new FamixJSONExporter("ImplicitVariable", this);
8
+ this.addPropertiesToExporter(json);
9
+ return json.getJSON();
10
10
  }
11
11
 
12
12
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -39,9 +39,9 @@ export class ImportClause extends Association {
39
39
 
40
40
 
41
41
  public getJSON(): string {
42
- const mse: FamixJSONExporter = new FamixJSONExporter("ImportClause", this);
43
- this.addPropertiesToExporter(mse);
44
- return mse.getJSON();
42
+ const json: FamixJSONExporter = new FamixJSONExporter("ImportClause", this);
43
+ this.addPropertiesToExporter(json);
44
+ return json.getJSON();
45
45
  }
46
46
 
47
47
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -1,42 +1,40 @@
1
- export {Access} from "./access";
2
- export {Accessor} from "./accessor";
3
- export {Alias} from "./alias";
4
- export {Association} from "./association";
5
- export {BehavioralEntity} from "./behavioral_entity";
6
- export {CSourceLanguage} from "./c_source_language";
7
- export {Class} from "./class";
8
- export {Comment} from "./comment";
9
- export {ContainerEntity} from "./container_entity";
10
- export {CustomSourceLanguage} from "./custom_source_language";
11
- export {Decorator} from "./decorator";
12
- export {Entity} from "./entity";
13
- export {EnumValue} from "./enum_value";
14
- export {Enum} from "./enum";
15
- export {Property} from "./property";
16
- export {Function} from "./function";
17
- export {ImplicitVariable} from "./implicit_variable";
18
- export {ImportClause} from "./import_clause";
19
- export {IndexedFileAnchor} from "./indexed_file_anchor";
20
- export {Inheritance} from "./inheritance";
21
- export {Interface} from "./interface";
22
- export {Invocation} from "./invocation";
23
- export {Method} from "./method";
24
- export {Module} from "./module";
25
- export {NamedEntity} from "./named_entity";
26
- export {Namespace} from "./namespace";
27
- export {TypeParameter} from "./type_parameter";
28
- export {Parameter} from "./parameter";
29
- export {ParameterizableClass} from "./parameterizable_class";
30
- export {ParameterizableInterface} from "./parameterizable_interface";
31
- export {ParameterizedType} from "./parameterized_type";
32
- export {PrimitiveType} from "./primitive_type";
33
- export {Reference} from "./reference";
34
- export {ScopingEntity} from "./scoping_entity";
35
- export {ScriptEntity} from "./script_entity";
36
- export {SourceAnchor} from "./source_anchor";
37
- export {SourceLanguage} from "./source_language";
38
- export {SourcedEntity} from "./sourced_entity";
39
- export {StructuralEntity} from "./structural_entity";
40
- export {TextAnchor} from "./text_anchor";
41
- export {Type} from "./type";
42
- export {Variable} from "./variable";
1
+ export { Access } from "./access";
2
+ export { Accessor } from "./accessor";
3
+ export { Alias } from "./alias";
4
+ export { Association } from "./association";
5
+ export { BehavioralEntity } from "./behavioral_entity";
6
+ export { Class } from "./class";
7
+ export { Comment } from "./comment";
8
+ export { ContainerEntity } from "./container_entity";
9
+ export { Decorator } from "./decorator";
10
+ export { Entity } from "./entity";
11
+ export { EnumValue } from "./enum_value";
12
+ export { Enum } from "./enum";
13
+ export { Property } from "./property";
14
+ export { Function } from "./function";
15
+ export { ImplicitVariable } from "./implicit_variable";
16
+ export { ImportClause } from "./import_clause";
17
+ export { IndexedFileAnchor } from "./indexed_file_anchor";
18
+ export { Inheritance } from "./inheritance";
19
+ export { Interface } from "./interface";
20
+ export { Invocation } from "./invocation";
21
+ export { Method } from "./method";
22
+ export { Module } from "./module";
23
+ export { NamedEntity } from "./named_entity";
24
+ export { Namespace } from "./namespace";
25
+ export { ParameterType } from "./parameter_type";
26
+ export { Parameter } from "./parameter";
27
+ export { ParameterizableClass } from "./parameterizable_class";
28
+ export { ParameterizableInterface } from "./parameterizable_interface";
29
+ export { ParameterizedType } from "./parameterized_type";
30
+ export { PrimitiveType } from "./primitive_type";
31
+ export { Reference } from "./reference";
32
+ export { ScopingEntity } from "./scoping_entity";
33
+ export { ScriptEntity } from "./script_entity";
34
+ export { SourceAnchor } from "./source_anchor";
35
+ export { SourceLanguage } from "./source_language";
36
+ export { SourcedEntity } from "./sourced_entity";
37
+ export { StructuralEntity } from "./structural_entity";
38
+ export { TextAnchor } from "./text_anchor";
39
+ export { Type } from "./type";
40
+ export { Variable } from "./variable";
@@ -35,9 +35,9 @@ export class IndexedFileAnchor extends SourceAnchor {
35
35
 
36
36
 
37
37
  public getJSON(): string {
38
- const mse: FamixJSONExporter = new FamixJSONExporter("IndexedFileAnchor", this);
39
- this.addPropertiesToExporter(mse);
40
- return mse.getJSON();
38
+ const json: FamixJSONExporter = new FamixJSONExporter("IndexedFileAnchor", this);
39
+ this.addPropertiesToExporter(json);
40
+ return json.getJSON();
41
41
  }
42
42
 
43
43
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -29,9 +29,9 @@ export class Inheritance extends Association {
29
29
 
30
30
 
31
31
  public getJSON(): string {
32
- const mse: FamixJSONExporter = new FamixJSONExporter("Inheritance", this);
33
- this.addPropertiesToExporter(mse);
34
- return mse.getJSON();
32
+ const json: FamixJSONExporter = new FamixJSONExporter("Inheritance", this);
33
+ this.addPropertiesToExporter(json);
34
+ return json.getJSON();
35
35
  }
36
36
 
37
37
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -60,9 +60,9 @@ export class Interface extends Type {
60
60
 
61
61
 
62
62
  public getJSON(): string {
63
- const mse: FamixJSONExporter = new FamixJSONExporter("Interface", this);
64
- this.addPropertiesToExporter(mse);
65
- return mse.getJSON();
63
+ const json: FamixJSONExporter = new FamixJSONExporter("Interface", this);
64
+ this.addPropertiesToExporter(json);
65
+ return json.getJSON();
66
66
  }
67
67
 
68
68
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {
@@ -53,9 +53,9 @@ export class Invocation extends Association {
53
53
 
54
54
 
55
55
  public getJSON(): string {
56
- const mse: FamixJSONExporter = new FamixJSONExporter("Invocation", this);
57
- this.addPropertiesToExporter(mse);
58
- return mse.getJSON();
56
+ const json: FamixJSONExporter = new FamixJSONExporter("Invocation", this);
57
+ this.addPropertiesToExporter(json);
58
+ return json.getJSON();
59
59
  }
60
60
 
61
61
  public addPropertiesToExporter(exporter: FamixJSONExporter): void {