View | Details | Raw Unified | Return to bug 239096
Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/hierarchy/TypeHierarchy.java (-16 / +24 lines)
Lines 438-491 Link Here
438
 * @see ITypeHierarchy
438
 * @see ITypeHierarchy
439
 */
439
 */
440
public IType[] getAllSuperInterfaces(IType type) {
440
public IType[] getAllSuperInterfaces(IType type) {
441
	ArrayList supers = new ArrayList();
441
	ArrayList supers = getAllSuperInterfaces0(type, null);
442
	if (this.typeToSuperInterfaces.get(type) == null) {
442
	if (supers == null)
443
		return NO_TYPE;
443
		return NO_TYPE;
444
	}
445
	getAllSuperInterfaces0(type, supers);
446
	IType[] superinterfaces = new IType[supers.size()];
444
	IType[] superinterfaces = new IType[supers.size()];
447
	supers.toArray(superinterfaces);
445
	supers.toArray(superinterfaces);
448
	return superinterfaces;
446
	return superinterfaces;
449
}
447
}
450
private void getAllSuperInterfaces0(IType type, ArrayList supers) {
448
private ArrayList getAllSuperInterfaces0(IType type, ArrayList supers) {
451
	IType[] superinterfaces = (IType[]) this.typeToSuperInterfaces.get(type);
449
	IType[] superinterfaces = (IType[]) this.typeToSuperInterfaces.get(type);
452
	if (superinterfaces != null && superinterfaces.length != 0) {
450
	if (superinterfaces == null) // type is not part of the hierarchy
451
		return supers;
452
	if (superinterfaces.length != 0) {
453
		if (supers == null)
454
			supers = new ArrayList();
453
		addAllCheckingDuplicates(supers, superinterfaces);
455
		addAllCheckingDuplicates(supers, superinterfaces);
454
		for (int i = 0; i < superinterfaces.length; i++) {
456
		for (int i = 0; i < superinterfaces.length; i++) {
455
			getAllSuperInterfaces0(superinterfaces[i], supers);
457
			supers = getAllSuperInterfaces0(superinterfaces[i], supers);
456
		}
458
		}
457
	}
459
	}
458
	IType superclass = (IType) this.classToSuperclass.get(type);
460
	IType superclass = (IType) this.classToSuperclass.get(type);
459
	if (superclass != null) {
461
	if (superclass != null) {
460
		getAllSuperInterfaces0(superclass, supers);
462
		supers = getAllSuperInterfaces0(superclass, supers);
461
	}
463
	}
464
	return supers;
462
}
465
}
463
/**
466
/**
464
 * @see ITypeHierarchy
467
 * @see ITypeHierarchy
465
 */
468
 */
466
public IType[] getAllSupertypes(IType type) {
469
public IType[] getAllSupertypes(IType type) {
467
	ArrayList supers = new ArrayList();
470
	ArrayList supers = getAllSupertypes0(type, null);
468
	if (this.typeToSuperInterfaces.get(type) == null) {
471
	if (supers == null)
469
		return NO_TYPE;
472
		return NO_TYPE;
470
	}
471
	getAllSupertypes0(type, supers);
472
	IType[] supertypes = new IType[supers.size()];
473
	IType[] supertypes = new IType[supers.size()];
473
	supers.toArray(supertypes);
474
	supers.toArray(supertypes);
474
	return supertypes;
475
	return supertypes;
475
}
476
}
476
private void getAllSupertypes0(IType type, ArrayList supers) {
477
private ArrayList getAllSupertypes0(IType type, ArrayList supers) {
477
	IType[] superinterfaces = (IType[]) this.typeToSuperInterfaces.get(type);
478
	IType[] superinterfaces = (IType[]) this.typeToSuperInterfaces.get(type);
478
	if (superinterfaces != null && superinterfaces.length != 0) {
479
	if (superinterfaces == null) // type is not part of the hierarchy
480
		return supers;
481
	if (superinterfaces.length != 0) {
482
		if (supers == null)
483
			supers = new ArrayList();
479
		addAllCheckingDuplicates(supers, superinterfaces);
484
		addAllCheckingDuplicates(supers, superinterfaces);
480
		for (int i = 0; i < superinterfaces.length; i++) {
485
		for (int i = 0; i < superinterfaces.length; i++) {
481
			getAllSuperInterfaces0(superinterfaces[i], supers);
486
			supers = getAllSuperInterfaces0(superinterfaces[i], supers);
482
		}
487
		}
483
	}
488
	}
484
	IType superclass = (IType) this.classToSuperclass.get(type);
489
	IType superclass = (IType) this.classToSuperclass.get(type);
485
	if (superclass != null) {
490
	if (superclass != null) {
491
		if (supers == null)
492
			supers = new ArrayList();
486
		supers.add(superclass);
493
		supers.add(superclass);
487
		getAllSupertypes0(superclass, supers);
494
		supers = getAllSupertypes0(superclass, supers);
488
	}
495
	}
496
	return supers;
489
}
497
}
490
/**
498
/**
491
 * @see ITypeHierarchy
499
 * @see ITypeHierarchy
(-)src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java (+28 lines)
Lines 1240-1245 Link Here
1240
		types);
1240
		types);
1241
}
1241
}
1242
/**
1242
/**
1243
 * Ensures that the correct supertypes of a type exist in the type
1244
 * hierarchy.
1245
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=239096 )
1246
 */
1247
public void testGetAllSupertypes3() throws JavaModelException {
1248
	IType type = getCompilationUnit("TypeHierarchy", "src", "p1", "A.java").getType("B");
1249
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1250
	IType[] types = hierarchy.getAllSupertypes(type);
1251
	assertTypesEqual(
1252
		"Unexpected all super types of B",
1253
		"java.lang.Object\n",
1254
		types);
1255
}
1256
/**
1257
 * Ensures that the correct supertypes of a type exist in the type
1258
 * hierarchy.
1259
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=239096 )
1260
 */
1261
public void testGetAllSupertypes4() throws JavaModelException {
1262
	IType type = getCompilationUnit("TypeHierarchy", "src", "p1", "A.java").getType("B");
1263
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1264
	IType[] types = hierarchy.getAllSuperInterfaces(type);
1265
	assertTypesEqual(
1266
		"Unexpected all super interfaces of B",
1267
		"",
1268
		types);
1269
}
1270
/**
1243
 * Ensures that the correct types exist in the type
1271
 * Ensures that the correct types exist in the type
1244
 * hierarchy.
1272
 * hierarchy.
1245
 */
1273
 */

Return to bug 239096