]> git.uio.no Git - ifi-stolz-refaktor.git/blob - software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/analyze/collectors/LastStatementCollector.java
UnfixesCollector: checking explicitly for interface types
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor / src / no / uio / ifi / refaktor / analyze / collectors / LastStatementCollector.java
1 package no.uio.ifi.refaktor.analyze.collectors;
2
3 import no.uio.ifi.refaktor.utils.CompilationUnitTextSelection;
4
5 import org.eclipse.jdt.core.dom.ASTNode;
6 import org.eclipse.jdt.core.dom.Statement;
7
8 public class LastStatementCollector extends PropertyCollector {
9         private final ASTNode coveringNode;
10         private Statement lastStatement;
11
12         public LastStatementCollector(CompilationUnitTextSelection selection, ASTNode coveringNode) {
13                 super(selection);
14                 this.coveringNode = coveringNode;
15         }
16
17         @Override
18         public boolean preVisit2(ASTNode node) {
19                 if (node == coveringNode)
20                         return true;
21                 
22                 if (!nodeInSelection(node))
23                         return false;
24                 
25                 if (node instanceof Statement && isPlacedAfterLastStatement(node)) {
26                         lastStatement = (Statement) node;
27                 }
28
29                 return false;
30         }
31
32         private boolean isPlacedAfterLastStatement(ASTNode node) {
33                 if (lastStatement == null)
34                         return true;
35                 
36                 int nodeEndPosition = node.getStartPosition() + node.getLength();
37                 int lastStatementEndPosition = lastStatement.getStartPosition() + lastStatement.getLength();
38                 return nodeEndPosition > lastStatementEndPosition;
39         }
40
41         public Statement getLastStatement() {
42                 return lastStatement;
43         }
44
45         @Override
46         public void clearData() {
47                 lastStatement = null;
48         }
49 }