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 (-2 / +33 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
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 Will be removed shortly before 3.6M5. 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 (-3 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
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 Will be removed shortly before 3.6M5. 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 (-12 / +19 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
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 (+98 lines)
Lines 11039-11044 Link Here
11039
}
11039
}
11040
11040
11041
/**
11041
/**
11042
 * @bug 295894: Search shows focus type implementation for nested types even though the scope is restricted to subtypes.
11043
 * @test using the hierarchy with the old API includes the focus type. 
11044
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=295894"
11045
 */
11046
public void testBug295894() throws Exception {
11047
	this.workingCopies = new ICompilationUnit[1];
11048
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/Test.java",
11049
		"public class Test {\n" + 
11050
		"    void test() {\n" + 
11051
		"        Test t = new Test();\n" + 
11052
		"        t.foo();\n" + 
11053
		"    }\n" + 
11054
		"    public void foo() {\n" + 
11055
		"    }\n" + 
11056
		"    public class Sub extends Test {\n" + 
11057
		"        public void foo() {}\n" + 
11058
		"    }\n" + 
11059
		"}\n" + 
11060
		""
11061
	);
11062
	search(
11063
		"foo",
11064
		METHOD,
11065
		DECLARATIONS,
11066
		SearchEngine.createHierarchyScope(this.workingCopies[0].findPrimaryType()),
11067
		this.resultCollector);
11068
	assertSearchResults(
11069
		"src/Test.java void Test.foo() [foo] EXACT_MATCH\n" + 
11070
		"src/Test.java void Test$Sub.foo() [foo] EXACT_MATCH"
11071
	);
11072
}
11073
/**
11074
 * @bug 295894: Search shows focus type implementation for nested types even though the scope is restricted to subtypes.
11075
 * @test explicitly excluding the focus type
11076
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=295894"
11077
 */
11078
public void testBug295894a() throws Exception {
11079
	this.workingCopies = new ICompilationUnit[1];
11080
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/Test.java",
11081
		"public class Test {\n" + 
11082
		"    void test() {\n" + 
11083
		"        Test t = new Test();\n" + 
11084
		"        t.foo();\n" + 
11085
		"    }\n" + 
11086
		"    public void foo() {\n" + 
11087
		"    }\n" + 
11088
		"    public class Sub extends Test {\n" + 
11089
		"        public void foo() {}\n" + 
11090
		"    }\n" + 
11091
		"}\n" + 
11092
		""
11093
	);
11094
	search(
11095
		"foo",
11096
		METHOD,
11097
		DECLARATIONS,
11098
		SearchEngine.createStrictHierarchyScope(null, this.workingCopies[0].findPrimaryType(), true, false, null),
11099
		this.resultCollector);
11100
	// Test$Sub is a true sub type, not affected by filtering member types
11101
	assertSearchResults(
11102
		"src/Test.java void Test$Sub.foo() [foo] EXACT_MATCH"
11103
	);
11104
}
11105
/**
11106
 * @bug 295894: Search shows focus type implementation for nested types even though the scope is restricted to subtypes.
11107
 * @test explicitly including the focus type
11108
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=295894"
11109
 */
11110
public void testBug295894b() throws Exception {
11111
	this.workingCopies = new ICompilationUnit[1];
11112
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/Test.java",
11113
		"public class Test {\n" + 
11114
		"    void test() {\n" + 
11115
		"        Test t = new Test();\n" + 
11116
		"        t.foo();\n" + 
11117
		"    }\n" + 
11118
		"    public void foo() {\n" + 
11119
		"    }\n" + 
11120
		"    public class Sub extends Test {\n" + 
11121
		"        public void foo() {}\n" + 
11122
		"    }\n" + 
11123
		"}\n" + 
11124
		""
11125
	);
11126
	search(
11127
		"foo",
11128
		METHOD,
11129
		DECLARATIONS,
11130
		SearchEngine.createStrictHierarchyScope(null, this.workingCopies[0].findPrimaryType(), false, true, null),
11131
		this.resultCollector);
11132
	// Same results as with the old API
11133
	assertSearchResults(
11134
		"src/Test.java void Test.foo() [foo] EXACT_MATCH\n" + 
11135
		"src/Test.java void Test$Sub.foo() [foo] EXACT_MATCH"
11136
	);
