1 package no.uio.ifi.refaktor.analyze.collectors;
3 import no.uio.ifi.refaktor.analyze.CollectorManager;
4 import no.uio.ifi.refaktor.analyze.ReturnStatementFinder;
5 import no.uio.ifi.refaktor.analyze.analyzers.Checker;
6 import no.uio.ifi.refaktor.analyze.analyzers.IllegalExpressionFoundException;
7 import no.uio.ifi.refaktor.analyze.analyzers.IllegalStatementFoundException;
8 import no.uio.ifi.refaktor.utils.CompilationUnitTextSelection;
10 import org.eclipse.jdt.core.dom.IfStatement;
11 import org.eclipse.jdt.core.dom.ReturnStatement;
12 import org.eclipse.jdt.core.dom.Statement;
13 import org.eclipse.jdt.core.dom.SwitchStatement;
15 public class EveryConditionalBranchEndsInReturnCheckerCollector extends PropertyCollector implements Checker {
17 private CompilationUnitTextSelection privateSelection;
19 public EveryConditionalBranchEndsInReturnCheckerCollector(CompilationUnitTextSelection selection) {
21 privateSelection = selection;
25 public void clearData() {
29 public boolean visit(IfStatement node) {
30 if (!nodeInSelection(node))
33 ReturnStatementFinder returnStatementFinder = new ReturnStatementFinder();
34 node.getThenStatement().accept(returnStatementFinder);
36 if (returnStatementFinder.hasFoundReturnStatement()) {
37 Statement elseStatement = node.getElseStatement();
39 if (elseStatement == null) {
40 throw new IllegalStatementFoundException(ReturnStatement.class);
43 returnStatementFinder.reset();
44 elseStatement.accept(returnStatementFinder);
46 if (!returnStatementFinder.hasFoundReturnStatement()) {
47 throw new IllegalStatementFoundException(ReturnStatement.class);
55 public boolean visit(SwitchStatement node) {
56 // TODO: Handle switch statements in another way?
57 if (!nodeInSelection(node))
60 node.accept(new IllegalReturnStatementChecker());
66 public void check() throws IllegalStatementFoundException, IllegalExpressionFoundException {
67 CollectorManager.collectProperties(privateSelection, this);