Lines 16-26
Link Here
|
16 |
|
16 |
|
17 |
import org.eclipse.core.resources.IProject; |
17 |
import org.eclipse.core.resources.IProject; |
18 |
import org.eclipse.core.resources.IResource; |
18 |
import org.eclipse.core.resources.IResource; |
|
|
19 |
import org.eclipse.core.resources.ResourcesPlugin; |
19 |
import org.eclipse.core.runtime.IPath; |
20 |
import org.eclipse.core.runtime.IPath; |
20 |
import org.eclipse.core.runtime.Path; |
21 |
import org.eclipse.core.runtime.Path; |
21 |
import org.eclipse.jdt.core.*; |
22 |
import org.eclipse.jdt.core.IClasspathContainer; |
|
|
23 |
import org.eclipse.jdt.core.IClasspathEntry; |
24 |
import org.eclipse.jdt.core.IJavaElement; |
25 |
import org.eclipse.jdt.core.IJavaElementDelta; |
26 |
import org.eclipse.jdt.core.IJavaModel; |
27 |
import org.eclipse.jdt.core.IJavaProject; |
28 |
import org.eclipse.jdt.core.IMember; |
29 |
import org.eclipse.jdt.core.IPackageFragmentRoot; |
30 |
import org.eclipse.jdt.core.JavaCore; |
31 |
import org.eclipse.jdt.core.JavaModelException; |
22 |
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; |
32 |
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; |
23 |
import org.eclipse.jdt.internal.core.*; |
33 |
import org.eclipse.jdt.internal.core.ClasspathEntry; |
|
|
34 |
import org.eclipse.jdt.internal.core.JavaElement; |
35 |
import org.eclipse.jdt.internal.core.JavaModel; |
36 |
import org.eclipse.jdt.internal.core.JavaModelManager; |
37 |
import org.eclipse.jdt.internal.core.JavaProject; |
38 |
import org.eclipse.jdt.internal.core.PackageFragment; |
24 |
import org.eclipse.jdt.internal.core.util.Util; |
39 |
import org.eclipse.jdt.internal.core.util.Util; |
25 |
|
40 |
|
26 |
/** |
41 |
/** |
Lines 44-50
Link Here
|
44 |
|
59 |
|
45 |
private IPath[] enclosingProjectsAndJars; |
60 |
private IPath[] enclosingProjectsAndJars; |
46 |
public final static AccessRuleSet NOT_ENCLOSED = new AccessRuleSet(null, null); |
61 |
public final static AccessRuleSet NOT_ENCLOSED = new AccessRuleSet(null, null); |
47 |
|
62 |
|
48 |
public JavaSearchScope() { |
63 |
public JavaSearchScope() { |
49 |
this(5); |
64 |
this(5); |
50 |
} |
65 |
} |
Lines 158-164
Link Here
|
158 |
if ((includeMask & SOURCES) != 0) { |
173 |
if ((includeMask & SOURCES) != 0) { |
159 |
IPath path = entry.getPath(); |
174 |
IPath path = entry.getPath(); |
160 |
if (pathToAdd == null || pathToAdd.equals(path)) { |
175 |
if (pathToAdd == null || pathToAdd.equals(path)) { |
161 |
add(null, Util.relativePath(path,1/*remove project segment*/), projectPathString, false/*not a package*/, access); |
176 |
add(projectPath.toString(), Util.relativePath(path,1/*remove project segment*/), projectPathString, false/*not a package*/, access); |
162 |
} |
177 |
} |
163 |
} |
178 |
} |
164 |
break; |
179 |
break; |
Lines 187-206
Link Here
|
187 |
containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath; |
202 |
containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath; |
188 |
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
203 |
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
189 |
IResource rootResource = root.getResource(); |
204 |
IResource rootResource = root.getResource(); |
|
|
205 |
String projectPath = root.getJavaProject().getPath().toString(); |
190 |
if (rootResource != null && rootResource.isAccessible()) { |
206 |
if (rootResource != null && rootResource.isAccessible()) { |
191 |
String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount()); |
207 |
String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount()); |
192 |
add(null, relativePath, containerPathToString, false/*not a package*/, null); |
208 |
add(projectPath, relativePath, containerPathToString, false/*not a package*/, null); |
193 |
} else { |
209 |
} else { |
194 |
add(null, "", containerPathToString, false/*not a package*/, null); //$NON-NLS-1$ |
210 |
add(projectPath, "", containerPathToString, false/*not a package*/, null); //$NON-NLS-1$ |
195 |
} |
211 |
} |
196 |
break; |
212 |
break; |
197 |
case IJavaElement.PACKAGE_FRAGMENT: |
213 |
case IJavaElement.PACKAGE_FRAGMENT: |
198 |
root = (IPackageFragmentRoot)element.getParent(); |
214 |
root = (IPackageFragmentRoot)element.getParent(); |
|
|
215 |
projectPath = root.getJavaProject().getPath().toString(); |
199 |
if (root.isArchive()) { |
216 |
if (root.isArchive()) { |
200 |
String relativePath = Util.concatWith(((PackageFragment) element).names, '/'); |
217 |
String relativePath = Util.concatWith(((PackageFragment) element).names, '/'); |
201 |
containerPath = root.getPath(); |
218 |
containerPath = root.getPath(); |
202 |
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
219 |
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
203 |
add(null, relativePath, containerPathToString, true/*package*/, null); |
220 |
add(projectPath, relativePath, containerPathToString, true/*package*/, null); |
204 |
} else { |
221 |
} else { |
205 |
IResource resource = element.getResource(); |
222 |
IResource resource = element.getResource(); |
206 |
if (resource != null) { |
223 |
if (resource != null) { |
Lines 212-218
Link Here
|
212 |
} |
229 |
} |
213 |
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
230 |
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
214 |
String relativePath = Util.relativePath(resource.getFullPath(), containerPath.segmentCount()); |
231 |
String relativePath = Util.relativePath(resource.getFullPath(), containerPath.segmentCount()); |
215 |
add(null, relativePath, containerPathToString, true/*package*/, null); |
232 |
add(projectPath, relativePath, containerPathToString, true/*package*/, null); |
216 |
} |
233 |
} |
217 |
} |
234 |
} |
218 |
break; |
235 |
break; |
Lines 225-230
Link Here
|
225 |
this.elements.add(element); |
242 |
this.elements.add(element); |
226 |
} |
243 |
} |
227 |
root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); |
244 |
root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); |
|
|
245 |
projectPath = root.getJavaProject().getPath().toString(); |
228 |
String relativePath; |
246 |
String relativePath; |
229 |
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { |
247 |
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { |
230 |
containerPath = root.getParent().getPath(); |
248 |
containerPath = root.getParent().getPath(); |
Lines 234-240
Link Here
|
234 |
relativePath = getPath(element, true/*relative path*/).toString(); |
252 |
relativePath = getPath(element, true/*relative path*/).toString(); |
235 |
} |
253 |
} |
236 |
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
254 |
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
237 |
add(null, relativePath, containerPathToString, false/*not a package*/, null); |
255 |
add(projectPath, relativePath, containerPathToString, false/*not a package*/, null); |
238 |
} |
256 |
} |
239 |
|
257 |
|
240 |
if (containerPath != null) |
258 |
if (containerPath != null) |
Lines 259-272
Link Here
|
259 |
index = 0; |
277 |
index = 0; |
260 |
} |
278 |
} |
261 |
} |
279 |
} |
262 |
int idx = -1; |
280 |
int idx = this.projectPaths.indexOf(projectPath); |
263 |
if (projectPath != null && !containerPath.startsWith(projectPath)) { |
281 |
if (idx == -1) { |
|
|
282 |
// store project in separated list to minimize memory footprint |
283 |
this.projectPaths.add(projectPath); |
264 |
idx = this.projectPaths.indexOf(projectPath); |
284 |
idx = this.projectPaths.indexOf(projectPath); |
265 |
if (idx == -1) { |
|
|
266 |
// store project in separated list to minimize memory footprint |
267 |
this.projectPaths.add(projectPath); |
268 |
idx = this.projectPaths.indexOf(projectPath); |
269 |
} |
270 |
} |
285 |
} |
271 |
this.projectIndexes[index] = idx; |
286 |
this.projectIndexes[index] = idx; |
272 |
this.relativePaths[index] = relativePath; |
287 |
this.relativePaths[index] = relativePath; |
Lines 546-555
Link Here
|
546 |
* @param resourcePathString path of the resource |
561 |
* @param resourcePathString path of the resource |
547 |
* @return the project path of the resource |
562 |
* @return the project path of the resource |
548 |
*/ |
563 |
*/ |
549 |
public String projectPathFor(String resourcePathString) { |
564 |
public IPackageFragmentRoot packageFragmentRoot(String resourcePathString) { |
550 |
int index = -1; |
565 |
int index = -1; |
551 |
int separatorIndex = resourcePathString.indexOf(JAR_FILE_ENTRY_SEPARATOR); |
566 |
int separatorIndex = resourcePathString.indexOf(JAR_FILE_ENTRY_SEPARATOR); |
552 |
if (separatorIndex != -1) { |
567 |
boolean isJarFile = separatorIndex != -1; |
|
|
568 |
if (isJarFile) { |
553 |
// internal or external jar (case 3, 4, or 5) |
569 |
// internal or external jar (case 3, 4, or 5) |
554 |
String jarPath = resourcePathString.substring(0, separatorIndex); |
570 |
String jarPath = resourcePathString.substring(0, separatorIndex); |
555 |
String relativePath = resourcePathString.substring(separatorIndex+1); |
571 |
String relativePath = resourcePathString.substring(separatorIndex+1); |
Lines 560-567
Link Here
|
560 |
} |
576 |
} |
561 |
if (index >= 0) { |
577 |
if (index >= 0) { |
562 |
int idx = projectIndexes[index]; |
578 |
int idx = projectIndexes[index]; |
563 |
if (idx != -1) { |
579 |
String projectPath = idx == -1 ? null : (String) this.projectPaths.get(idx); |
564 |
return (String) this.projectPaths.get(idx); |
580 |
if (projectPath != null) { |
|
|
581 |
IJavaProject project =JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getProject(projectPath)); |
582 |
if (isJarFile) { |
583 |
return project.getPackageFragmentRoot(this.containerPaths[index]); |
584 |
} |
585 |
Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(this.containerPaths[index]+'/'+this.relativePaths[index]), false); |
586 |
if (target instanceof IResource) { |
587 |
return project.getPackageFragmentRoot((IResource)target); |
588 |
} |
565 |
} |
589 |
} |
566 |
} |
590 |
} |
567 |
return null; |
591 |
return null; |