01: package spoon.vsuite.common;
02:
03: import spoon.processing.AbstractManualProcessor;
04: import spoon.processing.Property;
05: import spoon.processing.Severity;
06: import spoon.reflect.declaration.CtVariable;
07: import spoon.reflect.declaration.ModifierKind;
08:
09: /**
10: * Report warnings when unused variable are found.
11: */
12: public class CouldBeFinalFieldProcessor extends AbstractManualProcessor {
13:
14: @Property
15: Severity level = Severity.WARNING;
16:
17: public void process() {
18: for (CtVariable<?> v : VariableProcessor.getVariables()) {
19: if ((!VariableProcessor.getWrittenVariables().contains(v))
20: && (!ignore(v))) {
21: getFactory()
22: .getEnvironment()
23: .report(
24: this ,
25: level,
26: v,
27: "Variable '"
28: + v.getSimpleName()
29: + "' is never written in the source code and could be declared final");
30: }
31: }
32: }
33:
34: private boolean ignore(CtVariable<?> v) {
35: return v.hasModifier(ModifierKind.FINAL);
36: }
37: }
|