01: package spoon.vsuite.findbugs.dm;
02:
03: import spoon.processing.AbstractProcessor;
04: import spoon.processing.Property;
05: import spoon.processing.Severity;
06: import spoon.reflect.Factory;
07: import spoon.reflect.code.CtInvocation;
08: import spoon.reflect.reference.CtExecutableReference;
09: import spoon.reflect.reference.CtTypeReference;
10:
11: /**
12: * Dm: Method invokes System.exit(...) (DM_EXIT) Invoking System.exit shuts down
13: * the entire Java virtual machine. This should only been done when it is
14: * appropriate. Such calls make it hard or impossible for your code to be
15: * invoked by other code. Consider throwing a RuntimeException instead.
16: *
17: * @author Nicolas Petitprez
18: */
19: public class Exit extends AbstractProcessor<CtInvocation<?>> {
20: @Property
21: static Severity level = Severity.WARNING;
22:
23: static CtExecutableReference<?> ref;
24:
25: public static CtExecutableReference<?> getRef(Factory factory) {
26: if (ref == null) {
27: ref = factory.Executable().createReference(
28: factory.Type().createReference(System.class),
29: factory.Type().createReference(void.class),
30: "exit",
31: new CtTypeReference[] { factory.Type()
32: .createReference(int.class) });
33: }
34: return ref;
35: }
36:
37: public void process(CtInvocation<?> element) {
38: if (element.getExecutable().equals(getRef(getFactory()))) {
39: getFactory()
40: .getEnvironment()
41: .report(this , level, element,
42: "Invoking System.exit shuts down the entire Java virtual machine.");
43: }
44:
45: }
46:
47: }
|