1 19 20 package soot.toolkits.astmetrics; 21 22 import polyglot.ast.Branch; 23 import polyglot.ast.ClassDecl; 24 import polyglot.ast.Node; 25 import polyglot.visit.NodeVisitor; 26 27 41 public class AbruptEdgesMetric extends ASTMetric { 42 43 private int iBreaks, eBreaks; 44 private int iContinues, eContinues; 45 46 public AbruptEdgesMetric(polyglot.ast.Node astNode){ 47 super(astNode); 48 } 49 50 51 57 public void reset(){ 58 iBreaks=eBreaks=iContinues=eContinues=0; 59 } 60 61 66 public void addMetrics(ClassData data){ 67 68 data.addMetric(new MetricData("Total-breaks",new Integer (iBreaks+eBreaks))); 69 data.addMetric(new MetricData("Implicit-breaks",new Integer (iBreaks))); 70 data.addMetric(new MetricData("Expicit-breaks",new Integer (eBreaks))); 71 72 data.addMetric(new MetricData("Total-continues",new Integer (iContinues+eContinues))); 73 data.addMetric(new MetricData("Implicit-continues",new Integer (iContinues))); 74 data.addMetric(new MetricData("Expicit-continues",new Integer (eContinues))); 75 } 76 77 78 81 public NodeVisitor enter(Node parent, Node n){ 82 if(n instanceof Branch){ 83 Branch branch = (Branch)n; 84 if(branch.kind().equals(Branch.BREAK)){ 85 if(branch.label() != null) 86 eBreaks++; 87 else 88 iBreaks++; 89 } 90 else if(branch.kind().equals(Branch.CONTINUE)){ 91 if(branch.label() != null) 92 eContinues++; 93 else 94 iContinues++; 95 } 96 else{ 97 System.out.println("\t Error:'"+branch.toString()+"'"); 98 } 99 } 100 return enter(n); 101 } 102 } 103 | Popular Tags |