]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/util/TypeUnparsingContext.java
Fixed incorrect interaction of EAmbigious and TMetaVar.setRef
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / types / util / TypeUnparsingContext.java
1 package org.simantics.scl.compiler.types.util;
2
3 import gnu.trove.map.hash.THashMap;
4
5 public class TypeUnparsingContext {
6     
7     THashMap<Object, String> names;
8     int nameId;
9     public boolean showSkeletons;
10     
11     public TypeUnparsingContext() {
12         this.names = new THashMap<Object, String>();
13         this.nameId = 0;
14     }
15     
16     public TypeUnparsingContext(TypeUnparsingContext parent) {
17         this.names = new THashMap<Object, String>(parent.names);
18         this.nameId = parent.nameId;
19     }
20
21     public String getName(Object var) {
22         String name = names.get(var);
23         if(name == null) {
24             name = idToName(nameId++);
25             names.put(var, name);
26         }
27         return name;
28     }
29
30     private static final int alphabetCount = 'z'-'a'+1;
31     
32     private static String idToName(int id) {
33         String name = Character.toString((char)('a' + id % alphabetCount));
34         id /= alphabetCount;
35         if(id > 0)
36             name = idToName(id-1) + name;
37         return name;
38     }
39
40 }