11137
}
11138
11139
/**
11042
 * @bug 288174: NullPointerException when searching for type references
11140
 * @bug 288174: NullPointerException when searching for type references
11043
 * @test Ensure that no NPE occurs when searching for type references
11141
 * @test Ensure that no NPE occurs when searching for type references
11044
 * 		when a binary type has matches in several member or anonymous types
11142
 * 		when a binary type has matches in several member or anonymous types
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java (-84 / +44 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 1356-1362 Link Here
1356
}
1356
}
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
1360
 */
1359
 */
1361
public void testMethodDeclaration04() throws CoreException { // was testMethodDeclarationInHierarchyScope1
1360
public void testMethodDeclaration04() throws CoreException { // was testMethodDeclarationInHierarchyScope1
1362
	IType type = getCompilationUnit("JavaSearch", "src", "p", "X.java").getType("X");
1361
	IType type = getCompilationUnit("JavaSearch", "src", "p", "X.java").getType("X");
Lines 1365-1388 Link Here
1365
		"foo",
1364
		"foo",
1366
		METHOD,
1365
		METHOD,
1367
		DECLARATIONS,
1366
		DECLARATIONS,
1368
		SearchEngine.createHierarchyScope(null, type, false, true, null),
1369
		this.resultCollector);
1370
	assertSearchResults(
1371
		"src/p/X.java void p.X.foo(int, String, X) [foo]\n" +
1372
		"src/p/Z.java void p.Z.foo(int, String, X) [foo]",
1373
		this.resultCollector);
1374
}
1375
/**
1376
 * Method declaration in hierarchy test.
1377
 * After https://bugs.eclipse.org/bugs/show_bug.cgi?id=215139 result contains more types.
1378
 */
1379
public void testMethodDeclaration04a() throws CoreException { // was testMethodDeclarationInHierarchyScope1
1380
	IType type = getCompilationUnit("JavaSearch", "src", "p", "X.java").getType("X");
1381
1382
	search(
1383
		"foo",
1384
		METHOD,
1385
		DECLARATIONS,
1386
		SearchEngine.createHierarchyScope(type),
1367
		SearchEngine.createHierarchyScope(type),
1387
		this.resultCollector);
1368
		this.resultCollector);
1388
	assertSearchResults(
1369
	assertSearchResults(
Lines 2450-2456 Link Here
2450
    	ICompilationUnit cuB = this. getCompilationUnit("JavaSearch", "src", "a10", "B.java");
2431
    	ICompilationUnit cuB = this. getCompilationUnit("JavaSearch", "src", "a10", "B.java");
2451
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2432
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2452
        IType type = cuC.getType("C");
2433
        IType type = cuC.getType("C");
2453
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2434
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2454
        
2435
        
2455
        // don't include super-classes:
2436
        // don't include super-classes:
2456
        assertFalse("a10.A should not be included in hierarchy scope", scope.encloses(cuB.getType("A")));
2437
        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 {
2445
public void testSearchScope07() throws CoreException {
2465
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2446
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2466
        IType type = cuC.getType("C");
2447
        IType type = cuC.getType("C");
2467
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2448
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2468
        
2449
        
2469
        // don't include focus type:
2450
        // don't include focus type:
2470
        assertFalse("a10.C should be not included in hierarchy scope", scope.encloses(type));
2451
        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()));       
2452
        assertFalse("a10/C.java should not be included in hierarchy scope", scope.encloses(cuC.getUnderlyingResource().getFullPath().toString()));       
2453
}
2454
/**
2455
 * Hierarchy scope test.
2456
 * test for enhancement bug 215139 encloses(): find only subtypes.
2457
 * also test enhancement bug 295894: include focus type.
2458
 */
2459
public void testSearchScope07a() throws CoreException {
2460
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2461
        IType type = cuC.getType("C");
2462
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, true, null);
2463
        
2464
        // include focus type:
2465
        assertTrue("a10.C should be included in hierarchy scope", scope.encloses(type));
2466
        assertTrue("a10/C.java should be included in hierarchy scope", scope.encloses(cuC.getUnderlyingResource().getFullPath().toString()));       
2472
}
2467
}
2473
/**
2468
/**
2474
 * Hierarchy scope test.
2469
 * Hierarchy scope test.
Lines 2479-2485 Link Here
2479
        ICompilationUnit cuD = this. getCompilationUnit("JavaSearch", "src", "a10", "D.java");
2474
        ICompilationUnit cuD = this. getCompilationUnit("JavaSearch", "src", "a10", "D.java");
2480
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2475
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2481
        IType type = cuC.getType("C");
2476
        IType type = cuC.getType("C");
2482
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2477
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2483
        
2478
        
2484
        // regular sub-types:
2479
        // regular sub-types:
2485
        assertTrue("a10.D should be included in hierarchy scope", scope.encloses(cuD.getType("D")));
2480
        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");
2491
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2497
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2492
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2498
        IType type = cuC.getType("C");
2493
        IType type = cuC.getType("C");
2499
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2494
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2500
        
2495
        
2501
        // sub-type is a nested type:
2496
        // sub-type is a nested type:
2502
        assertTrue("a10.H$I should be included in hierarchy scope", scope.encloses(cuE.getType("H").getType("I")));
2497
        assertTrue("a10.H$I should be included in hierarchy scope", scope.encloses(cuE.getType("H").getType("I")));
Lines 2509-2541 Link Here
2509
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2504
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2510
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2505
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2511
        IType type = cuC.getType("C");
2506
        IType type = cuC.getType("C");
2512
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2507
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2513
        
2508
        
2514
        // member of a sub-type:
2509
        // member of a sub-type:
2515
        assertFalse("a10.F$G should not be included in hierarchy scope", scope.encloses(cuE.getType("F").getType("G")));
2510
        assertFalse("a10.F$G should not be included in hierarchy scope", scope.encloses(cuE.getType("F").getType("G")));
2516
}
2511
}
2517
/**
2512
/**
2518
 * Hierarchy scope test.
2513
 * Hierarchy scope test.
2519
 * (test for enhancement bug 215139 encloses(): find only subtypes and their member types).
2520
 */
