1 package polyglot.util; 2 3 import polyglot.main.Report; 4 import polyglot.types.*; 5 6 import java.util.*; 7 import java.io.*; 8 9 10 public class TypeInputStream extends ObjectInputStream 11 { 12 protected TypeSystem ts; 13 protected Map cache; 14 15 public TypeInputStream( InputStream in, TypeSystem ts) 16 throws IOException 17 { 18 super( in); 19 enableResolveObject(true); 20 this.ts = ts; 21 this.cache = new HashMap(); 22 } 23 24 public TypeSystem getTypeSystem() 25 { 26 return ts; 27 } 28 29 protected Object resolveObject(Object o) { 30 String s = ""; 31 if (Report.should_report(Report.serialize, 2)) { 32 try { 33 s = o.toString(); 34 } catch (NullPointerException e) { 35 s = "<NullPointerException thrown>"; 36 } 37 } 38 if (o instanceof PlaceHolder) { 39 Object k = new IdentityKey(o); 40 TypeObject t = (TypeObject) cache.get(k); 41 if (t == null) { 42 t = ((PlaceHolder) o).resolve(ts); 43 cache.put(k, t); 44 } 45 if (Report.should_report(Report.serialize, 2)) { 46 Report.report(2, "- Resolving " + s + " : " + o.getClass() 47 + " to " + t + " : " + t.getClass()); 48 } 49 return t; 50 } 51 else if (o instanceof Enum ) { 52 if (Report.should_report(Report.serialize, 2)) { 53 Report.report(2, "- Interning " + s + " : " + o.getClass()); 54 } 55 return ((Enum ) o).intern(); 56 } 57 else { 58 if (Report.should_report(Report.serialize, 2)) { 59 Report.report(2, "- " + s + " : " + o.getClass()); 60 } 61 return o; 62 } 63 } 64 } 65 | Popular Tags |