View | Details | Raw Unified | Return to bug 136095 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java (-8 / +77 lines)
Lines 1000-1006 Link Here
1000
/*
1000
/*
1001
 * Ensures that a hierarchy on a generic type can be opened
1001
 * Ensures that a hierarchy on a generic type can be opened
1002
 */
1002
 */
1003
public void testGeneric1() throws JavaModelException {
1003
public void testGeneric01() throws JavaModelException {
1004
	IType type = getCompilationUnit("/TypeHierarchy15/src/X.java").getType("X");
1004
	IType type = getCompilationUnit("/TypeHierarchy15/src/X.java").getType("X");
1005
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1005
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1006
	assertHierarchyEquals(
1006
	assertHierarchyEquals(
Lines 1018-1024 Link Here
1018
/*
1018
/*
1019
 * Ensures that a hierarchy on a generic type can be opened
1019
 * Ensures that a hierarchy on a generic type can be opened
1020
 */
1020
 */
1021
public void testGeneric2() throws JavaModelException {
1021
public void testGeneric02() throws JavaModelException {
1022
	IType type = getPackageFragmentRoot("/TypeHierarchy15/lib15.jar").getPackageFragment("util").getClassFile("ArrayList.class").getType();
1022
	IType type = getPackageFragmentRoot("/TypeHierarchy15/lib15.jar").getPackageFragment("util").getClassFile("ArrayList.class").getType();
1023
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1023
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1024
	assertHierarchyEquals(
1024
	assertHierarchyEquals(
Lines 1036-1042 Link Here
1036
/*
1036
/*
1037
 * Ensures that a hierarchy on a generic type can be opened
1037
 * Ensures that a hierarchy on a generic type can be opened
1038
 */
1038
 */
1039
public void testGeneric3() throws JavaModelException {
1039
public void testGeneric03() throws JavaModelException {
1040
	IType type = getCompilationUnit("/TypeHierarchy15/src/Y.java").getType("Y");
1040
	IType type = getCompilationUnit("/TypeHierarchy15/src/Y.java").getType("Y");
1041
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1041
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1042
	assertHierarchyEquals(
1042
	assertHierarchyEquals(
Lines 1055-1061 Link Here
1055
 * Ensures that a super type hierarchy on a generic type can be opened
1055
 * Ensures that a super type hierarchy on a generic type can be opened
1056
 * (regression test for bug 72348 [1.5][Type Hierarchy] Super type hierarchy of class extending generic type is empty)
1056
 * (regression test for bug 72348 [1.5][Type Hierarchy] Super type hierarchy of class extending generic type is empty)
1057
 */
1057
 */
1058
public void testGeneric4() throws JavaModelException {
1058
public void testGeneric04() throws JavaModelException {
1059
	IType type = getCompilationUnit("/TypeHierarchy15/src/X.java").getType("X");
1059
	IType type = getCompilationUnit("/TypeHierarchy15/src/X.java").getType("X");
1060
	ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);
1060
	ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null);
1061
	assertHierarchyEquals(
1061
	assertHierarchyEquals(
Lines 1075-1081 Link Here
1075
 * Ensures that a hierarchy on a generic interface can be opened
1075
 * Ensures that a hierarchy on a generic interface can be opened
1076
 * (regression test for bug 82004 [model][5.0] 3.1M4 type hierarchy for generic interface)
1076
 * (regression test for bug 82004 [model][5.0] 3.1M4 type hierarchy for generic interface)
1077
 */
1077
 */
1078
public void testGeneric5() throws JavaModelException {
1078
public void testGeneric05() throws JavaModelException {
1079
	IType type = getCompilationUnit("/TypeHierarchy15/src/I.java").getType("I");
1079
	IType type = getCompilationUnit("/TypeHierarchy15/src/I.java").getType("I");
1080
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1080
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1081
	assertHierarchyEquals(
1081
	assertHierarchyEquals(
Lines 1090-1096 Link Here
1090
 * Ensure that the key of a binary type in a hierarchy is correct when this type is not part of the Java model cache.
1090
 * Ensure that the key of a binary type in a hierarchy is correct when this type is not part of the Java model cache.
1091
 * (regression test for bug 93854 IAE in Util.scanTypeSignature when scanning a signature retrieved from a binding key)
1091
 * (regression test for bug 93854 IAE in Util.scanTypeSignature when scanning a signature retrieved from a binding key)
1092
 */
1092
 */
1093
public void testGeneric6() throws CoreException {
1093
public void testGeneric06() throws CoreException {
1094
	getJavaProject("TypeHierarcht15").close();
1094
	getJavaProject("TypeHierarcht15").close();
1095
	IType type = getClassFile("TypeHierarchy15","lib15.jar", "util", "AbstractList.class").getType();
1095
	IType type = getClassFile("TypeHierarchy15","lib15.jar", "util", "AbstractList.class").getType();
1096
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1096
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
Lines 1101-1107 Link Here
1101
 * Ensures that a hierarchy on a generic type that is extended using a member as a type parameter can be opened
1101
 * Ensures that a hierarchy on a generic type that is extended using a member as a type parameter can be opened
1102
 * (regression test for bug 99606 Subtype not found if parameterized on inner class)
1102
 * (regression test for bug 99606 Subtype not found if parameterized on inner class)
1103
 */
1103
 */
1104
public void testGeneric7() throws JavaModelException {
1104
public void testGeneric07() throws JavaModelException {
1105
	IType type = getCompilationUnit("/TypeHierarchy15/src/Y99606.java").getType("Y99606");
1105
	IType type = getCompilationUnit("/TypeHierarchy15/src/Y99606.java").getType("Y99606");
1106
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1106
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1107
	assertHierarchyEquals(
1107
	assertHierarchyEquals(
Lines 1114-1120 Link Here
1114
	);
1114
	);
1115
}
1115
}
1116
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=108740
1116
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=108740
1117
public void testGeneric8() throws JavaModelException {
1117
public void testGeneric08() throws JavaModelException {
1118
	IType type = getCompilationUnit("/TypeHierarchy15/src/D108740.java").getType("D108740");
1118
	IType type = getCompilationUnit("/TypeHierarchy15/src/D108740.java").getType("D108740");
1119
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1119
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1120
	assertHierarchyEquals(
1120
	assertHierarchyEquals(
Lines 1127-1132 Link Here
1127
		hierarchy
1127
		hierarchy
1128
	);
1128
	);
1129
}
1129
}
1130
/*
1131
 * Ensures that a hierarchy is where a type inherits conflicting paratemerized types is still correctly reported
1132
 * (regression test for bug 136095 Type Hierarchy incomplete with illegally parameterized superinterfaces)
1133
 */
1134
public void testGeneric09() throws CoreException {
1135
	try {
1136
		createFile(
1137
			"/TypeHierarchy15/src/I1_136095.java", 
1138
			"public interface I1_136095<E> {\n" + 
1139
			"}"
1140
		);
1141
		createFile(
1142
			"/TypeHierarchy15/src/I2_136095.java", 
1143
			"public interface I2_136095 extends I1_136095<String>{\n" + 
1144
			"}"
1145
		);
1146
		createFile(
1147
			"/TypeHierarchy15/src/X_136095.java", 
1148
			"public abstract class X_136095 implements I1_136095<Integer>, I2_136095 {\n" + 
1149
			"}"
1150
		);
1151
		IType type = getCompilationUnit("/TypeHierarchy15/src/X_136095.java").getType("X_136095");
1152
		ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1153
		assertHierarchyEquals(
1154
			"Focus: X_136095 [in X_136095.java [in <default> [in src [in TypeHierarchy15]]]]\n" + 
1155
			"Super types:\n" + 
1156
			"  I1_136095 [in I1_136095.java [in <default> [in src [in TypeHierarchy15]]]]\n" + 
1157
			"  I2_136095 [in I2_136095.java [in <default> [in src [in TypeHierarchy15]]]]\n" + 
1158
			"    I1_136095 [in I1_136095.java [in <default> [in src [in TypeHierarchy15]]]]\n" + 
1159
			"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString("1.5") + " [in TypeHierarchy15]]]]\n" + 
1160
			"Sub types:\n",
1161
			hierarchy
1162
		);
1163
	} finally {
1164
		deleteFile("/TypeHierarchy15/src/I1_136095.java");
1165
		deleteFile("/TypeHierarchy15/src/I2_136095.java");
1166
		deleteFile("/TypeHierarchy15/src/X_136095.java");
1167
	}
1168
}
1130
/**
1169
/**
1131
 * Ensures the correctness of all classes in a type hierarchy based on a region.
1170
 * Ensures the correctness of all classes in a type hierarchy based on a region.
1132
 */
1171
 */
Lines 1522-1525 Link Here
1522
		project.setRawClasspath(originalClasspath, null);
1561
		project.setRawClasspath(originalClasspath, null);
1523
	}
1562
	}
1524
}
1563
}
1564
/*
1565
 * Ensures that a hierarchy where the super type is not visible can still be constructed.
1566
 */
1567
public void testVisibility1() throws JavaModelException {
1568
	IType type = getCompilationUnit("/TypeHierarchy/src/q6/Y.java").getType("Y");
1569
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1570
	assertHierarchyEquals(
1571
		"Focus: Y [in Y.java [in q6 [in src [in TypeHierarchy]]]]\n" + 
1572
		"Super types:\n" + 
1573
		"  NonVisibleClass [in X.java [in q5 [in src [in TypeHierarchy]]]]\n" + 
1574
		"    Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + " [in TypeHierarchy]]]]\n" + 
1575
		"Sub types:\n",
1576
		hierarchy
1577
	);
1578
}
1579
/*
1580
 * Ensures that a hierarchy where the super interface is not visible can still be constructed.
1581
 */
1582
public void testVisibility2() throws JavaModelException {
1583
	IType type = getCompilationUnit("/TypeHierarchy/src/q6/Z.java").getType("Z");
1584
	ITypeHierarchy hierarchy = type.newTypeHierarchy(null);
1585
	assertHierarchyEquals(
1586
		"Focus: Z [in Z.java [in q6 [in src [in TypeHierarchy]]]]\n" + 
1587
		"Super types:\n" + 
1588
		"  NonVisibleInterface [in X.java [in q5 [in src [in TypeHierarchy]]]]\n" + 
1589
		"  Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + " [in TypeHierarchy]]]]\n" + 
1590
		"Sub types:\n",
1591
		hierarchy
1592
	);
1593
}
1525
}
1594
}
(-)workspace/TypeHierarchy/src/q6/Y.java (+3 lines)
Added Link Here
1
package q6;
2
public class Y extends q5.NonVisibleClass {
3
}
(-)workspace/TypeHierarchy/src/q6/Z.java (+3 lines)
Added Link Here
1
package q6;
2
public class Z implements q5.NonVisibleInterface {
3
}
(-)workspace/TypeHierarchy/src/q5/X.java (+7 lines)
Added Link Here
1
package q5;
2
public class X {
3
}
4
class NonVisibleClass {
5
}
6
interface NonVisibleInterface {
7
}
(-)model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java (+38 lines)
Lines 155-160 Link Here
155
 */
155
 */
156
private IType findSuperClass(IGenericType type, ReferenceBinding typeBinding) {
156
private IType findSuperClass(IGenericType type, ReferenceBinding typeBinding) {
157
	ReferenceBinding superBinding = typeBinding.superclass();
157
	ReferenceBinding superBinding = typeBinding.superclass();
158
	
159
	// check if the super binding was replaced with the java.lang.Object binding (because of a visibility problem for example)
160
	ClassScope scope;
161
	if (typeBinding instanceof SourceTypeBinding && (scope = ((SourceTypeBinding) typeBinding).scope) != null) {
162
		TypeDeclaration typeDeclaration = scope.referenceContext;
163
		TypeReference superclassRef = typeDeclaration == null ? null : typeDeclaration.superclass;
164
		TypeBinding superclass = superclassRef == null ? null : superclassRef.resolvedType;
165
		if (superclass instanceof ProblemReferenceBinding) {
166
			superclass = ((ProblemReferenceBinding) superclass).closestMatch;
167
			if (superclass != null) 
168
				((SourceTypeBinding) typeBinding).superclass = superBinding = (ReferenceBinding) superclass;
169
		}
170
	}
171
	
158
	if (superBinding != null) {
172
	if (superBinding != null) {
159
		superBinding = (ReferenceBinding) superBinding.erasure();
173
		superBinding = (ReferenceBinding) superBinding.erasure();
160
		if (superBinding.id == TypeIds.T_JavaLangObject && typeBinding.isHierarchyInconsistent()) {
174
		if (superBinding.id == TypeIds.T_JavaLangObject && typeBinding.isHierarchyInconsistent()) {
Lines 233-238 Link Here
233
	}
247
	}
234
	
248
	
235
	ReferenceBinding[] interfaceBindings = typeBinding.superInterfaces();
249
	ReferenceBinding[] interfaceBindings = typeBinding.superInterfaces();
250
	
251
	// check if bindings were removed while resolving (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=136095)
252
	ClassScope scope;
253
	if (typeBinding instanceof SourceTypeBinding && (scope = ((SourceTypeBinding) typeBinding).scope) != null) {
254
		TypeDeclaration typeDeclaration = scope.referenceContext;
255
		TypeReference[] superInterfaces = typeDeclaration == null ? null : typeDeclaration.superInterfaces;
256
		int length;
257
		if (superInterfaces != null && (length = superInterfaces.length) > interfaceBindings.length) {
258
			
259
			interfaceBindings = new ReferenceBinding[length];
260
			int index = 0;
261
			for (int i = 0; i < length; i++) {
262
				ReferenceBinding superInterface = (ReferenceBinding) superInterfaces[i].resolvedType;
263
				if (superInterface instanceof ProblemReferenceBinding)
264
					superInterface = ((ProblemReferenceBinding) superInterface).closestMatch;
265
				if (superInterface != null)
266
					interfaceBindings[index++] = superInterface;
267
			}
268
			if (index < length)
269
				System.arraycopy(interfaceBindings, 0, interfaceBindings = new ReferenceBinding[index], 0 , index);
270
			((SourceTypeBinding) typeBinding).superInterfaces = interfaceBindings;
271
		}
272
	}
273
	
236
	int bindingIndex = 0;
274
	int bindingIndex = 0;
237
	int bindingLength = interfaceBindings == null ? 0 : interfaceBindings.length;
275
	int bindingLength = interfaceBindings == null ? 0 : interfaceBindings.length;
238
	int length = superInterfaceNames == null ? 0 : superInterfaceNames.length;
276
	int length = superInterfaceNames == null ? 0 : superInterfaceNames.length;

Return to bug 136095