01: package spoon.aval.support.validator;
02:
03: import java.lang.annotation.Annotation;
04: import java.util.List;
05:
06: import spoon.aval.Validator;
07: import spoon.aval.annotation.structure.Inside;
08: import spoon.aval.annotation.structure.ProhibitsInside;
09: import spoon.aval.processing.ValidationPoint;
10: import spoon.aval.support.validator.util.ValidatorHelper;
11: import spoon.reflect.declaration.CtAnnotation;
12: import spoon.reflect.declaration.CtElement;
13:
14: public class ProhibitsInsideValidator implements
15: Validator<ProhibitsInside> {
16:
17: public void check(ValidationPoint<ProhibitsInside> vp) {
18: Inside in = vp.getDslElement().getAnnotation(Inside.class);
19:
20: if (in == null)
21: return; // reported by requires @Inside
22: Class<? extends Annotation> scope = in.value();
23:
24: CtElement parentScope = ValidatorHelper.getParentAnnotatedWith(
25: scope, vp.getProgramElement());
26:
27: if (parentScope == null)
28: return; // reported by inside
29:
30: List<CtElement> elems = parentScope.getAnnotatedChildren(vp
31: .getValAnnotation().value());
32:
33: if (elems.size() != 0) {
34: for (CtElement element : elems) {
35: Annotation ann2 = element.getAnnotation(vp
36: .getValAnnotation().value());
37: CtAnnotation dslAnnotation = vp.getDslAnnotation();
38:
39: String message = vp.getValAnnotation().message()
40: .replace("?ann", dslAnnotation.toString())
41: .replace("?in", scope.getName()).replace("?a2",
42: ann2.toString());
43: ValidationPoint.report(
44: vp.getValAnnotation().severity(),
45: dslAnnotation, message, vp.fixerFactory(vp
46: .getValAnnotation().fixers()));
47: }
48:
49: }
50:
51: }
52:
53: }
|