]>
Commit | Line | Data |
---|---|---|
33b364ef | 1 | package no.uio.ifi.refaktor.analyze.analyzers; |
7256e850 EK |
2 | |
3 | import java.util.LinkedList; | |
4 | import java.util.List; | |
5 | ||
33b364ef | 6 | import no.uio.ifi.refaktor.analyze.ExtractAndMoveMethodAnalysisResult; |
d6c79186 | 7 | import no.uio.ifi.refaktor.analyze.comparators.FavorNoUnfixesAnalysisResultComparator; |
ee0f23c0 | 8 | import no.uio.ifi.refaktor.analyze.exceptions.NoTargetFoundException; |
a554b0ce | 9 | import no.uio.ifi.refaktor.analyze.exceptions.RefaktorAnalyzerException; |
7256e850 EK |
10 | import no.uio.ifi.refaktor.utils.RefaktorDebug; |
11 | ||
12 | import org.eclipse.jdt.core.IMethod; | |
13 | import org.eclipse.jdt.core.IType; | |
14 | import org.eclipse.jdt.core.JavaModelException; | |
15 | ||
e5c9c9b3 EK |
16 | /** |
17 | * Responsible for analyzing all methods in a type for | |
18 | * candidates to the Extract and Move Method refactoring. | |
19 | */ | |
856d61fb | 20 | public class TypeWideExtractAndMoveMethodAnalyzer implements AggregationAnalyzer<ExtractAndMoveMethodAnalysisResult> { |
7256e850 EK |
21 | |
22 | private final IType type; | |
7256e850 EK |
23 | private final List<ExtractAndMoveMethodAnalysisResult> results; |
24 | ||
a03a233d | 25 | public TypeWideExtractAndMoveMethodAnalyzer(IType type) { |
7256e850 | 26 | this.type = type; |
7256e850 EK |
27 | results = new LinkedList<ExtractAndMoveMethodAnalysisResult>(); |
28 | } | |
29 | ||
85bef15c | 30 | @Override |
7256e850 EK |
31 | public List<ExtractAndMoveMethodAnalysisResult> getResults() { |
32 | return results; | |
33 | } | |
34 | ||
85bef15c | 35 | @Override |
a554b0ce | 36 | public void analyze() throws RefaktorAnalyzerException { |
7256e850 EK |
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 = | |
a3170a79 | 53 | new SearchBasedExtractAndMoveMethodAnalyzer(method, new FavorNoUnfixesAnalysisResultComparator()); |
7256e850 EK |
54 | analyzer.analyze(); |
55 | results.add(analyzer.getResult()); | |
56 | } catch (NoTargetFoundException e) { | |
57 | // Ignoring | |
58 | } catch (AssertionError err) { | |
59 | RefaktorDebug.log(err); | |
60 | } | |
61 | } | |
62 | } |