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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/CompletionTests2.java (+82 lines)
Lines 5144-5147 Link Here
5144
		JavaCore.setOptions(oldOptions);
5144
		JavaCore.setOptions(oldOptions);
5145
	}
5145
	}
5146
}
5146
}
5147
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=281598
5148
public void testBug281598() throws Exception {
5149
5150
	try {
5151
		// Create project and jar
5152
		IJavaProject p = createJavaProject("P", new String[] {"src"}, new String[]{"JCL_LIB", "/P/empty.jar"}, "bin");
5153
		createFile("/P/empty.jar", "");
5154
		refresh(p);
5155
		waitUntilIndexesReady();
5156
5157
		// Create working copy
5158
		this.workingCopies = new ICompilationUnit[1];
5159
		this.workingCopies[0] = getWorkingCopy(
5160
				"/P/src/test/Test.java",
5161
				"package test;"+
5162
				"public class Test {\n" +
5163
				"  void foo() {\n" +
5164
				"    sys\n" +
5165
				"  }\n" +
5166
				"}");
5167
5168
		// do completion
5169
		CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true);
5170
		requestor.allowAllRequiredProposals();
5171
		NullProgressMonitor monitor = new NullProgressMonitor() {
5172
			long start = System.currentTimeMillis();
5173
5174
			public boolean isCanceled() {
5175
	            long time = System.currentTimeMillis() - this.start;
5176
	            return time > 1000; // cancel after 1 sec
5177
            }
5178
			
5179
		};
5180
5181
	    String str = this.workingCopies[0].getSource();
5182
	    String completeBehind = "sys";
5183
	    int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
5184
	    this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor);
5185
	    
5186
	    // no results expected, just verify that no cancel operation exception occurs...
5187
	    assertResults("", requestor.getResults());
5188
	} finally {
5189
		deleteProject("P");
5190
	}
5191
}
5192
public void testBug281598b() throws Exception {
5193
	try {
5194
		// Create project and jar
5195
		IJavaProject p = createJavaProject("P", new String[] {"src"}, new String[]{"JCL_LIB", "/P/empty.jar"}, "bin");
5196
		createFile("/P/empty.jar", "");
5197
		refresh(p);
5198
		waitUntilIndexesReady();
5199
5200
		// Create working copy
5201
		this.workingCopies = new ICompilationUnit[1];
5202
		this.workingCopies[0] = getWorkingCopy(
5203
				"/P/src/test/Test.java",
5204
				"package test;"+
5205
				"public class Test {\n" +
5206
				"  void foo() {\n" +
5207
				"    new String\n" +
5208
				"  }\n" +
5209
				"}");
5210
5211
		// do completion
5212
		CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true);
5213
		requestor.allowAllRequiredProposals();
5214
		NullProgressMonitor monitor = new NullProgressMonitor();
5215
5216
	    String str = this.workingCopies[0].getSource();
5217
	    String completeBehind = "String";
5218
	    int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
5219
	    this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor);
5220
	    
5221
	    assertResults(
5222
			"String[CONSTRUCTOR_INVOCATION]{(), Ljava.lang.String;, ()V, String, null, "+(R_DEFAULT+R_RESOLVED+R_INTERESTING+R_CASE+R_EXACT_NAME+R_UNQUALIFIED+R_NON_RESTRICTED)+"}\n" +
5223
			"   String[TYPE_REF]{String, java.lang, Ljava.lang.String;, null, null, "+(R_DEFAULT+R_RESOLVED+R_INTERESTING+R_CASE+R_EXACT_NAME+R_UNQUALIFIED+R_NON_RESTRICTED)+"}",
5224
			requestor.getResults());
5225
	} finally {
5226
		deleteProject("P");
5227
	}
