]>
Commit | Line | Data |
---|---|---|
33b364ef | 1 | package no.uio.ifi.refaktor.analyze.analyzers; |
64970e7f | 2 | |
e09f9054 | 3 | import java.util.Iterator; |
fc35e1b0 | 4 | import no.uio.ifi.refaktor.analyze.collectors.PrefixesCollector; |
2b4a9262 | 5 | import no.uio.ifi.refaktor.change.changers.ExtractAndMoveMethodChanger; |
e411ecf3 | 6 | import no.uio.ifi.refaktor.prefix.Prefix; |
e0fe6563 | 7 | import no.uio.ifi.refaktor.prefix.PrefixSet; |
ede92818 | 8 | import no.uio.ifi.refaktor.textselection.CompilationUnitTextSelection; |
64970e7f | 9 | |
fc35e1b0 | 10 | //TODO: rewrite docs |
7a978020 | 11 | /** |
520985c2 EK |
12 | * A property extractor that collects all the expression prefixes within a selection |
13 | * (see {@link PrefixesCollector}) that forms the base for calculating the | |
14 | * candidates for the move refactoring, and also the unfixes | |
15 | * that are non-candidates for the move refactoring. | |
16 | * | |
17 | * The set of prefixes that are not enclosing any unfixes is put in the set of safe prefixes. | |
18 | * This set is used by an Extract and Move Method refactoring to find a suitable target | |
19 | * for the Move Method. | |
20 | * | |
21 | * The class is typically used by the {@link ExtractAndMoveMethodChanger}. | |
7a978020 | 22 | */ |
f15e2302 | 23 | public class ExtractAndMoveMethodSelectionAnalyzer extends AbstractSelectionAnalyzer { |
64970e7f | 24 | |
f15e2302 A |
25 | /** |
26 | * @param selection The selection containing the possible targets of the refactoring | |
27 | */ | |
28 | public ExtractAndMoveMethodSelectionAnalyzer(CompilationUnitTextSelection selection) { | |
f5bcaf5d | 29 | super(selection); |
64970e7f | 30 | } |
74581229 | 31 | |
f15e2302 A |
32 | /** |
33 | * Removes prefixes unusable for ExtractAndMoveMethod refactoring: | |
34 | * prefixes with simple expression and only one occurrence | |
35 | * @param safePrefixes The collected prefixes; will be edited | |
36 | */ | |
f5bcaf5d | 37 | protected void removeUnusablePrefixes(PrefixSet safePrefixes) { |
e09f9054 | 38 | for (Iterator<Prefix> iter = safePrefixes.iterator(); iter.hasNext();) { |
c9e9a5bb | 39 | final Prefix i = iter.next(); |
f15e2302 | 40 | //final IVariableBinding ie = i.getVariableBindingOfFirstExpression(); |
17442801 | 41 | if (prefixHasSimpleExpressionAndOnlyOneOccurrence(i) |
c9e9a5bb | 42 | /* Filter out non-final fields as well? */ |
f15e2302 A |
43 | //|| (ONLY_SAFE && ie.isField() && !Modifier.isFinal(ie.getModifiers())) |
44 | ) | |
e09f9054 EK |
45 | iter.remove(); |
46 | } | |
47 | } | |
c4d4c07b | 48 | |
64970e7f | 49 | } |