package urban.validation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.eclipse.xtext.validation.Check;
import urban.kappa.Agent;
import urban.kappa.Expression;
import urban.kappa.KappaPackage;
import urban.kappa.Link;
import urban.kappa.Site;
public class KappaJavaValidator extends AbstractKappaJavaValidator {
// @Check
// public void checkTypeNameStartsWithCapital(Type type) {
// if (!Character.isUpperCase(type.getName().charAt(0))) {
// warning("Name should start with a capital", MyDslPackage.TYPE__NAME);
// }
// }
@Check
public void checkBindings(Expression exp) {
HashMap<Integer,Link> declared = new HashMap<Integer,Link>();
List<Integer> used = new ArrayList<Integer>();
for (Agent a : exp.getAgents()) {
for (Site site : a.getSites()) {
Link link = site.getLink();
if (link != null && link.getC() == null){
Integer n = link.getN();
if (used.contains(n)){
error("The binding indicator:"+n+" has been used more than twice",link, KappaPackage.LINK__N);
} else {
if (declared.keySet().contains(n)){
declared.remove(n);
used.add(n);
} else {
declared.put(n,link);
}
}
}
}
}
if (!declared.isEmpty()){
for (Link l : declared.values())
error("The binding indicator:"+l.getN()+" has only been used once",l, KappaPackage.LINK__N);
}
}
}