Transcript
Page 1: Class graph neo4j and software metrics

Neo4j in Action

1

Software Metrics

Michael Hunger (@mesirii)

1

Page 2: Class graph neo4j and software metrics

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

Page 3: Class graph neo4j and software metrics

Code City

3

3

Page 4: Class graph neo4j and software metrics

Class Diagram is a Graph

4

4

Page 5: Class graph neo4j and software metrics

SonarJ

5

5

Page 6: Class graph neo4j and software metrics

But there is more

6

๏Visualize & query Method, Field dependencies

๏Collaborative filtering (co-usage)

๏Ranking

๏God classes

๏Paths between classes

6

Page 7: Class graph neo4j and software metrics

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

Page 8: Class graph neo4j and software metrics

Welcome to Class-Graph

8

8

Page 9: Class graph neo4j and software metrics

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

Page 10: Class graph neo4j and software metrics

Task: Find java.lang.Number and return it

10

10

Page 11: Class graph neo4j and software metrics

Task: Find java.lang.Number and return it

10

START o=node:types(name="java.lang.Number") RETURN o;

10

Page 12: Class graph neo4j and software metrics

Task: Subclasses of Number?

11

•Return just the name•Order them alphabetically

11

Page 13: Class graph neo4j and software metrics

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

Page 14: Class graph neo4j and software metrics

Task: Which Methods does it have / how many

12

•Find the top 5 classes with the most members

12

Page 15: Class graph neo4j and software metrics

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

Page 16: Class graph neo4j and software metrics

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

Page 17: Class graph neo4j and software metrics

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

Page 18: Class graph neo4j and software metrics

Task: Find longest Inheritance Path

14

14

Page 19: Class graph neo4j and software metrics

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

Page 20: Class graph neo4j and software metrics

Task: Find the class that used IOException most often

15

15

Page 21: Class graph neo4j and software metrics

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

Page 22: Class graph neo4j and software metrics

Task: Which other classes did classes that threw IOException use most often?

16

•What could be a source of IOExceptions

16

Page 23: Class graph neo4j and software metrics

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

Page 24: Class graph neo4j and software metrics

Task: Find a class you like and add a field with your name and some type

17

17

Page 25: Class graph neo4j and software metrics

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

Page 26: Class graph neo4j and software metrics

Task: Delete the most annoying class and all its methods, fields and their relationships

18

18

Page 27: Class graph neo4j and software metrics

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


Top Related