Bug 110336 - [plan][search] Should optionaly return the local variable for type reference
Summary: [plan][search] Should optionaly return the local variable for type reference
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M4   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 111215 (view as bug list)
Depends on:
Blocks: 37219
  Show dependency tree
 
Reported: 2005-09-22 11:31 EDT by Jerome Lanneluc CLA
Modified: 2005-12-13 08:02 EST (History)
3 users (show)

See Also:


Attachments
Patch to implement this functionality (21.29 KB, patch)
2005-11-21 04:38 EST, Frederic Fusier CLA
no flags Details | Diff
New version to implement this functionality (41.83 KB, patch)
2005-11-23 12:59 EST, Frederic Fusier CLA
no flags Details | Diff
Final patch which fixes issues described in comment 8 and comment 9 (47.96 KB, patch)
2005-11-24 13:03 EST, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jerome Lanneluc CLA 2005-09-22 11:31:46 EDT
I20050922

The search engine should optionaly return the local variable when searching for
reference to a type.

This should be an option (flag on SearchEngine#search(...) ?) and the local
variable should be returned using a new API (SearchMatch#getReferingElement()
?), SearchMatch#getElement() should still return the enclosing method.
Comment 1 Jerome Lanneluc CLA 2005-09-30 10:58:50 EDT
*** Bug 111215 has been marked as a duplicate of this bug. ***
Comment 2 Jerome Lanneluc CLA 2005-09-30 11:00:19 EDT
Note that bug 111225 wants type parameters as enclosing elements as well.
Comment 3 Markus Keller CLA 2005-09-30 11:08:35 EDT
Type parameters are currently not a requirement, but I think it would be more
consistent if those would be resolved as well.
Comment 4 Philipe Mulet CLA 2005-11-16 11:48:30 EST
We should try to deliver this soon, so UI can leverage this within M4.
Comment 5 Frederic Fusier CLA 2005-11-21 04:38:01 EST
Created attachment 30295 [details]
Patch to implement this functionality

Note that this is a workspace patch which contains 2 projects:
  - org.eclipse.jdt.core
  - org.eclipse.jdt.core.tests.model
Comment 6 Philip Mayer CLA 2005-11-21 13:01:45 EST
I just tried the patch and it works fine for temporaries and variables in for loops, but it seems getLocalElement() returns null for method parameters and exception variables:

public class Foo extends Exception { <-- search for references to "Foo"
	void foo(Foo foo) { // <- no local element
		Foo foo2; // <- local element
		
		try {
			throw new Foo();
		}
		catch (Foo foo4) { // <- no local element
		}
		
		for(Foo foo3;;) {} // <- local element
	}
}
Comment 7 Frederic Fusier CLA 2005-11-23 12:59:14 EST
Created attachment 30493 [details]
New version to implement this functionality

New version after a loooong discussion with Markus... ;-)

Main changes are:
1) SearchRequestor is unchanged. That means that search engine *always* reports 
   local element (and other elements, see below...).
   Note that this behavior may change if performance tests (not written yet)
   show that it's too much time consuming...
2) localElement is now implemented only on TypeReferenceMatch instead of
   SearchMatch. This change has been done to avoid pollution of existing other
   kind of matches as currently only type reference matches need it.
3) Add otherElements on TypeReferenceMatch to address multiple fields
   declaration. Search engine reported only one match for type reference on
   multiple fields declaration which was problematic for this refactoring
   functionality.
   Markus, note that I didn't create subclasses as we talked about. While
   implementing it sounds that other elements may also be implemented at this
   level as they can also be considered as specific information of a type
   reference match.
4) I fixed problems with method parameters and catch exception declaration.
Comment 8 Markus Keller CLA 2005-11-23 18:26:57 EST
If I see that right, getOtherElements() will return either IFields (additional elements) or ILocalVariables (additional localElements). This should be documented, e.g.:
/**
 * Returns other enclosing elements of this search match.
 *
 * If {@link #getLocalElement()} is not <code>null</code>, these may be other
 * local elements such as additional local variables of a multiple local
 * variables declaration. Otherwise, these may be other elements such as
 * additional fields of a multiple fields declaration.
 * 
 * @return the other elements of the search match, or <code>null</code> if none
 */
Comment 9 Philip Mayer CLA 2005-11-24 04:44:24 EST
Thanks! 

One more thing: Local variables inside initializers are not yet reported (local element is null).
Comment 10 Frederic Fusier CLA 2005-11-24 13:03:04 EST
Created attachment 30567 [details]
Final patch which fixes issues described in comment 8 and comment 9
Comment 11 Frederic Fusier CLA 2005-11-24 14:08:00 EST
Patch released in HEAD.

Test cases are in JavaSearchBugsTests
Comment 12 Frederic Fusier CLA 2005-11-24 14:08:25 EST
.
Comment 13 Jerome Lanneluc CLA 2005-12-13 08:02:58 EST
Verified for 3.2 M4 using build I20051213-0010.
(new APIs still need @since 3.2 tag)