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

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/HierarchyScope.java (+5 lines)
Lines 128-133 Link Here
128
		IType[] types = null;
128
		IType[] types = null;
129
		if (this.subTypes != null) {
129
		if (this.subTypes != null) {
130
			types = this.hierarchy.getAllSubtypes(this.focusType);
130
			types = this.hierarchy.getAllSubtypes(this.focusType);
131
			if (this.includeFocusType) {
132
				int len = types.length;
133
				System.arraycopy(types, 0, types=new IType[len+1], 0, len);
134
				types[len] = this.focusType;
135
			}
131
		} else {
136
		} else {
132
			types = this.hierarchy.getAllTypes();
137
			types = this.hierarchy.getAllTypes();
133
		}
138
		}
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+124 lines)
Lines 11137-11142 Link Here
11137
}
11137
}
11138
11138
11139
/**
11139
/**
11140
 * @bug 295894: Search shows focus type implementation for nested types even though the scope is restricted to subtypes.
11141
 * @test explicitly including the focus type, which has no subtypes.
11142
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=295894"
11143
 */
11144
public void testBug295894c() throws Exception {
11145
	this.workingCopies = new ICompilationUnit[1];
11146
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/A.java",
11147
		"public class A {\n" + 
11148
		"    void test() {\n" + 
11149
		"        A a= new A();\n" + 
11150
		"        a.toString();\n" + 
11151
		"    }\n" + 
11152
		"    @Override\n" +
11153
		"    public String toString() {\n" +
11154
		"        return \"\";\n" + 
11155
		"    }\n" + 
11156
		"}\n" + 
11157
		""
11158
	);
11159
	search(
11160
		"toString",
11161
		METHOD,
11162
		DECLARATIONS,
11163
		SearchEngine.createStrictHierarchyScope(null, this.workingCopies[0].findPrimaryType(), true, true, null),
11164
		this.resultCollector);
11165
	assertSearchResults(
11166
		"src/A.java String A.toString() [toString] EXACT_MATCH"
11167
	);
11168
}
11169
//Failing test while working with a compilation unit instead of working copy
11170
public void testBug295894c2() throws Exception {
11171
	try {
11172
		createJavaProject("P");
11173
		createFile(
11174
			"/P/A.java",
11175
			"public class A {\n" + 
11176
			"    void test() {\n" + 
11177
			"        A a= new A();\n" + 
11178
			"        a.toString();\n" + 
11179
			"    }\n" + 
11180
			"    @Override\n" +
11181
			"    public String toString() {\n" +
11182
			"        return \"\";\n" + 
11183
			"    }\n" + 
11184
			"}\n"
11185
		);
11186
		final ICompilationUnit cu = getCompilationUnit("/P/A.java");
11187
		IMethod method = selectMethod(cu, "toString");
11188
		search(method,
11189
			DECLARATIONS|IGNORE_RETURN_TYPE,
11190
			SearchEngine.createStrictHierarchyScope(null, cu.findPrimaryType(), true, true, null),
11191
			this.resultCollector);
11192
		assertSearchResults(
11193
			"A.java String A.toString() [toString] EXACT_MATCH"
11194
		);
11195
	}
11196
	finally {
11197
		deleteProject("P");
11198
	}
11199
}
11200
// Similar test passing when the focus type has a subclass
11201
public void testBug295894c3() throws Exception {
11202
	try {
11203
		createJavaProject("P");
11204
		createFile(
11205
			"/P/A.java",
11206
			"public class A {\n" + 
11207
			"    void test() {\n" + 
11208
			"        A a= new A();\n" + 
11209
			"        a.toString();\n" + 
11210
			"    }\n" + 
11211
			"    @Override\n" +
11212
			"    public String toString() {\n" +
11213
			"        return \"\";\n" + 
11214
			"    }\n" + 
11215
			"}\n" + 
11216
			"class B extends A {\n" + 
11217
			"}\n"
11218
		);
11219
		final ICompilationUnit cu = getCompilationUnit("/P/A.java");
11220
		IMethod method = selectMethod(cu, "toString");
11221
		search(method,
11222
			DECLARATIONS|IGNORE_RETURN_TYPE,
11223
			SearchEngine.createStrictHierarchyScope(null, cu.findPrimaryType(), true, true, null),
11224
			this.resultCollector);
11225
		assertSearchResults(
11226
			"A.java String A.toString() [toString] EXACT_MATCH"
11227
		);
11228
	}
11229
	finally {
11230
		deleteProject("P");
11231
	}
11232
}
11233
public void testBug295894c4() throws Exception {
11234
	try {
11235
		createJavaProject("P");
11236
		createFile(
11237
			"/P/A.java",
11238
			"public class A {\n" + 
11239
			"    void test() {\n" + 
11240
			"        A a= new A();\n" + 
11241
			"        a.toString();\n" + 
11242
			"    }\n" + 
11243
			"    @Override\n" +
11244
			"    public String toString() {\n" +
11245
			"        return \"\";\n" + 
11246
			"    }\n" + 
11247
			"}\n"
11248
		);
11249
		final ICompilationUnit cu = getCompilationUnit("/P/A.java");
11250
		IMethod method = selectMethod(cu, "toString");
11251
		search(method,
11252
			DECLARATIONS|IGNORE_RETURN_TYPE,
11253
			SearchEngine.createHierarchyScope(cu.findPrimaryType(), null),
11254
			this.resultCollector);
11255
		assertSearchResults(
11256
			"A.java String A.toString() [toString] EXACT_MATCH"
11257
		);
11258
	}
11259
	finally {
11260
		deleteProject("P");
11261
	}
11262
}
11263
/**
11140
 * @bug 288174: NullPointerException when searching for type references
11264
 * @bug 288174: NullPointerException when searching for type references
11141
 * @test Ensure that no NPE occurs when searching for type references
11265
 * @test Ensure that no NPE occurs when searching for type references
11142
 * 		when a binary type has matches in several member or anonymous types
11266
 * 		when a binary type has matches in several member or anonymous types

Return to bug 295894