Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Class graph neo4j and software metrics

2,266 views

Published on

Each of the files or classes of a projects source code represents a tree (AST). Looking at dependencies to other classes besides inheritance creates a graph though. Field types and method parameters are also implicit dependencies. Storing this information in a graph database like Neo4j allows for interesting queries and insights. Class-Graph provides that and is available as open-source github project.

Published in: Technology, Education
  • Be the first to comment

Class graph neo4j and software metrics

  1. 1. Neo4j in ActionSoftware Metrics Michael Hunger (@mesirii) 1 1
  2. 2. Graphs in Software Technolgoy๏ 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 2
  3. 3. Code City 3 3
  4. 4. Class Diagram is a Graph 4 4
  5. 5. SonarJ 5 5
  6. 6. But there is more๏Visualize & query Method, Field dependencies๏Collaborative filtering (co-usage)๏Ranking๏God classes๏Paths between classes 6 6
  7. 7. Welcome to Class-Graph๏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 7
  8. 8. Welcome to Class-Graph 8 8
  9. 9. Interactive Hands-On Session๏Lots of tasks๏use Cypher to solve them http://neo4j.org/resources/cypher๏be creative, work together๏ask !๏Server http://bit.ly/innoq-neo4j๏just the beginning 9 9
  10. 10. Task: Find java.lang.Number and return it 10 10
  11. 11. Task: Find java.lang.Number and return itSTART o=node:types(name="java.lang.Number") RETURN o; 10 10
  12. 12. Task: Subclasses of Number?•Return just the name•Order them alphabetically 11 11
  13. 13. Task: Subclasses of Number?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 11
  14. 14. Task: Which Methods does it have / how many•Find the top 5 classes with the most members 12 12
  15. 15. Task: Which Methods does it have / how manySTART 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 12
  16. 16. Task: Calculate the fan-out ofjava.lang.StringBuilder•Calculate fan-in•Which class has the highest fan-out•What about package-level? 13 13
  17. 17. Task: Calculate the fan-out of java.lang.StringBuilderSTART 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 13
  18. 18. Task: Find longest Inheritance Path 14 14
  19. 19. Task: Find longest Inheritance Pathstart 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 14
  20. 20. Task: Find the class that used IOExceptionmost often 15 15
  21. 21. Task: Find the class that used IOExceptionmost oftenSTART ex=node:types(name="java.io.IOException"MATCH ex<-[:THROWS]-m<-[:METHOD_OF]-cRETURN c, count(*)ORDER BY count(*)LIMIT 5; 15 15
  22. 22. Task: Which other classes did classes that threw IOException use most often?•What could be a source of IOExceptions 16 16
  23. 23. Task: Which other classes did classes that threw IOException use most often?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 16
  24. 24. Task: Find a class you like and add a field withyour name and some type 17 17
  25. 25. Task: Find a class you like and add a field with your name and some typeSTART c=node:types(name="void"), t=node:types(name="java.lang.reflect.Proxy") CREATE c-[:FIELD_OF]->(field {name:“Michael“}) -[:FIELD_TYPE]->t; 17 17
  26. 26. Task: Delete the most annoying class and all itsmethods, fields and their relationships 18 18
  27. 27. Task: Delete the most annoying class and all its methods, fields and their relationshipsSTART 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 18

×