Skip to content

Commit 3f8b24b

Browse files
committed
Query interface segregation candidates for Typescript
1 parent 406c268 commit 3f8b24b

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Candidates for Interface Segregation for Typescript
2+
3+
MATCH (type:Type)-[:DECLARES]->(method:Method)-[:INVOKES]->(dependentMethod:Method)
4+
MATCH (dependentMethod)<-[:DECLARES]-(dependentType:Type)
5+
MATCH (dependentType)-[:IMPLEMENTS*1..9]->(superType:Type)-[:DECLARES]->(inheritedMethod:Method)
6+
WHERE type.fqn <> dependentType.fqn
7+
AND dependentMethod.name IS NOT NULL
8+
AND inheritedMethod.name IS NOT NULL
9+
AND dependentMethod.name <> '<init>' // ignore constructors
10+
AND inheritedMethod.name <> '<init>' // ignore constructors
11+
WITH type.fqn AS fullTypeName
12+
,dependentType.fqn AS fullDependentTypeName
13+
,collect(DISTINCT dependentMethod.name) AS calledMethodNames
14+
,count(DISTINCT dependentMethod) AS calledMethods
15+
// Count the different signatures without the return type
16+
// of all declared methods including the inherited ones
17+
,count(DISTINCT split(method.signature, ' ')[1]) + count(DISTINCT split(inheritedMethod.signature, ' ')[1]) AS declaredMethods
18+
// Filter out types that declare only a few more methods than those that are actually used.
19+
// A good interface segregation candidate declares a lot of methods where only a few of them are used widely.
20+
WHERE declaredMethods > calledMethods + 2
21+
WITH fullDependentTypeName
22+
,declaredMethods
23+
,calledMethodNames
24+
,calledMethods
25+
,count(DISTINCT fullTypeName) AS callerTypes
26+
RETURN fullDependentTypeName, declaredMethods, calledMethodNames, calledMethods, callerTypes
27+
ORDER BY callerTypes DESC, declaredMethods DESC, fullDependentTypeName

jupyter/InternalDependenciesTypescript.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@
381381
"source": [
382382
"### Table 4 - Top 40 most used combinations of methods\n",
383383
"\n",
384-
"The following table shows the top 40 most used combinations of methods of larger types that might benefit from applying the *Interface Segregation Principle*. The whole table can be found in the CSV report `Candidates_for_Interface_Segregation`."
384+
"The following table shows the top 40 most used combinations of methods of larger types that might benefit from applying the *Interface Segregation Principle*. The whole table can be found in the CSV report `Candidates_for_Interface_Segregation_for_Typescript`."
385385
]
386386
},
387387
{
@@ -393,7 +393,7 @@
393393
},
394394
"outputs": [],
395395
"source": [
396-
"interface_segregation_candidates=query_cypher_to_data_frame(\"../cypher/Candidates_for_Interface_Segregation.cypher\", limit=40)\n",
396+
"interface_segregation_candidates=query_cypher_to_data_frame(\"../cypher/Internal_Dependencies/Candidates_for_Interface_Segregation_for_Typescript.cypher\", limit=40)\n",
397397
"interface_segregation_candidates"
398398
]
399399
},

scripts/reports/InternalDependenciesCsv.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ execute_cypher "${CYCLIC_DEPENDENCIES_CYPHER_DIR}/Cyclic_Dependencies_between_Ar
4949
execute_cypher "${CYCLIC_DEPENDENCIES_CYPHER_DIR}/Cyclic_Dependencies_for_Typescript.cypher" > "${FULL_REPORT_DIRECTORY}/Cyclic_Dependencies_for_Typescript.csv"
5050

5151
execute_cypher "${INTERNAL_DEPENDENCIES_CYPHER_DIR}/Candidates_for_Interface_Segregation.cypher" > "${FULL_REPORT_DIRECTORY}/InterfaceSegregationCandidates.csv"
52+
execute_cypher "${INTERNAL_DEPENDENCIES_CYPHER_DIR}/Candidates_for_Interface_Segregation_for_Typescript.cypher" > "${FULL_REPORT_DIRECTORY}/Candidates_for_Interface_Segregation_for_Typescript.csv"
5253

5354
execute_cypher "${INTERNAL_DEPENDENCIES_CYPHER_DIR}/List_all_Java_artifacts.cypher" > "${FULL_REPORT_DIRECTORY}/List_all_Java_artifacts.csv"
5455
execute_cypher "${INTERNAL_DEPENDENCIES_CYPHER_DIR}/List_types_that_are_used_by_many_different_packages.cypher" > "${FULL_REPORT_DIRECTORY}/WidelyUsedTypes.csv"

0 commit comments

Comments
 (0)