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

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/hierarchy/IndexBasedHierarchyBuilder.java (-2 / +6 lines)
Lines 521-534 Link Here
521
			// search all index references to a given supertype
521
			// search all index references to a given supertype
522
			pattern.superSimpleName = currentTypeName;
522
			pattern.superSimpleName = currentTypeName;
523
			indexManager.performConcurrentJob(job, waitingPolicy, progressMonitor == null ? null : new NullProgressMonitor() { 
523
			indexManager.performConcurrentJob(job, waitingPolicy, progressMonitor == null ? null : new NullProgressMonitor() { 
524
				// don't report progress since this is too costly for deep hierarchies
524
				// don't report progress since this is too costly for deep hierarchies (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=34078 )
525
				// just handle isCanceled() (seehttps://bugs.eclipse.org/bugs/show_bug.cgi?id=179511)
525
				// just handle isCanceled() (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=179511 )
526
				public void setCanceled(boolean value) {
526
				public void setCanceled(boolean value) {
527
					progressMonitor.setCanceled(value);
527
					progressMonitor.setCanceled(value);
528
				}
528
				}
529
				public boolean isCanceled() {
529
				public boolean isCanceled() {
530
					return progressMonitor.isCanceled();
530
					return progressMonitor.isCanceled();
531
				}
531
				}
532
				// and handle subTask(...) (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=34078 )
533
				public void subTask(String name) {
534
					progressMonitor.subTask(name);
535
				}
532
			});
536
			});
533
			if (progressMonitor != null && ++ticks <= MAXTICKS)
537
			if (progressMonitor != null && ++ticks <= MAXTICKS)
534
				progressMonitor.worked(1);
538
				progressMonitor.worked(1);
(-)src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java (+32 lines)
Lines 20-25 Link Here
20
import org.eclipse.core.runtime.Path;
20
import org.eclipse.core.runtime.Path;
21
21
22
import org.eclipse.jdt.core.*;
22
import org.eclipse.jdt.core.*;
23
import org.eclipse.jdt.core.tests.model.SearchTests.WaitingJob;
24
import org.eclipse.jdt.core.tests.model.Semaphore.TimeOutException;
23
import org.eclipse.jdt.core.tests.util.Util;
25
import org.eclipse.jdt.core.tests.util.Util;
24
26
25
import junit.framework.Test;
27
import junit.framework.Test;
Lines 1526-1531 Link Here
1526
	);
1528
	);
1527
}
1529
}
1528
/*
1530
/*
1531
 * Ensures that progress is reported while waiting for indexing to finish
1532
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=210094 )
1533
 */
1534
public void testProgressWhileIndexing() throws CoreException, TimeOutException {
1535
	final WaitingJob job = new WaitingJob();
1536
	try {
1537
		createJavaProject("P");
1538
		createFile("/P/X210094.java", "public class X210094 {}");
1539
		job.suspend();
1540
		createFile("/P/Y210094.java", "public class Y210094 {}");
1541
		IType type = getCompilationUnit("/P/X210094.java").getType("X210094");
1542
		class ProgressCounter extends TestProgressMonitor {
1543
			int count = 0;
1544
			public void subTask(String name) {
1545
				if (this.count++ == 0)
1546
					job.resume();
1547
			}
1548
			public boolean isCanceled() {
1549
				return false;
1550
			}
1551
		}
1552
		ProgressCounter counter = new ProgressCounter();
1553
		type.newTypeHierarchy(counter);
1554
		assertTrue("subTask() should be notified", counter.count > 0);
1555
	} finally {
1556
		job.resume();
1557
		deleteProject("P");
1558
	}
1559
}
1560
/*
1529
 * Ensures that a type hierarchy on a region contains all subtypes
1561
 * Ensures that a type hierarchy on a region contains all subtypes
1530
 * (regression test for bug 47743 Open type hiearchy problems [type hierarchy])
1562
 * (regression test for bug 47743 Open type hiearchy problems [type hierarchy])
1531
 */
1563
 */
(-)src/org/eclipse/jdt/core/tests/model/SearchTests.java (-44 / +49 lines)
Lines 101-110 Link Here
101
			return this.results.size();
101
			return this.results.size();
102
		}
102
		}
103
	}
103
	}
