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

Collapse All | Expand All

(-)search/org/eclipse/jdt/core/search/SearchEngine.java (-1 / +32 lines)
Lines 7-13 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann - Contribution for bug 215139
10
 *     Stephan Herrmann - Contributions for bug 215139 and bug 295894
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.jdt.core.search;
12
package org.eclipse.jdt.core.search;
13
13
Lines 212-217 Link Here
212
	 *        or <code>null</code> if the primary working copy owner should be used
212
	 *        or <code>null</code> if the primary working copy owner should be used
213
	 * @return a new hierarchy scope
213
	 * @return a new hierarchy scope
214
	 * @exception JavaModelException if the hierarchy could not be computed on the given type
214
	 * @exception JavaModelException if the hierarchy could not be computed on the given type
215
	 * @deprecated Use {@link #createStrictHierarchyScope(IJavaProject, IType, boolean, boolean, WorkingCopyOwner)} instead.
215
	 * @since 3.6
216
	 * @since 3.6
216
	 */
217
	 */
217
	public static IJavaSearchScope createHierarchyScope(IJavaProject project, IType type, boolean onlySubtypes, boolean noMemberTypes, WorkingCopyOwner owner) throws JavaModelException {
218
	public static IJavaSearchScope createHierarchyScope(IJavaProject project, IType type, boolean onlySubtypes, boolean noMemberTypes, WorkingCopyOwner owner) throws JavaModelException {
Lines 219-224 Link Here
219
	}
220
	}
220
221
221
	/**
222
	/**
223
	 * Returns a Java search scope limited to the hierarchy of the given type and to a given project.
224
	 * The Java elements resulting from a search with this scope will be types in this hierarchy.
225
	 * <p>
226
	 * Unlike the <code>createHierarchyScope</code> methods, this method creates <em>strict</em>
227
	 * scopes that only contain types that actually span the hierarchy of the focus
228
	 * type, but do not include additional enclosing or member types.
229
	 * </p>
230
	 * <p>
231
	 * By default, hierarchy scopes include all direct and indirect supertypes and subtypes of the
232
	 * focus type. This method, however, allows to restrict the hierarchy to true subtypes,
233
	 * not including supertypes. Also inclusion of the focus type itself is controled by a parameter. 
234
	 * </p>
235
	 * 
236
	 * @param project the project to which to constrain the search, or <code>null</code> if
237
	 *        search should consider all types in the workspace 
238
	 * @param type the focus of the hierarchy scope
239
	 * @param onlySubtypes if true only subtypes of <code>type</code> are considered
240
	 * @param includeFocusType if true the focus type <code>type</code> is included in the resulting scope, 
241
	 * 		  otherwise it is excluded
242
	 * @param owner the owner of working copies that take precedence over original compilation units, 
243
	 *        or <code>null</code> if the primary working copy owner should be used
244
	 * @return a new hierarchy scope
245
	 * @exception JavaModelException if the hierarchy could not be computed on the given type
246
	 * @since 3.6
247
	 */
248
	public static IJavaSearchScope createStrictHierarchyScope(IJavaProject project, IType type, boolean onlySubtypes, boolean includeFocusType, WorkingCopyOwner owner) throws JavaModelException {
249
		return BasicSearchEngine.createStrictHierarchyScope(project, type, onlySubtypes, includeFocusType, owner);
250
	}
251
252
	/**
222
	 * Returns a Java search scope limited to the given resources.
253
	 * Returns a Java search scope limited to the given resources.
223
	 * The Java elements resulting from a search with this scope will
254
	 * The Java elements resulting from a search with this scope will
224
	 * have their underlying resource included in or equals to one of the given
255
	 * have their underlying resource included in or equals to one of the given
(-)search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java (-2 / +10 lines)
Lines 7-13 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann - Contribution for bug 215139
10
 *     Stephan Herrmann - Contributions for bug 215139 and bug 295894
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.core.search;
12
package org.eclipse.jdt.internal.core.search;
13
13
Lines 110-118 Link Here
110
110
111
	/**
111
	/**
112
	 * @see SearchEngine#createHierarchyScope(IJavaProject,IType,boolean,boolean,WorkingCopyOwner) for detailed comment.
112
	 * @see SearchEngine#createHierarchyScope(IJavaProject,IType,boolean,boolean,WorkingCopyOwner) for detailed comment.
113
	 * @deprecated Use {@link #createHierarchyScope(IJavaProject, IType, boolean, boolean, WorkingCopyOwner)} instead.
113
	 */
114
	 */
114
	public static IJavaSearchScope createHierarchyScope(IJavaProject project, IType type, boolean onlySubtypes, boolean noMemberTypes, WorkingCopyOwner owner) throws JavaModelException {
115
	public static IJavaSearchScope createHierarchyScope(IJavaProject project, IType type, boolean onlySubtypes, boolean noMemberTypes, WorkingCopyOwner owner) throws JavaModelException {
115
		return new HierarchyScope(project, type, owner, onlySubtypes, noMemberTypes);
116
		return new HierarchyScope(project, type, owner, onlySubtypes, noMemberTypes, !onlySubtypes);
117
	}
118
119
	/**
120
	 * @see SearchEngine#createStrictHierarchyScope(IJavaProject,IType,boolean,boolean,WorkingCopyOwner) for detailed comment.
121
	 */
122
	public static IJavaSearchScope createStrictHierarchyScope(IJavaProject project, IType type, boolean onlySubtypes, boolean includeFocusType, WorkingCopyOwner owner) throws JavaModelException {
123
		return new HierarchyScope(project, type, owner, onlySubtypes, true, includeFocusType);
116
	}
124
	}
117
125
118
	/**
126
	/**
(-)search/org/eclipse/jdt/internal/core/search/HierarchyScope.java (-11 / +18 lines)
Lines 7-13 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann - Contribution for bug 215139
10
 *     Stephan Herrmann - Contributions for bug 215139 and bug 295894
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.core.search;
12
package org.eclipse.jdt.internal.core.search;
13
13
Lines 43-49 Link Here
43
43
44
	private HashSet subTypes = null; // null means: don't filter for subTypes
44
	private HashSet subTypes = null; // null means: don't filter for subTypes
45
	private IJavaProject javaProject = null; // null means: don't constrain the search to a project
45
	private IJavaProject javaProject = null; // null means: don't constrain the search to a project
46
	private boolean allowMemberTypes = true;
46
	private boolean allowMemberAndEnclosingTypes = true;
47
	private boolean includeFocusType = true;
47
48
48
	/* (non-Javadoc)
49
	/* (non-Javadoc)
49
	 * Adds the given resource to this search scope.
50
	 * Adds the given resource to this search scope.
Lines 61-82 Link Here
61
	}
62
	}
62
63
63
	/**
64
	/**
64
	 * Creates a new hierarchy scope for the given type.
65
	 * Creates a new hierarchy scope for the given type with the given configuration options.
65
	 * @param project      constrain the search result to this project, 
66
	 * @param project      constrain the search result to this project, 
66
	 *                     or <code>null</code> if search should consider all types in the workspace 
67
	 *                     or <code>null</code> if search should consider all types in the workspace 
67
	 * @param type         the focus type of the hierarchy
68
	 * @param type         the focus type of the hierarchy
68
	 * @param owner 	   the owner of working copies that take precedence over original compilation units, 
69
	 * @param owner 	   the owner of working copies that take precedence over original compilation units, 
69
	 *                     or <code>null</code> if the primary working copy owner should be used
70
	 *                     or <code>null</code> if the primary working copy owner should be used
70
	 * @param onlySubtypes if true search only subtypes of 'type' (not including 'type')
71
	 * @param onlySubtypes if true search only subtypes of 'type'
71
	 * @param noMemberTypes if true do not consider member or enclosing types of types in the given type hierarchy.
72
	 * @param noMembersOrEnclosingTypes if true the hierarchy is strict, 
73
	 * 					   i.e., no additional member types or enclosing types of types spanning the hierarchy are included,
74
	 * 					   otherwise all member and enclosing types of types in the hierarchy are included.
75
	 * @param includeFocusType if true the focus type <code>type</code> is included in the resulting scope, otherwise it is excluded
72
	 */
76
	 */
73
	public HierarchyScope(IJavaProject project, IType type, WorkingCopyOwner owner, boolean onlySubtypes, boolean noMemberTypes) throws JavaModelException {
77
	public HierarchyScope(IJavaProject project, IType type, WorkingCopyOwner owner, boolean onlySubtypes, boolean noMembersOrEnclosingTypes, boolean includeFocusType) throws JavaModelException {
74
		this(type, owner);
78
		this(type, owner);
75
		this.javaProject = project;
79
		this.javaProject = project;
76
		if (onlySubtypes) {
80
		if (onlySubtypes) {
77
			this.subTypes = new HashSet();
81
			this.subTypes = new HashSet();
78
		}
82
		}
79
		this.allowMemberTypes = !noMemberTypes;
83
		this.includeFocusType = includeFocusType;
84
		this.allowMemberAndEnclosingTypes = !noMembersOrEnclosingTypes;
80
	}
85
	}
81
86
82
	/* (non-Javadoc)
87
	/* (non-Javadoc)
Lines 293-299 Link Here
293
	 *         (regarding subtypes and members) is requested
298
	 *         (regarding subtypes and members) is requested
294
	 */
299
	 */
295
	public boolean enclosesFineGrained(IJavaElement element) {
300
	public boolean enclosesFineGrained(IJavaElement element) {
296
		if ((this.subTypes == null) && this.allowMemberTypes) 
301
		if ((this.subTypes == null) && this.allowMemberAndEnclosingTypes) 
297
			return true; // no fine grained checking requested
302
			return true; // no fine grained checking requested
298
		return encloses(element);
303
		return encloses(element);
299
	}
304
	}
Lines 302-308 Link Here
302
	 */
307
	 */
303
	public boolean encloses(IJavaElement element) {
308
	public boolean encloses(IJavaElement element) {
304
		if (this.hierarchy == null) {
309
		if (this.hierarchy == null) {
305
			if (this.subTypes == null && this.focusType.equals(element.getAncestor(IJavaElement.TYPE))) {
310
			if (this.includeFocusType && this.focusType.equals(element.getAncestor(IJavaElement.TYPE))) {
306
				return true;
311
				return true;
307
			} else {
312
			} else {
308
				if (this.needsRefresh) {
313
				if (this.needsRefresh) {
Lines 332-342 Link Here
332
			type = ((IMember) element).getDeclaringType();
337
			type = ((IMember) element).getDeclaringType();
333
		}
338
		}
334
		if (type != null) {
339
		if (type != null) {
340
			if (this.focusType.equals(type))
341
				return this.includeFocusType;
335
			// potentially allow travelling in:
342
			// potentially allow travelling in:
336
			if (enclosesType(type, this.allowMemberTypes)) {
343
			if (enclosesType(type, this.allowMemberAndEnclosingTypes)) {
337
				return true;
344
				return true;
338
			}
345
			}
339
			if (this.allowMemberTypes) {
346
			if (this.allowMemberAndEnclosingTypes) {
340
				// travel out: queried type is enclosed in this scope if its (indirect) declaring type is:
347
				// travel out: queried type is enclosed in this scope if its (indirect) declaring type is:
341
				IType enclosing = type.getDeclaringType();
348
				IType enclosing = type.getDeclaringType();
342
				while (enclosing != null) {
349
				while (enclosing != null) {
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+99 lines)
Lines 11064-11067 Link Here
11064
		removeClasspathEntry(JAVA_PROJECT, new Path(libPath));
11064
		removeClasspathEntry(JAVA_PROJECT, new Path(libPath));
11065
	}
11065
	}
11066
}
11066
}
11067
11068
static { TESTS_PREFIX = "testBug295894"; }
11069
/**
11070
 * @bug 295894: Search shows focus type implementation for nested types even though the scope is restricted to subtypes.
11071
 * @test using the hierarchy with the old API includes the focus type. 
11072
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=295894"
11073
 */
11074
public void testBug295894() throws Exception {
11075
	this.workingCopies = new ICompilationUnit[1];
11076
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/Test.java",
11077
		"public class Test {\n" + 
11078
		"    void test() {\n" + 
11079
		"        Test t = new Test();\n" + 
11080
		"        t.foo();\n" + 
11081
		"    }\n" + 
11082
		"    public void foo() {\n" + 
11083
		"    }\n" + 
11084
		"    public class Sub extends Test {\n" + 
11085
		"        public void foo() {}\n" + 
11086
		"    }\n" + 
11087
		"}\n" + 
11088
		""
11089
	);
11090
	search(
11091
		"foo",
11092
		METHOD,
11093
		DECLARATIONS,
11094
		SearchEngine.createHierarchyScope(this.workingCopies[0].findPrimaryType()),
11095
		this.resultCollector);
11096
	assertSearchResults(
11097
		"src/Test.java void Test.foo() [foo] EXACT_MATCH\n" + 
11098
		"src/Test.java void Test$Sub.foo() [foo] EXACT_MATCH"
11099
	);
11100
}
11101
/**
11102
 * @bug 295894: Search shows focus type implementation for nested types even though the scope is restricted to subtypes.
11103
 * @test explicitly excluding the focus type
11104
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=295894"
11105
 */
11106
public void testBug295894a() throws Exception {
11107
	this.workingCopies = new ICompilationUnit[1];
11108
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/Test.java",
11109
		"public class Test {\n" + 
11110
		"    void test() {\n" + 
11111
		"        Test t = new Test();\n" + 
11112
		"        t.foo();\n" + 
11113
		"    }\n" + 
11114
		"    public void foo() {\n" + 
11115
		"    }\n" + 
11116
		"    public class Sub extends Test {\n" + 
11117
		"        public void foo() {}\n" + 
11118
		"    }\n" + 
11119
		"}\n" + 
11120
		""
11121
	);
11122
	search(
11123
		"foo",
11124
		METHOD,
11125
		DECLARATIONS,
11126
		SearchEngine.createStrictHierarchyScope(null, this.workingCopies[0].findPrimaryType(), true, false, null),
11127
		this.resultCollector);
11128
	// Test$Sub is a true sub type, not affected by filtering member types
11129
	assertSearchResults(
11130
		"src/Test.java void Test$Sub.foo() [foo] EXACT_MATCH"
11131
	);
11132
}
11133
/**
11134
 * @bug 295894: Search shows focus type implementation for nested types even though the scope is restricted to subtypes.
11135
 * @test explicitly including the focus type
11136
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=295894"
11137
 */
11138
public void testBug295894b() throws Exception {
11139
	this.workingCopies = new ICompilationUnit[1];
11140
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/Test.java",
11141
		"public class Test {\n" + 
11142
		"    void test() {\n" + 
11143
		"        Test t = new Test();\n" + 
11144
		"        t.foo();\n" + 
11145
		"    }\n" + 
11146
		"    public void foo() {\n" + 
11147
		"    }\n" + 
11148
		"    public class Sub extends Test {\n" + 
11149
		"        public void foo() {}\n" + 
11150
		"    }\n" + 
11151
		"}\n" + 
11152
		""
11153
	);
11154
	search(
11155
		"foo",
11156
		METHOD,
11157
		DECLARATIONS,
11158
		SearchEngine.createStrictHierarchyScope(null, this.workingCopies[0].findPrimaryType(), false, true, null),
11159
		this.resultCollector);
11160
	// Same results as with the old API
11161
	assertSearchResults(
11162
		"src/Test.java void Test.foo() [foo] EXACT_MATCH\n" + 
11163
		"src/Test.java void Test$Sub.foo() [foo] EXACT_MATCH"
11164
	);
11165
}
11067
}
11166
}
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java (-12 / +51 lines)
Lines 1357-1362 Link Here
1357
/**
1357
/**
1358
 * Method declaration in hierarchy test.
1358
 * Method declaration in hierarchy test.
1359
 * Explicitly request behavior pre https://bugs.eclipse.org/bugs/show_bug.cgi?id=215139
1359
 * Explicitly request behavior pre https://bugs.eclipse.org/bugs/show_bug.cgi?id=215139
1360
 * @deprecated tests a deprecated API
1360
 */
1361
 */
1361
public void testMethodDeclaration04() throws CoreException { // was testMethodDeclarationInHierarchyScope1
1362
public void testMethodDeclaration04() throws CoreException { // was testMethodDeclarationInHierarchyScope1
1362
	IType type = getCompilationUnit("JavaSearch", "src", "p", "X.java").getType("X");
1363
	IType type = getCompilationUnit("JavaSearch", "src", "p", "X.java").getType("X");
Lines 2450-2456 Link Here
2450
    	ICompilationUnit cuB = this. getCompilationUnit("JavaSearch", "src", "a10", "B.java");
2451
    	ICompilationUnit cuB = this. getCompilationUnit("JavaSearch", "src", "a10", "B.java");
2451
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2452
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2452
        IType type = cuC.getType("C");
2453
        IType type = cuC.getType("C");
2453
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2454
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2454
        
2455
        
2455
        // don't include super-classes:
2456
        // don't include super-classes:
2456
        assertFalse("a10.A should not be included in hierarchy scope", scope.encloses(cuB.getType("A")));
2457
        assertFalse("a10.A should not be included in hierarchy scope", scope.encloses(cuB.getType("A")));
Lines 2464-2474 Link Here
2464
public void testSearchScope07() throws CoreException {
2465
public void testSearchScope07() throws CoreException {
2465
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2466
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2466
        IType type = cuC.getType("C");
2467
        IType type = cuC.getType("C");
2467
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2468
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2468
        
2469
        
2469
        // don't include focus type:
2470
        // don't include focus type:
2470
        assertFalse("a10.C should be not included in hierarchy scope", scope.encloses(type));
2471
        assertFalse("a10.C should not be included in hierarchy scope", scope.encloses(type));
2471
        assertFalse("a10/C.java should be included in hierarchy scope", scope.encloses(cuC.getUnderlyingResource().getFullPath().toString()));       
2472
        assertFalse("a10/C.java should not be included in hierarchy scope", scope.encloses(cuC.getUnderlyingResource().getFullPath().toString()));       
2473
}
2474
/**
2475
 * Hierarchy scope test.
2476
 * test for enhancement bug 215139 encloses(): find only subtypes.
2477
 * also test enhancement bug 295894: include focus type.
2478
 */
2479
public void testSearchScope07a() throws CoreException {
2480
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2481
        IType type = cuC.getType("C");
2482
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, true, null);
2483
        
2484
        // include focus type:
2485
        assertTrue("a10.C should be included in hierarchy scope", scope.encloses(type));
2486
        assertTrue("a10/C.java should be included in hierarchy scope", scope.encloses(cuC.getUnderlyingResource().getFullPath().toString()));       
2472
}
2487
}
2473
/**
2488
/**
2474
 * Hierarchy scope test.
2489
 * Hierarchy scope test.
Lines 2479-2485 Link Here
2479
        ICompilationUnit cuD = this. getCompilationUnit("JavaSearch", "src", "a10", "D.java");
2494
        ICompilationUnit cuD = this. getCompilationUnit("JavaSearch", "src", "a10", "D.java");
2480
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2495
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2481
        IType type = cuC.getType("C");
2496
        IType type = cuC.getType("C");
2482
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2497
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2483
        
2498
        
2484
        // regular sub-types:
2499
        // regular sub-types:
2485
        assertTrue("a10.D should be included in hierarchy scope", scope.encloses(cuD.getType("D")));
2500
        assertTrue("a10.D should be included in hierarchy scope", scope.encloses(cuD.getType("D")));
Lines 2496-2502 Link Here
2496
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2511
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2497
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2512
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2498
        IType type = cuC.getType("C");
2513
        IType type = cuC.getType("C");
2499
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2514
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2500
        
2515
        
2501
        // sub-type is a nested type:
2516
        // sub-type is a nested type:
2502
        assertTrue("a10.H$I should be included in hierarchy scope", scope.encloses(cuE.getType("H").getType("I")));
2517
        assertTrue("a10.H$I should be included in hierarchy scope", scope.encloses(cuE.getType("H").getType("I")));
Lines 2509-2515 Link Here
2509
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2524
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2510
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2525
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2511
        IType type = cuC.getType("C");
2526
        IType type = cuC.getType("C");
2512
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2527
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2513
        
2528
        
2514
        // member of a sub-type:
2529
        // member of a sub-type:
2515
        assertFalse("a10.F$G should not be included in hierarchy scope", scope.encloses(cuE.getType("F").getType("G")));
2530
        assertFalse("a10.F$G should not be included in hierarchy scope", scope.encloses(cuE.getType("F").getType("G")));
Lines 2517-2522 Link Here
2517
/**
2532
/**
2518
 * Hierarchy scope test.
2533
 * Hierarchy scope test.
2519
 * (test for enhancement bug 215139 encloses(): find only subtypes and their member types).
2534
 * (test for enhancement bug 215139 encloses(): find only subtypes and their member types).
2535
 * @deprecated tests a deprecated API
2520
 */
2536
 */
2521
public void testSearchScope11() throws CoreException {
2537
public void testSearchScope11() throws CoreException {
2522
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2538
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
Lines 2535-2541 Link Here
2535
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2551
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2536
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2552
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2537
        IType type = cuC.getType("C");
2553
        IType type = cuC.getType("C");
2538
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2554
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2539
        
2555
        
2540
        // enclosing of a sub-type:
2556
        // enclosing of a sub-type:
2541
        assertFalse("a10.H should not be included in hierarchy scope", scope.encloses(cuE.getType("H")));
2557
        assertFalse("a10.H should not be included in hierarchy scope", scope.encloses(cuE.getType("H")));
Lines 2548-2554 Link Here
2548
public void testSearchScope13() throws CoreException {
2564
public void testSearchScope13() throws CoreException {
2549
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2565
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2550
        IType type = cuC.getType("C");
2566
        IType type = cuC.getType("C");
2551
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2567
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2552
        
2568
        
2553
        search("**", TYPE, DECLARATIONS, scope);
2569
        search("**", TYPE, DECLARATIONS, scope);
2554
        assertSearchResults(
2570
        assertSearchResults(
Lines 2565-2571 Link Here
2565
public void testSearchScope14() throws CoreException {
2581
public void testSearchScope14() throws CoreException {
2566
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2582
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2567
        IType type = cuC.getType("C");
2583
        IType type = cuC.getType("C");
2568
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, /*onlySubTypes*/false, true, null);
2584
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, /*onlySubTypes*/false, true, null);
2569
        
2585
        
2570
        search("**", TYPE, DECLARATIONS, scope);
2586
        search("**", TYPE, DECLARATIONS, scope);
2571
        assertSearchResults(
2587
        assertSearchResults(
Lines 2581-2592 Link Here
2581
}
2597
}
2582
/**
2598
/**
2583
 * Hierarchy scope test.
2599
 * Hierarchy scope test.
2600
 * test for enhancement bug 215139 search: find only subtypes - disabled,
2601
 * also test enhancement bug 295894: exclude focus type.
2602
 */
2603
public void testSearchScope14a() throws CoreException {
2604
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2605
        IType type = cuC.getType("C");
2606
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, /*onlySubTypes*/false, false, null);
2607
        
2608
        search("**", TYPE, DECLARATIONS, scope);
2609
        assertSearchResults(
2610
        		"src/a10/B.java a10.A [A]\n" + 
2611
        		"src/a10/B.java a10.B [B]\n" + 
2612
        		"src/a10/D.java a10.D [D]\n" + 
2613
        		"src/a10/E.java a10.E [E]\n" + 
2614
        		"src/a10/E.java a10.F [F]\n" + 
2615
        		"src/a10/E.java a10.H$I [I]\n" + 
2616
        		getExternalJCLPathString() + " java.lang.Object"
2617
        		);
2618
}
2619
/**
2620
 * Hierarchy scope test.
2584
 * (test for enhancement bug 215139 search: find only subtypes - different call chain).
2621
 * (test for enhancement bug 215139 search: find only subtypes - different call chain).
2585
 */
2622
 */
2586
public void testSearchScope15() throws CoreException {
2623
public void testSearchScope15() throws CoreException {
2587
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2624
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2588
        IType type = cuC.getType("C");
2625
        IType type = cuC.getType("C");
2589
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2626
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2590
    	TypeNameMatchCollector collector = new TypeNameMatchCollector() {
2627
    	TypeNameMatchCollector collector = new TypeNameMatchCollector() {
2591
    		public String toString(){
2628
    		public String toString(){
2592
    			return toFullyQualifiedNamesString();
2629
    			return toFullyQualifiedNamesString();
Lines 2610-2615 Link Here
2610
/**
2647
/**
2611
 * Hierarchy scope test.
2648
 * Hierarchy scope test.
2612
 * (test for enhancement bug 215139 search: find only subtypes plus member & enclosing types - different call chain).
2649
 * (test for enhancement bug 215139 search: find only subtypes plus member & enclosing types - different call chain).
2650
 * @deprecated tests a deprecated API
2613
 */
2651
 */
2614
public void testSearchScope16() throws CoreException {
2652
public void testSearchScope16() throws CoreException {
2615
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2653
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
Lines 2645-2651 Link Here
2645
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2683
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2646
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2684
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2647
        IType type = cuC.getType("C");
2685
        IType type = cuC.getType("C");
2648
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2686
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2649
        
2687
        
2650
        // method of a member of a sub-type:
2688
        // method of a member of a sub-type:
2651
        assertFalse("a10.F$G.m() should not be included in hierarchy scope", scope.encloses(cuE.getType("F").getType("G").getMethod("m", new String[0])));
2689
        assertFalse("a10.F$G.m() should not be included in hierarchy scope", scope.encloses(cuE.getType("F").getType("G").getMethod("m", new String[0])));
Lines 2653-2658 Link Here
2653
/**
2691
/**
2654
 * Hierarchy scope test.
2692
 * Hierarchy scope test.
2655
 * (test for enhancement bug 215139 encloses(method): find only subtypes but also member types).
2693
 * (test for enhancement bug 215139 encloses(method): find only subtypes but also member types).
2694
 * @deprecated tests a deprecated API
2656
 */
2695
 */
2657
public void testSearchScope18() throws CoreException {
2696
public void testSearchScope18() throws CoreException {
2658
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2697
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");

Return to bug 295894