import java.util.LinkedList;
import java.util.Set;
-import no.uio.ifi.refaktor.analyze.AnalysisStatistics;
import no.uio.ifi.refaktor.analyze.ExtractAndMoveMethodAnalysisResult;
import no.uio.ifi.refaktor.analyze.comparators.ExtractAndMoveMethodAnalysisResultComparator;
import no.uio.ifi.refaktor.analyze.comparators.IgnorantAnalysisResultComparator;
private final IMethod method;
private final ExtractAndMoveMethodAnalysisResultComparator analysisResultComparator;
- private final AnalysisStatistics statistics;
private Set<CompilationUnitTextSelection> textSelections;
private LinkedList<ExtractAndMoveMethodAnalysisResult> possibleResults;
private ExtractAndMoveMethodAnalysisResult chosenResult;
this(method, new IgnorantAnalysisResultComparator());
}
- public SearchBasedExtractAndMoveMethodAnalyzer(IMethod method,
- ExtractAndMoveMethodAnalysisResultComparator analysisResultComparator) {
- this(method, analysisResultComparator, new AnalysisStatistics());
- }
-
/**
* @param method The handler for the method to analyze.
* @param analysisResultComparator A result comparator to compare two analysis results when deciding
* which of them that is the best candidate for the refactoring.
- * @param statistics
*/
- public SearchBasedExtractAndMoveMethodAnalyzer(IMethod method,
- ExtractAndMoveMethodAnalysisResultComparator analysisResultComparator, AnalysisStatistics statistics) {
+ public SearchBasedExtractAndMoveMethodAnalyzer(IMethod method, ExtractAndMoveMethodAnalysisResultComparator analysisResultComparator) {
this.method = method;
this.analysisResultComparator = analysisResultComparator;
- this.statistics = statistics;
possibleResults = new LinkedList<ExtractAndMoveMethodAnalysisResult>();
statementsCreator = new StatementsCreator(method);
}
@Override
public void analyze() throws RefaktorAnalyzerException {
- statistics.incrementMethodCount();
-
- printDebugInfo();
-
// TODO: make the Extract and Move Method Refactoring work with static methods
abortIfStaticMethod();
chooseResult();
}
- private void printDebugInfo() {
- try {
- RefaktorDebug.println("#" + statistics.getMethodCount() + " (" + statistics.timeSinceStart() + "): " + method.getDeclaringType().getElementName() + "." + method.getElementName() + " (" + "offset: "
- + method.getSourceRange().getOffset() + ", length: " + method.getSourceRange().getLength() + ")");
- } catch (JavaModelException e) {
- RefaktorDebug.println("No info about " + method.getElementName());
- }
- }
-
private void abortIfStaticMethod() {
try {
if (Flags.isStatic(method.getFlags()))
--- /dev/null
+package no.uio.ifi.refaktor.aspects;
+
+import no.uio.ifi.refaktor.analyze.analyzers.SearchBasedExtractAndMoveMethodAnalyzer;
+import no.uio.ifi.refaktor.utils.RefaktorDebug;
+
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.JavaModelException;
+
+privileged public aspect StatisticsAspect {
+ private long startTime;
+ private int methodCount;
+
+ pointcut methodAnalyze(SearchBasedExtractAndMoveMethodAnalyzer analyzer) :
+ call(* SearchBasedExtractAndMoveMethodAnalyzer.analyze()) && target(analyzer);
+
+ before(SearchBasedExtractAndMoveMethodAnalyzer analyzer) : methodAnalyze(analyzer) {
+ methodCount++;
+ debugPrintMethodAnalysisProgress(analyzer.method);
+ }
+
+ private void debugPrintMethodAnalysisProgress(IMethod method) {
+ try {
+ RefaktorDebug.println("#" + methodCount + " (" + timeSinceStart() + "): "
+ + method.getDeclaringType().getElementName() + "." + method.getElementName() + " (" + "offset: "
+ + method.getSourceRange().getOffset() + ", length: " + method.getSourceRange().getLength() + ")");
+ } catch (JavaModelException e) {
+ RefaktorDebug.println("No info about " + method.getElementName());
+ }
+ }
+
+ public void init() {
+ startTime = System.currentTimeMillis();
+ methodCount = 0;
+ }
+
+ private String timeSinceStart() {
+ long durationInMillis = System.currentTimeMillis() - startTime;
+ long secondsSinceAnalysisStart = durationInMillis/1000;
+
+ if (secondsSinceAnalysisStart > 0)
+ return secondsSinceAnalysisStart/60 + "m" + secondsSinceAnalysisStart % 60 + "s";
+ else
+ return durationInMillis + "ms";
+ }
+
+ public int getMethodCount() {
+ return methodCount;
+ }
+
+}