Skip to content

Commit d314e65

Browse files
committed
Enrich graph for Typescript
1 parent 943d9d8 commit d314e65

7 files changed

+60
-19
lines changed

cypher/Exploration/Add_module_property_to_ExternalModule.cypher

Lines changed: 0 additions & 7 deletions
This file was deleted.

cypher/Exploration/Add_name_and_module_properties_to_ExternalDeclaration.cypher

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Propagates "DEPENDS_ON" relations between modules to their resolved modules with a property "resolved:true".
2+
// Inspired by https://github.com/jQAssistant/jqa-java-plugin/blob/f092122b62bb13d597840b64b73b2010bd074d1f/src/main/resources/META-INF/jqassistant-rules/java-classpath.xml#L59
3+
4+
MATCH (module:TS:Module)-[dependsOn:DEPENDS_ON]->(externalModule:TS:ExternalModule)
5+
MATCH (externalModule)-[:RESOLVES_TO]->(resolvedModule:TS:Module)
6+
WHERE module <> resolvedModule
7+
CALL { WITH module, dependsOn, resolvedModule
8+
MERGE (module)-[resolvedDependsOn:DEPENDS_ON]->(resolvedModule)
9+
SET resolvedDependsOn = dependsOn
10+
,resolvedDependsOn.resolved=true
11+
} IN TRANSACTIONS
12+
RETURN count(*) as resolvedDependencies
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Adds a relation "RESOLVES_TO" from a Typescript element to an external declaration if their global fully qualified names match.
2+
// Inspired by https://github.com/jQAssistant/jqa-java-plugin/blob/f092122b62bb13d597840b64b73b2010bd074d1f/src/main/resources/META-INF/jqassistant-rules/java-classpath.xml#L5
3+
4+
MATCH (element:TS&!ExternalDeclaration)
5+
MATCH (external:TS&ExternalDeclaration)
6+
WHERE (element.globalFqn = external.globalFqn
7+
OR toLower(element.globalFqn) = toLower(external.globalFqn))
8+
AND element <> external
9+
CALL { WITH element, external
10+
MERGE (external)-[:RESOLVES_TO]->(element)
11+
} IN TRANSACTIONS
12+
RETURN count(*) AS resolvedElements
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Adds a relation "RESOLVES_TO" from an external module to a module if their global fully qualified names match.
2+
// Inspired by https://github.com/jQAssistant/jqa-java-plugin/blob/f092122b62bb13d597840b64b73b2010bd074d1f/src/main/resources/META-INF/jqassistant-rules/java-classpath.xml#L5
3+
4+
MATCH (module:TS:Module)
5+
MATCH (externalModule:TS:ExternalModule)
6+
WHERE (toLower(module.globalFqn) = toLower(externalModule.globalFqn)
7+
OR toLower(module.globalFqn) = split(toLower(externalModule.globalFqn), '/index.')[0]
8+
OR toLower(externalModule.globalFqn) = split(toLower(module.globalFqn), '/index.')[0]
9+
)
10+
AND module <> externalModule
11+
CALL { WITH module, externalModule
12+
MERGE (externalModule)-[:RESOLVES_TO]->(module)
13+
} IN TRANSACTIONS
14+
RETURN count(*) AS resolvedModules
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Add "name" and "module" properties to Typescript nodes that have a globalFqn property
2+
3+
MATCH (ts:TS)
4+
WHERE ts.globalFqn IS NOT NULL
5+
WITH ts
6+
,replace(split(ts.globalFqn, '".')[0],'"', '') AS moduleName
7+
,replace(split(ts.globalFqn, '/index')[0],'"', '') AS moduleNameWithoutIndex
8+
,split(ts.globalFqn, '".')[1] AS symbolName
9+
WITH *
10+
,reverse(split(reverse(moduleNameWithoutIndex), '/')[0]) AS indexedName
11+
SET ts.module = moduleName
12+
,ts.name = coalesce(symbolName, indexedName)
13+
RETURN count(*) AS updatedModules

scripts/prepareAnalysis.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ METRICS_CYPHER_DIR="$CYPHER_DIR/Metrics"
3636
EXTERNAL_DEPENDENCIES_CYPHER_DIR="$CYPHER_DIR/External_Dependencies"
3737
ARTIFACT_DEPENDENCIES_CYPHER_DIR="$CYPHER_DIR/Artifact_Dependencies"
3838
TYPES_CYPHER_DIR="$CYPHER_DIR/Types"
39+
TYPESCRIPT_CYPHER_DIR="$CYPHER_DIR/Typescript_Enrichment"
3940

4041
# Preparation - Data verification: DEPENDS_ON releationships
4142
dataVerificationResult=$( execute_cypher "${CYPHER_DIR}/Data_verification_DEPENDS_ON_relationships.cypher" "${@}")
@@ -52,6 +53,14 @@ execute_cypher "${CYPHER_DIR}/Create_index_for_full_qualified_type_name.cypher"
5253
# execute_cypher "${CYPHER_DIR}/Create_a_DEPENDS_ON_relationship_for_every_DEPENDS_ON_PACKAGE.cypher"
5354
# execute_cypher "${CYPHER_DIR}/Create_a_DEPENDS_ON_relationship_for_every_DEPENDS_ON_ARTIFACT.cypher"
5455

56+
# Preparation - Enrich Graph for Typescript by adding "module" and "name" properties
57+
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_name_and_module_properties.cypher"
58+
59+
# Preparation - Enrich Graph for Typescript by adding relationships between Modules with the same globalFqn
60+
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_RESOLVES_TO_relationship_for_matching_modules.cypher"
61+
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_RESOLVES_TO_relationship_for_matching_declarations.cypher"
62+
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_DEPENDS_ON_relationship_to_resolved_modules.cypher"
63+
5564
# Preparation - Add weights to Java Package DEPENDS_ON relationships
5665
execute_cypher "${DEPENDS_ON_CYPHER_DIR}/Add_weight_property_for_Java_Interface_Dependencies_to_Package_DEPENDS_ON_Relationship.cypher"
5766
execute_cypher "${DEPENDS_ON_CYPHER_DIR}/Add_weight_property_to_Java_Package_DEPENDS_ON_Relationship.cypher"
@@ -87,9 +96,6 @@ execute_cypher "${TYPES_CYPHER_DIR}/Label_resolved_duplicate_types.cypher"
8796
execute_cypher "${EXTERNAL_DEPENDENCIES_CYPHER_DIR}/Remove_external_type_and_annotation_labels.cypher"
8897
execute_cypher "${EXTERNAL_DEPENDENCIES_CYPHER_DIR}/Label_external_types_and_annotations.cypher"
8998

90-
# Preparation - Add Typescript Package node properties "incomingDependencies" and "outgoingDependencies"
91-
# TODO
92-
9399
# Preparation - Add Java Artifact node properties "incomingDependencies" and "outgoingDependencies"
94100
execute_cypher "${ARTIFACT_DEPENDENCIES_CYPHER_DIR}/Incoming_Java_Artifact_Dependencies.cypher"
95101
execute_cypher "${ARTIFACT_DEPENDENCIES_CYPHER_DIR}/Outgoing_Java_Artifact_Dependencies.cypher"

0 commit comments

Comments
 (0)