1 package polyglot.ext.jl.types; 2 3 import polyglot.types.*; 4 import polyglot.util.*; 5 import java.util.*; 6 7 12 public abstract class ReferenceType_c extends Type_c implements ReferenceType 13 { 14 protected ReferenceType_c() { 15 super(); 16 } 17 18 public ReferenceType_c(TypeSystem ts) { 19 this(ts, null); 20 } 21 22 public ReferenceType_c(TypeSystem ts, Position pos) { 23 super(ts, pos); 24 } 25 26 public boolean isReference() { return true; } 27 public ReferenceType toReference() { return this; } 28 29 33 public abstract List methods(); 34 35 39 public abstract List fields(); 40 41 45 public abstract Type superType(); 46 47 50 public abstract List interfaces(); 51 52 53 public final boolean hasMethod(MethodInstance mi) { 54 return ts.hasMethod(this, mi); 55 } 56 57 58 public boolean hasMethodImpl(MethodInstance mi) { 59 for (Iterator j = methods().iterator(); j.hasNext(); ) { 60 MethodInstance mj = (MethodInstance) j.next(); 61 62 if (ts.isSameMethod(mi, mj)) { 63 return true; 64 } 65 } 66 67 return false; 68 } 69 70 public boolean descendsFromImpl(Type ancestor) { 71 if (! ancestor.isCanonical()) { 72 return false; 73 } 74 75 if (ancestor.isNull()) { 76 return false; 77 } 78 79 if (ts.equals(this, ancestor)) { 80 return false; 81 } 82 83 if (! ancestor.isReference()) { 84 return false; 85 } 86 87 if (ts.equals(ancestor, ts.Object())) { 88 return true; 89 } 90 91 for (Iterator i = interfaces().iterator(); i.hasNext(); ) { 93 Type parentType = (Type) i.next(); 94 95 if (ts.isSubtype(parentType, ancestor)) { 96 return true; 97 } 98 } 99 100 return false; 101 } 102 103 public boolean isImplicitCastValidImpl(Type toType) { 104 return ts.isSubtype(this, toType); 105 } 106 107 public List methodsNamed(String name) { 108 List l = new LinkedList(); 109 110 for (Iterator i = methods().iterator(); i.hasNext(); ) { 111 MethodInstance mi = (MethodInstance) i.next(); 112 if (mi.name().equals(name)) { 113 l.add(mi); 114 } 115 } 116 117 return l; 118 } 119 120 public List methods(String name, List argTypes) { 121 List l = new LinkedList(); 122 123 for (Iterator i = methodsNamed(name).iterator(); i.hasNext(); ) { 124 MethodInstance mi = (MethodInstance) i.next(); 125 if (mi.hasFormals(argTypes)) { 126 l.add(mi); 127 } 128 } 129 130 return l; 131 } 132 133 139 public boolean isCastValidImpl(Type toType) { 140 if (! toType.isReference()) return false; 141 return ts.isSubtype(this, toType) || ts.isSubtype(toType, this); 142 } 143 } 144 | Popular Tags |