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 114603 Details for
Bug 215139
[search] More options for HierarchyScope
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Improved patch
bug_215139_patch4.txt (text/plain), 18.65 KB, created by
Stephan Herrmann
on 2008-10-08 16:51:57 EDT
(
hide
)
Description:
Improved patch
Filename:
MIME Type:
Creator:
Stephan Herrmann
Created:
2008-10-08 16:51:57 EDT
Size:
18.65 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: search/org/eclipse/jdt/core/search/IJavaSearchScope.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/IJavaSearchScope.java,v >retrieving revision 1.26 >diff -u -r1.26 IJavaSearchScope.java >--- search/org/eclipse/jdt/core/search/IJavaSearchScope.java 27 Jun 2008 16:04:08 -0000 1.26 >+++ search/org/eclipse/jdt/core/search/IJavaSearchScope.java 8 Oct 2008 19:49:28 -0000 >@@ -12,6 +12,7 @@ > > import org.eclipse.core.runtime.IPath; > import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IType; > > /** > * An <code>IJavaSearchScope</code> defines where search result should be found by a >@@ -68,6 +69,16 @@ > */ > public boolean encloses(IJavaElement element); > /** >+ * Extra check whether a given type is enclosed, after the >+ * containing resource has already been found to be enclosed. >+ * >+ * @param type the given type. >+ * @return <code>true</code> if the type is in this scope or if no >+ * additional check is required after checking the resource. >+ * @since 3.5 >+ */ >+public boolean enclosesTypeOfEnclosedResource(IType type); >+/** > * Returns the paths to the enclosing projects and JARs for this search scope. > * <ul> > * <li> If the path is a project path, this is the full path of the project >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.147 >diff -u -r1.147 SearchEngine.java >--- search/org/eclipse/jdt/core/search/SearchEngine.java 27 Jun 2008 16:04:08 -0000 1.147 >+++ search/org/eclipse/jdt/core/search/SearchEngine.java 8 Oct 2008 19:49:31 -0000 >@@ -171,6 +171,37 @@ > } > > /** >+ * 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. >+ * >+ * 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. >+ * >+ * 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>false</code> to the parameter <code>noMemberTypes</code>. >+ * >+ * @param project the project to which to constrain the search >+ * @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 owner the owner of working copies that take precedence over original compilation units >+ * @return a new hierarchy scope >+ * @exception JavaModelException if the hierarchy could not be computed on the given type >+ */ >+ public static IJavaSearchScope createHierarchyScope( >+ IJavaProject project, >+ IType type, >+ boolean onlySubtypes, >+ boolean noMemberTypes, >+ WorkingCopyOwner owner) >+ throws JavaModelException >+ { >+ return BasicSearchEngine.createHierarchyScope(project, type, onlySubtypes, noMemberTypes, owner); >+ } >+ >+ /** > * Returns a Java search scope limited to the hierarchy of the given type. > * When the hierarchy is computed, the types defined in the working copies owned > * by the given owner take precedence over the original compilation units. >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.46 >diff -u -r1.46 HierarchyScope.java >--- search/org/eclipse/jdt/internal/core/search/HierarchyScope.java 27 Jun 2008 16:04:09 -0000 1.46 >+++ search/org/eclipse/jdt/internal/core/search/HierarchyScope.java 8 Oct 2008 19:49:34 -0000 >@@ -20,9 +20,6 @@ > import org.eclipse.jdt.core.*; > import org.eclipse.jdt.internal.compiler.util.SuffixConstants; > import org.eclipse.jdt.internal.core.*; >-import org.eclipse.jdt.internal.core.JarPackageFragmentRoot; >-import org.eclipse.jdt.internal.core.JavaElement; >-import org.eclipse.jdt.internal.core.JavaModel; > import org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy; > > /** >@@ -35,7 +32,6 @@ > private WorkingCopyOwner owner; > > private ITypeHierarchy hierarchy; >- private IType[] types; > private HashSet resourcePaths; > private IPath[] enclosingProjectsAndJars; > >@@ -44,6 +40,11 @@ > > public boolean needsRefresh; > >+ private boolean onlySubtypes= false; >+ private HashSet subTypes; // only set when onlySubtypes==true >+ private IJavaProject javaProject= null; >+ private boolean noMemberTypes= false; >+ > /* (non-Javadoc) > * Adds the given resource to this search scope. > */ >@@ -59,6 +60,23 @@ > this.elements[this.elementCount++] = element; > } > >+ /** >+ * Creates a new hierarchy scope for the given type. >+ * @param project constrain the search result to this project >+ * @param type the focus type of the hierarchy >+ * @param owner the owner of working copies that take precedence over original compilation units >+ * @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 hiearchy. >+ */ >+ public HierarchyScope(IJavaProject project, IType type, WorkingCopyOwner owner, boolean onlySubtypes, boolean noMemberTypes) >+ throws JavaModelException >+ { >+ this(type, owner); >+ this.javaProject= project; >+ this.onlySubtypes= onlySubtypes; >+ this.noMemberTypes= noMemberTypes; >+ } >+ > /* (non-Javadoc) > * Creates a new hiearchy scope for the given type. > */ >@@ -100,10 +118,18 @@ > private void buildResourceVector() { > HashMap resources = new HashMap(); > HashMap paths = new HashMap(); >- this.types = this.hierarchy.getAllTypes(); >- for (int i = 0; i < this.types.length; i++) { >- IType type = this.types[i]; >- IResource resource = ((JavaElement) type).resource(); >+ IType[] types = null; >+ if (this.onlySubtypes) { >+ types= this.hierarchy.getAllSubtypes(this.focusType); >+ this.subTypes= new HashSet(types.length); >+ } else { >+ types = this.hierarchy.getAllTypes(); >+ } >+ for (int i = 0; i < types.length; i++) { >+ IType type = types[i]; >+ if (this.onlySubtypes) >+ this.subTypes.add(type); >+ IResource resource = type.getResource(); > if (resource != null && resources.get(resource) == null) { > resources.put(resource, resource); > add(resource); >@@ -287,6 +313,16 @@ > IType type = null; > if (element instanceof IType) { > type = (IType) element; >+ if (this.onlySubtypes) { >+ // searching subtypes and have a type: only check in this.subTypes: >+ if (this.subTypes.contains(type)) >+ return true; >+ // be flexible: look at original element (see bug 14106 and below) >+ IType original = type.isBinary() ? null : (IType)type.getPrimaryElement(); >+ if (original != type && this.subTypes.contains(original)) >+ return true; >+ return false; >+ } > } else if (element instanceof IMember) { > type = ((IMember) element).getDeclaringType(); > } >@@ -305,6 +341,15 @@ > return false; > } > /* (non-Javadoc) >+ * @see IJavaSearchScope#enclosesElementOfEnclosedResource(IJavaElement) >+ */ >+ public boolean enclosesTypeOfEnclosedResource(IType type) { >+ if (this.noMemberTypes) { >+ return this.encloses(type); >+ } >+ return true; // no further check requested >+ } >+ /* (non-Javadoc) > * @see IJavaSearchScope#enclosingProjectsAndJars() > * @deprecated > */ >@@ -324,7 +369,10 @@ > this.elementCount = 0; > this.needsRefresh = false; > if (this.hierarchy == null) { >- this.hierarchy = this.focusType.newTypeHierarchy(this.owner, null); >+ if (this.javaProject != null) >+ this.hierarchy = this.focusType.newTypeHierarchy(this.javaProject, this.owner, null); >+ else >+ this.hierarchy = this.focusType.newTypeHierarchy(this.owner, null); > } else { > this.hierarchy.refresh(null); > } >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.56 >diff -u -r1.56 BasicSearchEngine.java >--- search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 27 Jun 2008 16:04:09 -0000 1.56 >+++ search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 8 Oct 2008 19:49:33 -0000 >@@ -100,6 +100,20 @@ > return createHierarchyScope(type, DefaultWorkingCopyOwner.PRIMARY); > } > >+ >+ /** >+ * @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); >+ } >+ > /** > * @see SearchEngine#createHierarchyScope(IType,WorkingCopyOwner) for detailed comment. > */ >Index: search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java,v >retrieving revision 1.12 >diff -u -r1.12 TypeNameMatchRequestorWrapper.java >--- search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java 27 Jun 2008 16:04:09 -0000 1.12 >+++ search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java 8 Oct 2008 19:49:34 -0000 >@@ -107,7 +107,7 @@ > ? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames) > : createTypeFromJar(path, separatorIndex); > } >- if (type != null) { >+ if (type != null && this.scope.enclosesTypeOfEnclosedResource(type)) { > this.requestor.acceptTypeNameMatch(new JavaSearchTypeNameMatch(type, modifiers)); > } > } catch (JavaModelException e) { >Index: search/org/eclipse/jdt/internal/core/search/AbstractSearchScope.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/AbstractSearchScope.java,v >retrieving revision 1.15 >diff -u -r1.15 AbstractSearchScope.java >--- search/org/eclipse/jdt/internal/core/search/AbstractSearchScope.java 27 May 2008 23:46:43 -0000 1.15 >+++ search/org/eclipse/jdt/internal/core/search/AbstractSearchScope.java 8 Oct 2008 19:49:31 -0000 >@@ -11,11 +11,19 @@ > package org.eclipse.jdt.internal.core.search; > > import org.eclipse.jdt.core.IJavaElementDelta; >+import org.eclipse.jdt.core.IType; > import org.eclipse.jdt.core.search.IJavaSearchScope; > > public abstract class AbstractSearchScope implements IJavaSearchScope { > > /** >+ * @see IJavaSearchScope#enclosesTypeOfEnclosedResource(IType) >+ * @since 3.5 >+ */ >+public boolean enclosesTypeOfEnclosedResource(IType type) { >+ return true; // default: no additional checking >+} >+/** > * @see IJavaSearchScope#includesBinaries() > * @deprecated > */ >#P org.eclipse.jdt.core.tests.model >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.179 >diff -u -r1.179 JavaSearchTests.java >--- src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 9 Sep 2008 12:43:37 -0000 1.179 >+++ src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 8 Oct 2008 19:49:42 -0000 >@@ -2422,6 +2422,107 @@ > > } > /** >+ * Hierarchy scope test. >+ * (test for enhancement bug 215139 search: find only subtypes). >+ */ >+public void testSearchScope06() throws CoreException { >+ ICompilationUnit cuB = this. getCompilationUnit("JavaSearch", "src", "a10", "B.java"); >+ ICompilationUnit cuC = this. getCompilationUnit("JavaSearch", "src", "a10", "C.java"); >+ 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); >+ >+ // don't include super-classes: >+ assertFalse("a10.A should not be included in hierarchy scope", scope.encloses(cuB.getType("A"))); >+ assertFalse("a10.B should not be included in hierarchy scope", scope.encloses(cuB.getType("B"))); >+ assertFalse("a10/B.java should not be included in hierarchy scope", scope.encloses(cuB.getUnderlyingResource().getFullPath().toString())); >+ >+ // 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())); >+ >+ // regular sub-types: >+ assertTrue("a10.D should be included in hierarchy scope", scope.encloses(cuD.getType("D"))); >+ assertTrue("a10/D.java should be included in hierarchy scope", scope.encloses(cuD.getUnderlyingResource().getFullPath().toString())); >+ >+ assertTrue("a10.E should be included in hierarchy scope", scope.encloses(cuE.getType("E"))); >+ assertTrue("a10.F should be included in hierarchy scope", scope.encloses(cuE.getType("F"))); >+ // sub-type is a nested type: >+ assertTrue("a10.H$I should be included in hierarchy scope", scope.encloses(cuE.getType("H").getType("I"))); >+ // member of a sub-type: >+ assertFalse("a10.F$G should not be included in hierarchy scope", scope.encloses(cuE.getType("F").getType("G"))); >+ // enclosing of a sub-type: >+ assertFalse("a10.H should not be included in hierarchy scope", scope.encloses(cuE.getType("H"))); >+ assertTrue("a10/E.java should be included in hierarchy scope", scope.encloses(cuE.getUnderlyingResource().getFullPath().toString())); >+} >+/** >+ * Hierarchy scope test. >+ * (test for enhancement bug 215139 search: find only subtypes). >+ */ >+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); >+ >+ search("**", TYPE, DECLARATIONS, scope); >+ assertSearchResults( >+ "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]" >+ ); >+} >+/** >+ * Hierarchy scope test. >+ * (test for enhancement bug 215139 search: find only subtypes - disabled). >+ */ >+public void testSearchScope08() 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); >+ >+ search("**", TYPE, DECLARATIONS, scope); >+ assertSearchResults( >+ "src/a10/B.java a10.A [A]\n" + >+ "src/a10/B.java a10.B [B]\n" + >+ "src/a10/C.java a10.C [C]\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 testSearchScope09() 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); >+ TypeNameMatchCollector collector = new TypeNameMatchCollector() { >+ public String toString(){ >+ return toFullyQualifiedNamesString(); >+ } >+ }; >+ new SearchEngine().searchAllTypeNames( >+ null, >+ null, >+ scope, >+ collector, >+ IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, >+ null); >+ String expected = >+ "a10.D\n" + >+ "a10.E\n" + >+ "a10.F\n" + >+ "a10.H$I"; >+ assertTrue("We should get some types!", collector.size() > 0); >+ assertEquals("Found types sounds not to be correct", expected, collector.toString()); >+} >+/** > * Simple type declaration test. > */ > public void testTypeDeclaration01() throws CoreException { // was testSimpleTypeDeclaration >Index: workspace/JavaSearch/src/a10/D.java >=================================================================== >RCS file: workspace/JavaSearch/src/a10/D.java >diff -N workspace/JavaSearch/src/a10/D.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ workspace/JavaSearch/src/a10/D.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,3 @@ >+package a10; >+ >+public class D extends C {} >Index: workspace/JavaSearch/src/a10/C.java >=================================================================== >RCS file: workspace/JavaSearch/src/a10/C.java >diff -N workspace/JavaSearch/src/a10/C.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ workspace/JavaSearch/src/a10/C.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,3 @@ >+package a10; >+ >+public class C extends B {} >Index: workspace/JavaSearch/src/a10/E.java >=================================================================== >RCS file: workspace/JavaSearch/src/a10/E.java >diff -N workspace/JavaSearch/src/a10/E.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ workspace/JavaSearch/src/a10/E.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,11 @@ >+package a10; >+ >+public class E extends D {} >+ >+class F extends C { >+ class G {} >+} >+ >+class H { >+ class I extends E {} >+} >Index: workspace/JavaSearch/src/a10/B.java >=================================================================== >RCS file: workspace/JavaSearch/src/a10/B.java >diff -N workspace/JavaSearch/src/a10/B.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ workspace/JavaSearch/src/a10/B.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,5 @@ >+package a10; >+ >+class A { } >+ >+public class B extends A {}
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 215139
:
86773
|
89335
|
111360
|
114603
|
115095
|
119647
|
123432
|
145834
|
147723
|
148863