]> git.uio.no Git - ifi-stolz-refaktor.git/blob - software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/aspects/StatisticsAspect.aj
468a0ef833bbd6f40c8f6d407ddbb22b16f52115
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor / src / no / uio / ifi / refaktor / aspects / StatisticsAspect.aj
1 package no.uio.ifi.refaktor.aspects;
2
3 import no.uio.ifi.refaktor.analyze.analyzers.SearchBasedExtractAndMoveMethodAnalyzer;
4 import no.uio.ifi.refaktor.utils.RefaktorDebug;
5
6 import org.eclipse.jdt.core.IMethod;
7 import org.eclipse.jdt.core.JavaModelException;
8
9 privileged public aspect StatisticsAspect {
10         private long startTime;
11         private int methodCount;
12
13         pointcut methodAnalyze(SearchBasedExtractAndMoveMethodAnalyzer analyzer) : 
14                 call(* SearchBasedExtractAndMoveMethodAnalyzer.analyze()) && target(analyzer);
15         
16         before(SearchBasedExtractAndMoveMethodAnalyzer analyzer) : methodAnalyze(analyzer) {
17                 methodCount++;
18                 debugPrintMethodAnalysisProgress(analyzer.method);
19         }
20         
21         private void debugPrintMethodAnalysisProgress(IMethod method) {
22                 try {
23                         RefaktorDebug.println("#" + methodCount + " (" + timeSinceStart() + "): " 
24                                         + method.getDeclaringType().getElementName() + "." + method.getElementName() + " (" + "offset: "
25                                         + method.getSourceRange().getOffset() + ", length: " + method.getSourceRange().getLength() + ")");
26                 } catch (JavaModelException e) {
27                         RefaktorDebug.println("No info about " + method.getElementName());
28                 }
29         }
30         
31         public void init() {
32                 startTime = System.currentTimeMillis();
33                 methodCount = 0;
34         }
35         
36         public String timeSinceStart() {
37                 long durationInMillis = System.currentTimeMillis() - startTime;
38                 long secondsSinceAnalysisStart = durationInMillis/1000;
39
40                 if (secondsSinceAnalysisStart > 0)
41                         return secondsSinceAnalysisStart/60 + "m" + secondsSinceAnalysisStart % 60 + "s";
42                 else
43                         return durationInMillis + "ms";
44         }
45         
46         public int getMethodCount() {
47                 return methodCount;
48         }
49
50 //      @Override
51 //      public String toString() {
52 //              return (getPackageCount() > 0 ? "Number of packages analyzed: " + getPackageCount() : "") 
53 //                              + (getCompilationUnitCount() > 0 ? "\nNumber of compilation units analyzed: " + getCompilationUnitCount() : "")
54 //                              + (getTypeCount() > 0 ? "\nNumber of types analyzed: " + getTypeCount() : "")
55 //                              + "\nNumber of methods analyzed: " + getMethodCount()
56 //                              + "\nTime used: " + getTimeUsed();
57 //      }
58         
59 }