01: package spoon.vsuite.findbugs.de;
02:
03: import java.util.ArrayList;
04: import java.util.List;
05:
06: import spoon.processing.ProblemFixer;
07: import spoon.processing.Property;
08: import spoon.processing.Severity;
09: import spoon.reflect.code.CtThrow;
10: import spoon.reflect.reference.CtTypeReference;
11:
12: /**
13: * DE: Method might drop exception (DE_MIGHT_DROP) This method might drop an
14: * exception. In general, exceptions should be handled or reported in some way,
15: * or they should be thrown out of the method.
16: *
17: * @author Nicolas Petitprez
18: */
19: public class MightDrop extends ExceptionAnalyse<CtThrow> {
20:
21: @Property
22: Severity level = Severity.WARNING;
23:
24: public void process(CtThrow arg0) {
25: if (getUncaptured(arg0) != null
26: && !getUncaptured(arg0).isEmpty()) {
27: getEnvironment()
28: .report(
29: this ,
30: level,
31: arg0,
32: "Exception wasn't handled or declared to be thrown out",
33: getFixer(arg0).toArray(new ProblemFixer[0]));
34: }
35: }
36:
37: @Override
38: public List<CtTypeReference<? extends Throwable>> getThrownExceptionForElement(
39: CtThrow element) {
40: List<CtTypeReference<? extends Throwable>> ret = new ArrayList<CtTypeReference<? extends Throwable>>();
41: ret.add(element.getThrownExpression().getType());
42: return ret;
43: }
44:
45: }
|