Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 153865 Details for
Bug 295894
[search] Search shows focus type implementation for nested types even though the scope is restricted to subtypes.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
combined changes
bug_295894_patch2.txt (text/plain), 21.02 KB, created by
Stephan Herrmann
on 2009-12-05 13:01:51 EST
(
hide
)
Description:
combined changes
Filename:
MIME Type:
Creator:
Stephan Herrmann
Created:
2009-12-05 13:01:51 EST
Size:
21.02 KB
patch
obsolete
>### 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 5 Dec 2009 17:38:11 -0000 >@@ -193,29 +193,30 @@ > * The Java elements resulting from a search with this scope will be types in this hierarchy, > * or members or enclosing types of the types in this hierarchy. > * <p> >- * 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, >- * neither including supertypes nor the focus type itself. >+ * Unlike the other <code>createHierarchyScope</code> methods, this method creates >+ * scopes that only contain types that actually span the hierarchy of the focus >+ * type, but do not include additional enclosing or member types. > * </p> > * <p> >- * By default, hierarchy scopes include also member types and enclosing types of those types >- * that actually span the hierarchy. This method, however, allows to inhibit this behavior, >- * by passing <code>true</code> to the parameter <code>noMemberTypes</code>. >+ * 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. > * </p> > * > * @param project the project to which to constrain the search, or <code>null</code> if > * search should consider all types in the workspace > * @param type the focus of the hierarchy scope > * @param onlySubtypes if true only subtypes of <code>type</code> are considered >- * @param noMemberTypes if true do not consider member or enclosing types of types in the given type hiearchy >+ * @param includeFocusType if true the focus type <code>type</code> 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 <code>null</code> 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 createHierarchyScope(IJavaProject project, IType type, boolean onlySubtypes, boolean noMemberTypes, WorkingCopyOwner owner) throws JavaModelException { >- return BasicSearchEngine.createHierarchyScope(project, type, onlySubtypes, noMemberTypes, owner); >+ public static IJavaSearchScope createHierarchyScope(IJavaProject project, IType type, boolean onlySubtypes, boolean includeFocusType, WorkingCopyOwner owner) throws JavaModelException { >+ return BasicSearchEngine.createHierarchyScope(project, type, onlySubtypes, includeFocusType, owner); > } > > /** >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 5 Dec 2009 17:38:14 -0000 >@@ -111,8 +111,8 @@ > /** > * @see SearchEngine#createHierarchyScope(IJavaProject,IType,boolean,boolean,WorkingCopyOwner) for detailed comment. > */ >- public static IJavaSearchScope createHierarchyScope(IJavaProject project, IType type, boolean onlySubtypes, boolean noMemberTypes, WorkingCopyOwner owner) throws JavaModelException { >- return new HierarchyScope(project, type, owner, onlySubtypes, noMemberTypes); >+ public static IJavaSearchScope createHierarchyScope(IJavaProject project, IType type, boolean onlySubtypes, boolean includeFocusType, WorkingCopyOwner owner) throws JavaModelException { >+ return new HierarchyScope(project, type, owner, onlySubtypes, 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 5 Dec 2009 17:38:15 -0000 >@@ -44,6 +44,7 @@ > 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 includeFocusType = true; > > /* (non-Javadoc) > * Adds the given resource to this search scope. >@@ -62,21 +63,25 @@ > > /** > * Creates a new hierarchy scope for the given type. >+ * Unlike the other constructor, this constructor creates scopes that only contain types >+ * that actually span the hierarchy of the focus type, but do not include additional >+ * enclosing or member types. > * @param project constrain the search result to this project, > * or <code>null</code> 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 <code>null</code> 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 includeFocusType if true the focus type <code>type</code> 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 includeFocusType) throws JavaModelException { > this(type, owner); > this.javaProject = project; > if (onlySubtypes) { > this.subTypes = new HashSet(); > } >- this.allowMemberTypes = !noMemberTypes; >+ this.includeFocusType = includeFocusType; >+ this.allowMemberTypes = false; > } > > /* (non-Javadoc) >@@ -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,6 +337,8 @@ > type = ((IMember) element).getDeclaringType(); > } > if (type != null) { >+ if (this.focusType.equals(type)) >+ return this.includeFocusType; > // potentially allow travelling in: > if (enclosesType(type, this.allowMemberTypes)) { > return true; >#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 5 Dec 2009 17:38:35 -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 when restricting the hierarchy to sub types the focus should not be included >+ * @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.createHierarchyScope(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 when not restricting the hierarchy to sub types the focus should be included >+ * @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.createHierarchyScope(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 5 Dec 2009 17:38:42 -0000 >@@ -2450,7 +2450,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.createHierarchyScope(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 +2464,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.createHierarchyScope(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.createHierarchyScope(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 +2493,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.createHierarchyScope(null, type, true, false, null); > > // regular sub-types: > assertTrue("a10.D should be included in hierarchy scope", scope.encloses(cuD.getType("D"))); >@@ -2496,7 +2510,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.createHierarchyScope(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 +2523,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.createHierarchyScope(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,8 +2531,9 @@ > /** > * Hierarchy scope test. > * (test for enhancement bug 215139 encloses(): find only subtypes and their member types). >+ * Note: this combination of arguments is no longer supported after the change from bug 295894 > */ >-public void testSearchScope11() throws CoreException { >+public void _testSearchScope11() throws CoreException { > ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java"); > ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java"); > IType type = cuC.getType("C"); >@@ -2535,7 +2550,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.createHierarchyScope(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 +2563,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.createHierarchyScope(null, type, true, false, null); > > search("**", TYPE, DECLARATIONS, scope); > assertSearchResults( >@@ -2581,12 +2596,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.createHierarchyScope(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.createHierarchyScope(null, type, true, false, null); > TypeNameMatchCollector collector = new TypeNameMatchCollector() { > public String toString(){ > return toFullyQualifiedNamesString(); >@@ -2610,8 +2646,9 @@ > /** > * Hierarchy scope test. > * (test for enhancement bug 215139 search: find only subtypes plus member & enclosing types - different call chain). >+ * Note: this combination of arguments is no longer supported after the change from bug 295894 > */ >-public void testSearchScope16() throws CoreException { >+public void _testSearchScope16() throws CoreException { > ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java"); > IType type = cuC.getType("C"); > IJavaSearchScope scope = SearchEngine.createHierarchyScope(null, type, true, false, null); >@@ -2645,7 +2682,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.createHierarchyScope(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,8 +2690,9 @@ > /** > * Hierarchy scope test. > * (test for enhancement bug 215139 encloses(method): find only subtypes but also member types). >+ * Note: this combination of arguments is no longer supported after the change from bug 295894 > */ >-public void testSearchScope18() throws CoreException { >+public void _testSearchScope18() throws CoreException { > ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java"); > ICompilationUnit cuE = this. getCompilationUnit("JavaSearch", "src", "a10", "E.java"); > IType type = cuC.getType("C");
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 295894
:
152929
|
152945
|
153058
|
153865
|
153938
|
155994
|
156008
|
156074
|
156084
|
156088
|
156091
|
156098