2222
2323public class JSAnalyzer {
2424
25+
26+
27+
28+
29+ private int coveredEventCallback = 0 ;
30+ public int getCoveredEventCallback () {
31+ return coveredEventCallback ;
32+ }
33+
34+ private int missedEventCallback = 0 ;
35+ public int getMissedEventCallback () {
36+ return missedEventCallback ;
37+ }
38+
39+ private int coveredAsyncCallback = 0 ;
40+ public int getCoveredAsyncCallback () {
41+ return coveredAsyncCallback ;
42+ }
43+
44+ private int missedAsyncCallback = 0 ;
45+ public int getMissedAsyncCallback () {
46+ return missedAsyncCallback ;
47+ }
48+
49+ private int coveredCallback = 0 ;
50+ public int getCoveredCallback () {
51+ return coveredCallback ;
52+ }
53+
54+ private int missedCallback = 0 ;
55+ public int getMissedCallback () {
56+ return missedCallback ;
57+ }
58+
59+ private int coveredClosure = 0 ;
60+ public int getCoveredClosure () {
61+ return coveredClosure ;
62+ }
63+
64+ private int missedClosure = 0 ;
65+ public int getMissedClosure () {
66+ return missedClosure ;
67+ }
68+
69+ private int coveredRegularFunc = 0 ;
70+ public int getCoveredRegularFunc () {
71+ return coveredRegularFunc ;
72+ }
73+
74+ private int missedRegularFunc = 0 ;
75+ public int getMissedRegularFunc () {
76+ return missedRegularFunc ;
77+ }
78+
79+ private int neverExecFunCallSites = 0 ;
80+ public int getNeverExecFunCallSites () {
81+ return neverExecFunCallSites ;
82+ }
83+
84+ private int totalMissedStatementLinesInMissedFunctionCounter = 0 ;
85+ public int getTotalMissedStatementLinesInMissedFunctionCounter () {
86+ return totalMissedStatementLinesInMissedFunctionCounter ;
87+ }
88+
89+ private int totalMissedStatementLines ;
90+ public int getTotalMissedStatementLines () {
91+ return totalMissedStatementLines ;
92+ }
93+
94+
2595 private List <String > excludeFilenamePatterns ;
2696
2797 private JSASTInstrumentor astVisitor ;
2898 private String outputfolder ;
2999 private String jsAddress , scopeName ;
30100
101+
31102 public void setJSAddress (String jsAddress ){
32103 this .jsAddress = jsAddress ;
33104 }
@@ -271,7 +342,8 @@ public void analyze(ArrayList<Integer> coveredLines, ArrayList<Integer> missedLi
271342 System .out .println ("MissedFunctions :" + astVisitor .getMissedFunctions ());
272343 //System.out.println("MissedFunctions.size() :" + astVisitor.getMissedFunctions().size());
273344 System .out .println ("MissedFunctionLines :" + astVisitor .getMissedFunctionLines ());
274-
345+
346+
275347 astVisitor .setVisitOnly ("FunctionCall" );
276348 ast .visit (astVisitor );
277349
@@ -280,23 +352,55 @@ public void analyze(ArrayList<Integer> coveredLines, ArrayList<Integer> missedLi
280352 for (String functionCall : astVisitor .getFunctionCalls ()){
281353 if (functionCall .contains (".call" ) || functionCall .contains (".apply" )) // The call() and apply() methods calls a function with a given this value and arguments
282354 functionCall = functionCall .replace (".call" , "" ).replace (".apply" , "" );
283- if (astVisitor .getMissedFunctions ().contains (functionCall ))
355+ if (astVisitor .getMissedFunctions ().contains (functionCall )){
284356 System .out .println ("The call to function " + functionCall + " was never executed!" );
357+ neverExecFunCallSites ++;
358+ }
285359 }
286360
361+
362+
363+ coveredRegularFunc = astVisitor .getCoveredRegularFunc ();
364+ missedRegularFunc = astVisitor .getMissedRegularFunc ();
365+ coveredCallback = astVisitor .getCoveredCallback ();
366+ missedCallback = astVisitor .getMissedCallback ();
367+ coveredAsyncCallback = astVisitor .getCoveredAsyncCallback ();
368+ missedAsyncCallback = astVisitor .getMissedAsyncCallback ();
369+ coveredEventCallback = astVisitor .getCoveredAsyncCallback ();
370+ missedEventCallback = astVisitor .getMissedEventCallback ();
371+ coveredClosure = astVisitor .getCoveredClosure ();
372+ missedClosure = astVisitor .getMissedClosure ();
373+
374+
375+ System .out .println ("++++ coveredRegularFunc: " + astVisitor .getCoveredRegularFunc ());
376+ System .out .println ("++++ missedRegularFunc: " + astVisitor .getMissedRegularFunc ());
377+ System .out .println ("++++ coveredCallback: " + astVisitor .getCoveredCallback ());
378+ System .out .println ("++++ missedCallback: " + astVisitor .getMissedCallback ());
379+ System .out .println ("++++ coveredAsyncCallback: " + astVisitor .getCoveredAsyncCallback ());
380+ System .out .println ("++++ missedAsyncCallback: " + astVisitor .getMissedAsyncCallback ());
381+ System .out .println ("++++ coveredEventCallback: " + astVisitor .getCoveredAsyncCallback ());
382+ System .out .println ("++++ missedEventCallback: " + astVisitor .getMissedEventCallback ());
383+ System .out .println ("++++ coveredClosure: " + astVisitor .getCoveredClosure ());
384+ System .out .println ("++++ missedClosure: " + astVisitor .getMissedClosure ());
385+
386+ System .out .println ("++++ neverExecFunCallSites: " + neverExecFunCallSites );
387+
388+
287389 ArrayList <Integer > msimf = astVisitor .getMissedStatementInMissedFunction ();
288- System .out .println ("msimf: " + msimf );
289- int totalMissedStatementLinesInMissedFunctionCounter = 0 ;
390+ //System.out.println("msimf: " + msimf);
290391 for (int i =0 ; i <msimf .size (); i ++){
291392 if (msimf .get (i ) >= 0 )
292- totalMissedStatementLinesInMissedFunctionCounter ++;
393+ totalMissedStatementLinesInMissedFunctionCounter ++;
293394 }
395+
396+ totalMissedStatementLines = astVisitor .getMissedStatementLines ().size ();
294397
295398 System .out .println ("@ Total missed statement lines in missed functioncounter = " + totalMissedStatementLinesInMissedFunctionCounter );
296- System .out .println ("@ Total number of missed statements = " + astVisitor .getMissedStatementLines ().size ());
297- float ratio = (float )totalMissedStatementLinesInMissedFunctionCounter /(float )astVisitor .getMissedStatementLines ().size ();
298- if (astVisitor .getMissedStatementLines ().size ()!=0 )
299- System .out .println ("@ Ratio of total missed statement lines = " + ratio );
399+ System .out .println ("@ Total number of missed statements = " + totalMissedStatementLines );
400+ if (totalMissedStatementLines !=0 ){
401+ float ratio = (float )totalMissedStatementLinesInMissedFunctionCounter /(float )totalMissedStatementLines ;
402+ System .out .println ("@ Percentage of missed statement in missed functions = " + ratio *100 + "%" );
403+ }
300404
301405
302406 /*
0 commit comments