1 package no.uio.ifi.refaktor.analyze.collectors;
3 import no.uio.ifi.refaktor.prefix.Prefix;
4 import no.uio.ifi.refaktor.textselection.CompilationUnitTextSelection;
6 import org.eclipse.jdt.core.dom.IVariableBinding;
7 import org.eclipse.jdt.core.dom.QualifiedName;
8 import org.eclipse.jdt.core.dom.SimpleName;
11 * An abstract property collector responsible for finding
12 * prefixes within a selection.
14 * Subclasses are responsible for implementing the
15 * {@link #registerPrefix(Prefix)} method. I.e. they
16 * decide how to handle the encountered prefixes.
18 public abstract class AbstractPrefixCollector extends PropertyCollector {
20 public AbstractPrefixCollector(CompilationUnitTextSelection selection) {
25 * Register a prefix encountered by the collector.
26 * @param prefix The prefix to register.
28 protected abstract void registerPrefix(Prefix prefix);
31 public boolean visit(QualifiedName node) {
32 if (!nodeInSelection(node))
35 Prefix prefix = new Prefix(node);
36 if (prefix.firstExpressionIsBoundToVariable())
37 registerPrefix(prefix);
39 // Must be false. Important to prevent double count for simple names.
44 public boolean visit(SimpleName node) {
45 if (!nodeInSelection(node))
48 if (nodeIsUsageOfVariable(node))
49 registerPrefix(new Prefix(node));
54 private boolean nodeIsUsageOfVariable(SimpleName node) {
55 return !node.isDeclaration() && node.resolveBinding() instanceof IVariableBinding;