2521
public void testSearchScope11() throws CoreException {
2522
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2523
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2524
        IType type = cuC.getType("C");
2525
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, false, null);
2526
        
2527
        // member of a sub-type:
2528
        assertTrue("a10.F$G should be included in hierarchy scope", scope.encloses(cuE.getType("F").getType("G")));
2529
}
2530
/**
2531
 * Hierarchy scope test.
2532
 * (test for enhancement bug 215139 encloses(): find only subtypes).
2514
 * (test for enhancement bug 215139 encloses(): find only subtypes).
2533
 */
2515
 */
2534
public void testSearchScope12() throws CoreException {
2516
public void testSearchScope12() throws CoreException {
2535
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2517
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2536
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2518
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2537
        IType type = cuC.getType("C");
2519
        IType type = cuC.getType("C");
2538
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2520
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2539
        
2521
        
2540
        // enclosing of a sub-type:
2522
        // enclosing of a sub-type:
2541
        assertFalse("a10.H should not be included in hierarchy scope", scope.encloses(cuE.getType("H")));
2523
        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 {
2530
public void testSearchScope13() throws CoreException {
2549
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2531
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2550
        IType type = cuC.getType("C");
2532
        IType type = cuC.getType("C");
2551
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2533
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2552
        
2534
        
2553
        search("**", TYPE, DECLARATIONS, scope);
2535
        search("**", TYPE, DECLARATIONS, scope);
2554
        assertSearchResults(
2536
        assertSearchResults(
Lines 2565-2571 Link Here
2565
public void testSearchScope14() throws CoreException {
2547
public void testSearchScope14() throws CoreException {
2566
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2548
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2567
        IType type = cuC.getType("C");
2549
        IType type = cuC.getType("C");
2568
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, /*onlySubTypes*/false, true, null);
2550
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, /*onlySubTypes*/false, true, null);
2569
        
2551
        
2570
        search("**", TYPE, DECLARATIONS, scope);
2552
        search("**", TYPE, DECLARATIONS, scope);
2571
        assertSearchResults(
2553
        assertSearchResults(
Lines 2581-2620 Link Here
2581
}
2563
}
2582
/**
2564
/**
2583
 * Hierarchy scope test.
2565
 * Hierarchy scope test.
2584
 * (test for enhancement bug 215139 search: find only subtypes - different call chain).
2566
 * test for enhancement bug 215139 search: find only subtypes - disabled,
2567
 * also test enhancement bug 295894: exclude focus type.
2585
 */
2568
 */
2586
public void testSearchScope15() throws CoreException {
2569
public void testSearchScope14a() throws CoreException {
2587
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2570
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2588
        IType type = cuC.getType("C");
2571
        IType type = cuC.getType("C");
2589
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2572
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, /*onlySubTypes*/false, false, null);
2590
    	TypeNameMatchCollector collector = new TypeNameMatchCollector() {
2573
        
2591
    		public String toString(){
2574
        search("**", TYPE, DECLARATIONS, scope);
2592
    			return toFullyQualifiedNamesString();
2575
        assertSearchResults(
2593
    		}
2576
        		"src/a10/B.java a10.A [A]\n" + 
2594
    	};
2577
        		"src/a10/B.java a10.B [B]\n" + 
2595
    	new SearchEngine().searchAllTypeNames(
2578
        		"src/a10/D.java a10.D [D]\n" + 
2596
    		null,
2579
        		"src/a10/E.java a10.E [E]\n" + 
2597
    		null,
2580
        		"src/a10/E.java a10.F [F]\n" + 
2598
    		scope,
2581
        		"src/a10/E.java a10.H$I [I]\n" + 
2599
    		collector,
2582
        		getExternalJCLPathString() + " java.lang.Object"
2600
    		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
2583
        		);
2601
    		null);
2602
    	String expected = 
2603
    			"a10.D\n" +
2604
    			"a10.E\n" +
2605
    			"a10.F\n" +
2606
    			"a10.H$I";
2607
    	assertTrue("We should get some types!", collector.size() > 0);
2608
    	assertEquals("Found types sound not to be correct", expected, collector.toString());
2609
}
2584
}
2610
/**
2585
/**
2611
 * Hierarchy scope test.
2586
 * Hierarchy scope test.
2612
 * (test for enhancement bug 215139 search: find only subtypes plus member & enclosing types - different call chain).
2587
 * (test for enhancement bug 215139 search: find only subtypes - different call chain).
2613
 */
2588
 */
2614
public void testSearchScope16() throws CoreException {
2589
public void testSearchScope15() throws CoreException {
2615
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2590
        ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2616
        IType type = cuC.getType("C");
2591
        IType type = cuC.getType("C");
2617
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, false, null);
2592
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2618
    	TypeNameMatchCollector collector = new TypeNameMatchCollector() {
2593
    	TypeNameMatchCollector collector = new TypeNameMatchCollector() {
2619
    		public String toString(){
2594
    		public String toString(){
2620
    			return toFullyQualifiedNamesString();
2595
    			return toFullyQualifiedNamesString();
Lines 2631-2638 Link Here
2631
    			"a10.D\n" +
2606
    			"a10.D\n" +
2632
    			"a10.E\n" +
2607
    			"a10.E\n" +
2633
    			"a10.F\n" +
2608
    			"a10.F\n" +
2634
    			"a10.F$G\n" +
2635
    			"a10.H\n" +
2636
    			"a10.H$I";
2609
    			"a10.H$I";
2637
    	assertTrue("We should get some types!", collector.size() > 0);
2610
    	assertTrue("We should get some types!", collector.size() > 0);
2638
    	assertEquals("Found types sound not to be correct", expected, collector.toString());
2611
    	assertEquals("Found types sound not to be correct", expected, collector.toString());
Lines 2645-2669 Link Here
2645
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2618
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2646
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2619
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2647
        IType type = cuC.getType("C");
2620
        IType type = cuC.getType("C");
2648
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
2621
        IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
2649
        
2622
        
2650
        // method of a member of a sub-type:
2623
        // 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])));
2624
        assertFalse("a10.F$G.m() should not be included in hierarchy scope", scope.encloses(cuE.getType("F").getType("G").getMethod("m", new String[0])));
2652
}
2625
}
2653
/**
2626
/**
2654
 * Hierarchy scope test.
2655
 * (test for enhancement bug 215139 encloses(method): find only subtypes but also member types).
2656
 */
2657
public void testSearchScope18() throws CoreException {
2658
    	ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
2659
        ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
2660
        IType type = cuC.getType("C");
2661
        IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, false, null);
2662
        
2663
        // method of a member of a sub-type:
2664
        assertTrue("a10.F$G.m() should be included in hierarchy scope", scope.encloses(cuE.getType("F").getType("G").getMethod("m", new String[0])));
2665
}
2666
/**
2667
 * Simple type declaration test.
2627
 * Simple type declaration test.
2668
 */
2628
 */
2669
public void testTypeDeclaration01() throws CoreException { // was testSimpleTypeDeclaration
2629
public void testTypeDeclaration01() throws CoreException { // was testSimpleTypeDeclaration

Return to bug 295894