1 20 21 package spoon.aval.support.validator; 22 23 import java.util.HashMap ; 24 import java.util.Map ; 25 26 import spoon.aval.Validator; 27 import spoon.aval.annotation.value.Unique; 28 import spoon.aval.processing.AValProcessor; 29 import spoon.aval.processing.ValidationPoint; 30 import spoon.reflect.declaration.CtAnnotation; 31 import spoon.reflect.reference.CtFieldReference; 32 45 public class UniqueValueValidator implements Validator<Unique> { 46 47 static private Map <Object ,CtAnnotation> cache = new HashMap <Object ,CtAnnotation>(); 48 49 52 public void check(ValidationPoint<Unique> vp) { 53 String attribName = ((CtFieldReference)vp.getDslElement()).getSimpleName(); 54 Object value = vp.getDslAnnotation().getElementValue(attribName); 55 if((cache.get(value))!=null){ 56 CtAnnotation dslAnnotation = vp.getDslAnnotation(); 57 58 String message = vp.getValAnnotation().message().replace("?val", value.toString()); 59 ValidationPoint.report(vp.getValAnnotation().severity(), dslAnnotation, message,vp.fixerFactory(vp.getValAnnotation().fixers())); 60 } 61 cache.put(value,vp.getDslAnnotation()); 62 } 63 64 } 65 | Popular Tags |