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.UniqueInside;
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 UniqueInsideValidator implements Validator<UniqueInside> {
15:
16: public void check(ValidationPoint<UniqueInside> vp) {
17:
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> children = parentScope.getAnnotatedChildren(vp
31: .getDslAnnotation().getActualAnnotation()
32: .annotationType());
33:
34: if (children.size() != 1) {
35: CtAnnotation dslAnnotation = vp.getDslAnnotation();
36:
37: String message = vp.getValAnnotation().message().replace(
38: "?ann", dslAnnotation.toString()).replace("?in",
39: scope.getName());
40: ValidationPoint.report(vp.getValAnnotation().severity(),
41: dslAnnotation, message, vp.fixerFactory(vp
42: .getValAnnotation().fixers()));
43:
44: }
45: }
46:
47: }
|