package org.simantics.scl.compiler.internal.parsing.translation; import java.util.ArrayList; import java.util.Collection; import org.simantics.scl.compiler.elaboration.errors.NotPatternException; import org.simantics.scl.compiler.internal.parsing.declarations.DAnnotationAst; import org.simantics.scl.compiler.internal.parsing.declarations.DRelationAst; import gnu.trove.map.hash.THashMap; public class RelationRepository { THashMap> relations = new THashMap>(); THashMap> annotations = new THashMap>(); public String add(DRelationAst relation) throws NotPatternException { String name = relation.lhs.getPatternHead().name; ArrayList vs = relations.get(name); if(vs == null) { vs = new ArrayList(2); relations.put(name, vs); } vs.add(relation); return name; } public void addDefinitions(String name, ArrayList relationList) { ArrayList vs = relations.get(name); if(vs == null) { vs = new ArrayList(relationList.size()); relations.put(name, vs); } vs.addAll(relationList); } public void addAnnotation(String name, DAnnotationAst annotation) { ArrayList as = annotations.get(name); if(as == null) { as = new ArrayList(2); annotations.put(name, as); } as.add(annotation); } public void addAnnotations(String name, ArrayList annotationList) { ArrayList as = annotations.get(name); if(as == null) { as = new ArrayList(annotationList.size()); annotations.put(name, as); } as.addAll(annotationList); } public Collection getRelationNames() { return relations.keySet(); } public ArrayList getDefinition(String name) { return relations.get(name); } public ArrayList getAnnotations(String name) { return annotations.get(name); } public void addFrom(RelationRepository repo, String oldName, String newName) { addDefinitions(newName, repo.getDefinition(oldName)); ArrayList as = repo.getAnnotations(oldName); if(as != null) addAnnotations(newName, as); } }