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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/TypeHierarchyNotificationTests.java (+89 lines)
Lines 1244-1249 Link Here
1244
		h.removeTypeHierarchyChangedListener(this);
1244
		h.removeTypeHierarchyChangedListener(this);
1245
	}
1245
	}
1246
}
1246
}
1247
1248
/*
1249
 * Ensures that getting a non-primary working copy does NOT trigger
1250
 * a type hierarchy notification for the concerned hierarchy. 
1251
 * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=275805
1252
 */
1253
public void testGetWorkingCopy() throws CoreException {
1254
	ITypeHierarchy h = null;
1255
	ICompilationUnit superCopy = null;
1256
	ICompilationUnit aWorkingCopy = null;
1257
	try {
1258
		
1259
		createJavaProject("P");
1260
		createFolder("/P/p");
1261
		createFile(
1262
			"/P/p/IX.java",
1263
			"package p;\n" +
1264
			"public interface IX {\n" +
1265
			"}"
1266
		);
1267
		
1268
		createFile(
1269
				"/P/p/X.java",
1270
				"package p;\n" +
1271
				"public class X implements IX{\n" +
1272
				"}"
1273
			);
1274
1275
		superCopy = getCompilationUnit("/P/p/IX.java");
1276
		superCopy.becomeWorkingCopy(null/*no progress*/);
1277
		h = superCopy.getType("IX").newTypeHierarchy(null);		
1278
		h.addTypeHierarchyChangedListener(this);
1279
		
1280
		aWorkingCopy = getCompilationUnit("P/p/X.java").getWorkingCopy(null);
1281
		
1282
		assertTrue("Should receive NO change", !this.changeReceived);
1283
	} finally {
1284
		if (h != null)
1285
			h.removeTypeHierarchyChangedListener(this);
1286
		if (aWorkingCopy != null)
1287
			aWorkingCopy.discardWorkingCopy();
1288
		if (superCopy!= null)
1289
			superCopy.discardWorkingCopy();
1290
		
1291
		deleteProject("P");
1292
	}
1293
}
1294
1295
/*
1296
 * Ensures that working copies with different owner than that of the
1297
 * type hierarchy listener are ignored. 
1298
 * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=275805
1299
 */
1300
public void testOwner() throws CoreException {
1301
	ITypeHierarchy h = null;
1302
	ICompilationUnit aWorkingCopy = null;
1303
	ICompilationUnit anotherWorkingCopy = null;
1304
	try {
1305
		createJavaProject("P");
1306
		createFolder("/P/p");
1307
		createFile(
1308
			"/P/p/X.java",
1309
			"package p;\n" +
1310
			"public class X {\n" +
1311
			"}"
1312
		);
1313
		
1314
		aWorkingCopy = getCompilationUnit("/P/p/X.java").getWorkingCopy(null);
1315
		h = aWorkingCopy.getType("X").newTypeHierarchy(null);
1316
		h.addTypeHierarchyChangedListener(this);
1317
1318
		anotherWorkingCopy = getCompilationUnit("/P/p/X.java").getWorkingCopy(null);
1319
		anotherWorkingCopy.getBuffer().setContents(
1320
			"package p;\n" +
1321
			"public class X extends Throwable {\n" +
1322
			"}"
1323
		);
1324
		anotherWorkingCopy.commitWorkingCopy(false/*don't force*/, null/*no progress*/);
1325
		assertTrue("Should receive NO change", !this.changeReceived);
1326
	} finally {
1327
		if (h != null)
1328
			h.removeTypeHierarchyChangedListener(this);
1329
		if (aWorkingCopy != null)
1330
			aWorkingCopy.discardWorkingCopy();
1331
		if (anotherWorkingCopy != null)
1332
			anotherWorkingCopy.discardWorkingCopy();
1333
		deleteProject("P");
1334
	}
1335
}
1247
/**
1336
/**
1248
 * Make a note of the change
1337
 * Make a note of the change
1249
 */
1338
 */
(-)model/org/eclipse/jdt/internal/core/hierarchy/TypeHierarchy.java (+8 lines)
Lines 984-989 Link Here
984
protected boolean isAffectedByOpenable(IJavaElementDelta delta, IJavaElement element, int eventType) {
984
protected boolean isAffectedByOpenable(IJavaElementDelta delta, IJavaElement element, int eventType) {
985
	if (element instanceof CompilationUnit) {
985
	if (element instanceof CompilationUnit) {
986
		CompilationUnit cu = (CompilationUnit)element;
986
		CompilationUnit cu = (CompilationUnit)element;
987
		ICompilationUnit focusCU = 
988
			this.focusType != null ? this.focusType.getCompilationUnit() : null;
989
		if (focusCU != null && focusCU.getOwner() != cu.getOwner())
990
			return false;
991
		//ADDED delta arising from getWorkingCopy() should be ignored
992
		if (eventType != ElementChangedEvent.POST_RECONCILE && !cu.isPrimary() &&
993
				delta.getKind() == IJavaElementDelta.ADDED)
994
			return false;
987
		ChangeCollector collector = this.changeCollector;
995
		ChangeCollector collector = this.changeCollector;
988
		if (collector == null) {
996
		if (collector == null) {
989
		    collector = new ChangeCollector(this);
997
		    collector = new ChangeCollector(this);

Return to bug 275805