Bug 4921 - Serach does not find types in internal jar
Summary: Serach does not find types in internal jar
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P1 normal (vote)
Target Milestone: 2.0 M1   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-10-12 08:24 EDT by Martin Aeschlimann CLA
Modified: 2002-01-11 09:04 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2001-10-12 08:24:19 EDT
203
1. new worksace, use jdk1.2.2 as JRE
2. create project xxx
3. get project org.eclipse.swt
4. to project xxx add swt.jar
5. open all types: Composit. Only awt composite, but not swt

I have a saved (small) workspace, in case this is not reproducable.
I struggle with problems like this since yeserday, it must be a regression.
Comment 1 Jerome Lanneluc CLA 2001-10-17 04:58:41 EDT
Could not reproduce. Can you send me your workspace?
Comment 2 Martin Aeschlimann CLA 2001-10-17 05:26:16 EDT
workspace sent by mail (8MB)

All types workes when you add the JRE to the swt project.
But:
 1. Create a class A in XXX.
 2. Type 'Composite', select
 3. Add import. No swt-Composite
 4. When you debug you see that search for types does not contain it.
    (AddImportOnSelectionAction.java, findAllTypes)
Comment 3 Jerome Lanneluc CLA 2001-10-17 06:29:36 EDT
Yes, now I can reproduce. The orignal steps could not fail because the search 
was done on the whole workspace.

The problem with AddImportOnSelectionAction is that it searches in a search 
scope that contains only the project XXX. If you want to find matches in the 
swt.jar (which is not part of the project), then you need to explicitely add it.

Note that before (not sure when this changed), the search scope was wrongly 
adding all the prerequesites of the project for free. Now the rule is the 
following: if a project is included in the search scope, only its source 
folders, the jars internal to the project and its external jars are added for 
free. Jars that are contained in other projects must be included explicitely.

I just updated the specifications of SearchEngine.createJavaSearchScope
(IResource[])

Moving to JDT UI.
Comment 4 Martin Aeschlimann CLA 2001-10-17 06:59:19 EDT
When you remove JRE_LIB from the swt project, The all types dialog does not 
contain the SWT-Composite. How about that? This is a workspace-scoped search.
Comment 5 Martin Aeschlimann CLA 2001-10-17 07:05:41 EDT
On the search scope there is a method 'setIncludesClasspaths'
Setting to true does not change anything.

It is not specified by the documentation what is the default
setting of this flag. From looking at the code, it was true.
Comment 6 Jerome Lanneluc CLA 2001-10-17 08:00:51 EDT
You didn't specify that swt.jar was not included in the classpath of 
org.eclipse.swt either. (it's hard to guess :-)

In this case, I see the problem: the workbench scope doesn't include swt.jar. I 
will fix this. However this won't fix your second problem (ie. with 
AddImportOnSelectionAction)

Moving back to JDT Core.
Comment 7 Martin Aeschlimann CLA 2001-10-17 08:11:48 EDT
I think you have to resolve the classpath. What should the method
IJavaSearchScope.setIncludesClasspaths mean then?

If you really decide to have the user put in the paths from the class path,
please offer a method createJavaScope(IJavaProject project, boolean 
includeClasspath)
Comment 8 Martin Aeschlimann CLA 2001-10-17 08:29:15 EDT
Having looked at our code I see that we use the JavaSearchScope at around 10 
places with the idea that you get types visible by a class path:
Type selection dialog in wizards, search in refactorings...

I vote to keep the original behavoir.  
Comment 9 Jerome Lanneluc CLA 2001-10-17 09:30:11 EDT
Will add createJavaScope(IJavaProject project, boolean 
includesClasspaths)

If includesClasspaths is true, then everything that is visible by the project 
will be added for free. In other words, the project, its source folders, its 
jars (internal or external), the referenced projects, and recursively the 
referenced projects' source folders, jars, etc. will be added to the search 
scope.

If includesClasspaths is false, then only the project will be added to the 
search scope. In other words, its source folders, its jars, and the referenced 
projects won't be added for free.

Please, let me know if this is what you want.

Comment 10 Jerome Lanneluc CLA 2001-10-18 07:38:10 EDT
After more talking with Martin and Philippe, made the following change:

SearchEngine.createJavaSearchScope(IResource[]) has been deprecated.
  	Use SearchEngine.createJavaSearchScope(IJavaElement[]) instead.
  	The rational is that createJavaSearchScope(IResource[]) was not well
  	defined for projects, and it could not define a search scope for java
  	elements that didn't have a corresponding resource (e.g. external jars).
  	
The specification of createJavaSearchScope(IJavaElement[]) is as follows:
    - If an element is an IJavaProject, then the project's source folders, 
      its jars (external and internal) and its references projects (with their 
      source folders and jars, recursively) will be included.
    - If an element is an IPackageFragmentRoot, then only the package fragments 
      of this package fragment root will be included.
    - If an element is an IPackageFragment, then only the compilation unit and 
      class files of this package fragment will be included. Subpackages will 
      NOT be included.

This fixes the second test case.

The worspace scope that was used in the original test case has also been fixed 
to include everything in the workspace.