]> git.uio.no Git - ifi-stolz-refaktor.git/blob - software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/extractors/collectors/UnfixesCollector.java
Adding a TODO in the code.
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor / src / no / uio / ifi / refaktor / extractors / collectors / UnfixesCollector.java
1 package no.uio.ifi.refaktor.extractors.collectors;
2
3 import no.uio.ifi.refaktor.prefix.Prefix;
4 import no.uio.ifi.refaktor.prefix.PrefixSet;
5 import no.uio.ifi.refaktor.utils.RefaktorDebug;
6 import no.uio.ifi.refaktor.utils.SmartTextSelection;
7
8 import org.eclipse.jdt.core.dom.Assignment;
9 import org.eclipse.jdt.core.dom.Expression;
10 import org.eclipse.jdt.core.dom.Name;
11 import org.eclipse.jdt.core.dom.SimpleName;
12
13 public class UnfixesCollector extends PropertyCollector {
14         private PrefixSet unfixes;
15
16         public UnfixesCollector(SmartTextSelection selection) {
17                 super(selection);
18                 this.unfixes = new PrefixSet();
19         }
20
21         public PrefixSet getUnfixes() {
22                 return unfixes;
23         }
24         
25         // TODO: handle VariableDeclaration statements
26         // with initializers
27
28         @Override
29         public boolean visit(Assignment node) {
30                 if (!nodeInSelection(node))
31                         return false;
32         
33                 addLeftHandSideToUnfixesIfSimpleName(node);
34                 return true;
35         }
36
37         private void addLeftHandSideToUnfixesIfSimpleName(Assignment node) {
38                 Expression lhs = node.getLeftHandSide();
39                 assert lhs instanceof Name;
40                 Name name = (Name) lhs;
41                 if (name.isSimpleName()) {
42                         SimpleName simpleName = (SimpleName) name;
43                         Prefix p = new Prefix(simpleName, getDocument());
44                         RefaktorDebug.println("Unfix string: " + p.toString());
45                         unfixes.add(p);
46                 }
47         }
48 }