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.CtInvocation;
10: import spoon.reflect.reference.CtExecutableReference;
11: import spoon.reflect.reference.CtTypeReference;
12:
13: /**
14: * DE: Method might ignore exception (DE_MIGHT_IGNORE) This method might ignore
15: * an exception. In general, exceptions should be handled or reported in some
16: * way, or they should be thrown out of the method.
17: *
18: * @author Nicolas Petitprez
19: */
20: public class MightIgnore extends ExceptionAnalyse<CtInvocation<?>> {
21:
22: @Property
23: Severity level = Severity.WARNING;
24:
25: @Override
26: public List<CtTypeReference<? extends Throwable>> getThrownExceptionForElement(
27: CtInvocation<?> element) {
28: CtExecutableReference<?> ref = element.getExecutable();
29:
30: List<CtTypeReference<? extends Throwable>> ret = new ArrayList<CtTypeReference<? extends Throwable>>();
31:
32: if (ref.getDeclaration() != null) {
33: for (CtTypeReference<? extends Throwable> th : ref
34: .getDeclaration().getThrownTypes()) {
35: ret.add(th);
36: }
37: } else {
38: // TODO if executable is not accessible, try with Runtime Reflexion
39: }
40: return ret;
41: }
42:
43: public void process(CtInvocation<?> arg0) {
44: if (getUncaptured(arg0) != null
45: && !getUncaptured(arg0).isEmpty()) {
46: getEnvironment()
47: .report(
48: this ,
49: level,
50: arg0,
51: "Exception wasn't handled or declared to be thrown out",
52: getFixer(arg0).toArray(new ProblemFixer[0]));
53: }
54: }
55:
56: }
|