001 /* Copyright (c) 2005-2008, Torbjorn Ekman 002 * All rights reserved. 003 * 004 * Redistribution and use in source and binary forms, with or without 005 * modification, are permitted provided that the following conditions are met: 006 * 007 * 1. Redistributions of source code must retain the above copyright notice, 008 * this list of conditions and the following disclaimer. 009 * 010 * 2. Redistributions in binary form must reproduce the above copyright notice, 011 * this list of conditions and the following disclaimer in the documentation 012 * and/or other materials provided with the distribution. 013 * 014 * 3. Neither the name of the copyright holder nor the names of its 015 * contributors may be used to endorse or promote products derived from this 016 * software without specific prior written permission. 017 * 018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 021 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 022 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 028 * POSSIBILITY OF SUCH DAMAGE. 029 */ 030 031 aspect GenericsSubtype { 032 // use of this in generic classes 033 // all references to this are compatible with the raw counterpart 034 eq GenericClassDecl.subtype(TypeDecl type) = type.supertypeGenericClassDecl(this); 035 syn boolean TypeDecl.supertypeGenericClassDecl(GenericClassDecl type) = supertypeClassDecl(type); 036 eq RawClassDecl.supertypeGenericClassDecl(GenericClassDecl type) = 037 type.subtype(genericDecl().original()); 038 039 eq GenericInterfaceDecl.subtype(TypeDecl type) = type.supertypeGenericInterfaceDecl(this); 040 syn boolean TypeDecl.supertypeGenericInterfaceDecl(GenericInterfaceDecl type) = 041 this == type || supertypeInterfaceDecl(type); 042 eq RawInterfaceDecl.supertypeGenericInterfaceDecl(GenericInterfaceDecl type) = 043 type.subtype(genericDecl().original()); 044 045 eq RawClassDecl.subtype(TypeDecl type) = type.supertypeRawClassDecl(this); 046 syn boolean TypeDecl.supertypeRawClassDecl(RawClassDecl type) = 047 supertypeParClassDecl(type); 048 049 eq RawInterfaceDecl.subtype(TypeDecl type) = type.supertypeRawInterfaceDecl(this); 050 syn boolean TypeDecl.supertypeRawInterfaceDecl(RawInterfaceDecl type) = 051 supertypeParInterfaceDecl(type); 052 053 // 5.1.9 Unchecked Conversion 054 eq ParClassDecl.supertypeGenericClassDecl(GenericClassDecl type) = 055 type.subtype(genericDecl().original()); 056 eq ParInterfaceDecl.supertypeGenericClassDecl(GenericClassDecl type) = 057 type.subtype(genericDecl().original()); 058 eq ParInterfaceDecl.supertypeGenericInterfaceDecl(GenericInterfaceDecl type) = 059 type.subtype(genericDecl().original()); 060 061 062 // 5.1.10 Capture Conversion 063 // TODO: 064 065 eq WildcardType.subtype(TypeDecl type) = type.supertypeWildcard(this); 066 syn boolean TypeDecl.supertypeWildcard(WildcardType type) = false; 067 eq WildcardType.supertypeWildcard(WildcardType type) = true; 068 eq TypeVariable.supertypeWildcard(WildcardType type) = true; 069 eq WildcardExtendsType.supertypeWildcard(WildcardType type) = typeObject().subtype(this); 070 eq WildcardSuperType.supertypeWildcard(WildcardType type) = superType().subtype(typeObject()); 071 072 eq WildcardExtendsType.subtype(TypeDecl type) = type.supertypeWildcardExtends(this); 073 syn boolean TypeDecl.supertypeWildcardExtends(WildcardExtendsType type) = false; 074 eq WildcardType.supertypeWildcardExtends(WildcardExtendsType type) = true; 075 eq TypeVariable.supertypeWildcardExtends(WildcardExtendsType type) = 076 type.extendsType().subtype(this); 077 eq WildcardExtendsType.supertypeWildcardExtends(WildcardExtendsType type) = 078 type.extendsType().subtype(extendsType()); 079 080 eq WildcardSuperType.subtype(TypeDecl type) = type.supertypeWildcardSuper(this); 081 syn boolean TypeDecl.supertypeWildcardSuper(WildcardSuperType type) = false; 082 eq WildcardType.supertypeWildcardSuper(WildcardSuperType type) = true; 083 eq TypeVariable.supertypeWildcardSuper(WildcardSuperType type) = type.superType().subtype(this); 084 eq WildcardSuperType.supertypeWildcardSuper(WildcardSuperType type) = 085 type.superType().subtype(superType()); 086 087 088 eq WildcardType.supertypeClassDecl(ClassDecl type) = true; 089 eq WildcardType.supertypeInterfaceDecl(InterfaceDecl type) = true; 090 eq WildcardType.supertypeParClassDecl(ParClassDecl type) = true; 091 eq WildcardType.supertypeParInterfaceDecl(ParInterfaceDecl type) = true; 092 eq WildcardType.supertypeRawClassDecl(RawClassDecl type) = true; 093 eq WildcardType.supertypeRawInterfaceDecl(RawInterfaceDecl type) = true; 094 eq WildcardType.supertypeTypeVariable(TypeVariable type) = true; 095 eq WildcardType.supertypeArrayDecl(ArrayDecl type) = true; 096 097 eq WildcardExtendsType.supertypeClassDecl(ClassDecl type) = type.subtype(extendsType()); 098 eq WildcardExtendsType.supertypeInterfaceDecl(InterfaceDecl type) = type.subtype(extendsType()); 099 eq WildcardExtendsType.supertypeParClassDecl(ParClassDecl type) = type.subtype(extendsType()); 100 eq WildcardExtendsType.supertypeParInterfaceDecl(ParInterfaceDecl type) = type.subtype(extendsType()); 101 eq WildcardExtendsType.supertypeRawClassDecl(RawClassDecl type) = type.subtype(extendsType()); 102 eq WildcardExtendsType.supertypeRawInterfaceDecl(RawInterfaceDecl type) = type.subtype(extendsType()); 103 eq WildcardExtendsType.supertypeTypeVariable(TypeVariable type) = type.subtype(extendsType()); 104 eq WildcardExtendsType.supertypeArrayDecl(ArrayDecl type) = type.subtype(extendsType()); 105 106 eq WildcardSuperType.supertypeClassDecl(ClassDecl type) = superType().subtype(type); 107 eq WildcardSuperType.supertypeInterfaceDecl(InterfaceDecl type) = superType().subtype(type); 108 eq WildcardSuperType.supertypeParClassDecl(ParClassDecl type) = superType().subtype(type); 109 eq WildcardSuperType.supertypeParInterfaceDecl(ParInterfaceDecl type) = superType().subtype(type); 110 eq WildcardSuperType.supertypeRawClassDecl(RawClassDecl type) = superType().subtype(type); 111 eq WildcardSuperType.supertypeRawInterfaceDecl(RawInterfaceDecl type) = superType().subtype(type); 112 eq WildcardSuperType.supertypeTypeVariable(TypeVariable type) = superType().subtype(type); 113 eq WildcardSuperType.supertypeArrayDecl(ArrayDecl type) = superType().subtype(type); 114 115 syn boolean TypeDecl.isWildcard() = false; 116 eq AbstractWildcardType.isWildcard() = true; 117 118 eq ParClassDecl.supertypeClassDecl(ClassDecl type) = super.supertypeClassDecl(type); 119 eq ParInterfaceDecl.supertypeClassDecl(ClassDecl type) = super.supertypeClassDecl(type); 120 121 eq RawClassDecl.supertypeClassDecl(ClassDecl type) = type.subtype(genericDecl().original()); 122 eq RawClassDecl.supertypeInterfaceDecl(InterfaceDecl type) = 123 type.subtype(genericDecl().original()); 124 eq RawClassDecl.supertypeParClassDecl(ParClassDecl type) = 125 type.genericDecl().original().subtype(genericDecl().original()); 126 127 eq RawInterfaceDecl.supertypeClassDecl(ClassDecl type) = type.subtype(genericDecl().original()); 128 eq RawInterfaceDecl.supertypeInterfaceDecl(InterfaceDecl type) = 129 type.subtype(genericDecl().original()); 130 eq RawInterfaceDecl.supertypeParInterfaceDecl(ParInterfaceDecl type) = 131 type.genericDecl().original().subtype(genericDecl().original()); 132 133 eq ParClassDecl.subtype(TypeDecl type) = type.supertypeParClassDecl(this); 134 syn boolean TypeDecl.supertypeParClassDecl(ParClassDecl type) = supertypeClassDecl(type); 135 136 eq ParInterfaceDecl.subtype(TypeDecl type) = type.supertypeParInterfaceDecl(this); 137 syn boolean TypeDecl.supertypeParInterfaceDecl(ParInterfaceDecl type) = 138 supertypeInterfaceDecl(type); 139 140 eq ParClassDecl.supertypeRawClassDecl(RawClassDecl type) = 141 type.genericDecl().original().subtype(genericDecl().original()); 142 eq ParClassDecl.supertypeRawInterfaceDecl(RawInterfaceDecl type) = 143 type.genericDecl().original().subtype(genericDecl().original()); 144 eq ParInterfaceDecl.supertypeRawClassDecl(RawClassDecl type) = 145 type.genericDecl().original().subtype(genericDecl().original()); 146 eq ParInterfaceDecl.supertypeRawInterfaceDecl(RawInterfaceDecl type) = 147 type.genericDecl().original().subtype(genericDecl().original()); 148 149 syn boolean TypeDecl.containedIn(TypeDecl type) circular [true] { 150 if (type == this || type instanceof WildcardType) { 151 return true; 152 } else if (type instanceof WildcardExtendsType) { 153 return this.subtype(((WildcardExtendsType) type).extendsType()); 154 } else if (type instanceof WildcardSuperType) { 155 return ((WildcardSuperType) type).superType().subtype(this); 156 } else if (type instanceof TypeVariable) { 157 return subtype(type); 158 } 159 return sameStructure(type); 160 //return false; 161 } 162 eq WildcardExtendsType.containedIn(TypeDecl type) { 163 if (type == this || type instanceof WildcardType) { 164 return true; 165 } else if (type instanceof WildcardExtendsType) { 166 return extendsType().subtype(((WildcardExtendsType) type).extendsType()); 167 } else { 168 return false; 169 } 170 } 171 eq WildcardSuperType.containedIn(TypeDecl type) { 172 if (type == this || type instanceof WildcardType) { 173 return true; 174 } else if (type instanceof WildcardSuperType) { 175 return ((WildcardSuperType) type).superType().subtype(superType()); 176 } else { 177 return false; 178 } 179 } 180 eq WildcardType.containedIn(TypeDecl type) { 181 if (type == this) { 182 return true; 183 } else if (type instanceof WildcardExtendsType) { 184 return typeObject().subtype(((WildcardExtendsType) type).extendsType()); 185 } else { 186 return false; 187 } 188 } 189 190 syn boolean TypeDecl.sameStructure(TypeDecl t) circular [true] = t == this; 191 eq ParClassDecl.sameStructure(TypeDecl t) { 192 if (!(t instanceof ParClassDecl)) { 193 return false; 194 } 195 ParClassDecl type = (ParClassDecl) t; 196 if (type.genericDecl().original() == genericDecl().original() && 197 type.getNumArgument() == getNumArgument()) { 198 for (int i = 0; i < getNumArgument(); i++) 199 if (!type.getArgument(i).type().sameStructure(getArgument(i).type())) { 200 return false; 201 } 202 if (isNestedType() && type.isNestedType()) { 203 return type.enclosingType().sameStructure(enclosingType()); 204 } 205 return true; 206 } 207 return false; 208 } 209 eq ParInterfaceDecl.sameStructure(TypeDecl t) { 210 if (!(t instanceof ParInterfaceDecl)) { 211 return false; 212 } 213 ParInterfaceDecl type = (ParInterfaceDecl) t; 214 if (type.genericDecl().original() == genericDecl().original() && 215 type.getNumArgument() == getNumArgument()) { 216 for (int i = 0; i < getNumArgument(); i++) 217 if (!type.getArgument(i).type().sameStructure(getArgument(i).type())) { 218 return false; 219 } 220 if (isNestedType() && type.isNestedType()) { 221 return type.enclosingType().sameStructure(enclosingType()); 222 } 223 return true; 224 } 225 return false; 226 } 227 eq WildcardExtendsType.sameStructure(TypeDecl t) = 228 super.sameStructure(t) || t instanceof WildcardExtendsType 229 && ((WildcardExtendsType) t).extendsType().sameStructure(extendsType()); 230 eq WildcardSuperType.sameStructure(TypeDecl t) = 231 super.sameStructure(t) || t instanceof WildcardSuperType 232 && ((WildcardSuperType) t).superType().sameStructure(superType()); 233 eq TypeVariable.sameStructure(TypeDecl t) { 234 if (!(t instanceof TypeVariable)) { 235 return false; 236 } 237 if (t == this) { 238 return true; 239 } 240 TypeVariable type = (TypeVariable) t; 241 if (type.getNumTypeBound() != getNumTypeBound()) { 242 return false; 243 } 244 for (int i = 0; i < getNumTypeBound(); i++) { 245 boolean found = false; 246 for (int j = i; !found && j < getNumTypeBound(); j++) 247 if (getTypeBound(i).type().sameStructure(type.getTypeBound(j).type())) { 248 found = true; 249 } 250 if (!found) { 251 return false; 252 } 253 } 254 return true; 255 } 256 257 eq ParClassDecl.supertypeParClassDecl(ParClassDecl type) { 258 if (type.genericDecl().original() == genericDecl().original() && 259 type.getNumArgument() == getNumArgument()) { 260 for (int i = 0; i < getNumArgument(); i++) 261 if (!type.getArgument(i).type().containedIn(getArgument(i).type())) { 262 return false; 263 } 264 if (isNestedType() && type.isNestedType()) { 265 return type.enclosingType().subtype(enclosingType()); 266 } 267 return true; 268 } 269 return supertypeClassDecl(type); 270 } 271 eq ParClassDecl.supertypeParInterfaceDecl(ParInterfaceDecl type) = false; 272 273 eq ParInterfaceDecl.supertypeParClassDecl(ParClassDecl type) { 274 if (type.genericDecl().original() == genericDecl().original() && 275 type.getNumArgument() == getNumArgument()) { 276 for (int i = 0; i < getNumArgument(); i++) 277 if (!type.getArgument(i).type().containedIn(getArgument(i).type())) { 278 return false; 279 } 280 if (isNestedType() && type.isNestedType()) { 281 return type.enclosingType().subtype(enclosingType()); 282 } 283 return true; 284 } 285 return supertypeClassDecl(type); 286 } 287 eq ParInterfaceDecl.supertypeParInterfaceDecl(ParInterfaceDecl type) { 288 if (type.genericDecl().original() == genericDecl().original() && 289 type.getNumArgument() == getNumArgument()) { 290 for (int i = 0; i < getNumArgument(); i++) 291 if (!type.getArgument(i).type().containedIn(getArgument(i).type())) { 292 return false; 293 } 294 if (isNestedType() && type.isNestedType()) { 295 return type.enclosingType().subtype(enclosingType()); 296 } 297 return true; 298 } 299 return supertypeInterfaceDecl(type); 300 } 301 302 eq GenericClassDecl.supertypeParClassDecl(ParClassDecl type) = 303 type.genericDecl().original().subtype(this); 304 eq GenericClassDecl.supertypeParInterfaceDecl(ParInterfaceDecl type) = 305 type.genericDecl().original().subtype(this); 306 eq GenericInterfaceDecl.supertypeParClassDecl(ParClassDecl type) = 307 type.genericDecl().original().subtype(this); 308 eq GenericInterfaceDecl.supertypeParInterfaceDecl(ParInterfaceDecl type) = 309 type.genericDecl().original().subtype(this); 310 311 eq TypeVariable.supertypeArrayDecl(ArrayDecl type) { 312 for (int i = 0; i < getNumTypeBound(); i++) 313 if (type.subtype(getTypeBound(i).type())) { 314 return true; 315 } 316 return false; 317 } 318 319 eq TypeVariable.subtype(TypeDecl type) = type.supertypeTypeVariable(this); 320 321 syn boolean TypeDecl.supertypeTypeVariable(TypeVariable type) { 322 if (type == this) { 323 return true; 324 } 325 for (int i = 0; i < type.getNumTypeBound(); i++) 326 if (type.getTypeBound(i).type().subtype(this)) { 327 return true; 328 } 329 return false; 330 } 331 332 eq TypeVariable.supertypeTypeVariable(TypeVariable type) { 333 if (type == this) { 334 return true; 335 } 336 for (int i = 0; i < getNumTypeBound(); i++) { 337 boolean found = false; 338 for (int j = 0; !found && j < type.getNumTypeBound(); j++) { 339 if (type.getSubstitutedTypeBound(j, this).type().subtype(getTypeBound(i).type())) { 340 found = true; 341 } 342 } 343 if (!found) { 344 return false; 345 } 346 } 347 return true; 348 } 349 350 syn lazy Access TypeVariable.getSubstitutedTypeBound(int i, TypeDecl type) { 351 Access bound = getTypeBound(i); 352 if (!bound.type().usesTypeVariable()) { 353 return bound; 354 } 355 final TypeDecl typeDecl = type; 356 Access access = bound.type().substitute( 357 new Parameterization() { 358 public boolean isRawType() { 359 return false; 360 } 361 public TypeDecl substitute(TypeVariable typeVariable) { 362 return typeVariable == TypeVariable.this ? typeDecl : typeVariable; 363 } 364 } 365 ); 366 access.setParent(this); 367 return access; 368 } 369 370 // type variable can not be a strict supertype to a concrete type because the type variable only has an upper bound 371 eq TypeVariable.supertypeClassDecl(ClassDecl type) = false; 372 373 eq TypeVariable.supertypeInterfaceDecl(InterfaceDecl type) = false; 374 375 eq LUBType.subtype(TypeDecl type) = type.supertypeLUBType(this); 376 syn boolean TypeDecl.supertypeLUBType(LUBType type) { 377 for (int i = 0; i < type.getNumTypeBound(); i++) 378 if (!type.getTypeBound(i).type().subtype(this)) { 379 return false; 380 } 381 return true; 382 } 383 eq GLBType.supertypeLUBType(LUBType type){ 384 ArrayList bounds = new ArrayList(getNumTypeBound()); 385 for (int i = 0; i < getNumTypeBound(); i++) { 386 bounds.add(getTypeBound(i)); 387 } 388 return type == lookupLUBType(bounds); 389 } 390 391 eq LUBType.supertypeClassDecl(ClassDecl type) = type.subtype(lub()); 392 eq LUBType.supertypeInterfaceDecl(InterfaceDecl type) = type.subtype(lub()); 393 eq GLBType.subtype(TypeDecl type) = type.supertypeGLBType(this); 394 syn boolean TypeDecl.supertypeGLBType(GLBType type) { 395 // T1 && .. && Tn <: this, if exists 0 < i <= n Ti <: this 396 for (int i = 0; i < type.getNumTypeBound(); i++) 397 if (type.getTypeBound(i).type().subtype(this)) { 398 return true; 399 } 400 return false; 401 } 402 403 eq GLBType.supertypeGLBType(GLBType type) = this == type; 404 eq LUBType.supertypeGLBType(GLBType type){ 405 ArrayList bounds = new ArrayList(getNumTypeBound()); 406 for (int i = 0; i < getNumTypeBound(); i++) { 407 bounds.add(getTypeBound(i)); 408 } 409 return type == lookupGLBType(bounds); 410 } 411 412 // refine rules to use a circular subtype attribute 413 414 refine TypeWideningAndIdentity eq TypeDecl.instanceOf(TypeDecl type) { return subtype(type); } 415 refine TypeWideningAndIdentity eq ClassDecl.instanceOf(TypeDecl type) { return subtype(type); } 416 refine TypeWideningAndIdentity eq InterfaceDecl.instanceOf(TypeDecl type) { return subtype(type); } 417 refine TypeWideningAndIdentity eq ArrayDecl.instanceOf(TypeDecl type) { return subtype(type); } 418 refine TypeWideningAndIdentity eq PrimitiveType.instanceOf(TypeDecl type) { return subtype(type); } 419 refine TypeWideningAndIdentity eq NullType.instanceOf(TypeDecl type) { return subtype(type); } 420 refine TypeWideningAndIdentity eq VoidType.instanceOf(TypeDecl type) { return subtype(type); } 421 refine TypeWideningAndIdentity eq UnknownType.instanceOf(TypeDecl type) { return subtype(type); } 422 eq GenericClassDecl.instanceOf(TypeDecl type) = subtype(type); 423 eq GenericInterfaceDecl.instanceOf(TypeDecl type) = subtype(type); 424 eq ParClassDecl.instanceOf(TypeDecl type) = subtype(type); 425 eq RawClassDecl.instanceOf(TypeDecl type) = subtype(type); 426 eq ParInterfaceDecl.instanceOf(TypeDecl type) = subtype(type); 427 eq RawInterfaceDecl.instanceOf(TypeDecl type) = subtype(type); 428 eq TypeVariable.instanceOf(TypeDecl type) = subtype(type); 429 eq WildcardType.instanceOf(TypeDecl type) = subtype(type); 430 eq WildcardExtendsType.instanceOf(TypeDecl type) = subtype(type); 431 eq WildcardSuperType.instanceOf(TypeDecl type) = subtype(type); 432 433 syn boolean TypeDecl.subtype(TypeDecl type) circular [true] = type == this; 434 eq ClassDecl.subtype(TypeDecl type) = type.supertypeClassDecl(this); 435 eq InterfaceDecl.subtype(TypeDecl type) = type.supertypeInterfaceDecl(this); 436 eq ArrayDecl.subtype(TypeDecl type) = type.supertypeArrayDecl(this); 437 eq PrimitiveType.subtype(TypeDecl type) = type.supertypePrimitiveType(this); 438 eq NullType.subtype(TypeDecl type) = type.supertypeNullType(this); 439 eq VoidType.subtype(TypeDecl type) = type.supertypeVoidType(this); 440 441 eq UnknownType.subtype(TypeDecl type) = true; 442 eq UnknownType.supertypeClassDecl(ClassDecl type) = true; 443 eq UnknownType.supertypeInterfaceDecl(InterfaceDecl type) = true; 444 eq UnknownType.supertypeArrayDecl(ArrayDecl type) = true; 445 eq UnknownType.supertypePrimitiveType(PrimitiveType type) = true; 446 eq UnknownType.supertypeNullType(NullType type) = true; 447 448 syn boolean TypeDecl.supertypeClassDecl(ClassDecl type) = type == this; 449 eq ClassDecl.supertypeClassDecl(ClassDecl type) = 450 super.supertypeClassDecl(type) || type.hasSuperclass() && type.superclass().subtype(this); 451 452 eq InterfaceDecl.supertypeClassDecl(ClassDecl type) { 453 if (super.supertypeClassDecl(type)) { 454 return true; 455 } 456 for (Iterator<TypeDecl> iter = type.interfacesIterator(); iter.hasNext(); ) { 457 TypeDecl typeDecl = iter.next(); 458 if (typeDecl.subtype(this)) { 459 return true; 460 } 461 } 462 return type.hasSuperclass() && type.superclass().subtype(this); 463 } 464 465 syn boolean TypeDecl.supertypeInterfaceDecl(InterfaceDecl type) = type == this; 466 eq ClassDecl.supertypeInterfaceDecl(InterfaceDecl type) = isObject(); 467 eq InterfaceDecl.supertypeInterfaceDecl(InterfaceDecl type) { 468 if (super.supertypeInterfaceDecl(type)) { 469 return true; 470 } 471 for (Iterator<TypeDecl> iter = type.interfacesIterator(); iter.hasNext(); ) { 472 TypeDecl superinterface = iter.next(); 473 if (superinterface.subtype(this)) { 474 return true; 475 } 476 } 477 return false; 478 } 479 480 syn boolean TypeDecl.supertypeArrayDecl(ArrayDecl type) = this == type; 481 eq ClassDecl.supertypeArrayDecl(ArrayDecl type) { 482 if (super.supertypeArrayDecl(type)) { 483 return true; 484 } 485 return type.hasSuperclass() && type.superclass().subtype(this); 486 } 487 eq InterfaceDecl.supertypeArrayDecl(ArrayDecl type) { 488 if (super.supertypeArrayDecl(type)) { 489 return true; 490 } 491 for (Iterator<TypeDecl> iter = type.interfacesIterator(); iter.hasNext(); ) { 492 TypeDecl typeDecl = iter.next(); 493 if (typeDecl.subtype(this)) { 494 return true; 495 } 496 } 497 return false; 498 } 499 eq ArrayDecl.supertypeArrayDecl(ArrayDecl type) { 500 if (type.elementType().isPrimitive() && elementType().isPrimitive()) { 501 return type.dimension() == dimension() && type.elementType() == elementType(); 502 } 503 return type.componentType().subtype(componentType()); 504 } 505 506 syn boolean TypeDecl.supertypePrimitiveType(PrimitiveType type) = type == this; 507 eq PrimitiveType.supertypePrimitiveType(PrimitiveType type) { 508 if (super.supertypePrimitiveType(type)) { 509 return true; 510 } 511 return type.hasSuperclass() && type.superclass().isPrimitive() && type.superclass().subtype(this); 512 } 513 514 syn boolean TypeDecl.supertypeNullType(NullType type) = false; 515 eq ReferenceType.supertypeNullType(NullType type) = true; 516 eq NullType.supertypeNullType(NullType type) = true; 517 518 syn boolean TypeDecl.supertypeVoidType(VoidType type) = false; 519 eq VoidType.supertypeVoidType(VoidType type) = true; 520 521 eq ClassDeclSubstituted.instanceOf(TypeDecl type) = subtype(type); 522 eq InterfaceDeclSubstituted.instanceOf(TypeDecl type) = subtype(type); 523 eq GenericClassDeclSubstituted.instanceOf(TypeDecl type) = subtype(type); 524 eq GenericInterfaceDeclSubstituted.instanceOf(TypeDecl type) = subtype(type); 525 526 eq ClassDeclSubstituted.subtype(TypeDecl type) = type.supertypeClassDeclSubstituted(this); 527 syn boolean TypeDecl.supertypeClassDeclSubstituted(ClassDeclSubstituted type) = 528 type.original() == this || supertypeClassDecl(type); 529 eq ClassDeclSubstituted.supertypeClassDeclSubstituted(ClassDeclSubstituted type) = 530 original() == type.original() && type.enclosingType().subtype(enclosingType()) 531 || super.supertypeClassDeclSubstituted(type); 532 533 eq ClassDeclSubstituted.supertypeClassDecl(ClassDecl type) = 534 super.supertypeClassDecl(type) || original().supertypeClassDecl(type); 535 536 eq InterfaceDeclSubstituted.subtype(TypeDecl type) = 537 type.supertypeInterfaceDeclSubstituted(this); 538 syn boolean TypeDecl.supertypeInterfaceDeclSubstituted(InterfaceDeclSubstituted type) = 539 type.original() == this || supertypeInterfaceDecl(type); 540 eq InterfaceDeclSubstituted.supertypeInterfaceDeclSubstituted(InterfaceDeclSubstituted type) = 541 original() == type.original() && type.enclosingType().subtype(enclosingType()) 542 || super.supertypeInterfaceDeclSubstituted(type); 543 544 eq InterfaceDeclSubstituted.supertypeInterfaceDecl(InterfaceDecl type) = 545 super.supertypeInterfaceDecl(type) || original().supertypeInterfaceDecl(type); 546 547 eq GenericClassDeclSubstituted.subtype(TypeDecl type) = type.supertypeGenericClassDeclSubstituted(this); 548 syn boolean TypeDecl.supertypeGenericClassDeclSubstituted(GenericClassDeclSubstituted type) = 549 type.original() == this || supertypeGenericClassDecl(type); 550 eq GenericClassDeclSubstituted.supertypeGenericClassDeclSubstituted(GenericClassDeclSubstituted type) = 551 original() == type.original() && type.enclosingType().subtype(enclosingType()) 552 || super.supertypeGenericClassDeclSubstituted(type); 553 554 eq GenericClassDeclSubstituted.supertypeGenericClassDecl(GenericClassDecl type) = 555 super.supertypeGenericClassDecl(type) || original().supertypeGenericClassDecl(type); 556 557 eq GenericInterfaceDeclSubstituted.subtype(TypeDecl type) = 558 type.supertypeGenericInterfaceDeclSubstituted(this); 559 syn boolean TypeDecl.supertypeGenericInterfaceDeclSubstituted(GenericInterfaceDeclSubstituted type) = 560 type.original() == this || supertypeGenericInterfaceDecl(type); 561 eq GenericInterfaceDeclSubstituted.supertypeGenericInterfaceDeclSubstituted( 562 GenericInterfaceDeclSubstituted type) = 563 original() == type.original() && type.enclosingType().subtype(enclosingType()) 564 || super.supertypeGenericInterfaceDeclSubstituted(type); 565 eq GenericInterfaceDeclSubstituted.supertypeGenericInterfaceDecl(GenericInterfaceDecl type) = 566 super.supertypeGenericInterfaceDecl(type) || original().supertypeGenericInterfaceDecl(type); 567 568 } 569