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.RequiresInside;
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 RequiresInsideValidator implements
15: Validator<RequiresInside> {
16:
17: public void check(ValidationPoint<RequiresInside> 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: CtAnnotation dslAnnotation = vp.getDslAnnotation();
35:
36: String message = vp.getValAnnotation().message().replace(
37: "?ann", dslAnnotation.toString()).replace("?in",
38: scope.getName()).replace("?a2",
39: vp.getValAnnotation().value().getName());
40: ValidationPoint.report(vp.getValAnnotation().severity(),
41: dslAnnotation, message, vp.fixerFactory(vp
42: .getValAnnotation().fixers()));
43:
44: }
45:
46: }
47:
48: }
|