Skip to content

Commit 351e276

Browse files
committed
Add detailed reflection usage report
1 parent 00d9557 commit 351e276

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

cypher/Java/Java_Reflection_usage.cypher

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
MATCH (dependentArtifact:Artifact)-[:CONTAINS]-(dependentType:Type)
44
WITH replace(last(split(dependentArtifact.fileName, '/')), '.jar', '') AS dependentArtifactName
5-
,dependentType AS dependentType
5+
,dependentType
66
OPTIONAL MATCH (dependentType)-[:DEPENDS_ON]->(reflectionType:Type)
77
WHERE reflectionType.fqn STARTS WITH 'java.lang.reflect.'
88
OPTIONAL MATCH (dependentType)-[:DECLARES]->(dependentMethod:Method)-[:INVOKES]->(classForName:Method)
99
WHERE classForName.signature STARTS WITH 'java.lang.Class forName'
1010
WITH dependentArtifactName
11-
,collect(DISTINCT coalesce(reflectionType.fqn, 'Class.forName')) AS reflectionTypes
11+
,collect(DISTINCT coalesce(reflectionType.fqn, 'Class.' + classForName.name)) AS reflectionTypes
1212
,collect(DISTINCT dependentType.fqn) AS reflectionCaller
1313
,count(DISTINCT dependentType.fqn) AS numberOfReflectionCaller
1414
RETURN dependentArtifactName
1515
,numberOfReflectionCaller
16+
,reflectionCaller[0..19] AS someReflectionCaller
1617
,reflectionTypes[0..19] AS someReflectionTypes
17-
,reflectionCaller[0..19] AS someDependentTypes
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Query all types that use Java Reflection or "Class.forName"
2+
3+
MATCH (dependentArtifact:Artifact)-[:CONTAINS]-(dependentType:Type)
4+
WITH replace(last(split(dependentArtifact.fileName, '/')), '.jar', '') AS dependentArtifactName
5+
,dependentType
6+
OPTIONAL MATCH (dependentType)-[:DEPENDS_ON]->(reflectionType:Type)
7+
WHERE reflectionType.fqn STARTS WITH 'java.lang.reflect.'
8+
OPTIONAL MATCH (dependentType)-[:DECLARES]->(dependentMethod:Method)-[:INVOKES]->(classForName:Method)
9+
WHERE classForName.signature STARTS WITH 'java.lang.Class forName'
10+
WITH dependentArtifactName
11+
,dependentType.fqn AS reflectionCallerTypeName
12+
,collect(DISTINCT coalesce(reflectionType.fqn, 'Class.' + classForName.name)) AS reflectionTypes
13+
WHERE size(reflectionTypes) > 0
14+
RETURN dependentArtifactName
15+
,reflectionCallerTypeName
16+
,reflectionTypes[0..19] AS reflectionTypes

scripts/reports/JavaCsv.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ mkdir -p "${FULL_REPORT_DIRECTORY}"
3838
JAVA_CYPHER_DIR="${CYPHER_DIR}/Java"
3939

4040
execute_cypher "${JAVA_CYPHER_DIR}/Java_Reflection_usage.cypher" > "${FULL_REPORT_DIRECTORY}/ReflectionUsage.csv"
41+
execute_cypher "${JAVA_CYPHER_DIR}/Java_Reflection_usage_detailed.cypher" > "${FULL_REPORT_DIRECTORY}/ReflectionUsageDetailed.csv"
4142
execute_cypher "${JAVA_CYPHER_DIR}/Java_deprecated_element_usage.cypher" > "${FULL_REPORT_DIRECTORY}/DeprecatedElementUsage.csv"
4243
execute_cypher "${JAVA_CYPHER_DIR}/Annotated_code_elements.cypher" > "${FULL_REPORT_DIRECTORY}/AnnotatedCodeElements.csv"
4344
execute_cypher "${JAVA_CYPHER_DIR}/Annotated_code_elements_per_artifact.cypher" > "${FULL_REPORT_DIRECTORY}/AnnotatedCodeElementsPerArtifact.csv"

0 commit comments

Comments
 (0)