5228
}
5147
}
5229
}
(-)model/org/eclipse/jdt/internal/core/SearchableEnvironment.java (-42 / +35 lines)
Lines 25-30 Link Here
25
import org.eclipse.jdt.internal.core.search.BasicSearchEngine;
25
import org.eclipse.jdt.internal.core.search.BasicSearchEngine;
26
import org.eclipse.jdt.internal.core.search.IRestrictedAccessConstructorRequestor;
26
import org.eclipse.jdt.internal.core.search.IRestrictedAccessConstructorRequestor;
27
import org.eclipse.jdt.internal.core.search.IRestrictedAccessTypeRequestor;
27
import org.eclipse.jdt.internal.core.search.IRestrictedAccessTypeRequestor;
28
import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
28
import org.eclipse.jdt.internal.core.util.Util;
29
import org.eclipse.jdt.internal.core.util.Util;
29
30
30
/**
31
/**
Lines 407-437 Link Here
407
			int matchRule = SearchPattern.R_PREFIX_MATCH;
408
			int matchRule = SearchPattern.R_PREFIX_MATCH;
408
			if (camelCaseMatch) matchRule |= SearchPattern.R_CAMELCASE_MATCH;
409
			if (camelCaseMatch) matchRule |= SearchPattern.R_CAMELCASE_MATCH;
409
			if (monitor != null) {
410
			if (monitor != null) {
410
				found : while (true) { //the loop will finish if the search request ends or is cancelled
411
				IndexManager indexManager = JavaModelManager.getIndexManager();
412
				while (indexManager.awaitingJobsCount() > 0) {
411
					try {
413
					try {
412
						new BasicSearchEngine(this.workingCopies).searchAllTypeNames(
414
						Thread.sleep(50); // indexes are not ready, sleep 50ms...
413
							qualification,
415
					} catch (InterruptedException e) {
414
							SearchPattern.R_EXACT_MATCH,
416
						// Do nothing
415
							simpleName,
417
					}
416
							matchRule, // not case sensitive
418
					if (monitor.isCanceled()) {
417
							searchFor,
419
						throw new OperationCanceledException();
418
							getSearchScope(),
419
							typeRequestor,
420
							CANCEL_IF_NOT_READY_TO_SEARCH,
421
							progressMonitor);
422
						break found;
423
					} catch (OperationCanceledException e) {
424
						if (monitor.isCanceled()) {
425
							throw e;
426
						} else {
427
							try {
428
								Thread.sleep(50); // indexes are not ready. sleep 50ms and retry the search request
429
							} catch (InterruptedException e1) {
430
								// Do nothing
431
							}
432
						}
433
					}
420
					}
434
				}
421
				}
422
				new BasicSearchEngine(this.workingCopies).searchAllTypeNames(
423
					qualification,
424
					SearchPattern.R_EXACT_MATCH,
425
					simpleName,
426
					matchRule, // not case sensitive
427
					searchFor,
428
					getSearchScope(),
429
					typeRequestor,
430
					FORCE_IMMEDIATE_SEARCH,
431
					progressMonitor);
435
			} else {
432
			} else {
436
				try {
433
				try {
437
					new BasicSearchEngine(this.workingCopies).searchAllTypeNames(
434
					new BasicSearchEngine(this.workingCopies).searchAllTypeNames(
Lines 562-590 Link Here
562
			int matchRule = SearchPattern.R_PREFIX_MATCH;
559
			int matchRule = SearchPattern.R_PREFIX_MATCH;
563
			if (camelCaseMatch) matchRule |= SearchPattern.R_CAMELCASE_MATCH;
560
			if (camelCaseMatch) matchRule |= SearchPattern.R_CAMELCASE_MATCH;
564
			if (monitor != null) {
561
			if (monitor != null) {
565
				found : while (true) { //the loop will finish if the search request ends or is cancelled
562
				IndexManager indexManager = JavaModelManager.getIndexManager();
563
				while (indexManager.awaitingJobsCount() > 0) {
566
					try {
564
					try {
567
						new BasicSearchEngine(this.workingCopies).searchAllConstructorDeclarations(
565
						Thread.sleep(50); // indexes are not ready,  sleep 50ms...
568
								qualification,
566
					} catch (InterruptedException e) {
569
								simpleName,
567
						// Do nothing
570
								matchRule,
568
					}
571
								getSearchScope(),
569
					if (monitor.isCanceled()) {
572
								constructorRequestor,
570
						throw new OperationCanceledException();
573
								CANCEL_IF_NOT_READY_TO_SEARCH,
574
								progressMonitor);
575
						break found;
576
					} catch (OperationCanceledException e) {
577
						if (monitor.isCanceled()) {
578
							throw e;
579
						} else {
580
							try {
581
								Thread.sleep(50); // indexes are not ready. sleep 50ms and retry the search request
582
							} catch (InterruptedException e1) {
583
								// Do nothing
584
							}
585
						}
586
					}
571
					}
587
				}
572
				}
573
				new BasicSearchEngine(this.workingCopies).searchAllConstructorDeclarations(
574
						qualification,
575
						simpleName,
576
						matchRule,
577
						getSearchScope(),
578
						constructorRequestor,
579
						FORCE_IMMEDIATE_SEARCH,
580
						progressMonitor);
588
			} else {
581
			} else {
589
				try {
582
				try {
590
					new BasicSearchEngine(this.workingCopies).searchAllConstructorDeclarations(
583
					new BasicSearchEngine(this.workingCopies).searchAllConstructorDeclarations(

Return to bug 281598