01: package spoon.aval.support.validator;
02:
03: import java.lang.annotation.Annotation;
04:
05: import spoon.aval.Validator;
06: import spoon.aval.annotation.value.RefersToAnnotatedElement;
07: import spoon.aval.processing.ValidationPoint;
08: import spoon.reflect.Factory;
09: import spoon.reflect.declaration.CtField;
10: import spoon.reflect.reference.CtFieldReference;
11:
12: public class RefersToAnnotatedElementValidator implements
13: Validator<RefersToAnnotatedElement> {
14:
15: public void check(ValidationPoint<RefersToAnnotatedElement> vp) {
16:
17: Class<? extends Annotation> targetClass = vp.getValAnnotation()
18: .value();
19: Factory f = vp.getProgramElement().getFactory();
20:
21: //No class cast exception because of @type on @ReferesToAnnotatedElement
22: String attribName = ((CtFieldReference) vp.getDslElement())
23: .getSimpleName();
24: Class value = (Class) vp.getDslAnnotation().getElementValue(
25: attribName);
26:
27: Annotation a = f.Type().get(value).getAnnotation(targetClass);
28: if (a == null) {
29: //report error
30: String message = vp.getValAnnotation().message().replace(
31: "?val", value.getName()).replace("?ann",
32: "@" + targetClass.getName());
33:
34: ValidationPoint.report(vp.getValAnnotation().severity(), vp
35: .getDslAnnotation(), message, vp.fixerFactory(vp
36: .getValAnnotation().fixers()));
37:
38: }
39:
40: }
41:
42: }
|