### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java,v retrieving revision 1.189 diff -u -r1.189 JavaSearchBugsTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 13 Jan 2010 17:38:24 -0000 1.189 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 14 Jan 2010 12:36:24 -0000 @@ -11135,7 +11135,100 @@ "src/Test.java void Test$Sub.foo() [foo] EXACT_MATCH" ); } - +/** + * @bug 295894: Search shows focus type implementation for nested types even though the scope is restricted to subtypes. + * @test explicitly including the focus type, which has no subtypes. + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=295894" + */ +public void testBug295894c() throws Exception { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/A.java", + "public class A {\n" + + " void test() {\n" + + " A a= new A();\n" + + " a.toString();\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"\";\n" + + " }\n" + + "}\n" + + "" + ); + search( + "toString", + METHOD, + DECLARATIONS, + SearchEngine.createStrictHierarchyScope(null, this.workingCopies[0].findPrimaryType(), true, true, null), + this.resultCollector); + assertSearchResults( + "src/A.java String A.toString() [toString] EXACT_MATCH" + ); +} +// Failing test while working with a compilation unit instead of working copy +public void testBug295894c2() throws Exception { + try { + createJavaProject("P"); + createFile( + "/P/A.java", + "public class A {\n" + + " void test() {\n" + + " A a= new A();\n" + + " a.toString();\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"\";\n" + + " }\n" + + "}\n" + ); + final ICompilationUnit cu = getCompilationUnit("/P/A.java"); + IMethod method = selectMethod(cu, "toString"); + search(method, + DECLARATIONS|IGNORE_RETURN_TYPE, + SearchEngine.createStrictHierarchyScope(null, cu.findPrimaryType(), true, true, null), + this.resultCollector); + assertSearchResults( + "A.java String A.toString() [toString] EXACT_MATCH" + ); + } + finally { + deleteProject("P"); + } +} +// Similar test passing when the focus type has a subclass +public void testBug295894c3() throws Exception { + try { + createJavaProject("P"); + createFile( + "/P/A.java", + "public class A {\n" + + " void test() {\n" + + " A a= new A();\n" + + " a.toString();\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"\";\n" + + " }\n" + + "}\n" + + "class B extends A {\n" + + "}\n" + ); + final ICompilationUnit cu = getCompilationUnit("/P/A.java"); + IMethod method = selectMethod(cu, "toString"); + search(method, + DECLARATIONS|IGNORE_RETURN_TYPE, + SearchEngine.createStrictHierarchyScope(null, cu.findPrimaryType(), true, true, null), + this.resultCollector); + assertSearchResults( + "A.java String A.toString() [toString] EXACT_MATCH" + ); + } + finally { + deleteProject("P"); + } +} /** * @bug 288174: NullPointerException when searching for type references * @test Ensure that no NPE occurs when searching for type references