Bug 162865 - Content assist for undeclared locals when using local
Summary: Content assist for undeclared locals when using local
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.3 M6   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-31 04:45 EST by Benno Baumgartner CLA
Modified: 2013-06-24 02:51 EDT (History)
4 users (show)

See Also:


Attachments
Proposed fix (1020.96 KB, patch)
2007-03-01 07:34 EST, David Audel CLA
no flags Details | Diff
Better fix (1.01 MB, patch)
2007-03-02 09:42 EST, David Audel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benno Baumgartner CLA 2006-10-31 04:45:17 EST
I20061030-1704

Given:
package test;
public class E1 {
	void m() {
		variable = 10;
		System.out.println(v);
	}
}
1. Set cursor after 'v' in println
2. Ctrl-Space
Is:
 variable is not proposed
Should:
 variable should be proposed
Comment 1 Dani Megert CLA 2006-10-31 04:57:11 EST
I agree that this would be a nice feature. Erich mentioned this yesterday as well. The current support only shows proposals for the local variable declaration.

Moving to JDT Core for comment: maybe the new support can be leveraged to support this scenario as well.
Comment 2 Philipe Mulet CLA 2006-11-14 09:17:39 EST
Will investigate performance ramifications. Could be behavior conditionned by a new option (off by default).
Comment 3 David Audel CLA 2007-03-01 07:34:24 EST
Created attachment 60060 [details]
Proposed fix
Comment 4 David Audel CLA 2007-03-01 07:36:42 EST
The behavior added by this patch is the following.

All unresolved simple names are proposed as possible local variable.
--------------------------
package test;
public class E1 {
        void m() {
                variable = 10;
                System.out.println(v);
        }
}
//'variable' is proposed as a possible local variable.
--------------------------

These simple names are searched between the start of the most enclosing method and the completion location
--------------------------
package test;
public class E1 {
        void m() {
                variable1 = 10;
                new Object() {
                        void m2() {
                                variable2 = 10;
                                System.out.println(v);
                        }
                }
                variable3 = 10;
        }
}
//'variable1' and 'variable2' are proposed but not 'variable3'
--------------------------

The relevance of these possible local variables is lesser than declared local variables
--------------------------
package test;
public class E1 {
        void m() {
                variable1 = 10;
                int variable2 = 10;
                System.out.println(v);
        }
}
//the relevance of 'variable2' is higher than relevance of 'variable1'
--------------------------

The completion engine only searches unresolved names inside the previous 100 lines of code to avoid performance problem when the code is too big.
The performance of completion engine can be between 0% and 50% slower than before when completing a simple name.
But the full time is always very short even when it is 50% slower.
So add an option isn't necessary because performances are still good. The computing of type proposals has more impact on performance than this new behavior.

What do you think about this proposal?
Comment 5 David Audel CLA 2007-03-01 07:38:45 EST
I think about some possible variation of behavior:
1) Propose these proposals only if there is no other proposal. Unresolved names would be only spare proposals
2) Propose these proposals only if there is no other proposal or if there is more than two other proposals.
With this variation there is no impact for users who like insert single proposal automatically.
3) Add a JavaCore options to enable/disable this behavior

Personally i don't find these variations useful but maybe i am wrong.
Comment 6 Dani Megert CLA 2007-03-01 10:30:19 EST
>These simple names are searched between the start of the most enclosing method
I would prefer to scan above and below (we could then reduce it to 50 lines each).  That way we have a more coherent story.

I agree with you: the last variations would just be confusing since they make code assist less predictable. Since we didn't add a preference for the declaration proposal we won't need one for this as well.
Comment 7 David Audel CLA 2007-03-02 09:42:02 EST
Created attachment 60155 [details]
Better fix

Unresolved names are searched below and above the completion location with this patch
Comment 8 David Audel CLA 2007-03-02 09:43:46 EST
Released for 3.3M6

Tests added
   CompletionTests#testNameWithUnresolvedReferences001() -> testNameWithUnresolvedReferences0010()
   CompletionTests_1_5#testNameWithUnresolvedReferences001() -> testNameWithUnresolvedReferences003()

Updated all model completion tests caused by addition of R_RESOLVED
Comment 9 Maxime Daniel CLA 2007-03-20 02:50:44 EDT
Verified for 3.3 M6 using build I20070319-1335.
The implemented behavior is the one with a search above and below the insertion point.

Two remarks:
- using the original test case, the 'variable' proposal comes after pages of class
  names (in my workspace); completing 'var' still yields many ones; if you do that
  on the latest test case of comment #4, the class names separate variable2 (top
  proposal) from variable1 (near bottom proposal); I am not sure raising the
  relevance of variable1 would be appropriate, but I felt it looked odd;
- I also get 'void' as a proposal, which I believe is wrong; please let me know if
  it is expected or if I should enter a new bug (my search on 'void assist' did 
  not yield related bugs).