1 package no.uio.ifi.refaktor.analyze.collectors;
3 import static no.uio.ifi.refaktor.RefaktorAssert.assertThat;
4 import static org.hamcrest.CoreMatchers.instanceOf;
5 import no.uio.ifi.refaktor.prefix.Prefix;
6 import no.uio.ifi.refaktor.prefix.PrefixSet;
7 import no.uio.ifi.refaktor.utils.CompilationUnitTextSelection;
8 import no.uio.ifi.refaktor.utils.RefaktorDebug;
10 import org.eclipse.jdt.core.dom.ArrayAccess;
11 import org.eclipse.jdt.core.dom.Assignment;
12 import org.eclipse.jdt.core.dom.Expression;
13 import org.eclipse.jdt.core.dom.FieldAccess;
14 import org.eclipse.jdt.core.dom.Name;
15 import org.eclipse.jdt.core.dom.SimpleName;
16 import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
18 public class UnfixesCollector extends PropertyCollector {
19 private final PrefixSet unfixes;
21 public UnfixesCollector(CompilationUnitTextSelection selection) {
23 this.unfixes = new PrefixSet();
26 public PrefixSet getUnfixes() {
31 public boolean visit(VariableDeclarationFragment node) {
32 if (!nodeInSelection(node))
35 addSimpleNameToUnfixes(node.getName());
40 public boolean visit(Assignment node) {
41 if (!nodeInSelection(node))
44 addLeftHandSideToUnfixesIfSimpleName(node);
48 private void addLeftHandSideToUnfixesIfSimpleName(Assignment node) {
49 Expression lhs = node.getLeftHandSide();
50 if (lhs instanceof ArrayAccess)
53 if (lhs instanceof FieldAccess) {
54 addSimpleNameToUnfixes(((FieldAccess) lhs).getName());
56 assertThat(lhs, instanceOf(Name.class));
57 Name name = (Name) lhs;
58 if (name.isSimpleName())
59 addSimpleNameToUnfixes((SimpleName) name);
63 private void addSimpleNameToUnfixes(SimpleName simpleName) {
64 Prefix p = new Prefix(simpleName);
65 RefaktorDebug.println("Unfix string: " + p.toString());
70 public void clearData() {