Bug 9100 - Fill Arguments on method completion breaks method declaration code assist
Summary: Fill Arguments on method completion breaks method declaration code assist
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Claude Knaus CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 10477 14497 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-02-05 10:44 EST by Erich Gamma CLA
Modified: 2002-08-12 10:36 EDT (History)
6 users (show)

See Also:


Attachments
JAR containing 4 modified files from the 05022002 build. (12.46 KB, application/octet-stream)
2002-05-04 21:33 EDT, Andrew McCullough CLA
no flags Details
This is a diff on HEAD for JDT-UI as of 05/04/2002 - i realized this may be more useful (16.06 KB, patch)
2002-05-04 23:55 EDT, Andrew McCullough CLA
no flags Details | Diff
New Version of same thing, uncludes inherited/interface type matching (47.51 KB, application/zip)
2002-06-10 10:40 EDT, Andrew McCullough CLA
no flags Details
Latest completion-guess code. (32.91 KB, patch)
2002-07-28 15:21 EDT, Andrew McCullough CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Erich Gamma CLA 2002-02-05 10:44:00 EST
When the workbench preference
Java>Work in Progress>Fill Arguments on method completion is set 
then code assist on method declaration doesn't work. 
Suspect that the template code doesn't distinguish between method completion 
and method declaration completion.

(Dirk this explains why it didn't work for us)

Also we need to decide whether we promote this feature from experimental to 
real. I vote for yes it is useful (if this bug is fixed)
Comment 1 Claude Knaus CLA 2002-02-08 05:00:43 EST
How many votes do we need?
Comment 2 Dirk Baeumer CLA 2002-02-08 05:03:07 EST
+1

My two cents
Comment 3 Erich Gamma CLA 2002-02-08 09:35:30 EST
actually, the feature would be even more useful if it did some argument 
guessing as is done in template completions.

Comment 4 Claude Knaus CLA 2002-03-11 07:46:39 EST
the original bug is fixed >= 20020311.

degrading priority for the other requests.
Comment 5 Claude Knaus CLA 2002-03-11 08:47:57 EST
*** Bug 10477 has been marked as a duplicate of this bug. ***
Comment 6 Andrew McCullough CLA 2002-05-04 21:33:33 EDT
Created attachment 754 [details]
JAR containing 4 modified files from the 05022002 build.
Comment 7 Andrew McCullough CLA 2002-05-04 21:34:56 EDT
Please see attachment.

I have been playing around with this problem.. and I would like to submit some 
code that does parameter guessing on method completion, using the current 
ExperimentalResultCollector and ExperimentalProposal classes.  The code is 
written and tested against the latest integration build (05022002).  The patch 
will only significantly affect ExperimentalResultCollector, minor modifications 
are made to the Preference page classes and the messages properties file to 
promote this behavior as a preference -- those three changes are one-liners.  
Total changes involve 4 files, 3 java and one .properties.

The code registers a second ICompletionRequester to track local and member 
variables, and store their types and names.  When a method completion is 
triggered, for each parameter in the completing method, it searches the stored 
variables for the closest variable that matches the type of the parameter in 
the method being completed. "Closest" means it will take a local variable 
before a member variable, and it searches the list in the reverse order they 
are reported to the ICompletionRequester, which works out to be "closest" (in 
terms of character position of declaration) to the point of the method 
completion.  


Current limitations:

Packages of types are not reported by the CompletionEngine for local variables, 
so type matching is limited to the typeName for local variables.  In addition, 
package names are not currently tracked in the protected API of 
ResultCollector, so effectively, packages are always ignored (even for non-
local variables, where it is theoretically possible).  This second issue can be 
fixed by slightly modifiying ResultCollector, but I wanted to limit the "patch" 
the minimum number of classes.  If the ResultCollector protected API is 
modified to accept package names AND the CompletionEngine/local variable type 
binding report packages of local variables, packages can be included in 
computing a match.

It will not recognize variables that match the type because of inheritance or 
interface implementations unless the variable is declared to be of the exact 
type the method parameter expects.  This cannot be fixed until the packages are 
always available, and would require loading Class objects for the variable type 
and the parameter type, and using isAssignableFrom().  This might be a 
performance problem (Class.forName() calls, etc).  

It does not concern itself with variable naming.  In theory, if there are 
multiple type-based matches, a "best match" might be determined by comparing 
the variable name to the parameter name and choosing the "closest".  However, 
it is unclear what the algorithm would be, and it also might represent a 
performance issue.  

Preference: The preference for "guess parameter name" is dependent on the "Fill 
in method argument names" preference, but I do not know how to enforce that 
relationship in the preferences UI.

Performance:  This approach will have an impact on performance equal to the 
time necessary to trigger a second code completion for the purpose of tracking 
local and member variables.  That is, each code completion will actually 
involve two invokations of the CompletionEngine, with the second invocation 
having no UI effect, and limiting it's concern to local and member variables.

I would appreciate any feedback you have, and of course I hope you can/will use 
the code :) 

Thanks,

Andrew - a huge eclipse fan trying to put my-money-where-my-mouth-is

mccull1@us.ibm.com
Comment 8 Andrew McCullough CLA 2002-05-04 23:55:52 EDT
Created attachment 755 [details]
This is a diff on HEAD for JDT-UI as of 05/04/2002 - i realized this may be more useful
Comment 9 Claude Knaus CLA 2002-05-06 04:40:21 EDT
Thanks Andrew, I'll have a look.
Comment 10 Andrew McCullough CLA 2002-06-10 10:40:17 EDT
Created attachment 1335 [details]
New Version of same thing, uncludes inherited/interface type matching
Comment 11 Andrew McCullough CLA 2002-06-10 10:43:20 EDT
The previous attatchment contains the latest version of the parameter guessing 
code.  Major changes include using basic substring matching for smarter 
guessing, and using the SuperTypeHierarchy from JDT to match types other than 
the declared type (implemented interfaces, subclasses, etc).  I am also posting 
this to the newgroup figuring the odds of getting this in for 2.0 are slim to 
none :)

I also removed the preference page as I am trying to treat this as a patch to 
JDT-UI, and have no way of contributing to the Code Assist preference page. 

Comment 12 Johan Compagner CLA 2002-06-10 16:44:42 EDT
check it in the base!

Comment 13 Andrew McCullough CLA 2002-06-12 16:09:13 EDT
I have created a SourceForge project for this little patch.  FYI, there was a 
bit of a bug that is now fixed that caused a problem when completing with no 
prefix (e.g. varName.<complete>).  Sourceforge will be the place to find the 
code in the event that someone wants to use it.  I will stop attaching to this 
bug report.

http://sourceforge.net/projects/completeclipse

-Andrew
Comment 14 Andrew McCullough CLA 2002-07-28 15:21:39 EDT
Created attachment 1755 [details]
Latest completion-guess code.
Comment 15 Andrew McCullough CLA 2002-07-28 15:22:13 EDT
Patch to HEAD (2.1 stream) for JDT-UI.  I Suggest that a preference be added, 
but otherwise functional when "Fill in.. " is selected.  By making some of the 
private methods and variables in ResultCollector protected, some code can be 
removed/refactored, but I have tried to keep changes to JDT-UI code to a 
minimum for my own maintenence sanity. 

-Andrew
Comment 16 Claude Knaus CLA 2002-08-06 09:41:51 EDT
*** Bug 14497 has been marked as a duplicate of this bug. ***
Comment 17 Claude Knaus CLA 2002-08-12 10:36:05 EDT
fixed >= 20020812
released modified patch from 20020728 attached by Andrew. Thanks a lot for the 
contribution!