01: package spoon.vsuite.common;
02:
03: import spoon.processing.AbstractProcessor;
04: import spoon.processing.Property;
05: import spoon.processing.Severity;
06: import spoon.reflect.code.CtBlock;
07: import spoon.reflect.code.CtIf;
08:
09: /**
10: * Reports warnings an if or an else does not use blocks.
11: */
12: public class IfProcessor extends AbstractProcessor<CtIf> {
13:
14: @Property
15: Severity level = Severity.WARNING;
16:
17: public void process(CtIf ifElement) {
18: if (ifElement.getThenStatement() == null) {
19: getFactory().getEnvironment().report(this , level,
20: ifElement, "This if statement is empty");
21: return;
22: }
23: if (!(ifElement.getThenStatement() instanceof CtBlock)) {
24: getFactory()
25: .getEnvironment()
26: .report(this , level, ifElement.getThenStatement(),
27: "This expression should be enclosed in a block to avoid ambiguous coding style");
28: }
29: if (ifElement.getElseStatement() != null
30: && !(ifElement.getElseStatement() instanceof CtBlock)) {
31: getFactory()
32: .getEnvironment()
33: .report(this , level, ifElement.getElseStatement(),
34: "This expression should be enclosed in a block to avoid ambiguous coding style");
35: }
36: }
37:
38: }
|