### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core
Index: search/org/eclipse/jdt/core/search/SearchEngine.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/SearchEngine.java,v
retrieving revision 1.148
diff -u -r1.148 SearchEngine.java
--- search/org/eclipse/jdt/core/search/SearchEngine.java 7 Oct 2009 15:10:51 -0000 1.148
+++ search/org/eclipse/jdt/core/search/SearchEngine.java 7 Dec 2009 17:03:00 -0000
@@ -7,7 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- * Stephan Herrmann - Contribution for bug 215139
+ * Stephan Herrmann - Contributions for bug 215139 and bug 295894
*******************************************************************************/
package org.eclipse.jdt.core.search;
@@ -212,6 +212,7 @@
* or null
if the primary working copy owner should be used
* @return a new hierarchy scope
* @exception JavaModelException if the hierarchy could not be computed on the given type
+ * @deprecated Use {@link #createStrictHierarchyScope(IJavaProject, IType, boolean, boolean, WorkingCopyOwner)} instead.
* @since 3.6
*/
public static IJavaSearchScope createHierarchyScope(IJavaProject project, IType type, boolean onlySubtypes, boolean noMemberTypes, WorkingCopyOwner owner) throws JavaModelException {
@@ -219,6 +220,36 @@
}
/**
+ * Returns a Java search scope limited to the hierarchy of the given type and to a given project.
+ * The Java elements resulting from a search with this scope will be types in this hierarchy.
+ *
+ * Unlike the createHierarchyScope
methods, this method creates strict
+ * scopes that only contain types that actually span the hierarchy of the focus
+ * type, but do not include additional enclosing or member types.
+ *
+ * By default, hierarchy scopes include all direct and indirect supertypes and subtypes of the + * focus type. This method, however, allows to restrict the hierarchy to true subtypes, + * not including supertypes. Also inclusion of the focus type itself is controled by a parameter. + *
+ * + * @param project the project to which to constrain the search, ornull
if
+ * search should consider all types in the workspace
+ * @param type the focus of the hierarchy scope
+ * @param onlySubtypes if true only subtypes of type
are considered
+ * @param includeFocusType if true the focus type type
is included in the resulting scope,
+ * otherwise it is excluded
+ * @param owner the owner of working copies that take precedence over original compilation units,
+ * or null
if the primary working copy owner should be used
+ * @return a new hierarchy scope
+ * @exception JavaModelException if the hierarchy could not be computed on the given type
+ * @since 3.6
+ */
+ public static IJavaSearchScope createStrictHierarchyScope(IJavaProject project, IType type, boolean onlySubtypes, boolean includeFocusType, WorkingCopyOwner owner) throws JavaModelException {
+ return BasicSearchEngine.createStrictHierarchyScope(project, type, onlySubtypes, includeFocusType, owner);
+ }
+
+ /**
* Returns a Java search scope limited to the given resources.
* The Java elements resulting from a search with this scope will
* have their underlying resource included in or equals to one of the given
Index: search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java,v
retrieving revision 1.62
diff -u -r1.62 BasicSearchEngine.java
--- search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 7 Oct 2009 15:10:51 -0000 1.62
+++ search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 7 Dec 2009 17:03:03 -0000
@@ -7,7 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- * Stephan Herrmann - Contribution for bug 215139
+ * Stephan Herrmann - Contributions for bug 215139 and bug 295894
*******************************************************************************/
package org.eclipse.jdt.internal.core.search;
@@ -110,9 +110,17 @@
/**
* @see SearchEngine#createHierarchyScope(IJavaProject,IType,boolean,boolean,WorkingCopyOwner) for detailed comment.
+ * @deprecated Use {@link #createHierarchyScope(IJavaProject, IType, boolean, boolean, WorkingCopyOwner)} instead.
*/
public static IJavaSearchScope createHierarchyScope(IJavaProject project, IType type, boolean onlySubtypes, boolean noMemberTypes, WorkingCopyOwner owner) throws JavaModelException {
- return new HierarchyScope(project, type, owner, onlySubtypes, noMemberTypes);
+ return new HierarchyScope(project, type, owner, onlySubtypes, noMemberTypes, !onlySubtypes);
+ }
+
+ /**
+ * @see SearchEngine#createStrictHierarchyScope(IJavaProject,IType,boolean,boolean,WorkingCopyOwner) for detailed comment.
+ */
+ public static IJavaSearchScope createStrictHierarchyScope(IJavaProject project, IType type, boolean onlySubtypes, boolean includeFocusType, WorkingCopyOwner owner) throws JavaModelException {
+ return new HierarchyScope(project, type, owner, onlySubtypes, true, includeFocusType);
}
/**
Index: search/org/eclipse/jdt/internal/core/search/HierarchyScope.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/HierarchyScope.java,v
retrieving revision 1.47
diff -u -r1.47 HierarchyScope.java
--- search/org/eclipse/jdt/internal/core/search/HierarchyScope.java 7 Oct 2009 15:10:51 -0000 1.47
+++ search/org/eclipse/jdt/internal/core/search/HierarchyScope.java 7 Dec 2009 17:03:04 -0000
@@ -7,7 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- * Stephan Herrmann - Contribution for bug 215139
+ * Stephan Herrmann - Contributions for bug 215139 and bug 295894
*******************************************************************************/
package org.eclipse.jdt.internal.core.search;
@@ -43,7 +43,8 @@
private HashSet subTypes = null; // null means: don't filter for subTypes
private IJavaProject javaProject = null; // null means: don't constrain the search to a project
- private boolean allowMemberTypes = true;
+ private boolean allowMemberAndEnclosingTypes = true;
+ private boolean includeFocusType = true;
/* (non-Javadoc)
* Adds the given resource to this search scope.
@@ -61,22 +62,26 @@
}
/**
- * Creates a new hierarchy scope for the given type.
+ * Creates a new hierarchy scope for the given type with the given configuration options.
* @param project constrain the search result to this project,
* or null
if search should consider all types in the workspace
* @param type the focus type of the hierarchy
* @param owner the owner of working copies that take precedence over original compilation units,
* or null
if the primary working copy owner should be used
- * @param onlySubtypes if true search only subtypes of 'type' (not including 'type')
- * @param noMemberTypes if true do not consider member or enclosing types of types in the given type hierarchy.
+ * @param onlySubtypes if true search only subtypes of 'type'
+ * @param noMembersOrEnclosingTypes if true the hierarchy is strict,
+ * i.e., no additional member types or enclosing types of types spanning the hierarchy are included,
+ * otherwise all member and enclosing types of types in the hierarchy are included.
+ * @param includeFocusType if true the focus type type
is included in the resulting scope, otherwise it is excluded
*/
- public HierarchyScope(IJavaProject project, IType type, WorkingCopyOwner owner, boolean onlySubtypes, boolean noMemberTypes) throws JavaModelException {
+ public HierarchyScope(IJavaProject project, IType type, WorkingCopyOwner owner, boolean onlySubtypes, boolean noMembersOrEnclosingTypes, boolean includeFocusType) throws JavaModelException {
this(type, owner);
this.javaProject = project;
if (onlySubtypes) {
this.subTypes = new HashSet();
}
- this.allowMemberTypes = !noMemberTypes;
+ this.includeFocusType = includeFocusType;
+ this.allowMemberAndEnclosingTypes = !noMembersOrEnclosingTypes;
}
/* (non-Javadoc)
@@ -293,7 +298,7 @@
* (regarding subtypes and members) is requested
*/
public boolean enclosesFineGrained(IJavaElement element) {
- if ((this.subTypes == null) && this.allowMemberTypes)
+ if ((this.subTypes == null) && this.allowMemberAndEnclosingTypes)
return true; // no fine grained checking requested
return encloses(element);
}
@@ -302,7 +307,7 @@
*/
public boolean encloses(IJavaElement element) {
if (this.hierarchy == null) {
- if (this.subTypes == null && this.focusType.equals(element.getAncestor(IJavaElement.TYPE))) {
+ if (this.includeFocusType && this.focusType.equals(element.getAncestor(IJavaElement.TYPE))) {
return true;
} else {
if (this.needsRefresh) {
@@ -332,11 +337,13 @@
type = ((IMember) element).getDeclaringType();
}
if (type != null) {
+ if (this.focusType.equals(type))
+ return this.includeFocusType;
// potentially allow travelling in:
- if (enclosesType(type, this.allowMemberTypes)) {
+ if (enclosesType(type, this.allowMemberAndEnclosingTypes)) {
return true;
}
- if (this.allowMemberTypes) {
+ if (this.allowMemberAndEnclosingTypes) {
// travel out: queried type is enclosed in this scope if its (indirect) declaring type is:
IType enclosing = type.getDeclaringType();
while (enclosing != null) {
#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.183
diff -u -r1.183 JavaSearchBugsTests.java
--- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 1 Dec 2009 10:45:44 -0000 1.183
+++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 7 Dec 2009 17:03:24 -0000
@@ -11064,4 +11064,103 @@
removeClasspathEntry(JAVA_PROJECT, new Path(libPath));
}
}
+
+static { TESTS_PREFIX = "testBug295894"; }
+/**
+ * @bug 295894: Search shows focus type implementation for nested types even though the scope is restricted to subtypes.
+ * @test using the hierarchy with the old API includes the focus type.
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=295894"
+ */
+public void testBug295894() throws Exception {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/Test.java",
+ "public class Test {\n" +
+ " void test() {\n" +
+ " Test t = new Test();\n" +
+ " t.foo();\n" +
+ " }\n" +
+ " public void foo() {\n" +
+ " }\n" +
+ " public class Sub extends Test {\n" +
+ " public void foo() {}\n" +
+ " }\n" +
+ "}\n" +
+ ""
+ );
+ search(
+ "foo",
+ METHOD,
+ DECLARATIONS,
+ SearchEngine.createHierarchyScope(this.workingCopies[0].findPrimaryType()),
+ this.resultCollector);
+ assertSearchResults(
+ "src/Test.java void Test.foo() [foo] EXACT_MATCH\n" +
+ "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 excluding the focus type
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=295894"
+ */
+public void testBug295894a() throws Exception {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/Test.java",
+ "public class Test {\n" +
+ " void test() {\n" +
+ " Test t = new Test();\n" +
+ " t.foo();\n" +
+ " }\n" +
+ " public void foo() {\n" +
+ " }\n" +
+ " public class Sub extends Test {\n" +
+ " public void foo() {}\n" +
+ " }\n" +
+ "}\n" +
+ ""
+ );
+ search(
+ "foo",
+ METHOD,
+ DECLARATIONS,
+ SearchEngine.createStrictHierarchyScope(null, this.workingCopies[0].findPrimaryType(), true, false, null),
+ this.resultCollector);
+ // Test$Sub is a true sub type, not affected by filtering member types
+ assertSearchResults(
+ "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
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=295894"
+ */
+public void testBug295894b() throws Exception {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/Test.java",
+ "public class Test {\n" +
+ " void test() {\n" +
+ " Test t = new Test();\n" +
+ " t.foo();\n" +
+ " }\n" +
+ " public void foo() {\n" +
+ " }\n" +
+ " public class Sub extends Test {\n" +
+ " public void foo() {}\n" +
+ " }\n" +
+ "}\n" +
+ ""
+ );
+ search(
+ "foo",
+ METHOD,
+ DECLARATIONS,
+ SearchEngine.createStrictHierarchyScope(null, this.workingCopies[0].findPrimaryType(), false, true, null),
+ this.resultCollector);
+ // Same results as with the old API
+ assertSearchResults(
+ "src/Test.java void Test.foo() [foo] EXACT_MATCH\n" +
+ "src/Test.java void Test$Sub.foo() [foo] EXACT_MATCH"
+ );
+}
}
\ No newline at end of file
Index: src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java,v
retrieving revision 1.184
diff -u -r1.184 JavaSearchTests.java
--- src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 25 Nov 2009 12:26:50 -0000 1.184
+++ src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 7 Dec 2009 17:03:31 -0000
@@ -1357,6 +1357,7 @@
/**
* Method declaration in hierarchy test.
* Explicitly request behavior pre https://bugs.eclipse.org/bugs/show_bug.cgi?id=215139
+ * @deprecated tests a deprecated API
*/
public void testMethodDeclaration04() throws CoreException { // was testMethodDeclarationInHierarchyScope1
IType type = getCompilationUnit("JavaSearch", "src", "p", "X.java").getType("X");
@@ -2450,7 +2451,7 @@
ICompilationUnit cuB = this. getCompilationUnit("JavaSearch", "src", "a10", "B.java");
ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
IType type = cuC.getType("C");
- IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
+ IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
// don't include super-classes:
assertFalse("a10.A should not be included in hierarchy scope", scope.encloses(cuB.getType("A")));
@@ -2464,11 +2465,25 @@
public void testSearchScope07() throws CoreException {
ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
IType type = cuC.getType("C");
- IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
+ IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
// don't include focus type:
- assertFalse("a10.C should be not included in hierarchy scope", scope.encloses(type));
- assertFalse("a10/C.java should be included in hierarchy scope", scope.encloses(cuC.getUnderlyingResource().getFullPath().toString()));
+ assertFalse("a10.C should not be included in hierarchy scope", scope.encloses(type));
+ assertFalse("a10/C.java should not be included in hierarchy scope", scope.encloses(cuC.getUnderlyingResource().getFullPath().toString()));
+}
+/**
+ * Hierarchy scope test.
+ * test for enhancement bug 215139 encloses(): find only subtypes.
+ * also test enhancement bug 295894: include focus type.
+ */
+public void testSearchScope07a() throws CoreException {
+ ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
+ IType type = cuC.getType("C");
+ IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, true, null);
+
+ // include focus type:
+ assertTrue("a10.C should be included in hierarchy scope", scope.encloses(type));
+ assertTrue("a10/C.java should be included in hierarchy scope", scope.encloses(cuC.getUnderlyingResource().getFullPath().toString()));
}
/**
* Hierarchy scope test.
@@ -2479,7 +2494,7 @@
ICompilationUnit cuD = this. getCompilationUnit("JavaSearch", "src", "a10", "D.java");
ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
IType type = cuC.getType("C");
- IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
+ IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
// regular sub-types:
assertTrue("a10.D should be included in hierarchy scope", scope.encloses(cuD.getType("D")));
@@ -2496,7 +2511,7 @@
ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
IType type = cuC.getType("C");
- IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
+ IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
// sub-type is a nested type:
assertTrue("a10.H$I should be included in hierarchy scope", scope.encloses(cuE.getType("H").getType("I")));
@@ -2509,7 +2524,7 @@
ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
IType type = cuC.getType("C");
- IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
+ IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
// member of a sub-type:
assertFalse("a10.F$G should not be included in hierarchy scope", scope.encloses(cuE.getType("F").getType("G")));
@@ -2517,6 +2532,7 @@
/**
* Hierarchy scope test.
* (test for enhancement bug 215139 encloses(): find only subtypes and their member types).
+ * @deprecated tests a deprecated API
*/
public void testSearchScope11() throws CoreException {
ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
@@ -2535,7 +2551,7 @@
ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
IType type = cuC.getType("C");
- IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
+ IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
// enclosing of a sub-type:
assertFalse("a10.H should not be included in hierarchy scope", scope.encloses(cuE.getType("H")));
@@ -2548,7 +2564,7 @@
public void testSearchScope13() throws CoreException {
ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
IType type = cuC.getType("C");
- IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
+ IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
search("**", TYPE, DECLARATIONS, scope);
assertSearchResults(
@@ -2565,7 +2581,7 @@
public void testSearchScope14() throws CoreException {
ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
IType type = cuC.getType("C");
- IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, /*onlySubTypes*/false, true, null);
+ IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, /*onlySubTypes*/false, true, null);
search("**", TYPE, DECLARATIONS, scope);
assertSearchResults(
@@ -2581,12 +2597,33 @@
}
/**
* Hierarchy scope test.
+ * test for enhancement bug 215139 search: find only subtypes - disabled,
+ * also test enhancement bug 295894: exclude focus type.
+ */
+public void testSearchScope14a() throws CoreException {
+ ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
+ IType type = cuC.getType("C");
+ IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, /*onlySubTypes*/false, false, null);
+
+ search("**", TYPE, DECLARATIONS, scope);
+ assertSearchResults(
+ "src/a10/B.java a10.A [A]\n" +
+ "src/a10/B.java a10.B [B]\n" +
+ "src/a10/D.java a10.D [D]\n" +
+ "src/a10/E.java a10.E [E]\n" +
+ "src/a10/E.java a10.F [F]\n" +
+ "src/a10/E.java a10.H$I [I]\n" +
+ getExternalJCLPathString() + " java.lang.Object"
+ );
+}
+/**
+ * Hierarchy scope test.
* (test for enhancement bug 215139 search: find only subtypes - different call chain).
*/
public void testSearchScope15() throws CoreException {
ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
IType type = cuC.getType("C");
- IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
+ IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
TypeNameMatchCollector collector = new TypeNameMatchCollector() {
public String toString(){
return toFullyQualifiedNamesString();
@@ -2610,6 +2647,7 @@
/**
* Hierarchy scope test.
* (test for enhancement bug 215139 search: find only subtypes plus member & enclosing types - different call chain).
+ * @deprecated tests a deprecated API
*/
public void testSearchScope16() throws CoreException {
ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
@@ -2645,7 +2683,7 @@
ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");
ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java");
IType type = cuC.getType("C");
- IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, true, null);
+ IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(null, type, true, false, null);
// method of a member of a sub-type:
assertFalse("a10.F$G.m() should not be included in hierarchy scope", scope.encloses(cuE.getType("F").getType("G").getMethod("m", new String[0])));
@@ -2653,6 +2691,7 @@
/**
* Hierarchy scope test.
* (test for enhancement bug 215139 encloses(method): find only subtypes but also member types).
+ * @deprecated tests a deprecated API
*/
public void testSearchScope18() throws CoreException {
ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java");