01: package spoon.aval.support.validator;
02:
03: import spoon.aval.Validator;
04: import spoon.aval.annotation.structure.Modifier;
05: import spoon.aval.processing.ValidationPoint;
06: import spoon.reflect.declaration.CtAnnotation;
07: import spoon.reflect.declaration.CtElement;
08: import spoon.reflect.declaration.CtModifiable;
09: import spoon.reflect.declaration.ModifierKind;
10:
11: public class ModifierValidator implements Validator<Modifier> {
12:
13: public void check(ValidationPoint<Modifier> vp) {
14: ModifierKind[] validMods = vp.getValAnnotation().value();
15: CtElement element = vp.getProgramElement();
16: CtAnnotation dslAnnotation = vp.getDslAnnotation();
17:
18: boolean valid = true;
19:
20: if (element instanceof CtModifiable) {
21: CtModifiable mod = (CtModifiable) element;
22:
23: for (int i = 0; i < validMods.length; i++) {
24: ModifierKind kind = validMods[i];
25: valid &= mod.hasModifier(kind);
26: }
27:
28: if (!valid) {
29: String message = vp.getValAnnotation().message();
30: ValidationPoint.report(
31: vp.getValAnnotation().severity(),
32: dslAnnotation, message, vp.fixerFactory(vp
33: .getValAnnotation().fixers()));
34: }
35: }
36:
37: }
38:
39: }
|