001    /*
002     * The JastAdd Extensible Java Compiler (http://jastadd.org) is covered
003     * by the modified BSD License. You should have received a copy of the
004     * modified BSD license with this compiler.
005     * 
006     * Copyright (c) 2005-2008, Torbjorn Ekman
007     * All rights reserved.
008     */
009    
010    aspect GenericsSubtype {
011      // use of this in generic classes
012      // all references to this are compatible with the raw counterpart
013      eq GenericClassDecl.subtype(TypeDecl type) = type.supertypeGenericClassDecl(this);
014      syn boolean TypeDecl.supertypeGenericClassDecl(GenericClassDecl type) =
015        supertypeClassDecl(type);
016      eq RawClassDecl.supertypeGenericClassDecl(GenericClassDecl type) =
017        type.subtype(genericDecl().original());
018    
019      eq GenericInterfaceDecl.subtype(TypeDecl type) = type.supertypeGenericInterfaceDecl(this);
020      syn boolean TypeDecl.supertypeGenericInterfaceDecl(GenericInterfaceDecl type) =
021        this == type || supertypeInterfaceDecl(type);
022      eq RawInterfaceDecl.supertypeGenericInterfaceDecl(GenericInterfaceDecl type) =
023        type.subtype(genericDecl().original());
024    
025      eq RawClassDecl.subtype(TypeDecl type) = type.supertypeRawClassDecl(this);
026      syn boolean TypeDecl.supertypeRawClassDecl(RawClassDecl type) =
027        supertypeParClassDecl(type);
028    
029      eq RawInterfaceDecl.subtype(TypeDecl type) = type.supertypeRawInterfaceDecl(this);
030      syn boolean TypeDecl.supertypeRawInterfaceDecl(RawInterfaceDecl type) =
031        supertypeParInterfaceDecl(type);
032       
033      // 5.1.9 Unchecked Conversion
034      eq ParClassDecl.supertypeGenericClassDecl(GenericClassDecl type) =
035        type.subtype(genericDecl().original());
036      eq ParInterfaceDecl.supertypeGenericClassDecl(GenericClassDecl type) =
037        type.subtype(genericDecl().original());
038      eq ParInterfaceDecl.supertypeGenericInterfaceDecl(GenericInterfaceDecl type) =
039        type.subtype(genericDecl().original());
040    
041    
042      // 5.1.10 Capture Conversion
043      // TODO:
044    
045      eq WildcardType.subtype(TypeDecl type) = type.supertypeWildcard(this);
046      syn boolean TypeDecl.supertypeWildcard(WildcardType type) = false;
047      eq WildcardType.supertypeWildcard(WildcardType type) =
048        true;
049      eq TypeVariable.supertypeWildcard(WildcardType type) = 
050        true;
051      eq WildcardExtendsType.supertypeWildcard(WildcardType type) =
052        typeObject().subtype(this);
053      eq WildcardSuperType.supertypeWildcard(WildcardType type) =
054        superType().subtype(typeObject());
055    
056      eq WildcardExtendsType.subtype(TypeDecl type) = type.supertypeWildcardExtends(this);
057      syn boolean TypeDecl.supertypeWildcardExtends(WildcardExtendsType type) = false;
058      eq WildcardType.supertypeWildcardExtends(WildcardExtendsType type) = 
059        true;
060      eq TypeVariable.supertypeWildcardExtends(WildcardExtendsType type) =
061        type.extendsType().subtype(this);
062      eq WildcardExtendsType.supertypeWildcardExtends(WildcardExtendsType type) =
063        type.extendsType().subtype(extendsType());
064    
065      eq WildcardSuperType.subtype(TypeDecl type) = type.supertypeWildcardSuper(this);
066      syn boolean TypeDecl.supertypeWildcardSuper(WildcardSuperType type) = false;
067      eq WildcardType.supertypeWildcardSuper(WildcardSuperType type) = 
068        true;
069      eq TypeVariable.supertypeWildcardSuper(WildcardSuperType type) =
070        type.superType().subtype(this);
071      eq WildcardSuperType.supertypeWildcardSuper(WildcardSuperType type) =
072        type.superType().subtype(superType());
073    
074    
075      eq WildcardType.supertypeClassDecl(ClassDecl type) = true;
076      eq WildcardType.supertypeInterfaceDecl(InterfaceDecl type) = true;
077      eq WildcardType.supertypeParClassDecl(ParClassDecl type) = true;
078      eq WildcardType.supertypeParInterfaceDecl(ParInterfaceDecl type) = true;
079      eq WildcardType.supertypeRawClassDecl(RawClassDecl type) = true;
080      eq WildcardType.supertypeRawInterfaceDecl(RawInterfaceDecl type) = true;
081      eq WildcardType.supertypeTypeVariable(TypeVariable type) = true;
082      eq WildcardType.supertypeArrayDecl(ArrayDecl type) = true;
083    
084      eq WildcardExtendsType.supertypeClassDecl(ClassDecl type) = type.subtype(extendsType());
085      eq WildcardExtendsType.supertypeInterfaceDecl(InterfaceDecl type) = type.subtype(extendsType());
086      eq WildcardExtendsType.supertypeParClassDecl(ParClassDecl type) = type.subtype(extendsType());
087      eq WildcardExtendsType.supertypeParInterfaceDecl(ParInterfaceDecl type) = type.subtype(extendsType());
088      eq WildcardExtendsType.supertypeRawClassDecl(RawClassDecl type) = type.subtype(extendsType());
089      eq WildcardExtendsType.supertypeRawInterfaceDecl(RawInterfaceDecl type) = type.subtype(extendsType());
090      eq WildcardExtendsType.supertypeTypeVariable(TypeVariable type) = type.subtype(extendsType());
091      eq WildcardExtendsType.supertypeArrayDecl(ArrayDecl type) = type.subtype(extendsType());
092    
093      eq WildcardSuperType.supertypeClassDecl(ClassDecl type) = superType().subtype(type);
094      eq WildcardSuperType.supertypeInterfaceDecl(InterfaceDecl type) = superType().subtype(type);
095      eq WildcardSuperType.supertypeParClassDecl(ParClassDecl type) = superType().subtype(type);
096      eq WildcardSuperType.supertypeParInterfaceDecl(ParInterfaceDecl type) = superType().subtype(type);
097      eq WildcardSuperType.supertypeRawClassDecl(RawClassDecl type) = superType().subtype(type);
098      eq WildcardSuperType.supertypeRawInterfaceDecl(RawInterfaceDecl type) = superType().subtype(type);
099      eq WildcardSuperType.supertypeTypeVariable(TypeVariable type) = superType().subtype(type);
100      eq WildcardSuperType.supertypeArrayDecl(ArrayDecl type) = superType().subtype(type);
101    
102      syn boolean TypeDecl.isWildcard() = false;
103      eq AbstractWildcardType.isWildcard() = true;
104    
105      eq ParClassDecl.supertypeClassDecl(ClassDecl type) =
106        super.supertypeClassDecl(type);
107      eq ParInterfaceDecl.supertypeClassDecl(ClassDecl type) =
108        super.supertypeClassDecl(type);
109    
110      eq RawClassDecl.supertypeClassDecl(ClassDecl type) =
111        type.subtype(genericDecl().original());
112      eq RawClassDecl.supertypeInterfaceDecl(InterfaceDecl type) =
113        type.subtype(genericDecl().original());
114      eq RawClassDecl.supertypeParClassDecl(ParClassDecl type) =
115        type.genericDecl().original().subtype(genericDecl().original());
116    
117      eq RawInterfaceDecl.supertypeClassDecl(ClassDecl type) =
118        type.subtype(genericDecl().original());
119      eq RawInterfaceDecl.supertypeInterfaceDecl(InterfaceDecl type) =
120        type.subtype(genericDecl().original());
121      eq RawInterfaceDecl.supertypeParInterfaceDecl(ParInterfaceDecl type) =
122        type.genericDecl().original().subtype(genericDecl().original());
123    
124      eq ParClassDecl.subtype(TypeDecl type) = type.supertypeParClassDecl(this);
125      syn boolean TypeDecl.supertypeParClassDecl(ParClassDecl type) =
126        supertypeClassDecl(type);
127    
128      eq ParInterfaceDecl.subtype(TypeDecl type) = type.supertypeParInterfaceDecl(this);
129      syn boolean TypeDecl.supertypeParInterfaceDecl(ParInterfaceDecl type) =
130        supertypeInterfaceDecl(type);
131    
132      eq ParClassDecl.supertypeRawClassDecl(RawClassDecl type) =
133        type.genericDecl().original().subtype(genericDecl().original());
134      eq ParClassDecl.supertypeRawInterfaceDecl(RawInterfaceDecl type) =
135        type.genericDecl().original().subtype(genericDecl().original());
136      eq ParInterfaceDecl.supertypeRawClassDecl(RawClassDecl type) =
137        type.genericDecl().original().subtype(genericDecl().original());
138      eq ParInterfaceDecl.supertypeRawInterfaceDecl(RawInterfaceDecl type) =
139        type.genericDecl().original().subtype(genericDecl().original());
140    
141      syn boolean TypeDecl.containedIn(TypeDecl type) circular [true] {
142        if(type == this || type instanceof WildcardType) 
143          return true;
144        else if(type instanceof WildcardExtendsType)
145          return this.subtype(((WildcardExtendsType)type).extendsType());
146        else if(type instanceof WildcardSuperType)
147          return ((WildcardSuperType)type).superType().subtype(this);
148        else if(type instanceof TypeVariable)
149          return subtype(type);
150        return sameStructure(type);
151        //return false;
152      }
153      eq WildcardExtendsType.containedIn(TypeDecl type) {
154        if(type == this || type instanceof WildcardType) 
155          return true;
156        else if(type instanceof WildcardExtendsType)
157          return extendsType().subtype(((WildcardExtendsType)type).extendsType());
158        else 
159          return false;
160      }
161      eq WildcardSuperType.containedIn(TypeDecl type) {
162        if(type == this || type instanceof WildcardType) 
163          return true;
164        else if(type instanceof WildcardSuperType)
165          return ((WildcardSuperType)type).superType().subtype(superType());
166        else 
167          return false;
168      }
169      eq WildcardType.containedIn(TypeDecl type) {
170        if(type == this)
171          return true;
172        else if(type instanceof WildcardExtendsType)
173          return typeObject().subtype(((WildcardExtendsType)type).extendsType());
174        else 
175          return false;
176      }
177    
178      syn boolean TypeDecl.sameStructure(TypeDecl t) circular [true] = t == this;
179      eq ParClassDecl.sameStructure(TypeDecl t) {
180        if(!(t instanceof ParClassDecl))
181          return false;
182        ParClassDecl type = (ParClassDecl)t;
183        if(type.genericDecl().original() == genericDecl().original() &&
184           type.getNumArgument() == getNumArgument()) {
185          for(int i = 0; i < getNumArgument(); i++)
186            if(!type.getArgument(i).type().sameStructure(getArgument(i).type()))
187              return false;
188          if(isNestedType() && type.isNestedType())
189            return type.enclosingType().sameStructure(enclosingType());
190          return true;
191        }
192        return false;
193      }
194      eq ParInterfaceDecl.sameStructure(TypeDecl t) {
195        if(!(t instanceof ParInterfaceDecl))
196          return false;
197        ParInterfaceDecl type = (ParInterfaceDecl)t;
198        if(type.genericDecl().original() == genericDecl().original() &&
199           type.getNumArgument() == getNumArgument()) {
200          for(int i = 0; i < getNumArgument(); i++)
201            if(!type.getArgument(i).type().sameStructure(getArgument(i).type()))
202              return false;
203          if(isNestedType() && type.isNestedType())
204            return type.enclosingType().sameStructure(enclosingType());
205          return true;
206        }
207        return false;
208      }
209      eq WildcardExtendsType.sameStructure(TypeDecl t) =
210        super.sameStructure(t) || 
211        t instanceof WildcardExtendsType && ((WildcardExtendsType)t).extendsType().sameStructure(extendsType());
212      eq WildcardSuperType.sameStructure(TypeDecl t) =
213        super.sameStructure(t) || 
214        t instanceof WildcardSuperType && ((WildcardSuperType)t).superType().sameStructure(superType());
215      eq TypeVariable.sameStructure(TypeDecl t) {
216        if(!(t instanceof TypeVariable))
217          return false;
218        if(t == this)
219          return true;
220        TypeVariable type = (TypeVariable)t;
221        if(type.getNumTypeBound() != getNumTypeBound())
222          return false;
223        for(int i = 0; i < getNumTypeBound(); i++) {
224          boolean found = false;
225          for(int j = i; !found && j < getNumTypeBound(); j++)
226            if(getTypeBound(i).type().sameStructure(type.getTypeBound(j).type()))
227              found = true;
228          if(!found)
229            return false;
230        }
231        return true;
232      }
233    
234      eq ParClassDecl.supertypeParClassDecl(ParClassDecl type) {
235        if(type.genericDecl().original() == genericDecl().original() &&
236           type.getNumArgument() == getNumArgument()) {
237          for(int i = 0; i < getNumArgument(); i++)
238            if(!type.getArgument(i).type().containedIn(getArgument(i).type()))
239              return false;
240          if(isNestedType() && type.isNestedType())
241            return type.enclosingType().subtype(enclosingType());
242          return true;
243        }
244        return supertypeClassDecl(type);
245      }
246      eq ParClassDecl.supertypeParInterfaceDecl(ParInterfaceDecl type) = false;
247    
248      eq ParInterfaceDecl.supertypeParClassDecl(ParClassDecl type) {
249        if(type.genericDecl().original() == genericDecl().original() &&
250           type.getNumArgument() == getNumArgument()) {
251          for(int i = 0; i < getNumArgument(); i++)
252            if(!type.getArgument(i).type().containedIn(getArgument(i).type()))
253              return false;
254          if(isNestedType() && type.isNestedType())
255            return type.enclosingType().subtype(enclosingType());
256          return true;
257        }
258        return supertypeClassDecl(type);
259      }
260      eq ParInterfaceDecl.supertypeParInterfaceDecl(ParInterfaceDecl type) {
261        if(type.genericDecl().original() == genericDecl().original() &&
262           type.getNumArgument() == getNumArgument()) {
263          for(int i = 0; i < getNumArgument(); i++)
264            if(!type.getArgument(i).type().containedIn(getArgument(i).type()))
265              return false;
266          if(isNestedType() && type.isNestedType())
267            return type.enclosingType().subtype(enclosingType());
268          return true;
269        }
270        return supertypeInterfaceDecl(type);
271      }
272    
273      eq GenericClassDecl.supertypeParClassDecl(ParClassDecl type) =
274        type.genericDecl().original().subtype(this);
275      eq GenericClassDecl.supertypeParInterfaceDecl(ParInterfaceDecl type) =
276        type.genericDecl().original().subtype(this);
277      eq GenericInterfaceDecl.supertypeParClassDecl(ParClassDecl type) =
278        type.genericDecl().original().subtype(this);
279      eq GenericInterfaceDecl.supertypeParInterfaceDecl(ParInterfaceDecl type) =
280        type.genericDecl().original().subtype(this);
281      
282      eq TypeVariable.supertypeArrayDecl(ArrayDecl type) {
283        for(int i = 0; i < getNumTypeBound(); i++)
284          if(type.subtype(getTypeBound(i).type())) {
285            return true;
286          }
287        return false;
288      }
289    
290      eq TypeVariable.subtype(TypeDecl type) = type.supertypeTypeVariable(this);
291      syn boolean TypeDecl.supertypeTypeVariable(TypeVariable type) {
292        if(type == this)
293          return true;
294        for(int i = 0; i < type.getNumTypeBound(); i++)
295          if(type.getTypeBound(i).type().subtype(this))
296            return true;
297        return false;
298      }
299      eq TypeVariable.supertypeTypeVariable(TypeVariable type) {
300        if(type == this)
301          return true;
302        for(int i = 0; i < getNumTypeBound(); i++) {
303          boolean found = false;
304          for(int j = 0; !found && j < type.getNumTypeBound(); j++) {
305            if(type.getSubstitutedTypeBound(j, this).type().subtype(getTypeBound(i).type()))
306              found = true;
307          }
308          if(!found)
309            return false;
310        }
311        return true;
312      }
313    
314      syn lazy Access TypeVariable.getSubstitutedTypeBound(int i, TypeDecl type) {
315        Access bound = getTypeBound(i);
316        if(!bound.type().usesTypeVariable())
317          return bound;
318        final TypeDecl typeDecl = type;
319        Access access = bound.type().substitute(
320          new Parameterization() {
321                       public boolean isRawType() { 
322                               return false; 
323                       }
324                       public TypeDecl substitute(TypeVariable typeVariable) {
325                               return typeVariable == TypeVariable.this ? typeDecl : typeVariable;
326                       } 
327               }
328        );
329        access.setParent(this);
330        return access;
331      }
332    
333      eq TypeVariable.supertypeClassDecl(ClassDecl type) {
334        for(int i = 0; i < getNumTypeBound(); i++)
335          if(!type.subtype(getSubstitutedTypeBound(i, type).type()))
336            return false;
337        return true;
338      }
339      eq TypeVariable.supertypeInterfaceDecl(InterfaceDecl type) {
340        for(int i = 0; i < getNumTypeBound(); i++)
341          if(!type.subtype(getSubstitutedTypeBound(i, type).type()))
342            return false;
343        return true;
344      }
345    
346      eq LUBType.subtype(TypeDecl type) = type.supertypeLUBType(this);
347      syn boolean TypeDecl.supertypeLUBType(LUBType type) {
348        for(int i = 0; i < type.getNumTypeBound(); i++)
349          if(!type.getTypeBound(i).type().subtype(this))
350            return false;
351        return true;
352      }
353      eq GLBType.supertypeLUBType(LUBType type){
354        ArrayList bounds = new ArrayList(getNumTypeBound());
355        for (int i = 0; i < getNumTypeBound(); i++) {
356          bounds.add(getTypeBound(i));
357        }
358        return type == lookupLUBType(bounds);
359      }
360    
361      eq LUBType.supertypeClassDecl(ClassDecl type) = type.subtype(lub());
362      eq LUBType.supertypeInterfaceDecl(InterfaceDecl type) = type.subtype(lub());
363    
364    
365      eq GLBType.subtype(TypeDecl type) = type.supertypeGLBType(this);
366      syn boolean TypeDecl.supertypeGLBType(GLBType type) {
367        // T1 && .. && Tn <: this, if exists  0 < i <= n Ti <: this 
368        for(int i = 0; i < type.getNumTypeBound(); i++)
369          if(type.getTypeBound(i).type().subtype(this))
370            return true;
371        return false;
372      }
373    
374      eq GLBType.supertypeGLBType(GLBType type) = this == type;
375      eq LUBType.supertypeGLBType(GLBType type){
376        ArrayList bounds = new ArrayList(getNumTypeBound());
377        for (int i = 0; i < getNumTypeBound(); i++) {
378          bounds.add(getTypeBound(i));
379        }
380        return type == lookupGLBType(bounds);
381      }
382    
383    
384      // refine rules to use a circular subtype attribute
385      
386      refine TypeWideningAndIdentity eq TypeDecl.instanceOf(TypeDecl type) { return subtype(type); }
387      refine TypeWideningAndIdentity eq ClassDecl.instanceOf(TypeDecl type) { return subtype(type); }
388      refine TypeWideningAndIdentity eq InterfaceDecl.instanceOf(TypeDecl type) { return subtype(type); }
389      refine TypeWideningAndIdentity eq ArrayDecl.instanceOf(TypeDecl type) { return subtype(type); }
390      refine TypeWideningAndIdentity eq PrimitiveType.instanceOf(TypeDecl type) { return subtype(type); }
391      refine TypeWideningAndIdentity eq NullType.instanceOf(TypeDecl type) { return subtype(type); }
392      refine TypeWideningAndIdentity eq VoidType.instanceOf(TypeDecl type) { return subtype(type); }
393      refine TypeWideningAndIdentity eq UnknownType.instanceOf(TypeDecl type) { return subtype(type); }
394      eq GenericClassDecl.instanceOf(TypeDecl type) = subtype(type);
395      eq GenericInterfaceDecl.instanceOf(TypeDecl type) = subtype(type);
396      eq ParClassDecl.instanceOf(TypeDecl type) = subtype(type);
397      eq RawClassDecl.instanceOf(TypeDecl type) = subtype(type);
398      eq ParInterfaceDecl.instanceOf(TypeDecl type) = subtype(type);
399      eq RawInterfaceDecl.instanceOf(TypeDecl type) = subtype(type);
400      eq TypeVariable.instanceOf(TypeDecl type) = subtype(type);
401      eq WildcardType.instanceOf(TypeDecl type) = subtype(type);
402      eq WildcardExtendsType.instanceOf(TypeDecl type) = subtype(type);
403      eq WildcardSuperType.instanceOf(TypeDecl type) = subtype(type);
404    
405      syn boolean TypeDecl.subtype(TypeDecl type) circular [true] =
406        type == this;
407      eq ClassDecl.subtype(TypeDecl type) = type.supertypeClassDecl(this);
408      eq InterfaceDecl.subtype(TypeDecl type) = type.supertypeInterfaceDecl(this);
409      eq ArrayDecl.subtype(TypeDecl type) = type.supertypeArrayDecl(this);
410      eq PrimitiveType.subtype(TypeDecl type) = type.supertypePrimitiveType(this);
411      eq NullType.subtype(TypeDecl type) = type.supertypeNullType(this);
412      eq VoidType.subtype(TypeDecl type) = type.supertypeVoidType(this);
413    
414      eq UnknownType.subtype(TypeDecl type) = true;
415      eq UnknownType.supertypeClassDecl(ClassDecl type) = true;
416      eq UnknownType.supertypeInterfaceDecl(InterfaceDecl type) = true;
417      eq UnknownType.supertypeArrayDecl(ArrayDecl type) = true;
418      eq UnknownType.supertypePrimitiveType(PrimitiveType type) = true;
419      eq UnknownType.supertypeNullType(NullType type) = true;
420      
421      syn boolean TypeDecl.supertypeClassDecl(ClassDecl type) = type == this;
422      eq ClassDecl.supertypeClassDecl(ClassDecl type) =
423        super.supertypeClassDecl(type) || 
424        type.hasSuperclass() && type.superclass() != null && type.superclass().subtype(this);
425    
426      eq InterfaceDecl.supertypeClassDecl(ClassDecl type) {
427        if(super.supertypeClassDecl(type))
428          return true;
429        for(Iterator iter = type.interfacesIterator(); iter.hasNext(); ) {
430          TypeDecl typeDecl = (TypeDecl)iter.next();
431          if(typeDecl.subtype(this))
432            return true;
433        }
434        return type.hasSuperclass() && type.superclass() != null && type.superclass().subtype(this);
435      }
436      
437      syn boolean TypeDecl.supertypeInterfaceDecl(InterfaceDecl type) = type == this;
438      eq ClassDecl.supertypeInterfaceDecl(InterfaceDecl type) = isObject();
439      eq InterfaceDecl.supertypeInterfaceDecl(InterfaceDecl type) {
440        if(super.supertypeInterfaceDecl(type))
441          return true;
442        for(Iterator iter = type.superinterfacesIterator(); iter.hasNext(); ) {
443          TypeDecl superinterface = (TypeDecl)iter.next();
444          if(superinterface.subtype(this))
445            return true;
446        }
447        return false;
448      }
449    
450      syn boolean TypeDecl.supertypeArrayDecl(ArrayDecl type) = this == type;
451      eq ClassDecl.supertypeArrayDecl(ArrayDecl type) {
452        if(super.supertypeArrayDecl(type))
453          return true;
454        return type.hasSuperclass() && type.superclass() != null && type.superclass().subtype(this);
455      }
456      eq InterfaceDecl.supertypeArrayDecl(ArrayDecl type) {
457        if(super.supertypeArrayDecl(type))
458          return true;
459        for(Iterator iter = type.interfacesIterator(); iter.hasNext(); ) {
460          TypeDecl typeDecl = (TypeDecl)iter.next();
461          if(typeDecl.subtype(this))
462            return true;
463        }
464        return false;
465      }  
466      eq ArrayDecl.supertypeArrayDecl(ArrayDecl type) {
467        if(type.elementType().isPrimitive() && elementType().isPrimitive())
468          return type.dimension() == dimension() && type.elementType() == elementType();
469        return type.componentType().subtype(componentType());
470      }  
471    
472      syn boolean TypeDecl.supertypePrimitiveType(PrimitiveType type) = type == this;
473      eq PrimitiveType.supertypePrimitiveType(PrimitiveType type) {
474        if(super.supertypePrimitiveType(type))
475          return true;
476        return type.hasSuperclass() && type.superclass().isPrimitive() && type.superclass().subtype(this);
477      }
478      
479      syn boolean TypeDecl.supertypeNullType(NullType type) = false;
480      eq ReferenceType.supertypeNullType(NullType type) = true;
481      eq NullType.supertypeNullType(NullType type) = true;
482      
483      syn boolean TypeDecl.supertypeVoidType(VoidType type) = false;
484      eq VoidType.supertypeVoidType(VoidType type) = true;
485    
486      eq ClassDeclSubstituted.instanceOf(TypeDecl type) = subtype(type);
487      eq InterfaceDeclSubstituted.instanceOf(TypeDecl type) = subtype(type);
488      eq GenericClassDeclSubstituted.instanceOf(TypeDecl type) = subtype(type);
489      eq GenericInterfaceDeclSubstituted.instanceOf(TypeDecl type) = subtype(type);
490    
491      eq ClassDeclSubstituted.subtype(TypeDecl type) = 
492        type.supertypeClassDeclSubstituted(this);
493      syn boolean TypeDecl.supertypeClassDeclSubstituted(ClassDeclSubstituted type) =
494        type.original() == this || supertypeClassDecl(type);
495      eq ClassDeclSubstituted.supertypeClassDeclSubstituted(ClassDeclSubstituted type) =
496        original() == type.original() && type.enclosingType().subtype(enclosingType()) || super.supertypeClassDeclSubstituted(type);
497    
498      eq ClassDeclSubstituted.supertypeClassDecl(ClassDecl type) = 
499        super.supertypeClassDecl(type) || original().supertypeClassDecl(type);
500    
501      eq InterfaceDeclSubstituted.subtype(TypeDecl type) = 
502        type.supertypeInterfaceDeclSubstituted(this);
503      syn boolean TypeDecl.supertypeInterfaceDeclSubstituted(InterfaceDeclSubstituted type) =
504        type.original() == this || supertypeInterfaceDecl(type);
505      eq InterfaceDeclSubstituted.supertypeInterfaceDeclSubstituted(InterfaceDeclSubstituted type) =
506        original() == type.original() && type.enclosingType().subtype(enclosingType()) || super.supertypeInterfaceDeclSubstituted(type);
507    
508      eq InterfaceDeclSubstituted.supertypeInterfaceDecl(InterfaceDecl type) =
509        super.supertypeInterfaceDecl(type) || original().supertypeInterfaceDecl(type);
510    
511      eq GenericClassDeclSubstituted.subtype(TypeDecl type) =
512        type.supertypeGenericClassDeclSubstituted(this);
513      syn boolean TypeDecl.supertypeGenericClassDeclSubstituted(GenericClassDeclSubstituted type) =
514        type.original() == this || supertypeGenericClassDecl(type);
515      eq GenericClassDeclSubstituted.supertypeGenericClassDeclSubstituted(GenericClassDeclSubstituted type) =
516        original() == type.original() && type.enclosingType().subtype(enclosingType()) || super.supertypeGenericClassDeclSubstituted(type);
517    
518      eq GenericClassDeclSubstituted.supertypeGenericClassDecl(GenericClassDecl type) = 
519        super.supertypeGenericClassDecl(type) || original().supertypeGenericClassDecl(type);
520    
521      eq GenericInterfaceDeclSubstituted.subtype(TypeDecl type) =
522        type.supertypeGenericInterfaceDeclSubstituted(this);
523      syn boolean TypeDecl.supertypeGenericInterfaceDeclSubstituted(GenericInterfaceDeclSubstituted type) =
524        type.original() == this || supertypeGenericInterfaceDecl(type);
525      eq GenericInterfaceDeclSubstituted.supertypeGenericInterfaceDeclSubstituted(GenericInterfaceDeclSubstituted type) =
526        original() == type.original() && type.enclosingType().subtype(enclosingType()) || super.supertypeGenericInterfaceDeclSubstituted(type);
527      eq GenericInterfaceDeclSubstituted.supertypeGenericInterfaceDecl(GenericInterfaceDecl type) = 
528        super.supertypeGenericInterfaceDecl(type) || original().supertypeGenericInterfaceDecl(type);
529    
530    
531    }