]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/refaktor-after/src/no/uio/ifi/refaktor/analyze/analyzers/TypeWideExtractAndMoveMethodAnalyzer.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / refaktor-after / src / no / uio / ifi / refaktor / analyze / analyzers / TypeWideExtractAndMoveMethodAnalyzer.java
CommitLineData
1b2798f6
EK
1package no.uio.ifi.refaktor.analyze.analyzers;
2
3import java.util.LinkedList;
4import java.util.List;
5
6import no.uio.ifi.refaktor.analyze.ExtractAndMoveMethodCandidate;
7import no.uio.ifi.refaktor.analyze.comparators.FavorNoUnfixesCandidateComparator;
8import no.uio.ifi.refaktor.analyze.exceptions.NoTargetFoundException;
9import no.uio.ifi.refaktor.analyze.exceptions.RefaktorAnalyzerException;
10import no.uio.ifi.refaktor.debugging.RefaktorDebug;
11
12import org.eclipse.jdt.core.IMethod;
13import org.eclipse.jdt.core.IType;
14import org.eclipse.jdt.core.JavaModelException;
15
16/**
17 * Responsible for analyzing all methods in a type for
18 * candidates to the Extract and Move Method refactoring.
19 */
20public class TypeWideExtractAndMoveMethodAnalyzer implements AggregationAnalyzer<ExtractAndMoveMethodCandidate> {
21
22 private final IType type;
23 final List<ExtractAndMoveMethodCandidate> candidates;
24
25 public TypeWideExtractAndMoveMethodAnalyzer(IType type) {
26 this.type = type;
27 candidates = new LinkedList<ExtractAndMoveMethodCandidate>();
28 }
29
30 @Override
31 public List<ExtractAndMoveMethodCandidate> getResults() {
32 return candidates;
33 }
34
35 @Override
36 public void analyze() throws RefaktorAnalyzerException {
37 try {
38 analyzeMethodsInType();
39 } catch (JavaModelException e) {
40 RefaktorDebug.log(e);
41 }
42 }
43
44 private void analyzeMethodsInType() throws JavaModelException {
45 for (IMethod method: type.getMethods()) {
46 analyzeMethod(method);
47 }
48 }
49
50 private void analyzeMethod(IMethod method) {
51 try {
52 SearchBasedExtractAndMoveMethodAnalyzer analyzer =
53 new SearchBasedExtractAndMoveMethodAnalyzer(method, new FavorNoUnfixesCandidateComparator());
54 analyzer.generated_8976769988341837625(this);
55 } catch (NoTargetFoundException e) {
56 // Ignoring
57 } catch (AssertionError err) {
58 RefaktorDebug.log(err);
59 } catch (Exception e) {
60 RefaktorDebug.log(e);
61 }
62 }
63
64 public void generated_6956230269237502630(
65 CompilationUnitWideExtractAndMoveMethodAnalyzer compilationunitwideextractandmovemethodanalyzer) {
66 analyze();
67 compilationunitwideextractandmovemethodanalyzer.results.addAll(getResults());
68 }
69}