Package urban.validation

Source Code of urban.validation.KappaJavaValidator

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);     
    }
  }
}
TOP

Related Classes of urban.validation.KappaJavaValidator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.