Skip to main content
summaryrefslogtreecommitdiffstats
blob: d1c8c507ea9cfc30b7ef14c42451667931be2eb6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
/*******************************************************************************
 * Copyright (c) 2000, 2015 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.core.tests.model;

import junit.framework.Test;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.search.*;
public class WorkingCopySearchTests extends JavaSearchTests {
	ICompilationUnit workingCopy;

	public WorkingCopySearchTests(String name) {
		super(name);
	}
	public static Test suite() {
		return buildModelTestSuite(WorkingCopySearchTests.class);
	}
	// Use this static initializer to specify subset for tests
	// All specified tests which do not belong to the class are skipped...
	static {
//		TESTS_PREFIX =  "testAllTypeNames";
//		TESTS_NAMES = new String[] { "testAllTypeNamesBug98684" };
//		TESTS_NUMBERS = new int[] { 8 };
//		TESTS_RANGE = new int[] { -1, -1 };
	}

	/**
	 * Get a new working copy.
	 */
	protected void setUp() throws Exception {
		super.setUp();
		try {
			this.workingCopy = this.getCompilationUnit("JavaSearch", "src", "wc", "X.java").getWorkingCopy(null);
		} catch (JavaModelException e) {
			e.printStackTrace();
		}
	}

	/**
	 * Destroy the working copy.
	 */
	protected void tearDown() throws Exception {
		this.workingCopy.discardWorkingCopy();
		this.workingCopy = null;
		super.tearDown();
	}

	/**
	 * Hierarchy scope on a working copy test.
	 */
	public void testHierarchyScopeOnWorkingCopy() throws CoreException {
		ICompilationUnit unit = this. getCompilationUnit("JavaSearch", "src", "a9", "A.java");
		ICompilationUnit copy = unit.getWorkingCopy(null);
		try {
			IType type = copy.getType("A");
			IJavaSearchScope scope = SearchEngine.createHierarchyScope(type);
			assertTrue("a9.A should be included in hierarchy scope", scope.encloses(type));
			assertTrue("a9.C should be included in hierarchy scope", scope.encloses(copy.getType("C")));
			assertTrue("a9.B should be included in hierarchy scope", scope.encloses(copy.getType("B")));
			IPath path = unit.getUnderlyingResource().getFullPath();
			assertTrue("a9/A.java should be included in hierarchy scope", scope.encloses(path.toString()));
		} finally {
			copy.discardWorkingCopy();
		}
	}

	/**
	 * Type declaration in a working copy test.
	 * A new type is added in the working copy only.
	 */
	public void testAddNewType() throws CoreException {
		this.workingCopy.createType(
			"class NewType {\n" +
			"}",
			null,
			false,
			null);

		IJavaSearchScope scope =
			SearchEngine.createJavaSearchScope(
				new IJavaElement[] {this.workingCopy.getParent()});
	//	JavaSearchResultCollector resultCollector = new JavaSearchResultCollector();
		SearchPattern pattern = SearchPattern.createPattern(
			"NewType",
			TYPE,
			DECLARATIONS,
			SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).search(
			pattern,
			new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
			scope,
			this.resultCollector,
			null);
		assertSearchResults(
			"src/wc/X.java wc.NewType [NewType]",
			this.resultCollector);
	}

	/*
	 * Search all type names in working copies test.
	 * (Regression test for bug 40793 Primary working copies: Type search does not find type in modified CU)
	 */
	public void testAllTypeNames1() throws CoreException {
		this.workingCopy.getBuffer().setContents(
			"package wc;\n" +
			"public class Y {\n" +
			"  interface I {\n" +
			"  }\n" +
			"}"
		);
		this.workingCopy.makeConsistent(null);
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {this.workingCopy.getParent()});
		SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllTypeNames(
			null,
			SearchPattern.R_EXACT_MATCH,
			null,
			SearchPattern.R_PATTERN_MATCH, // case insensitive
			TYPE,
			scope,
			requestor,
			IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
			null
		);
		assertSearchResults(
			"Unexpected all type names",
			"wc.Y\n" +
			"wc.Y$I",
			requestor);
	}

	/*
	 * Search all type names in working copies test (without reconciling working copies).
	 * (Regression test for bug 40793 Primary working copies: Type search does not find type in modified CU)
	 */
	public void testAllTypeNames2() throws CoreException {
		this.workingCopy.getBuffer().setContents(
			"package wc;\n" +
			"public class Y {\n" +
			"  interface I {\n" +
			"  }\n" +
			"}"
		);
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {this.workingCopy.getParent()});
		SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllTypeNames(
			null,
			SearchPattern.R_EXACT_MATCH,
			null,
			SearchPattern.R_PATTERN_MATCH, // case insensitive
			TYPE,
			scope,
			requestor,
			IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
			null
		);
		assertSearchResults(
			"Unexpected all type names",
			"wc.Y\n" +
			"wc.Y$I",
			requestor);
	}

	/*
	 * Search all type names with a prefix in a primary working copy.
	 * (regression test for bug 44884 Wrong list displayed while code completion)
	 */
	public void testAllTypeNames3() throws CoreException {
		ICompilationUnit wc = getCompilationUnit("/JavaSearch/wc3/X44884.java");
		try {
			wc.becomeWorkingCopy(null);
			wc.getBuffer().setContents(
				"package wc3;\n" +
				"public class X44884 {\n" +
				"}\n" +
				"interface I {\n" +
				"}"
			);
			wc.makeConsistent(null);

			IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {wc.getParent()});
			SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
			new SearchEngine().searchAllTypeNames(
				"wc3".toCharArray(),
				SearchPattern.R_EXACT_MATCH,
				"X".toCharArray(),
				SearchPattern.R_PREFIX_MATCH, // case insensitive
				TYPE,
				scope,
				requestor,
				IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
				null
			);
			assertSearchResults(
				"Unexpected all type names",
				"wc3.X44884",
				requestor);
		} finally {
			wc.discardWorkingCopy();
		}
	}

	/*
	 * Search all type names with a prefix in a primary working copy (without reconciling it).
	 * (regression test for bug 44884 Wrong list displayed while code completion)
	 */
	public void testAllTypeNames4() throws CoreException {
		ICompilationUnit wc = getCompilationUnit("/JavaSearch/wc3/X44884.java");
		try {
			wc.becomeWorkingCopy(null);
			wc.getBuffer().setContents(
				"package wc3;\n" +
				"public class X44884 {\n" +
				"}\n" +
				"interface I {\n" +
				"}"
			);

			IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {wc.getParent()});
			SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
			new SearchEngine().searchAllTypeNames(
				"wc3".toCharArray(),
				SearchPattern.R_EXACT_MATCH,
				"X".toCharArray(),
				SearchPattern.R_PREFIX_MATCH, // case insensitive
				TYPE,
				scope,
				requestor,
				IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
				null
			);
			assertSearchResults(
				"Unexpected all type names",
				"wc3.X44884",
				requestor);
		} finally {
			wc.discardWorkingCopy();
		}
	}

	/**
	 * Bug 99915: [search] Open Type: not yet saved types not found if case-sensitve name is entered
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=99915"
	 */
	public void testAllTypeNamesBug99915() throws CoreException {
		this.workingCopy.getBuffer().setContents(
			"package wc;\n" +
			"public class X {\n" +
			"}\n"  +
			" class AAABBB {}\n" +
			" class BBBCCC {}\n"
		);
		this.workingCopy.makeConsistent(null);
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {this.workingCopy.getParent()});
		SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllTypeNames(
			null,
			SearchPattern.R_EXACT_MATCH,
			"A*".toCharArray(),
			SearchPattern.R_PATTERN_MATCH, // case insensitive
			TYPE,
			scope,
			requestor,
			IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
			null
		);
		assertSearchResults(
			"Unexpected all type names",
			"wc.AAABBB",
			requestor);
	}

	/**
	 * Bug 98684: [search] Code assist shown inner types of unreleated project
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=98684"
	 */
	public void testAllTypeNamesBug98684() throws CoreException {
		try {
			IJavaProject[] projects = new IJavaProject[2];
			projects[0] = createJavaProject("P1");
			projects[1] = createJavaProject("P2");
			this.workingCopies = new ICompilationUnit[2];
			this.workingCopies[0] = getWorkingCopy("/P1/p1/A1.java",
				"package p1;\n" +
				"public class A1 {\n" +
				"	public static class A1Inner1 {}" +
				"	public static class A1Inner2 {}" +
				"}"
			);
			this.workingCopies[1] = getWorkingCopy("/P2/p2/A2.java",
				"package p2;\n" +
				"public class A2 {\n" +
				"	public static class A2Inner1 {}" +
				"	public static class A2Inner2 {}" +
				"}"
			);
			TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
			IJavaSearchScope scope = 	SearchEngine.createJavaSearchScope(new IJavaElement[] { projects[1] });
			new SearchEngine(this.workingCopies).searchAllTypeNames(
				null,
				SearchPattern.R_EXACT_MATCH,
				"A".toCharArray(),
				SearchPattern.R_PREFIX_MATCH,
				TYPE,
				scope,
				requestor,
				IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
				null
			);
			assertSearchResults(
				"Unexpected all type names",
				"p2.A2\n" +
				"p2.A2$A2Inner1\n" +
				"p2.A2$A2Inner2",
				requestor);
		}
		finally {
			deleteProject("P1");
			deleteProject("P2");
		}
	}

	/**
	 * Declaration of referenced types test.
	 * (Regression test for bug 5355 search: NPE in searchDeclarationsOfReferencedTypes  )
	 */
	public void testDeclarationOfReferencedTypes() throws CoreException {
		IMethod method = this.workingCopy.getType("X").createMethod(
			"public void foo() {\n" +
			"  X x = new X();\n" +
			"}",
			null,
			true,
			null);
	//	JavaSearchResultCollector resultCollector = new JavaSearchResultCollector();
		searchDeclarationsOfReferencedTypes(
			method,
			this.resultCollector
		);
		assertSearchResults(
			"src/wc/X.java wc.X [X]",
			this.resultCollector);
	}

	/**
	 * Type declaration in a working copy test.
	 * A type is moved from one working copy to another.
	 */
	public void testMoveType() throws CoreException {

		// move type X from working copy in one package to a working copy in another package
		ICompilationUnit workingCopy1 = getCompilationUnit("JavaSearch", "src", "wc1", "X.java").getWorkingCopy(null);
		ICompilationUnit workingCopy2 = getCompilationUnit("JavaSearch", "src", "wc2", "Y.java").getWorkingCopy(null);

		try {
			workingCopy1.getType("X").move(workingCopy2, null, null, true, null);

			SearchEngine searchEngine = new SearchEngine(new ICompilationUnit[] {workingCopy1, workingCopy2});

			// type X should not be visible in old package
			IJavaSearchScope scope1 = SearchEngine.createJavaSearchScope(new IJavaElement[] {workingCopy1.getParent()});
	//		JavaSearchResultCollector resultCollector = new JavaSearchResultCollector();

			SearchPattern pattern = SearchPattern.createPattern(
				"X",
				TYPE,
				DECLARATIONS,
				SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
			searchEngine.search(
				pattern,
				new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
				scope1,
				this.resultCollector,
				null);
			assertEquals(
				"",
				this.resultCollector.toString());

			// type X should be visible in new package
			IJavaSearchScope scope2 = SearchEngine.createJavaSearchScope(new IJavaElement[] {workingCopy2.getParent()});
			this.resultCollector = new JavaSearchResultCollector();
			searchEngine.search(
				pattern,
				new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
				scope2,
				this.resultCollector,
				null);
			assertSearchResults(
				"src/wc2/Y.java wc2.X [X]",
				this.resultCollector);
		} finally {
			workingCopy1.discardWorkingCopy();
			workingCopy2.discardWorkingCopy();
		}
	}

	/**
	 * Type declaration in a working copy test.
	 * A type is removed from the working copy only.
	 */
	public void testRemoveType() throws CoreException {
		this.workingCopy.getType("X").delete(true, null);

		IJavaSearchScope scope =
			SearchEngine.createJavaSearchScope(
				new IJavaElement[] {this.workingCopy.getParent()});

		// type X should not be visible when working copy hides it
	//	JavaSearchResultCollector resultCollector = new JavaSearchResultCollector();
		SearchPattern pattern = SearchPattern.createPattern(
			"X",
			TYPE,
			DECLARATIONS,
			SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).search(
			pattern,
			new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
			scope,
			this.resultCollector,
			null);
		assertSearchResults(
			"",
			this.resultCollector);

		// ensure the type is still present in the compilation unit
		this.resultCollector = new JavaSearchResultCollector();
		new SearchEngine().search(
			pattern,
			new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
			scope,
			this.resultCollector,
			null);
		assertSearchResults(
			"src/wc/X.java wc.X [X]",
			this.resultCollector);

	}
	/*
	 * Search all method names in working copies test (without reconciling working copies).
	 */
	public void testBug478042_dirtyWC_001() throws CoreException {
		this.workingCopy.getBuffer().setContents(
				"package p478042;\n" +
				"public class AllMethodDeclarations01 {\n" +
				"  public void foo01() {}\n" +
				"  public int foo02(Object o) {return 0;}\n" +
				"  public char foo03(Object o, String s) {return '0';}\n" +
				"}\n"
		);
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {this.workingCopy.getParent()});
		SearchTests.SearchMethodNameRequestor requestor = new SearchTests.SearchMethodNameRequestor();
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllMethodNames(
				"p478042".toCharArray(), SearchPattern.R_EXACT_MATCH, //package
				null, SearchPattern.R_EXACT_MATCH,  // declaring Qualification
				"AllMethod".toCharArray(), SearchPattern.R_PREFIX_MATCH, // declaring SimpleType
				"foo".toCharArray(), SearchPattern.R_PREFIX_MATCH, 
				scope, requestor, 
				IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
		assertSearchResults(
				"/JavaSearch/src/wc/X.java char p478042.AllMethodDeclarations01.foo03(Object o,String s)\n" + 
				"/JavaSearch/src/wc/X.java int p478042.AllMethodDeclarations01.foo02(Object o)\n" + 
				"/JavaSearch/src/wc/X.java void p478042.AllMethodDeclarations01.foo01()",
				requestor
		);
	}
	/*
	 * Search all method names in working copies test (without reconciling working copies).
	 */
	public void testBug478042_dirtyWC_002() throws CoreException {
		this.workingCopy.getBuffer().setContents(
				"package p478042;\n" +
				"public class AllMethodDeclarations01 {\n" +
				"public class Nested {\n" +
				"  public void foo01() {}\n" +
				"  public int foo02(Object o) {return 0;}\n" +
				"  public char foo03(Object o, String s) {return '0';}\n" +
				"}\n" +
				"}\n"
		);
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {this.workingCopy.getParent()});
		SearchTests.SearchMethodNameRequestor requestor = new SearchTests.SearchMethodNameRequestor();
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllMethodNames(
				"p478042".toCharArray(), SearchPattern.R_EXACT_MATCH, //package
				"AllMethod".toCharArray(), SearchPattern.R_PREFIX_MATCH,  // declaring Qualification
				"Nested".toCharArray(), SearchPattern.R_EXACT_MATCH, // declaring SimpleType
				"foo".toCharArray(), SearchPattern.R_PREFIX_MATCH, 
				scope, requestor, 
				IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
		assertSearchResults(
				"/JavaSearch/src/wc/X.java char p478042.AllMethodDeclarations01.Nested.foo03(Object o,String s)\n" + 
				"/JavaSearch/src/wc/X.java int p478042.AllMethodDeclarations01.Nested.foo02(Object o)\n" + 
				"/JavaSearch/src/wc/X.java void p478042.AllMethodDeclarations01.Nested.foo01()",
				requestor
		);
	}
	/*
	 * Search all method names in working copies test (without reconciling working copies).
	 */
	public void testBug478042_dirtyWC_003() throws CoreException {
		this.workingCopy.getBuffer().setContents(
				"package p478042;\n" +
				"public class AllMethodDeclarations01 {\n" +
				"public class Nested {\n" +
				"public class Inner {\n" +
				"  public void foo01() {}\n" +
				"  public int foo02(Object o) {return 0;}\n" +
				"  public char foo03(Object o, String s) {return '0';}\n" +
				"}\n" +
				"}\n" +
				"}\n"
		);
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {this.workingCopy.getParent()});
		SearchTests.SearchMethodNameRequestor requestor = new SearchTests.SearchMethodNameRequestor();
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllMethodNames(
				"p478042".toCharArray(), SearchPattern.R_EXACT_MATCH, //package
				"AllMethod".toCharArray(), SearchPattern.R_PREFIX_MATCH,  // declaring Qualification
				"Inner".toCharArray(), SearchPattern.R_EXACT_MATCH, // declaring SimpleType
				"foo".toCharArray(), SearchPattern.R_PREFIX_MATCH, 
				scope, requestor, 
				IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
		assertSearchResults(
				"/JavaSearch/src/wc/X.java char p478042.AllMethodDeclarations01.Nested.Inner.foo03(Object o,String s)\n" + 
				"/JavaSearch/src/wc/X.java int p478042.AllMethodDeclarations01.Nested.Inner.foo02(Object o)\n" + 
				"/JavaSearch/src/wc/X.java void p478042.AllMethodDeclarations01.Nested.Inner.foo01()",
				requestor
		);
	}
	/*
	 * Search all method names in working copies test (without reconciling working copies).
	 */
	public void testBug478042_dirtyWC_004() throws CoreException {
		this.workingCopy.getBuffer().setContents(
				"package p478042;\n" +
				"public class AllMethodDeclarations01 {\n" +
				"  public void foo01() {}\n" +
				"  public int foo02(Object o) {return 0;}\n" +
				"  public char foo03(Object o, String s) {return '0';}\n" +
				"}\n"
		);
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {this.workingCopy.getParent()});
		SearchTests.SearchMethodNameRequestor requestor = new SearchTests.SearchMethodNameRequestor();
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllMethodNames(
				"p478042.AllMethod*".toCharArray(), SearchPattern.R_PATTERN_MATCH,
				"foo".toCharArray(), SearchPattern.R_PREFIX_MATCH, 
				scope, requestor, 
				IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
		assertSearchResults(
				"/JavaSearch/src/wc/X.java char p478042.AllMethodDeclarations01.foo03(Object o,String s)\n" + 
				"/JavaSearch/src/wc/X.java int p478042.AllMethodDeclarations01.foo02(Object o)\n" + 
				"/JavaSearch/src/wc/X.java void p478042.AllMethodDeclarations01.foo01()",
				requestor
		);
	}
	public void testBug483650_dirtyWC_001() throws CoreException {
		this.workingCopy.getBuffer().setContents(
				"package p478042;\n" +
				"public class AllMethodDeclarations01 {\n" +
				"  public void foo01() {}\n" +
				"  public int foo02(Object o) {return 0;}\n" +
				"  public char foo03(Object o, String s) {return '0';}\n" +
				"}\n"
		);
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {this.workingCopy.getParent()});
		SearchTests.SearchMethodNameRequestor requestor = new SearchTests.SearchMethodNameRequestor();
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllMethodNames(
				"p478042.AllMethod*".toCharArray(), SearchPattern.R_PATTERN_MATCH,
				"foo".toCharArray(), SearchPattern.R_PREFIX_MATCH, 
				scope, requestor, 
				IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
		assertSearchResults(
				"/JavaSearch/src/wc/X.java char p478042.AllMethodDeclarations01.foo03(Object o,String s)\n" + 
				"/JavaSearch/src/wc/X.java int p478042.AllMethodDeclarations01.foo02(Object o)\n" + 
				"/JavaSearch/src/wc/X.java void p478042.AllMethodDeclarations01.foo01()",
				requestor
		);
	}
	/*
	 * Search all method names in working copies test (without reconciling working copies).
	 */
	public void testBug483650_dirtyWC_002() throws CoreException {
		this.workingCopy.getBuffer().setContents(
				"package p478042;\n" +
				"public class AllMethodDeclarations01 {\n" +
				"public class Nested {\n" +
				"  public void foo01() {}\n" +
				"  public int foo02(Object o) {return 0;}\n" +
				"  public char foo03(Object o, String s) {return '0';}\n" +
				"}\n" +
				"}\n"
		);
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {this.workingCopy.getParent()});
		SearchTests.SearchMethodNameRequestor requestor = new SearchTests.SearchMethodNameRequestor();
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllMethodNames(
				"p478042.AllMethod*.Nested".toCharArray(), SearchPattern.R_PATTERN_MATCH,
				"foo".toCharArray(), SearchPattern.R_PREFIX_MATCH, 
				scope, requestor, 
				IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
		assertSearchResults(
				"/JavaSearch/src/wc/X.java char p478042.AllMethodDeclarations01.Nested.foo03(Object o,String s)\n" + 
				"/JavaSearch/src/wc/X.java int p478042.AllMethodDeclarations01.Nested.foo02(Object o)\n" + 
				"/JavaSearch/src/wc/X.java void p478042.AllMethodDeclarations01.Nested.foo01()",
				requestor
		);
	}
	/*
	 * Search all method names in working copies test (without reconciling working copies).
	 */
	public void testBug483650_dirtyWC_003() throws CoreException {
		this.workingCopy.getBuffer().setContents(
				"package p478042;\n" +
				"public class AllMethodDeclarations01 {\n" +
				"public class Nested {\n" +
				"public class Inner {\n" +
				"  public void foo01() {}\n" +
				"  public int foo02(Object o) {return 0;}\n" +
				"  public char foo03(Object o, String s) {return '0';}\n" +
				"}\n" +
				"}\n" +
				"}\n"
		);
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {this.workingCopy.getParent()});
		SearchTests.SearchMethodNameRequestor requestor = new SearchTests.SearchMethodNameRequestor();
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllMethodNames(
				"p478042.AllMethod*.Inner".toCharArray(), SearchPattern.R_PATTERN_MATCH,
				"foo".toCharArray(), SearchPattern.R_PREFIX_MATCH, 
				scope, requestor, 
				IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
		assertSearchResults(
				"/JavaSearch/src/wc/X.java char p478042.AllMethodDeclarations01.Nested.Inner.foo03(Object o,String s)\n" + 
				"/JavaSearch/src/wc/X.java int p478042.AllMethodDeclarations01.Nested.Inner.foo02(Object o)\n" + 
				"/JavaSearch/src/wc/X.java void p478042.AllMethodDeclarations01.Nested.Inner.foo01()",
				requestor
		);
	}
	/*
	 * Search all method names in working copies test (without reconciling working copies).
	 */
	public void testBug483650_dirtyWC_004() throws CoreException {
		this.workingCopy.getBuffer().setContents(
				"package p478042;\n" +
				"public class AllMethodDeclarations01 {\n" +
				"  public void foo01() {}\n" +
				"  public int foo02(Object o) {return 0;}\n" +
				"  public char foo03(Object o, String s) {return '0';}\n" +
				"}\n"
		);
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {this.workingCopy.getParent()});
		SearchTests.SearchMethodNameRequestor requestor = new SearchTests.SearchMethodNameRequestor();
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllMethodNames(
				"p478042.AllMethod*".toCharArray(), SearchPattern.R_PATTERN_MATCH,
				"foo".toCharArray(), SearchPattern.R_PREFIX_MATCH, 
				scope, requestor, 
				IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
		assertSearchResults(
				"/JavaSearch/src/wc/X.java char p478042.AllMethodDeclarations01.foo03(Object o,String s)\n" + 
				"/JavaSearch/src/wc/X.java int p478042.AllMethodDeclarations01.foo02(Object o)\n" + 
				"/JavaSearch/src/wc/X.java void p478042.AllMethodDeclarations01.foo01()",
				requestor
		);
	}

}

Back to the top