]> git.uio.no Git - ifi-stolz-refaktor.git/blame - software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/extractors/ExtractAndMoveMethodPrefixesExtractor.java
Renaming SmartTextSelection to DocumentTextSelection.
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor / src / no / uio / ifi / refaktor / extractors / ExtractAndMoveMethodPrefixesExtractor.java
CommitLineData
75689aad 1package no.uio.ifi.refaktor.extractors;
64970e7f 2
2f82d251
EK
3import java.util.List;
4
520985c2 5import no.uio.ifi.refaktor.changers.ExtractAndMoveMethodChanger;
74581229
EK
6import no.uio.ifi.refaktor.extractors.collectors.PrefixesCollector;
7import no.uio.ifi.refaktor.extractors.collectors.PropertyCollector;
8import no.uio.ifi.refaktor.extractors.collectors.UnfixesCollector;
e0fe6563 9import no.uio.ifi.refaktor.prefix.PrefixSet;
1f62df73 10import no.uio.ifi.refaktor.utils.DocumentTextSelection;
64970e7f
EK
11
12import 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 26public 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 31
1f62df73 32 public ExtractAndMoveMethodPrefixesExtractor(DocumentTextSelection selection, ICompilationUnit icu) {
64970e7f 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}