104
	class WaitingJob implements IJob {
104
	static class WaitingJob implements IJob {
105
		static final int MAX_WAIT = 30000; // wait 30s max
105
		private static final int MAX_WAIT = 30000; // wait 30s max
106
		Semaphore startingSem = new Semaphore();
106
		private Semaphore startingSem = new Semaphore();
107
		Semaphore runningSem = new Semaphore();
107
		private Semaphore runningSem = new Semaphore();
108
		public boolean belongsTo(String jobFamily) {
108
		public boolean belongsTo(String jobFamily) {
109
			return false;
109
			return false;
110
		}
110
		}
Lines 124-132 Link Here
124
		public String getJobFamily() {
124
		public String getJobFamily() {
125
			return "SearchTests.Waiting";
125
			return "SearchTests.Waiting";
126
		}
126
		}
127
		public void suspend() throws Semaphore.TimeOutException, CoreException {
128
	 		runAndSuspend(null);
129
		}
130
		public void runAndSuspend(IWorkspaceRunnable runnable) throws Semaphore.TimeOutException, CoreException {
131
	 		IndexManager indexManager = JavaModelManager.getIndexManager();
132
			indexManager.disable();
133
			if (runnable != null) {
134
				runnable.run(null);
135
			}
136
			indexManager.request(this);
137
			indexManager.enable();
138
			this.startingSem.acquire(30000); // wait for job to start (wait 30s max)
139
		}
140
141
		public void resume() {
142
			this.runningSem.release();
143
			JavaModelManager.getIndexManager().enable();
144
		}
127
	}
145
	}
128
static {
146
static {
129
	TESTS_PREFIX = "testSearchPatternValidateMatchRule";
147
	//TESTS_PREFIX = "testSearchPatternValidateMatchRule";
130
}
148
}
131
public static Test suite() {
149
public static Test suite() {
132
	return buildModelTestSuite(SearchTests.class);
150
	return buildModelTestSuite(SearchTests.class);
Lines 235-260 Link Here
235
 * a project causes another request to reindex.
253
 * a project causes another request to reindex.
236
 */
254
 */
237
public void testChangeClasspath() throws CoreException, TimeOutException {
255
public void testChangeClasspath() throws CoreException, TimeOutException {
238
	IndexManager indexManager = JavaModelManager.getIndexManager();
239
	WaitingJob job = new WaitingJob();
256
	WaitingJob job = new WaitingJob();
240
	try {
257
	try {
241
		// setup: suspend indexing and create a project (prj=src) with one cu
258
		// setup: suspend indexing and create a project (prj=src) with one cu
242
		indexManager.disable();
259
		job.runAndSuspend(new IWorkspaceRunnable() {
243
		JavaCore.run(new IWorkspaceRunnable() {
244
			public void run(IProgressMonitor monitor) throws CoreException {
260
			public void run(IProgressMonitor monitor) throws CoreException {
245
				createJavaProject("P1");
261
				JavaCore.run(new IWorkspaceRunnable() {
246
				createFile(
262
					public void run(IProgressMonitor monitor2) throws CoreException {
247
					"/P1/X.java",
263
						createJavaProject("P1");
248
					"public class X {\n" +
264
						createFile(
249
					"}"
265
							"/P1/X.java",
250
				);
266
							"public class X {\n" +
267
							"}"
268
						);
269
					}
270
				}, monitor);				
251
			}
271
			}
252
		}, null);
272
		});
253
		
254
		// add waiting job and wait for it to be executed
255
		indexManager.request(job);
256
		indexManager.enable();
257
		job.startingSem.acquire(30000); // wait for job to start (wait 30s max)
258
		
273
		
259
		// remove source folder from classpath
274
		// remove source folder from classpath
260
		IJavaProject project = getJavaProject("P1");
275
		IJavaProject project = getJavaProject("P1");
Lines 263-269 Link Here
263
			null);
278
			null);
264
			
279
			
265
		// resume waiting job
280
		// resume waiting job
266
		job.runningSem.release();
281
		job.resume();
267
		
282
		
268
		assertAllTypes(
283
		assertAllTypes(
269
			"Unexpected all types after removing source folder",
284
			"Unexpected all types after removing source folder",
Lines 271-279 Link Here
271
			""
286
			""
272
		);
287
		);
273
	} finally {
288
	} finally {
274
		job.runningSem.release();
289
		job.resume();
275
		deleteProject("P1");
290
		deleteProject("P1");
276
		indexManager.enable();
277
	}
291
	}
278
}
292
}
279
/*
293
/*
Lines 337-358 Link Here
337
 * (regression test for bug 35306 Index update request can be incorrectly handled)
351
 * (regression test for bug 35306 Index update request can be incorrectly handled)
338
 */
