Download - Class graph neo4j and software metrics
Neo4j in Action
1
Software Metrics
Michael Hunger (@mesirii)
1
Graphs in Software Technolgoy
2
๏UML Diagrams are graphs
๏dependencies between classes, packages, modules etc are graphs
๏Software Metrics use dependency analysis
๏Visualizations
๏Cyclomatic Complexity,
๏Fan-in (afferent-coupling) / Fan-out (efferent coupling) etc.
2
Code City
3
3
Class Diagram is a Graph
4
4
SonarJ
5
5
But there is more
6
๏Visualize & query Method, Field dependencies
๏Collaborative filtering (co-usage)
๏Ranking
๏God classes
๏Paths between classes
6
Welcome to Class-Graph
7
๏take a JAR
๏put it under ASM
๏scan it superfast
๏pull everything into Neo4j
๏add categories, indexes
๏Have Fun
http://github.com/jexp/class-graph
7
Welcome to Class-Graph
8
8
Interactive Hands-On Session
9
๏Lots of tasks
๏use Cypher to solve themhttp://neo4j.org/resources/cypher
๏be creative, work together
๏ask !
๏Server http://bit.ly/innoq-neo4j
๏just the beginning
9
Task: Find java.lang.Number and return it
10
10
Task: Find java.lang.Number and return it
10
START o=node:types(name="java.lang.Number") RETURN o;
10
Task: Subclasses of Number?
11
•Return just the name•Order them alphabetically
11
Task: Subclasses of Number?
11
START n=node:types(name="java.lang.Number") MATCH n<-[:SUPER_TYPE]-s RETURN s.name ORDER BY s.name;
•Return just the name•Order them alphabetically
11
Task: Which Methods does it have / how many
12
•Find the top 5 classes with the most members
12
Task: Which Methods does it have / how many
12
START n=node:types(name="java.lang.Number") MATCH n-[:METHOD_OF|FIELD_OF]->mRETURN m;
•Find the top 5 classes with the most members
12
Task: Calculate the fan-out of java.lang.StringBuilder
13
•Calculate fan-in•Which class has the highest fan-out•What about package-level?
13
Task: Calculate the fan-out of java.lang.StringBuilder
13
START o=node:types(name="j.l.StringBuilder") MATCH o-[:FIELD_OF]->f-[:FIELD_TYPE]->tf, o-[:METHOD_OF]->m-[:PARAM_TYPE]->tp, m-[:RETURN_TYPE]->trRETURN o,count(distinct tf) + count(distinct tp) + count(distinct tr) as fan_out;
•Calculate fan-in•Which class has the highest fan-out•What about package-level?
13
Task: Find longest Inheritance Path
14
14
Task: Find longest Inheritance Path
14
start c=node:types(name="java.lang.Object") match path=p<-[:SUPER_TYPE*]-c return extract(n in nodes(path) : n.name), length(path) as lenorder by len desc limit 5;
14
Task: Find the class that used IOException most often
15
15
Task: Find the class that used IOException most often
15
START ex=node:types(name="java.io.IOException") MATCH ex<-[:THROWS]-m<-[:METHOD_OF]-cRETURN c, count(*)ORDER BY count(*)LIMIT 5;
15
Task: Which other classes did classes that threw IOException use most often?
16
•What could be a source of IOExceptions
16
Task: Which other classes did classes that threw IOException use most often?
16
START ex=node:types(name="java.io.IOException") MATCH ex<-[:THROWS]-m<-[:METHOD_OF]-c, mbr<-[:METHOD_OF|FIELD_OF]-c, mbr-[:FIELD_TYPE|PARAM_TYPE| RETURN_TYPE|THROWS]->other_typeWHERE other_type.name =~ /.+[.].+/RETURN other_type.name, count(*)ORDER BY count(*) descLIMIT 10;
•What could be a source of IOExceptions
16
Task: Find a class you like and add a field with your name and some type
17
17
Task: Find a class you like and add a field with your name and some type
17
START c=node:types(name="void"), t=node:types(name="java.lang.reflect.Proxy") CREATE c-[:FIELD_OF]->(field {name:“Michael“}) -[:FIELD_TYPE]->t;
17
Task: Delete the most annoying class and all its methods, fields and their relationships
18
18
Task: Delete the most annoying class and all its methods, fields and their relationships
18
START c=node:types(name="java.awt.List"), MATCH c-[r1:FIELD_OF|METHOD_OF]->mbr-[r2]-() c-[r]-()DELETE c,mbr,r1,r2,r;
18