1 package no.uio.ifi.refaktor.extractors;
5 import no.uio.ifi.refaktor.changers.ExtractAndMoveMethodChanger;
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;
9 import no.uio.ifi.refaktor.prefix.PrefixSet;
10 import no.uio.ifi.refaktor.utils.SmartTextSelection;
12 import org.eclipse.jdt.core.ICompilationUnit;
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.
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.
24 * The class is typically used by the {@link ExtractAndMoveMethodChanger}.
26 public class ExtractAndMoveMethodPrefixesExtractor extends PropertyExtractor {
28 private PrefixesCollector prefixesCollector;
29 private UnfixesCollector unfixesCollector;
30 private PrefixSet safePrefixes = null;
32 public ExtractAndMoveMethodPrefixesExtractor(SmartTextSelection selection, ICompilationUnit icu) {
33 super(selection, icu);
34 prefixesCollector = new PrefixesCollector(selection);
35 unfixesCollector = new UnfixesCollector(selection);
39 protected void registerCollectors(List<PropertyCollector> collectors) {
40 collectors.add(prefixesCollector);
41 collectors.add(unfixesCollector);
44 public PrefixSet getSafePrefixes() {
45 if (safePrefixes == null) {
46 safePrefixes = createSafePrefixes();
51 private PrefixSet createSafePrefixes() {
52 return prefixesCollector.getPrefixes().minusEnclosedPrefixesFrom(unfixesCollector.getUnfixes());
55 public boolean hasUsefulResults() {
56 return !getSafePrefixes().isEmpty();