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 125382 Details for
Bug 250454
[search] Cannot find method references between projects
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
v05.txt (text/plain), 15.10 KB, created by
Frederic Fusier
on 2009-02-11 09:04:15 EST
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Frederic Fusier
Created:
2009-02-11 09:04:15 EST
Size:
15.10 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: search/org/eclipse/jdt/internal/core/search/IndexSelector.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/IndexSelector.java,v >retrieving revision 1.41 >diff -u -r1.41 IndexSelector.java >--- search/org/eclipse/jdt/internal/core/search/IndexSelector.java 27 Jun 2008 16:04:09 -0000 1.41 >+++ search/org/eclipse/jdt/internal/core/search/IndexSelector.java 11 Feb 2009 14:03:42 -0000 >@@ -12,11 +12,7 @@ > > import org.eclipse.core.resources.IFolder; > import org.eclipse.core.runtime.IPath; >-import org.eclipse.jdt.core.IClasspathEntry; >-import org.eclipse.jdt.core.IJavaElement; >-import org.eclipse.jdt.core.IJavaModel; >-import org.eclipse.jdt.core.IJavaProject; >-import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.core.*; > import org.eclipse.jdt.core.search.IJavaSearchScope; > import org.eclipse.jdt.core.search.SearchPattern; > import org.eclipse.jdt.internal.compiler.util.SimpleSet; >@@ -49,17 +45,14 @@ > * a JarPackageFragmentRot) either because the focus is part of the project or the jar, or because it is > * accessible throught the project's classpath > */ >-public static boolean canSeeFocus(IJavaElement focus, boolean isPolymorphicSearch, IPath projectOrJarPath) { >+public static boolean canSeeFocus(SearchPattern pattern, IPath projectOrJarPath) { > try { >- IClasspathEntry[] focusEntries = null; >- if (isPolymorphicSearch) { >- JavaProject focusProject = focus instanceof JarPackageFragmentRoot ? (JavaProject) focus.getParent() : (JavaProject) focus; >- focusEntries = focusProject.getExpandedClasspath(); >- } >- IJavaModel model = focus.getJavaModel(); >+ IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel(); > IJavaProject project = getJavaProject(projectOrJarPath, model); >- if (project != null) >- return canSeeFocus(focus, (JavaProject) project, focusEntries); >+ IJavaElement[] focuses = getFocusedElements(pattern, project); >+ if (project != null) { >+ return canSeeFocus(focuses, (JavaProject) project); >+ } > > // projectOrJarPath is a jar > // it can see the focus only if it is on the classpath of a project that can see the focus >@@ -67,30 +60,29 @@ > for (int i = 0, length = allProjects.length; i < length; i++) { > JavaProject otherProject = (JavaProject) allProjects[i]; > IClasspathEntry entry = otherProject.getClasspathEntryFor(projectOrJarPath); >- if (entry != null >- && entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY >- && canSeeFocus(focus, otherProject, focusEntries)) >- return true; >+ if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { >+ if (canSeeFocus(focuses, otherProject)) { >+ return true; >+ } >+ } > } > return false; > } catch (JavaModelException e) { > return false; > } > } >-public static boolean canSeeFocus(IJavaElement focus, JavaProject javaProject, IClasspathEntry[] focusEntriesForPolymorphicSearch) { >+private static boolean canSeeFocus(IJavaElement[] focuses, JavaProject javaProject) { >+ int length = focuses.length; >+ for (int i=0; i<length; i++) { >+ if (canSeeFocus(focuses[i], javaProject)) return true; >+ } >+ return false; >+} >+private static boolean canSeeFocus(IJavaElement focus, JavaProject javaProject) { > try { >- if (focus.equals(javaProject)) >- return true; >+ if (focus == null) return false; >+ if (focus.equals(javaProject)) return true; > >- if (focusEntriesForPolymorphicSearch != null) { >- // look for refering project >- IPath projectPath = javaProject.getProject().getFullPath(); >- for (int i = 0, length = focusEntriesForPolymorphicSearch.length; i < length; i++) { >- IClasspathEntry entry = focusEntriesForPolymorphicSearch[i]; >- if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT && entry.getPath().equals(projectPath)) >- return true; >- } >- } > if (focus instanceof JarPackageFragmentRoot) { > // focus is part of a jar > IPath focusPath = focus.getPath(); >@@ -115,6 +107,48 @@ > return false; > } > } >+ >+/* >+ * Create the list of focused jars or projects. >+ */ >+private static IJavaElement[] getFocusedElements(SearchPattern pattern, IJavaElement focusElement) throws JavaModelException { >+ if (pattern instanceof MethodPattern) { >+ // For method pattern, it needs to walk along the focus type super hierarchy >+ // and add jars/projects of all the encountered types. >+ IType type = (IType) pattern.focus.getAncestor(IJavaElement.TYPE); >+ MethodPattern methodPattern = (MethodPattern) pattern; >+ String selector = new String(methodPattern.selector); >+ int parameterCount = methodPattern.parameterCount; >+ ITypeHierarchy superHierarchy = type.newSupertypeHierarchy(null); >+ IType[] allTypes = superHierarchy.getAllSupertypes(type); >+ int length = allTypes.length; >+ SimpleSet focusSet = new SimpleSet(length+1); >+ focusSet.add(focusElement); >+ for (int i=0; i<length; i++) { >+ IMethod[] methods = allTypes[i].getMethods(); >+ int mLength = methods.length; >+ for (int m=0; m<mLength; m++) { >+ if (parameterCount == methods[m].getNumberOfParameters() && methods[m].getElementName().equals(selector)) { >+ IPackageFragmentRoot root = (IPackageFragmentRoot) allTypes[i].getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); >+ IJavaElement element = root.isArchive() ? root : root.getParent(); >+ focusSet.add(element); >+ } >+ } >+ } >+ // Rebuilt a contiguous array >+ IJavaElement[] focuses = new IJavaElement[focusSet.elementSize]; >+ Object[] values = focusSet.values; >+ int count = 0; >+ for (int i = values.length; --i >= 0;) { >+ if (values[i] != null) { >+ focuses[count++] = (IJavaElement) values[i]; >+ } >+ } >+ return focuses; >+ } >+ return new IJavaElement[] { focusElement }; >+} >+ > /* > * Compute the list of paths which are keying index files. > */ >@@ -139,18 +173,14 @@ > SimpleSet visitedProjects = new SimpleSet(length); > int projectIndex = 0; > SimpleSet externalLibsToCheck = new SimpleSet(length); >- IClasspathEntry[] focusEntries = null; >- if (this.pattern instanceof MethodPattern) { // should consider polymorphic search for method patterns >- JavaProject focusProject = focus instanceof JarPackageFragmentRoot ? (JavaProject) focus.getParent() : (JavaProject) focus; >- focusEntries = focusProject.getExpandedClasspath(); >- } >+ IJavaElement[] focuses = getFocusedElements(this.pattern, focus); > IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel(); > for (int i = 0; i < length; i++) { > IPath path = projectsAndJars[i]; > JavaProject project = (JavaProject) getJavaProject(path, model); > if (project != null) { > visitedProjects.add(project); >- if (canSeeFocus(focus, project, focusEntries)) { >+ if (canSeeFocus(focuses, project)) { > locations.add(manager.computeIndexLocation(path)); > projectsCanSeeFocus[projectIndex++] = project; > } >@@ -207,6 +237,7 @@ > if (values[i] != null) > this.indexLocations[count++] = (IPath) values[i]; > } >+ > public IPath[] getIndexLocations() { > if (this.indexLocations == null) { > initializeIndexLocations(); >Index: search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java,v >retrieving revision 1.319 >diff -u -r1.319 MatchLocator.java >--- search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 18 Sep 2008 15:24:57 -0000 1.319 >+++ search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 11 Feb 2009 14:03:42 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -169,7 +169,7 @@ > public static SearchDocument[] addWorkingCopies(SearchPattern pattern, SearchDocument[] indexMatches, org.eclipse.jdt.core.ICompilationUnit[] copies, SearchParticipant participant) { > if (copies == null) return indexMatches; > // working copies take precedence over corresponding compilation units >- HashMap workingCopyDocuments = workingCopiesThatCanSeeFocus(copies, pattern.focus, pattern.isPolymorphicSearch(), participant); >+ HashMap workingCopyDocuments = workingCopiesThatCanSeeFocus(copies, pattern, participant); > if (workingCopyDocuments.size() == 0) return indexMatches; > SearchDocument[] matches = null; > int length = indexMatches.length; >@@ -207,18 +207,13 @@ > /* > * Returns the working copies that can see the given focus. > */ >-private static HashMap workingCopiesThatCanSeeFocus(org.eclipse.jdt.core.ICompilationUnit[] copies, IJavaElement focus, boolean isPolymorphicSearch, SearchParticipant participant) { >+private static HashMap workingCopiesThatCanSeeFocus(org.eclipse.jdt.core.ICompilationUnit[] copies, SearchPattern pattern, SearchParticipant participant) { > if (copies == null) return new HashMap(); >- if (focus != null) { >- while (!(focus instanceof IJavaProject) && !(focus instanceof JarPackageFragmentRoot)) { >- focus = focus.getParent(); >- } >- } > HashMap result = new HashMap(); > for (int i=0, length = copies.length; i<length; i++) { > org.eclipse.jdt.core.ICompilationUnit workingCopy = copies[i]; > IPath projectOrJar = MatchLocator.getProjectOrJar(workingCopy).getPath(); >- if (focus == null || IndexSelector.canSeeFocus(focus, isPolymorphicSearch, projectOrJar)) { >+ if (pattern.focus == null || IndexSelector.canSeeFocus(pattern, projectOrJar)) { > result.put( > workingCopy.getPath().toString(), > new WorkingCopyDocument(workingCopy, participant) >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java,v >retrieving revision 1.53 >diff -u -r1.53 JavaSearchMultipleProjectsTests.java >--- src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java 23 Oct 2008 08:31:20 -0000 1.53 >+++ src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java 11 Feb 2009 14:03:44 -0000 >@@ -1210,9 +1210,9 @@ > } > > /** >- * @bug 48534: [search] Java Search for OR-pattern finds too much in strange project setup >- * @test Ensure that search does not find illegal references with given projects setup >- * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=48534" >+ * @bug 210689: [search] Import references not found on working copies not written on disk >+ * @test Ensure that import references are found when searching on working copies not written on disk >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=210689" > */ > public void testBug210689() throws CoreException { > try { >@@ -1429,4 +1429,130 @@ > deleteProjects(new String[] {"P1", "P2", "P3"}); > } > } >+ >+/** >+ * @bug 250454: [search] Cannot find method references between projects >+ * @test Ensure that search does not find illegal references with given projects setup >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=250454" >+ */ >+public void testBug250454() throws CoreException { >+ try { >+ // setup project P0 >+ createJavaProject("P0"); >+ createFolder("/P0/p"); >+ createFile( >+ "/P0/p/Shape.java", >+ "package p;\n" + >+ "public interface Shape {\n" + >+ " public void f();\n" + >+ "}\n" >+ ); >+ >+ // setup project P1 >+ createJavaProject("P1", new String[] {""}, new String[] {"JCL_LIB"}, new String[] { "/P0" }, ""); >+ createFolder("/P1/p"); >+ createFile( >+ "/P1/p/Square.java", >+ "package p;\n" + >+ "public class Square implements Shape {\n" + >+ " public void f() {}\n" + >+ "}\n" >+ ); >+ >+ // setup project P2 >+ createJavaProject("P2", new String[] {""}, new String[] {"JCL_LIB"}, new String[] { "/P0" }, ""); >+ createFolder("/P2/p"); >+ createFile( >+ "/P2/p/ShapeUser.java", >+ "package p;\n" + >+ "public class ShapeUser {\n" + >+ " public void useShape(Shape p_shape) {\n" + >+ " p_shape.f();\n" + >+ " }\n" >+ ); >+ >+ // Perform search >+ IType type = getCompilationUnit("/P1/p/Square.java").getType("Square"); >+ IMethod method = type.getMethod("f", new String[0]); >+ SearchPattern pattern = SearchPattern.createPattern(method, REFERENCES); >+ JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); >+ resultCollector.showProject(); >+ resultCollector.showAccuracy(true); >+ new SearchEngine().search( >+ pattern, >+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, >+ SearchEngine.createWorkspaceScope(), >+ resultCollector, >+ null >+ ); >+ assertSearchResults( >+ "Unexpected references to "+method, >+ "p/ShapeUser.java [in P2] void p.ShapeUser.useShape(Shape) [f()] EXACT_MATCH", >+ resultCollector); >+ } finally { >+ deleteProject("P0"); >+ deleteProject("P1"); >+ deleteProject("P2"); >+ } >+} >+public void testBug250454_jars() throws CoreException, IOException { >+ String jarPath = getExternalPath()+"b250454.jar"; >+ try { >+ // setup jar >+ String[] pathsAndContents= new String[] { >+ "p/Shape.java", >+ "package p;\n" + >+ "public interface Shape {\n" + >+ " public void f();\n" + >+ "}\n" >+ }; >+ createJar(pathsAndContents, jarPath); >+ >+ // setup project P1 >+ createJavaProject("P1", new String[] {""}, new String[] {"JCL_LIB", jarPath}, ""); >+ createFolder("/P1/p"); >+ createFile( >+ "/P1/p/Square.java", >+ "package p;\n" + >+ "public class Square implements Shape {\n" + >+ " public void f() {}\n" + >+ "}\n" >+ ); >+ >+ // setup project P2 >+ createJavaProject("P2", new String[] {""}, new String[] {"JCL_LIB", jarPath}, ""); >+ createFolder("/P2/p"); >+ createFile( >+ "/P2/p/ShapeUser.java", >+ "package p;\n" + >+ "public class ShapeUser {\n" + >+ " public void useShape(Shape p_shape) {\n" + >+ " p_shape.f();\n" + >+ " }\n" >+ ); >+ >+ // Perform search >+ IType type = getCompilationUnit("/P1/p/Square.java").getType("Square"); >+ IMethod method = type.getMethod("f", new String[0]); >+ SearchPattern pattern = SearchPattern.createPattern(method, REFERENCES); >+ JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); >+ resultCollector.showProject(); >+ resultCollector.showAccuracy(true); >+ new SearchEngine().search( >+ pattern, >+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, >+ SearchEngine.createWorkspaceScope(), >+ resultCollector, >+ null >+ ); >+ assertSearchResults( >+ "Unexpected references to "+method, >+ "p/ShapeUser.java [in P2] void p.ShapeUser.useShape(Shape) [f()] EXACT_MATCH", >+ resultCollector); >+ } finally { >+ deleteExternalFile(jarPath); >+ deleteProject("P1"); >+ deleteProject("P2"); >+ } >+} > }
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 250454
: 125382