]> git.uio.no Git - ifi-stolz-refaktor.git/blame - software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/analyze/collectors/EveryConditionalBranchEndsInReturnCheckerCollector.java
UnfixesCollector: checking explicitly for interface types
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor / src / no / uio / ifi / refaktor / analyze / collectors / EveryConditionalBranchEndsInReturnCheckerCollector.java
CommitLineData
5748b416
EK
1package no.uio.ifi.refaktor.analyze.collectors;
2
398d7e0c 3import no.uio.ifi.refaktor.analyze.CollectorManager;
5748b416 4import no.uio.ifi.refaktor.analyze.ReturnStatementFinder;
398d7e0c 5import no.uio.ifi.refaktor.analyze.analyzers.Checker;
39f52c8f
EK
6import no.uio.ifi.refaktor.analyze.exceptions.IllegalExpressionFoundException;
7import no.uio.ifi.refaktor.analyze.exceptions.IllegalStatementFoundException;
5748b416
EK
8import no.uio.ifi.refaktor.utils.CompilationUnitTextSelection;
9
5748b416 10import org.eclipse.jdt.core.dom.IfStatement;
398d7e0c 11import org.eclipse.jdt.core.dom.ReturnStatement;
5748b416
EK
12import org.eclipse.jdt.core.dom.Statement;
13import org.eclipse.jdt.core.dom.SwitchStatement;
14
398d7e0c 15public class EveryConditionalBranchEndsInReturnCheckerCollector extends PropertyCollector implements Checker {
5748b416 16
398d7e0c 17 public EveryConditionalBranchEndsInReturnCheckerCollector(CompilationUnitTextSelection selection) {
5748b416 18 super(selection);
5748b416
EK
19 }
20
21 @Override
22 public void clearData() {
5748b416
EK
23 }
24
25 @Override
26 public boolean visit(IfStatement node) {
27 if (!nodeInSelection(node))
28 return false;
29
30 ReturnStatementFinder returnStatementFinder = new ReturnStatementFinder();
31 node.getThenStatement().accept(returnStatementFinder);
398d7e0c 32
5748b416
EK
33 if (returnStatementFinder.hasFoundReturnStatement()) {
34 Statement elseStatement = node.getElseStatement();
35
36 if (elseStatement == null) {
398d7e0c 37 throw new IllegalStatementFoundException(ReturnStatement.class);
5748b416
EK
38 }
39
40 returnStatementFinder.reset();
41 elseStatement.accept(returnStatementFinder);
42
43 if (!returnStatementFinder.hasFoundReturnStatement()) {
398d7e0c 44 throw new IllegalStatementFoundException(ReturnStatement.class);
5748b416
EK
45 }
46 }
47
398d7e0c 48 return true;
5748b416
EK
49 }
50
51 @Override
52 public boolean visit(SwitchStatement node) {
53 // TODO: Handle switch statements in another way?
54 if (!nodeInSelection(node))
55 return false;
56
398d7e0c 57 node.accept(new IllegalReturnStatementChecker());
5748b416
EK
58
59 return false;
60 }
398d7e0c
EK
61
62 @Override
63 public void check() throws IllegalStatementFoundException, IllegalExpressionFoundException {
d67b7697 64 CollectorManager.collectProperties(selection, this);
398d7e0c 65 }
5748b416 66}