Bug 20011 - Searching for Inner Classes gives bad search results
Summary: Searching for Inner Classes gives bad search results
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.0 F4   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-06-12 09:50 EDT by Curtis d'Entremont CLA
Modified: 2002-06-24 04:58 EDT (History)
1 user (show)

See Also:


Attachments
Picture of Variables view (36.32 KB, image/jpeg)
2002-06-18 05:39 EDT, Dani Megert CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Curtis d'Entremont CLA 2002-06-12 09:50:16 EDT
Build 20020611

- Open java perspective
- Import all plugins to your workspace
- Go to Search->Java...
- Type in "Label", and select Type, Declarations, and Workspace, click Search

In the search results, one of the results is:
"Label - org.eclipse.ui.dialogs.FilteredList.Label"

This is an inner class. The icon for this one is a little red square, and 
double clicking on it to open it causes it to say:

"Could not open the editor. 
Reason: FilteredList$Label$Label.class does not exist."

Notice how it's looking for two nested "$Label".. and how in the search results 
it appends ".Label" at the end of the entry. Other search results don't append 
the class name, such as the following:

"Label - org.eclipse.swt.widgets"    <-- no ".Label" at the end
Comment 1 Dirk Baeumer CLA 2002-06-14 12:32:24 EDT
This also adds to the .log
Comment 2 Erich Gamma CLA 2002-06-15 05:00:59 EDT
should investigate in a fix
Comment 3 Erich Gamma CLA 2002-06-17 03:47:21 EDT

*** This bug has been marked as a duplicate of 19993 ***
Comment 4 Erich Gamma CLA 2002-06-17 04:42:14 EDT
reopen - accidently tagged as a dup
Comment 5 Dani Megert CLA 2002-06-18 05:38:47 EDT
Investigated. The match reported by J Core is unusable: the class file of the
binary type is wrong (see attached picture for more details).

This might affect other clients of the J Search infrastructure.
Comment 6 Dani Megert CLA 2002-06-18 05:39:43 EDT
Created attachment 1472 [details]
Picture of Variables view
Comment 7 Jerome Lanneluc CLA 2002-06-18 08:37:49 EDT
Problem with MatchLocator that creates a member type handle when the type 
handle of the class file should be used in case of a binary type.

Propose fix on MatchLocator:
	/**
	 * Reports the given type declaration to the search requestor.
	 */
	public void reportTypeDeclaration(
		TypeDeclaration typeDeclaration,
		IJavaElement parent,
		int accuracy)
		throws CoreException {

		// accept class or interface declaration
		this.report(
			typeDeclaration.sourceStart,
			typeDeclaration.sourceEnd,
			(parent == null) ?
				this.createTypeHandle(typeDeclaration.name) :
				(parent instanceof IType && !(parent instanceof 
BinaryType)) ?
					this.createTypeHandle((IType)parent, 
typeDeclaration.name) :
					parent,
			accuracy);
	}
Comment 8 Philipe Mulet CLA 2002-06-18 12:06:13 EDT
Please verify fix for local type members.
Comment 9 Jerome Lanneluc CLA 2002-06-18 13:24:48 EDT
Indeed the declaration of a local binary type is not found.
Need to investigate.
Comment 10 Philipe Mulet CLA 2002-06-18 18:36:15 EDT
If we get a fix for F4, we should fix it. Search works ok, only Java element 
creation is deficient, and prevents exploiting the search result.

Comment 11 Jerome Lanneluc CLA 2002-06-19 07:48:13 EDT
For local binary types, the problem is different: the type declaration pattern 
is not right. Entered separate bug 20631.
Comment 12 Jerome Lanneluc CLA 2002-06-19 07:54:29 EDT
So the above change fixes the case of reporting the result of a binary member 
type declaration. It would also fix the case of reporting the result of a 
binary local type declaration, but bug 20631 prevents it to go that far.

To summarize, the above change should go in F4 as it prevents to display wrong 
results when the search engine find some. It is a simple fix that affects only 
type declarations in binary types.
Comment 13 Jerome Lanneluc CLA 2002-06-19 11:03:21 EDT
I actually have a better fix. Instead of the above change, I propose the 
following method that now first creates the top-level type handle of a binary 
type. Thus when traversing the member types, the right member type handles are 
created from the top-level type handle:

	/**
	 * Creates an IType from the given simple top level type name. 
	 */
	public IType createTypeHandle(char[] simpleTypeName) {
		Openable currentOpenable = this.getCurrentOpenable();
		if (currentOpenable instanceof CompilationUnit) {
			// creates compilation unit
			CompilationUnit unit = (CompilationUnit)currentOpenable;
	
			// create type
			return unit.getType(new String(simpleTypeName));
		} else {
			IType type; 
			try {
				type = 
((org.eclipse.jdt.internal.core.ClassFile)currentOpenable).getType();
			} catch (JavaModelException e) {
				return null;
			}
			// ensure this is a top level type (see bug 20011  
Searching for Inner Classes gives bad search results)
			IType declaringType = type.getDeclaringType();
			while (declaringType != null) {
				type = declaringType;
				declaringType = type.getDeclaringType();
			}
			return type;
		}
	}
Comment 14 David Audel CLA 2002-06-19 12:22:57 EDT
This problem does not exists in 1.0.
Comment 15 Philipe Mulet CLA 2002-06-20 07:39:31 EDT
This defect is not a duplicate of bug 20532, which wasn't finding matches at 
all. This one defect is rather an issue when constructing the search result. 
The generated handle (pointing at the enclosing element) is invalid, and thus 
cannot be opened.
Comment 16 Philipe Mulet CLA 2002-06-21 06:51:34 EDT
From Adam, regarding to refactoring test suites:

our tests run smoothly
i activated the prevously disabled tests for 
20693 Finding references to variables does not find all occurances 
20520 Refactor - expression detection incorrect 
Comment 17 Philipe Mulet CLA 2002-06-21 07:17:49 EDT
Fix got approved, releasing into 20020621
Comment 18 David Audel CLA 2002-06-24 04:58:49 EDT
Verified.