352
 */
339
public void testConcurrentJob() throws CoreException, InterruptedException, IOException, TimeOutException {
353
public void testConcurrentJob() throws CoreException, InterruptedException, IOException, TimeOutException {
340
	IndexManager indexManager = JavaModelManager.getIndexManager();
341
	WaitingJob job = new WaitingJob();
354
	WaitingJob job = new WaitingJob();
342
	try {
355
	try {
343
		// setup: suspend indexing and create a project with one empty jar on its classpath
356
		// setup: suspend indexing and create a project with one empty jar on its classpath
344
		indexManager.disable();
357
		job.runAndSuspend(new IWorkspaceRunnable() {
345
		JavaCore.run(new IWorkspaceRunnable() {
346
			public void run(IProgressMonitor monitor) throws CoreException {
358
			public void run(IProgressMonitor monitor) throws CoreException {
347
				createJavaProject("P1", new String[] {}, new String[] {"/P1/jclMin.jar"}, "bin");
359
				JavaCore.run(new IWorkspaceRunnable() {
348
				createFile("/P1/jclMin.jar", EMPTY_JAR);
360
					public void run(IProgressMonitor monitor2) throws CoreException {
361
						createJavaProject("P1", new String[] {}, new String[] {"/P1/jclMin.jar"}, "bin");
362
						createFile("/P1/jclMin.jar", EMPTY_JAR);
363
					}
364
				}, monitor);
349
			}
365
			}
350
		}, null);
366
		});
351
		
352
		// add waiting job and wait for it to be executed
353
		indexManager.request(job);
354
		indexManager.enable();
355
		job.startingSem.acquire(30000); // wait for job to start (wait 30s max)
356
				
367
				
357
		final IJavaProject project = getJavaProject("P1");
368
		final IJavaProject project = getJavaProject("P1");
358
			
369
			
Lines 396-402 Link Here
396
		getFile("/P1/jclMin.jar").setContents(new FileInputStream(getExternalJCLPathString()), IResource.NONE, null);
407
		getFile("/P1/jclMin.jar").setContents(new FileInputStream(getExternalJCLPathString()), IResource.NONE, null);
397
			
408
			
398
		// resume waiting job
409
		// resume waiting job
399
		job.runningSem.release();
410
		job.resume();
400
		
411
		
401
		// wait for concurrent job to finish
412
		// wait for concurrent job to finish
402
		thread.join(10000); // 10s max
413
		thread.join(10000); // 10s max
Lines 404-412 Link Here
404
		assertTrue("Failed to get all types", success[0]);
415
		assertTrue("Failed to get all types", success[0]);
405
				
416
				
406
	} finally {
417
	} finally {
407
		job.runningSem.release();
418
		job.resume();
408
		deleteProject("P1");
419
		deleteProject("P1");
409
		indexManager.enable();
410
	}
420
	}
411
}
421
}
412
/*
422
/*
Lines 415-428 Link Here
415
 * (regression test for bug 33571 SearchEngine.searchAllTypeNames: NPE when passing null as progress monitor)
425
 * (regression test for bug 33571 SearchEngine.searchAllTypeNames: NPE when passing null as progress monitor)
416
 */
426
 */
417
 public void testNullProgressMonitor() throws CoreException, TimeOutException {
427
 public void testNullProgressMonitor() throws CoreException, TimeOutException {
418
	IndexManager indexManager = JavaModelManager.getIndexManager();
419
	WaitingJob job = new WaitingJob();
428
	WaitingJob job = new WaitingJob();
420
 	try {
429
 	try {
421
 		// add waiting job and wait for it to be executed
430
 		job.suspend();
422
		indexManager.disable();
423
		indexManager.request(job);
424
		indexManager.enable();
425
		job.startingSem.acquire(30000); // wait for job to start (wait 30s max)
426
		
431
		
427
		// query all type names with a null progress monitor
432
		// query all type names with a null progress monitor
428
		boolean operationCanceled = false;
433
		boolean operationCanceled = false;
Lines 437-443 Link Here
437
		}
442
		}
438
		assertTrue("Should throw an OperationCanceledException", operationCanceled);
443
		assertTrue("Should throw an OperationCanceledException", operationCanceled);
439
 	} finally {
444
 	} finally {
440
 		job.runningSem.release();
445
 		job.resume();
441
 	}
446
 	}
442
 }
447
 }
443
 /*
448
 /*

Return to bug 210094