]>
Commit | Line | Data |
---|---|---|
75689aad | 1 | package no.uio.ifi.refaktor.extractors; |
64970e7f | 2 | |
2f82d251 EK |
3 | import java.util.List; |
4 | ||
520985c2 | 5 | import no.uio.ifi.refaktor.changers.ExtractAndMoveMethodChanger; |
74581229 EK |
6 | import no.uio.ifi.refaktor.extractors.collectors.PrefixesCollector; |
7 | import no.uio.ifi.refaktor.extractors.collectors.PropertyCollector; | |
8 | import no.uio.ifi.refaktor.extractors.collectors.UnfixesCollector; | |
e0fe6563 | 9 | import no.uio.ifi.refaktor.prefix.PrefixSet; |
64970e7f EK |
10 | import no.uio.ifi.refaktor.utils.SmartTextSelection; |
11 | ||
12 | import org.eclipse.jdt.core.ICompilationUnit; | |
64970e7f | 13 | |
7a978020 | 14 | /** |
520985c2 EK |
15 | * A property extractor that collects all the expression prefixes within a selection |
16 | * (see {@link PrefixesCollector}) that forms the base for calculating the | |
17 | * candidates for the move refactoring, and also the unfixes | |
18 | * that are non-candidates for the move refactoring. | |
19 | * | |
20 | * The set of prefixes that are not enclosing any unfixes is put in the set of safe prefixes. | |
21 | * This set is used by an Extract and Move Method refactoring to find a suitable target | |
22 | * for the Move Method. | |
23 | * | |
24 | * The class is typically used by the {@link ExtractAndMoveMethodChanger}. | |
7a978020 | 25 | */ |
2f82d251 | 26 | public class ExtractAndMoveMethodPrefixesExtractor extends PropertyExtractor { |
64970e7f | 27 | |
c4d4c07b EK |
28 | protected final PrefixesCollector prefixesCollector; |
29 | protected final UnfixesCollector unfixesCollector; | |
062df6c3 | 30 | private PrefixSet safePrefixes = null; |
64970e7f EK |
31 | |
32 | public ExtractAndMoveMethodPrefixesExtractor(SmartTextSelection selection, ICompilationUnit icu) { | |
33 | super(selection, icu); | |
2f82d251 EK |
34 | prefixesCollector = new PrefixesCollector(selection); |
35 | unfixesCollector = new UnfixesCollector(selection); | |
64970e7f | 36 | } |
74581229 EK |
37 | |
38 | @Override | |
39 | protected void registerCollectors(List<PropertyCollector> collectors) { | |
40 | collectors.add(prefixesCollector); | |
41 | collectors.add(unfixesCollector); | |
42 | } | |
64970e7f | 43 | |
4ecbd2c6 | 44 | public PrefixSet getSafePrefixes() { |
062df6c3 EK |
45 | if (safePrefixes == null) { |
46 | safePrefixes = createSafePrefixes(); | |
64970e7f EK |
47 | } |
48 | return safePrefixes; | |
49 | } | |
087a79bf | 50 | |
062df6c3 | 51 | private PrefixSet createSafePrefixes() { |
2f82d251 | 52 | return prefixesCollector.getPrefixes().minusEnclosedPrefixesFrom(unfixesCollector.getUnfixes()); |
087a79bf | 53 | } |
062df6c3 | 54 | |
64970e7f EK |
55 | public boolean hasUsefulResults() { |
56 | return !getSafePrefixes().isEmpty(); | |
57 | } | |
c4d4c07b EK |
58 | |
59 | protected PrefixSet getPrefixes() { | |
60 | return prefixesCollector.getPrefixes(); | |
61 | } | |
62 | ||
63 | protected PrefixSet getUnfixes() { | |
64 | return unfixesCollector.getUnfixes(); | |
65 | } | |
64970e7f | 66 | } |