]>
Commit | Line | Data |
---|---|---|
75689aad | 1 | package no.uio.ifi.refaktor.extractors; |
64970e7f | 2 | |
2f82d251 EK |
3 | import java.util.List; |
4 | ||
64970e7f EK |
5 | import no.uio.ifi.refaktor.utils.SmartTextSelection; |
6 | ||
7 | import org.eclipse.jdt.core.ICompilationUnit; | |
2f82d251 | 8 | import org.eclipse.jdt.core.dom.ASTVisitor; |
64970e7f | 9 | |
7a978020 EK |
10 | /** |
11 | * A property extractor that extracts both the union of expression prefixes | |
12 | * (see {@link UnionOfLongestCommonPrefixesExtractor}), but also the unfixes | |
13 | * that are not candidates for a move refactoring. It is responsible for | |
14 | * calculating the safe targets of an Extract and Move Method refactoring | |
15 | * on the base of this knowledge. | |
16 | */ | |
2f82d251 | 17 | public class ExtractAndMoveMethodPrefixesExtractor extends PropertyExtractor { |
64970e7f | 18 | |
2f82d251 EK |
19 | private PrefixesCollector prefixesCollector; |
20 | private UnfixesCollector unfixesCollector; | |
062df6c3 | 21 | private PrefixSet safePrefixes = null; |
64970e7f EK |
22 | |
23 | public ExtractAndMoveMethodPrefixesExtractor(SmartTextSelection selection, ICompilationUnit icu) { | |
24 | super(selection, icu); | |
2f82d251 EK |
25 | prefixesCollector = new PrefixesCollector(selection); |
26 | unfixesCollector = new UnfixesCollector(selection); | |
64970e7f EK |
27 | } |
28 | ||
4ecbd2c6 | 29 | public PrefixSet getSafePrefixes() { |
062df6c3 EK |
30 | if (safePrefixes == null) { |
31 | safePrefixes = createSafePrefixes(); | |
64970e7f EK |
32 | } |
33 | return safePrefixes; | |
34 | } | |
087a79bf | 35 | |
062df6c3 | 36 | private PrefixSet createSafePrefixes() { |
2f82d251 | 37 | return prefixesCollector.getPrefixes().minusEnclosedPrefixesFrom(unfixesCollector.getUnfixes()); |
087a79bf | 38 | } |
062df6c3 | 39 | |
64970e7f EK |
40 | public boolean hasUsefulResults() { |
41 | return !getSafePrefixes().isEmpty(); | |
42 | } | |
2f82d251 EK |
43 | |
44 | @Override | |
45 | protected void registerVisitors(List<ASTVisitor> visitors) { | |
46 | visitors.add(prefixesCollector); | |
47 | visitors.add(unfixesCollector); | |
48 | } | |
64970e7f | 49 | } |